Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenvanvliet committed Apr 2, 2008
1 parent af4a7a6 commit b3f7f76
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ORM_Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ORM_Tree_Core{
protected $class;

protected $parent_column='parent_id';

public function __construct(ORM $model)
{
$this->model=$model;
Expand All @@ -14,28 +15,34 @@ public function set_parent_column($value)
{
$this->parent_column=$value;
}

public function get_parent_column()
{
return $this->parent_column;
}
public function get_children()
{
return $this->model->find_all_by_parent_id($this->model->id);
$method='find_all_by_'.$this->parent_column;
return $this->model->$method($this->model->id);
}
public function has_parent()
{
return !empty($this->model->parent_id);
return !empty($this->model->{$this->parent_column});
}
public function get_parent(){
if($this->has_parent())
return $this->model->find_all_by_id($this->model->parent_id);
return $this->model->find_all_by_id($this->model->{$this->parent_column});

return false;
}
public function get_siblings(){
$method='find_all_by_'.$this->parent_column;
$this->model->where(array('id!='=>$this->model->id));
return $this->model->find_all_by_parent_id($this->model->parent_id);
return $this->model->$method($this->model->{$this->parent_column});
}
public function get_self_and_siblings()
{
return $this->model->find_all_by_parent_id($this->model->parent_id);
$method='find_all_by_'.$this->parent_column;
return $this->model->$method($this->model->{$this->parent_column});
}
public function add_child(ORM $child)
{
Expand All @@ -47,7 +54,7 @@ public function add_child(ORM $child)
$this->model->save();
}

$child->parent_id=$this->model->id;
$child->{$this->parent_column}=$this->model->id;
return $child->save();

}
Expand Down

0 comments on commit b3f7f76

Please sign in to comment.