Ejemplo n.º 1
0
 /**
  * fix the positions of all feeds in this category
  * feed positions of 0 1 3 4 5 will become 0 1 2 3 4
  *
  * @return void
  * @param Zend_Db_Table_Row $category category model
  */
 public function fixPositions($category)
 {
     $position = 0;
     foreach ($category->findDependentRowset('application_models_feeds', null, $this->select()->order('position ASC')) as $feed) {
         $feed->position = $position++;
         $feed->save();
     }
 }
Ejemplo n.º 2
0
 /**
  * Get category childs.
  * @param Zend_Db_Table_Row $category Category
  * 
  * @return array Lowest level categories
  */
 private function categoryChilds($category)
 {
     $childs = $category->findDependentRowset("Model_DbTable_Categories");
     $categories = array();
     if (count($childs) > 0) {
         foreach ($childs as $child) {
             $categories = array_merge($categories, $this->categoryChilds($child));
         }
     } else {
         return array($category);
     }
     return $categories;
 }
Ejemplo n.º 3
0
 private function _rowToObject(Zend_Db_Table_Row $row)
 {
     $team = new User_Model_Team();
     $team->setId($row->ut_id)->setName($row->ut_name);
     $users = array();
     $usersRowSet = $row->findDependentRowset('User_Model_DbTable_Staffmembre');
     foreach ($usersRowSet as $userRow) {
         $user = new User_Model_Staffmembre();
         $user->setId($userRow->usm_id)->setFirstname($userRow->usm_firstname)->setLastname($userRow->usm_lastname)->setEmail($userRow->usm_email)->setLogin($userRow->usm_login)->setTeam($team);
         $users[] = $user;
     }
     $team->setUsers($users);
     return $team;
 }
Ejemplo n.º 4
0
 /**
  * Load the value of an external field. Sets an model instance or an array of
  * model instances depending on whether the field has multiple linked models or not.
  *
  * @param  string $fieldname Name of the external field.
  * @throws Opus_Model_Exception If no _fetch-method is defined for an external field.
  * @return void
  */
 protected function _loadExternal($fieldname)
 {
     $field = $this->_fields[$fieldname];
     // Check if the fetch mechanism for the field is overwritten in model.
     $callname = '_fetch' . $fieldname;
     if (method_exists($this, $callname) === true) {
         $result = $this->{$callname}();
     } else {
         // Determine the class of the field values model
         // For handling a link model, see 'through' option.
         $modelclass = $field->getLinkModelClass();
         if (!isset($modelclass)) {
             // For handling a value model, see 'model' option.
             $modelclass = $field->getValueModelClass();
         }
         // Make sure that a field's value model is inherited from Opus_Model_AbstractDb
         if (empty($modelclass) or is_subclass_of($modelclass, 'Opus_Model_AbstractDb') === false) {
             $message = "Field {$fieldname} must extend Opus_Model_AbstractDb.";
             throw new Opus_Model_Exception($message);
         }
         // Do nothing if the current model has not been persisted
         // (if no identifier given)
         if ($this->getId() === null) {
             return;
         }
         if (empty($modelclass) or is_subclass_of($modelclass, 'Opus_Model_Dependent_Abstract') === false) {
             throw new Opus_Model_Exception('Class of ' . $fieldname . ' does not extend Opus_Model_Dependent_Abstract.  Please check class ' . $modelclass . '.');
         }
         $tableclass = $modelclass::getTableGatewayClass();
         $table = Opus_Db_TableGateway::getInstance($tableclass);
         $select = $table->select();
         // If any declared constraints, add them to query
         if (isset($this->_externalFields[$fieldname]['options'])) {
             $options = $this->_externalFields[$fieldname]['options'];
             foreach ($options as $column => $value) {
                 $select = $select->where("{$column} = ?", $value);
             }
         }
         // If sort_order is defined, add to query
         if (isset($this->_externalFields[$fieldname]['sort_order'])) {
             $sort_order = $this->_externalFields[$fieldname]['sort_order'];
             foreach ($sort_order as $column => $order) {
                 $select = $select->order("{$column} {$order}");
             }
         }
         // Get dependent rows
         $result = array();
         $rows = $this->_primaryTableRow->findDependentRowset($table, null, $select);
         // Create new model for each row
         foreach ($rows as $row) {
             $newModel = new $modelclass($row);
             if (is_null($newModel->getParentId())) {
                 throw new Opus_Model_Exception('Object in ' . $fieldname . ' contains empty ParentId.  Please check class ' . get_class($newModel) . '.');
             }
             $result[] = $newModel;
         }
     }
     // Set the field value
     $field->setValue($result);
     // TODO: Could be removed!  Needs more testing before doing so...
     // iterate through dependend models and set parent id
     $list = $result;
     if (false === is_array($result)) {
         $list = array($list);
     }
     $myid = $this->getId();
     foreach ($list as $child) {
         if ($child instanceof Opus_Model_Dependent_Abstract) {
             $child->setParentId($myid);
         }
     }
     // Clear the modified flag for the just loaded field
     $field->clearModified();
 }
Ejemplo n.º 5
0
 /**
  * Finds primary keys of dependent rows
  *
  * @param \Zend_Db_Table_Row $row
  * @param string $dependentTableClass
  * @param string $rule
  * @return array
  */
 public function findDependentRowset(\Zend_Db_Table_Row $row, $ruleKey = null)
 {
     $table = $this->getDbTable();
     $select = $table->select(false)->from($table->info("name"), $table->info("primary"));
     $results = $row->findDependentRowset(get_class($table), $ruleKey, $select);
     return $this->_loadByPrimaryKeys($results);
 }