Example #1
0
 /**
  * Gets categorys.
  *
  * @param array $where
  * @return CategoryModel[]|null
  */
 public function getCategories($where = array())
 {
     $sql = 'SELECT lc.*, COUNT(l.id) as count
             FROM `[prefix]_link_cats` as lc
             LEFT JOIN `[prefix]_links` as l ON l.cat_id = lc.id
             WHERE 1 ';
     foreach ($where as $key => $value) {
         $sql .= ' AND lc.`' . $key . '` = "' . $this->db()->escape($value) . '"';
     }
     $sql .= 'GROUP BY lc.id';
     $categoryArray = $this->db()->queryArray($sql);
     if (empty($categoryArray)) {
         return null;
     }
     $categorys = array();
     foreach ($categoryArray as $categoryRow) {
         $categoryModel = new CategoryModel();
         $categoryModel->setId($categoryRow['id']);
         $categoryModel->setParentId($categoryRow['parent_id']);
         $categoryModel->setName($categoryRow['name']);
         $categoryModel->setDesc($categoryRow['desc']);
         $categoryModel->setLinksCount($categoryRow['count']);
         $categorys[] = $categoryModel;
     }
     return $categorys;
 }