src/Common/Model/Base.php
protected function getManyAssociatedItemsWithTaxonomy(
        array &$aItems,
        $sItemProperty,
        $sTaxonomyModel,
        $sTaxonomyModelProvider,
        $sAssociatedModel,
        $sAssociatedModelProvider,
        array $aAssociatedModelData = [],
        $sTaxonomyItemIdColumn = 'item_id',
        $sTaxonomyAssociatedIdColumn = 'associated_id'
    ) {
        if (!empty($aItems)) {

            //  Load the required models
            $oTaxonomyModel   = Factory::model($sTaxonomyModel, $sTaxonomyModelProvider);
            $oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);

            //  Extract all the item IDs and set the base array for the associated content
            $aItemIds = [];
            foreach ($aItems as $oItem) {

                //  Note the ID
                $aItemIds[] = $oItem->id;

                //  Set the base property
                $oItem->{$sItemProperty} = Factory::resource('ExpandableField');
            }

            //  Get all associations for items in the resultset
            $aTaxonomy = $oTaxonomyModel->getAll(
                null,
                null,
                [
                    'where_in' => [
                        [$sTaxonomyItemIdColumn, $aItemIds],
                    ],
                ]
            );

            if (!empty($aTaxonomy)) {

                //  Extract the IDs of the associated content
                $aAssociatedIds = [];
                foreach ($aTaxonomy as $oTaxonomy) {
                    $aAssociatedIds[] = $oTaxonomy->{$sTaxonomyAssociatedIdColumn};
                }
                $aAssociatedIds = array_unique($aAssociatedIds);

                if (!empty($aAssociatedIds)) {

                    //  Get all associated content
                    $aAssociated = $oAssociatedModel->getByIds($aAssociatedIds, $aAssociatedModelData);

                    if (!empty($aAssociated)) {

                        //  Merge associated content into items
                        foreach ($aAssociated as $oAssociated) {
                            foreach ($aTaxonomy as $oTaxonomy) {
                                if ($oTaxonomy->{$sTaxonomyAssociatedIdColumn} == $oAssociated->id) {
                                    foreach ($aItems as $oItem) {
                                        if ($oTaxonomy->{$sTaxonomyItemIdColumn} == $oItem->id) {
                                            $oItem->{$sItemProperty}->data[] = $oAssociated;
                                            $oItem->{$sItemProperty}->count++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
protected function getManyAssociatedItemsWithTaxonomy(
        array &$aItems,
        $sItemProperty,
        $sTaxonomyModel,
        $sTaxonomyModelProvider,
        $sAssociatedModel,
        $sAssociatedModelProvider,
        array $aAssociatedModelData = [],
        $sTaxonomyItemIdColumn = 'item_id',
        $sTaxonomyAssociatedIdColumn = 'associated_id'
    ) {
        if (!empty($aItems)) {

            //  Load the required models
            $oTaxonomyModel   = Factory::model($sTaxonomyModel, $sTaxonomyModelProvider);
            $oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);

            //  Extract all the item IDs and set the base array for the associated content
            $aItemIds = [];
            foreach ($aItems as $oItem) {

                //  Note the ID
                $aItemIds[] = $oItem->id;

                //  Set the base property
                $oItem->{$sItemProperty} = Factory::resource('ExpandableField');
            }

            //  Get all associations for items in the resultset
            $aTaxonomy = $oTaxonomyModel->getAll(
                null,
                null,
                [
                    'where_in' => [
                        [$sTaxonomyItemIdColumn, $aItemIds],
                    ],
                ]
            );

            if (!empty($aTaxonomy)) {

                //  Extract the IDs of the associated content
                $aAssociatedIds = [];
                foreach ($aTaxonomy as $oTaxonomy) {
                    $aAssociatedIds[] = $oTaxonomy->{$sTaxonomyAssociatedIdColumn};
                }
                $aAssociatedIds = array_unique($aAssociatedIds);

                if (!empty($aAssociatedIds)) {

                    //  Get all associated content
                    $aAssociated = $oAssociatedModel->getByIds($aAssociatedIds, $aAssociatedModelData);

                    if (!empty($aAssociated)) {

                        //  Merge associated content into items
                        foreach ($aAssociated as $oAssociated) {
                            foreach ($aTaxonomy as $oTaxonomy) {
                                if ($oTaxonomy->{$sTaxonomyAssociatedIdColumn} == $oAssociated->id) {
                                    foreach ($aItems as $oItem) {
                                        if ($oTaxonomy->{$sTaxonomyItemIdColumn} == $oItem->id) {
                                            $oItem->{$sItemProperty}->data[] = $oAssociated;
                                            $oItem->{$sItemProperty}->count++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
protected function getManyAssociatedItemsWithTaxonomy ( array & $ aItems , $ sItemProperty , $ sTaxonomyModel , $ sTaxonomyModelProvider , $ sAssociatedModel , $ sAssociatedModelProvider , array $ aAssociatedModelData = [ ] , $ sTaxonomyItemIdColumn = 'item_id' , $ sTaxonomyAssociatedIdColumn = 'associated_id' ) { if ( ! empty ( $ aItems ) ) { //  Load the required models $ oTaxonomyModel = Factory :: model ( $ sTaxonomyModel , $ sTaxonomyModelProvider ) ; $ oAssociatedModel = Factory :: model ( $ sAssociatedModel , $ sAssociatedModelProvider ) ; //  Extract all the item IDs and set the base array for the associated content $ aItemIds = [ ] ; foreach ( $ aItems as $ oItem ) { //  Note the ID $ aItemIds [ ] = $ oItem -> id ; //  Set the base property $ oItem -> { $ sItemProperty } = Factory :: resource ( 'ExpandableField' ) ; } //  Get all associations for items in the resultset $ aTaxonomy = $ oTaxonomyModel -> getAll ( null , null , [ 'where_in' => [ [ $ sTaxonomyItemIdColumn , $ aItemIds ] , ] , ] ) ; if ( ! empty ( $ aTaxonomy ) ) { //  Extract the IDs of the associated content $ aAssociatedIds = [ ] ; foreach ( $ aTaxonomy as $ oTaxonomy ) { $ aAssociatedIds [ ] = $ oTaxonomy -> { $ sTaxonomyAssociatedIdColumn } ; } $ aAssociatedIds = array_unique ( $ aAssociatedIds ) ; if ( ! empty ( $ aAssociatedIds ) ) { //  Get all associated content $ aAssociated = $ oAssociatedModel -> getByIds ( $ aAssociatedIds , $ aAssociatedModelData ) ; if ( ! empty ( $ aAssociated ) ) { //  Merge associated content into items foreach ( $ aAssociated as $ oAssociated ) { foreach ( $ aTaxonomy as $ oTaxonomy ) { if ( $ oTaxonomy -> { $ sTaxonomyAssociatedIdColumn } == $ oAssociated -> id ) { foreach ( $ aItems as $ oItem ) { if ( $ oTaxonomy -> { $ sTaxonomyItemIdColumn } == $ oItem -> id ) { $ oItem -> { $ sItemProperty } -> data [ ] = $ oAssociated ; $ oItem -> { $ sItemProperty } -> count ++ ; } } } } } } } } } }
Get associated content for the items in the result set using a taxonomy table

@param array  &$aItems                      The result set of items
@param string  $sItemProperty               What property of each item to assign the associated content
@param string  $sTaxonomyModel              The name of the model which handles the taxonomy relationships
@param string  $sTaxonomyModelProvider      Which module provides the taxonomy model
@param string  $sAssociatedModel            The name of the model which handles the associated content
@param string  $sAssociatedModelProvider    Which module provides the associated model
@param array   $aAssociatedModelData        Data to pass to the associated model's getByIds method()
@param string  $sTaxonomyItemIdColumn       The name of the column in the taxonomy table for the item ID
@param string  $sTaxonomyAssociatedIdColumn The name of the column in the taxonomy table for the associated ID

@return void
Get associated content for the items in the result set using a taxonomy table