Exemplo n.º 1
0
 public function save()
 {
     if ($this->loaded) {
         return parent::save();
     } else {
         $parent = ORM::factory('blogpost')->where('lft', 0)->find()->id;
         return $this->insert_as_last_child($parent);
     }
 }
Exemplo n.º 2
0
 public function delete($id = NULL)
 {
     if ($id === NULL) {
         $id = $this->id;
     }
     $descendants = $this->descendants(TRUE)->find_all();
     foreach ($descendants as $descendant) {
         $this->db->delete('page_contents', array('page_id' => $descendant->id));
     }
     if ($id === $this->id and isset(self::$page_cache[$this->_identifier])) {
         unset(self::$page_cache[$this->_identifier]);
     }
     return parent::delete($id);
 }
Exemplo n.º 3
0
 /**
  * Return the children of this album, and all of it's sub-albums.  Unless you specify a specific
  * sort order, the results will be ordered by this album's sort order.  Note that this
  * album's sort order is imposed on all sub-albums, regardless of their sort order.
  *
  * @chainable
  * @param   integer  SQL limit
  * @param   integer  SQL offset
  * @param   array    additional where clauses
  * @return object ORM_Iterator
  */
 function descendants($limit = null, $offset = 0, $where = array(), $orderby = null)
 {
     if (empty($orderby)) {
         $orderby = array($this->sort_column => $this->sort_order);
     }
     return parent::descendants($limit, $offset, $where, $orderby);
 }
Exemplo n.º 4
0
 /**
  * Return the children of this album, and all of it's sub-albums.  Unless you specify a specific
  * sort order, the results will be ordered by this album's sort order.  Note that this
  * album's sort order is imposed on all sub-albums, regardless of their sort order.
  *
  * @chainable
  * @param   integer  SQL limit
  * @param   integer  SQL offset
  * @param   array    additional where clauses
  * @return object ORM_Iterator
  */
 function descendants($limit = null, $offset = 0, $where = array(), $orderby = null)
 {
     if (empty($orderby)) {
         $orderby = array($this->sort_column => $this->sort_order);
         // Use id as a tie breaker
         if ($this->sort_column != "id") {
             $orderby["id"] = "ASC";
         }
     }
     return parent::descendants($limit, $offset, $where, $orderby);
 }
Exemplo n.º 5
0
    /**
     * Move
     *
     * @param ORM_MPTT|integer $target target node id or ORM_MPTT object.
     * @param bool $left_column use the left column or right column from target
     * @param integer $left_offset left value for the new node position.
     * @param integer $level_offset level
     * @param bool allow this movement to be allowed on the root node
     */
    protected function move($target, $left_column, $left_offset, $level_offset, $allow_root_target)
    {
        if (!$this->loaded()) {
            return FALSE;
        }
        // Make sure we have the most upto date version of this AFTER we lock
        $this->lock()->reload();
        if (!$target instanceof $this) {
            $target = ORM_MPTT::factory($this->_object_name, $target);
            if (!$target->loaded()) {
                $this->unlock();
                return FALSE;
            }
        } else {
            $target->reload();
        }
        // Stop $this being moved into a descendant or disallow if target is root
        if ($target->is_descendant($this) or $allow_root_target === FALSE and $target->is_root()) {
            $this->unlock();
            return FALSE;
        }
        $left_offset = ($left_column === TRUE ? $target->{$this->left_column} : $target->{$this->right_column}) + $left_offset;
        $level_offset = $target->{$this->level_column} - $this->{$this->level_column} + $level_offset;
        $size = $this->get_size();
        $this->create_space($left_offset, $size);
        // if node is moved to a position in the tree "above" its current placement
        // then its lft/rgt may have been altered by create_space
        $this->reload();
        $offset = $left_offset - $this->{$this->left_column};
        // Update the values.
        $this->_db->query(Database::UPDATE, 'UPDATE ' . $this->_table_name . ' SET `' . $this->left_column . '` = `' . $this->left_column . '` + ' . $offset . ', `' . $this->right_column . '` = `' . $this->right_column . '` + ' . $offset . '
		, `' . $this->level_column . '` = `' . $this->level_column . '` + ' . $level_offset . '
		, `' . $this->scope_column . '` = ' . $target->{$this->scope_column} . '
		WHERE `' . $this->left_column . '` >= ' . $this->{$this->left_column} . ' AND `' . $this->right_column . '` <= ' . $this->{$this->right_column} . ' AND `' . $this->scope_column . '` = ' . $this->{$this->scope_column}, FALSE);
        $this->delete_space($this->{$this->left_column}, $size);
        if ($this->path_calculation_enabled) {
            $this->update_path();
            parent::save();
        }
        $this->unlock();
        return $this;
    }
Exemplo n.º 6
0
 /**
  * Updates or Creates the record depending on loaded()
  *
  * @param   Validation $validation Validation object
  * @return  ORM
  */
 public function save(Validation $validation = NULL)
 {
     $this->params = empty($this->params) ? NULL : serialize($this->params);
     return parent::save($validation);
 }
Exemplo n.º 7
0
 /**
  * Specify our rules here so that we have access to the instance of this model.
  */
 public function validate(Validation $array = null)
 {
     if (!$array) {
         $this->rules = array("album_cover_item_id" => array("callbacks" => array(array($this, "valid_album_cover"))), "description" => array("rules" => array("length[0,65535]")), "mime_type" => array("callbacks" => array(array($this, "valid_field"))), "name" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_name"))), "parent_id" => array("callbacks" => array(array($this, "valid_parent"))), "rand_key" => array("rule" => array("decimal")), "slug" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_slug"))), "sort_column" => array("callbacks" => array(array($this, "valid_field"))), "sort_order" => array("callbacks" => array(array($this, "valid_field"))), "title" => array("rules" => array("length[0,255]", "required")), "type" => array("callbacks" => array(array($this, "read_only"), array($this, "valid_field"))));
         // Conditional rules
         if ($this->id == 1) {
             // We don't care about the name and slug for the root album.
             $this->rules["name"] = array();
             $this->rules["slug"] = array();
         }
         // Movies and photos must have data files.  Verify the data file on new items, or if it has
         // been replaced.
         if (($this->is_photo() || $this->is_movie()) && $this->data_file) {
             $this->rules["name"]["callbacks"][] = array($this, "valid_data_file");
         }
     }
     parent::validate($array);
 }
