Example #1
0
 /**
  * Method to get a category
  */
 public function getCategory($category_id = null)
 {
     // Only run this once
     if (empty($this->_category)) {
         // Set the ID
         if (empty($category_id)) {
             $category_id = $this->getId();
         }
         // Fetch the category of these items
         require_once JPATH_ADMINISTRATOR . '/components/com_simplelists/models/category.php';
         $model = new SimplelistsModelCategory();
         $model->setId($category_id);
         $category = $model->getData();
         // Fetch the related categories (parent and children) of this category
         require_once JPATH_ADMINISTRATOR . '/components/com_simplelists/models/categories.php';
         $model = new SimplelistsModelCategories();
         $model->addWhere('category.id = ' . (int) $category->parent_id . ' OR category.parent_id = ' . (int) $category->id);
         $related = $model->getData();
         foreach ($related as $id => $item) {
             // Make sure this related category is not the parent-category
             if ($item->id == $category->parent_id) {
                 $category->parent = $item;
                 unset($related[$id]);
                 continue;
             }
         }
         $category->childs = $related;
         // Insert this category in the model
         $this->_category = $category;
     }
     return $this->_category;
 }
Example #2
0
 /**
  * Method to get the fully loaded parent
  *
  * @access  private
  * @return  boolean True on success
  */
 public function getParent($parent_id = null)
 {
     if ($parent_id > 0) {
         $this->_parent_id = (int) $parent_id;
     }
     if (empty($this->_parent)) {
         // @todo: Check if there is a nicer way to do this
         require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_simplelists' . DS . 'models' . DS . 'category.php';
         $model = new SimplelistsModelCategory();
         $model->setId($this->_parent_id);
         $this->_parent = $model->getData();
     }
     return $this->_parent;
 }
Example #3
0
 public function _getRoot()
 {
     if (empty($this->root)) {
         require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_simplelists' . DS . 'models' . DS . 'category.php';
         require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_simplelists' . DS . 'tables' . DS . 'category.php';
         $model = new SimplelistsModelCategory();
         $model->setId(0, false);
         $this->root = $model->getData();
         $this->root->id = 0;
     }
     return $this->root;
 }