public function saveIncludes($componentId, $type, $includedComponents)
    {
        $m = $this->getModel('includes');
        $s = $m->select()
            ->whereEquals('component_id', $componentId)
            ->whereEquals('type', $type);
        $existingTargetIds = array();
        foreach ($m->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, array('columns'=>array('id', 'target_id', 'type'))) as $i) {
            $existingTargetIds[$i['id']] = $i['target_id'];
        }
        $newTargetIds = array();
        if ($includedComponents) {
            $data = array();
            foreach ($includedComponents as $includedComponent) {
                $cmp = Kwf_Component_Data_Root::getInstance()
                    ->getComponentById($componentId, array('ignoreVisible' => true));
                $id = substr($includedComponent, 0, strrpos($includedComponent, ':'));
                $targetCmp = Kwf_Component_Data_Root::getInstance()
                    ->getComponentById($id, array('ignoreVisible' => true));
                if ($cmp->getInheritsParent() !== $targetCmp->getInheritsParent()) {
                    if (!in_array($includedComponent, $existingTargetIds)) {
                        $c = array(
                            'target_id' => $includedComponent,
                            'type' => $type,
                            'component_id' => $componentId,
                        );
                        $data[] = $c;
                    }
                    $newTargetIds[] = $includedComponent;
                }
            }
            $m->import(Kwf_Model_Abstract::FORMAT_ARRAY, $data);
        }
        $diffTargetIds = array_diff($existingTargetIds, $newTargetIds);
        if ($diffTargetIds) {
            //delete not anymore included
            $m = $this->getModel('includes');
            $s = $m->select()
                ->whereEquals('component_id', $componentId)
                ->whereEquals('type', $type)
                ->whereEquals('target_id', $diffTargetIds);
            $m->deleteRows($s);
        }
    }
public function saveIncludes($componentId, $type, $includedComponents)
    {
        $m = $this->getModel('includes');
        $s = $m->select()
            ->whereEquals('component_id', $componentId)
            ->whereEquals('type', $type);
        $existingTargetIds = array();
        foreach ($m->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, array('columns'=>array('id', 'target_id', 'type'))) as $i) {
            $existingTargetIds[$i['id']] = $i['target_id'];
        }
        $newTargetIds = array();
        if ($includedComponents) {
            $data = array();
            foreach ($includedComponents as $includedComponent) {
                $cmp = Kwf_Component_Data_Root::getInstance()
                    ->getComponentById($componentId, array('ignoreVisible' => true));
                $id = substr($includedComponent, 0, strrpos($includedComponent, ':'));
                $targetCmp = Kwf_Component_Data_Root::getInstance()
                    ->getComponentById($id, array('ignoreVisible' => true));
                if ($cmp->getInheritsParent() !== $targetCmp->getInheritsParent()) {
                    if (!in_array($includedComponent, $existingTargetIds)) {
                        $c = array(
                            'target_id' => $includedComponent,
                            'type' => $type,
                            'component_id' => $componentId,
                        );
                        $data[] = $c;
                    }
                    $newTargetIds[] = $includedComponent;
                }
            }
            $m->import(Kwf_Model_Abstract::FORMAT_ARRAY, $data);
        }
        $diffTargetIds = array_diff($existingTargetIds, $newTargetIds);
        if ($diffTargetIds) {
            //delete not anymore included
            $m = $this->getModel('includes');
            $s = $m->select()
                ->whereEquals('component_id', $componentId)
                ->whereEquals('type', $type)
                ->whereEquals('target_id', $diffTargetIds);
            $m->deleteRows($s);
        }
    }
public function saveIncludes ( $ componentId , $ type , $ includedComponents ) { $ m = $ this -> getModel ( 'includes' ) ; $ s = $ m -> select ( ) -> whereEquals ( 'component_id' , $ componentId ) -> whereEquals ( 'type' , $ type ) ; $ existingTargetIds = array ( ) ; foreach ( $ m -> export ( Kwf_Model_Abstract :: FORMAT_ARRAY , $ s , array ( 'columns' => array ( 'id' , 'target_id' , 'type' ) ) ) as $ i ) { $ existingTargetIds [ $ i [ 'id' ] ] = $ i [ 'target_id' ] ; } $ newTargetIds = array ( ) ; if ( $ includedComponents ) { $ data = array ( ) ; foreach ( $ includedComponents as $ includedComponent ) { $ cmp = Kwf_Component_Data_Root :: getInstance ( ) -> getComponentById ( $ componentId , array ( 'ignoreVisible' => true ) ) ; $ id = substr ( $ includedComponent , 0 , strrpos ( $ includedComponent , ':' ) ) ; $ targetCmp = Kwf_Component_Data_Root :: getInstance ( ) -> getComponentById ( $ id , array ( 'ignoreVisible' => true ) ) ; if ( $ cmp -> getInheritsParent ( ) !== $ targetCmp -> getInheritsParent ( ) ) { if ( ! in_array ( $ includedComponent , $ existingTargetIds ) ) { $ c = array ( 'target_id' => $ includedComponent , 'type' => $ type , 'component_id' => $ componentId , ) ; $ data [ ] = $ c ; } $ newTargetIds [ ] = $ includedComponent ; } } $ m -> import ( Kwf_Model_Abstract :: FORMAT_ARRAY , $ data ) ; } $ diffTargetIds = array_diff ( $ existingTargetIds , $ newTargetIds ) ; if ( $ diffTargetIds ) { //delete not anymore included $ m = $ this -> getModel ( 'includes' ) ; $ s = $ m -> select ( ) -> whereEquals ( 'component_id' , $ componentId ) -> whereEquals ( 'type' , $ type ) -> whereEquals ( 'target_id' , $ diffTargetIds ) ; $ m -> deleteRows ( $ s ) ; } }
For unit testing - DO NOT DELETE!
For unit testing - DO NOT DELETE!