Exemplo n.º 8
0
 /**
  * Return all of the children of the specified type, ordered by the defined sort order.
  * @param   integer  SQL limit
  * @param   integer  SQL offset
  * @param   string   type to return
  * @return object ORM_Iterator
  */
 function descendants($limit = null, $offset = 0, $type = null)
 {
     return parent::descendants($limit, $offset, $type, array($this->sort_column => $this->sort_order));
 }
 /**
  * Removes a node and it's descendants.
  *
  * $usless_param prevents a strict error that breaks PHPUnit like hell!
  * @access public
  * @param bool $descendants remove the descendants?
  */
 public function delete($version, $usless_param = NULL)
 {
     versions_helper::version_position_table($this->table_name, $version);
     parent::delete($usless_param);
 }
Exemplo n.º 10
0
 /**
  * Specify our rules here so that we have access to the instance of this model.
  */
 public function validate($array = null)
 {
     if (!$array) {
         $this->rules = array("album_cover_item_id" => array("callbacks" => array(array($this, "valid_album_cover"))), "description" => array("rules" => array("length[0,65535]")), "mime_type" => array("callbacks" => array(array($this, "valid_field"))), "name" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_name"))), "parent_id" => array("callbacks" => array(array($this, "valid_parent"))), "rand_key" => array("rule" => array("decimal")), "slug" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_slug"))), "sort_column" => array("callbacks" => array(array($this, "valid_field"))), "sort_order" => array("callbacks" => array(array($this, "valid_field"))), "title" => array("rules" => array("length[0,255]", "required")), "type" => array("callbacks" => array(array($this, "read_only"), array($this, "valid_field"))));
         // Conditional rules
         if ($this->id == 1) {
             // Root album can't have a name or slug so replace the rules
             $this->rules["name"] = array("rules" => array("length[0]"));
             $this->rules["slug"] = array("rules" => array("length[0]"));
         }
         // Movies and photos must have data files
         if (($this->is_photo() || $this->is_movie()) && !$this->loaded()) {
             $this->rules["name"]["callbacks"][] = array($this, "valid_data_file");
         }
     }
     parent::validate($array);
 }
Exemplo n.º 11
0
 /**
  * Move to Next Sibling.
  *
  * Moves the current node to the next sibling of the target node.
  *
  * @param ORM_MPTT|integer $target target node id or ORM_MPTT object.
  * @return ORM_MPTT
  */
 public function move_to_next_sibling($target)
 {
     // Move should only work on nodes that are already in the tree.. if its not already it the tree it needs to be inserted!
     if (!$this->loaded) {
         return FALSE;
     }
     $this->lock();
     $this->reload();
     // Make sure we have the most upto date version of this AFTER we lock
     if (!$target instanceof $this) {
         $target = ORM_MPTT::factory($this->table_name, $target);
     }
     // Stop $this being moved into a descendant
     if ($target->is_descendant($this)) {
         $this->unlock();
         return FALSE;
     }
     $new_left = $target->{$this->right_column} + 1;
     $level_offset = $target->{$this->level_column} - $this->{$this->level_column};
     $this->move($new_left, $level_offset, $target->{$this->scope_column});
     $this->unlock();
     return $this;
 }
Exemplo n.º 12
0
 /**
  * Reading data from inaccessible properties
  *
  * @param   string  $field
  * @return  mixed
  *
  * @uses  HTML::chars
  * @uses  Route::get
  * @uses  Route::uri
  * @uses  Path::load
  */
 public function __get($field)
 {
     switch ($field) {
         case 'name':
             return HTML::chars(parent::__get('name'));
             break;
         case 'image':
             return is_null(parent::__get('image')) ? 'media/images/camera.png' : parent::__get('image');
             break;
         case 'rawname':
             // Raw fields without markup. Usage: during edit or etc!
             return parent::__get('name');
             break;
         case 'rawurl':
             // Raw fields without markup. Usage: during edit or etc!
             return Route::get($this->type)->uri(array('action' => 'term', 'id' => $this->id));
             break;
         case 'url':
         case 'link':
             // Model specific links; view, edit, delete url's.
             return ($path = Path::load($this->rawurl)) ? $path['alias'] : $this->rawurl;
             break;
         case 'edit_url':
             // Model specific links; view, edit, delete url's.
             return Route::get('admin/term')->uri(array('id' => $this->id, 'action' => 'edit'));
             break;
         case 'delete_url':
             // Model specific links; view, edit, delete url's.
             return Route::get('admin/term')->uri(array('id' => $this->id, 'action' => 'delete'));
             break;
     }
     return parent::__get($field);
 }
Exemplo n.º 13
0
 /**
  * @see ORM::save()
  */
 public function save()
 {
     if (!empty($this->changed) && $this->changed != array("view_count" => "view_count")) {
         $this->updated = time();
         if (!$this->loaded) {
             $this->created = $this->updated;
         }
     }
     return parent::save();
 }