/** * @param Category $category */ public function add(Category $category) { $id_parent = $category->get_id_parent(); $max_order = $this->db_querier->get_column_value($this->table_name, 'MAX(c_order)', 'WHERE id_parent=:id_parent', array('id_parent' => $id_parent)); $max_order = NumberHelper::numeric($max_order); if ($this->get_categories_cache()->category_exists($id_parent)) { $order = $category->get_order(); if ($order <= 0 || $order > $max_order) { $category->set_order($max_order + 1); $result = $this->db_querier->insert($this->table_name, $category->get_properties()); $this->regenerate_cache(); return $result->get_last_inserted_id(); } else { $result = PersistenceContext::get_querier()->select_rows($this->table_name, array('id', 'c_order'), 'WHERE id_parent=:id_parent AND c_order >= :order', array('id_parent' => $id_parent, 'order' => $category->get_order())); while ($row = $result->fetch()) { $this->db_querier->update($this->table_name, array('c_order' => $row['c_order'] + 1, 'WHERE id=:id', array('id' => $row['id']))); } $result = $this->db_querier->insert($this->table_name, $category->get_properties()); $this->regenerate_cache(); return $result->get_last_inserted_id(); } } else { throw new CategoryNotFoundException($id_parent); } }
public function get_properties() { return array_merge(parent::get_properties(), array('description' => $this->get_description(), 'image' => $this->get_image()->relative())); }
public function get_properties() { return array_merge(parent::get_properties(), array('description' => $this->get_description(), 'last_topic_id' => $this->get_last_topic_id(), 'url' => $this->get_url())); }
public function get_properties() { return array_merge(parent::get_properties(), array('color' => $this->get_color())); }