Exemplo n.º 1
0
 /**
  * Creates (not save) GPC Entity object
  *
  * @param 		string					storage_name
  * @param 		array					post
  * @param 		RM_Gpc_Entity|NULL		obEntity
  * @return		RM_Gpc_Entity
  **/
 public function createEntity($storage_name, $post = array(), RM_Gpc_Entity $obEntity = NULL)
 {
     // выберем из входных данных самое необходимое :)
     $data = array();
     foreach ($this->_fields[$storage_name] as $alias => $field) {
         if ($alias != 'id' && isset($post[$alias])) {
             $data[$alias] = $post[$alias];
         }
     }
     // запомним id родительского объекта obEntity, если таковой требуется для данной GPC сущности
     $parent_type = @$this->parent_types($storage_name);
     if ($parent_type) {
         if ($obEntity->type() != $parent_type) {
             throw new RM_Base_Exception_BadUsage(__METHOD__ . "(): inappropriate parent entity type. `" . $parent_type . "` expected, `" . $obEntity->type() . "` given.");
         }
         $data[$parent_type . '_id'] = $obEntity->id();
     }
     // создадим и вернем объект (без сохраннения в бд!)
     return $this->_storages[$storage_name]->createObject($data);
 }
Exemplo n.º 2
0
 /**
  * Moves entities (just moves, dosn't delete). Move all "children" and barcodes to obToEntity using restriction.
  *
  * @param 		RM_Gpc_Entity		obToEntity
  * @param 		array<brand_owner_id|brand_id|subbrand_id|generaltype_id>		restriction
  * @return		bool
  **/
 public function move(RM_Gpc_Entity $obToEntity, $restriction = array())
 {
     if ($this->type() !== $obToEntity->type()) {
         throw new RM_Base_Exception_BadUsage(__METHOD__ . "(): Cannot move objects of different gpc entity types `" . $this->type() . '` and `' . $obToEntity->type() . '`');
     }
     $result = FALSE;
     // перенесем все штрих-коды в другой GPC Entity
     $result = $this->moveBarcodes($obToEntity, $restriction);
     // поменяем "родителя" у всех дочерних элементов
     $children = $this->getChildren();
     if (!is_null($children)) {
         foreach ($children as $obChildren) {
             $obChildren->{$this->type() . '_id'} = $obToEntity->id();
             $obChildren->save();
         }
         $result = TRUE;
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Deletes this object
  *
  * @return bool
  **/
 public function delete()
 {
     if (parent::delete()) {
         // разорвем все связи данного брика с атрибутами - при удалении
         foreach ($this->getAttributes() as $obAttribute) {
             $obAttribute->removeBrick($this);
         }
         // разорвем все связи данного брика с вкусами - при удалении
         foreach ($this->getFlavours() as $obFlavour) {
             $obFlavour->removeBrick($this);
         }
         return TRUE;
     }
     return FALSE;
 }