/**
  * This "renders" a model for tree view.
  *
  * @param InterfaceGeneralModel $objModel     the model to render.
  *
  * @param int                   $intLevel     the current level in the tree hierarchy.
  *
  * @param array                 $arrToggle    the array that determines the current toggle states for the table of the given model.
  *
  * @param array                 $arrSubTables the tables that shall be rendered "below" this item.
  *
  */
 protected function treeWalkModel(InterfaceGeneralModel $objModel, $intLevel, $arrToggle, $arrSubTables = array())
 {
     $blnHasChild = false;
     $objModel->setMeta(DCGE::TREE_VIEW_LEVEL, $intLevel);
     $this->buildLabel($objModel);
     if ($arrToggle['all'] == 1 && !(key_exists($objModel->getID(), $arrToggle) && $arrToggle[$objModel->getID()] == 0)) {
         $objModel->setMeta(DCGE::TREE_VIEW_IS_OPEN, true);
     } else {
         if (key_exists($objModel->getID(), $arrToggle) && $arrToggle[$objModel->getID()] == 1) {
             $objModel->setMeta(DCGE::TREE_VIEW_IS_OPEN, true);
         } else {
             $objModel->setMeta(DCGE::TREE_VIEW_IS_OPEN, false);
         }
     }
     $arrChildCollections = array();
     foreach ($arrSubTables as $strSubTable) {
         // evaluate the child filter for this item.
         $arrChildFilter = $this->getDC()->getChildCondition($objModel, $strSubTable);
         // if we do not know how to render this table within here, continue with the next one.
         if (!$arrChildFilter) {
             continue;
         }
         // Create a new Config
         $objChildConfig = $this->getDC()->getDataProvider($strSubTable)->getEmptyConfig();
         $objChildConfig->setFilter($arrChildFilter);
         $objChildConfig->setFields($this->calcNeededFields($objModel, $strSubTable));
         $objChildConfig->setSorting(array('sorting' => 'ASC'));
         // Fetch all children
         $objChildCollection = $this->getDC()->getDataProvider($strSubTable)->fetchAll($objChildConfig);
         // Speed up
         if ($objChildCollection->length() > 0 && !$objModel->getMeta(DCGE::TREE_VIEW_IS_OPEN)) {
             $blnHasChild = true;
             break;
         } else {
             if ($objChildCollection->length() > 0) {
                 $blnHasChild = true;
                 // TODO: @CS we need this to be srctable_dsttable_tree for interoperability, for mode5 this will be self_self_tree but with strTable.
                 $strToggleID = $this->getDC()->getTable() . '_tree';
                 $arrSubToggle = $this->Session->get($strToggleID);
                 if (!is_array($arrSubToggle)) {
                     $arrSubToggle = array();
                 }
                 foreach ($objChildCollection as $objChildModel) {
                     // let the child know about it's parent.
                     $objModel->setMeta(DCGE::MODEL_PID, $objModel->getID());
                     $objModel->setMeta(DCGE::MODEL_PTABLE, $objModel->getProviderName());
                     // TODO: determine the real subtables here.
                     $this->treeWalkModel($objChildModel, $intLevel + 1, $arrSubToggle, $arrSubTables);
                 }
                 $arrChildCollections[] = $objChildCollection;
                 // speed up, if not open, one item is enough to break as we have some childs.
                 if (!$objModel->getMeta(DCGE::TREE_VIEW_IS_OPEN)) {
                     break;
                 }
             }
         }
     }
     // If open store children
     if ($objModel->getMeta(DCGE::TREE_VIEW_IS_OPEN) && count($arrChildCollections) != 0) {
         $objModel->setMeta(DCGE::TREE_VIEW_CHILD_COLLECTION, $arrChildCollections);
     }
     $objModel->setMeta(DCGE::TREE_VIEW_HAS_CHILDS, $blnHasChild);
 }
Esempio n. 2
0
 /**
  * Update the current model from a post request. Additionally, trigger meta palettes, if installed.
  */
 public function updateModelFromPOST()
 {
     // callback to tell visitors that we have just updated the model.
     $this->getCallbackClass()->onModelBeforeUpdateCallback($this->getCurrentModel());
     // process input and update changed properties.
     foreach (array_keys($this->getFieldList()) as $strKey) {
         $varNewValue = $this->processInput($strKey);
         if ($varNewValue !== NULL && $this->objCurrentModel->getProperty($strKey) !== $varNewValue) {
             $this->objCurrentModel->setProperty($strKey, $varNewValue);
             $this->objCurrentModel->setMeta(DCGE::MODEL_IS_CHANGED, true);
         }
     }
     if (in_array($this->arrDCA['list']['sorting']['mode'], array(4, 5, 6)) && strlen(Input::getInstance()->get('pid')) > 0) {
         // pull correct condition from DCA and update according to setOn values.
         $objParentModel = $this->getDataProvider('parent')->fetch($this->getDataProvider('parent')->getEmptyConfig()->setId(Input::getInstance()->get('pid')));
         $arrCond = $this->getParentChildCondition($objParentModel, $this->getDataProvider()->getEmptyModel()->getProviderName());
         if (is_array($arrCond) && key_exists('setOn', $arrCond)) {
             foreach ($arrCond['setOn'] as $arrSetOn) {
                 if ($arrSetOn['from_field']) {
                     $this->objCurrentModel->setProperty($arrSetOn['to_field'], $objParentModel->getProperty($arrSetOn['from_field']));
                 } else {
                     $this->objCurrentModel->setProperty($arrSetOn['to_field'], $arrSetOn['value']);
                 }
             }
         }
     }
     // TODO: is this really a wise idea here?
     if (in_array('metapalettes', Config::getInstance()->getActiveModules())) {
         MetaPalettes::getInstance()->generateSubSelectPalettes($this);
     }
     // callback to tell visitors that we have just updated the model.
     $this->getCallbackClass()->onModelUpdateCallback($this->getCurrentModel());
 }