getCat($catID); } /** * validate if category not exists */ private function validateCatTitleNotExists($title, $type, $catID=null){ $isExists = $this->isCatExistsByTitle($title, $type, $catID); if($isExists == true) UniteFunctionsUC::throwError("Category with title: $title already exists"); } /** * validate category title */ private function validateTitle($title){ UniteFunctionsUC::validateNotEmpty($title, "Category Title"); UniteFunctionsUC::validateNoTags($title, "Category Title"); } /** * validate new title before add or update by type */ private function validateTitleByType($title, $type, $catID = null){ $this->validateTitle($title); //validate that not exists for all the types $this->validateCatTitleNotExists($title, $type, $catID); } private function a______________GETTERS____________(){} /** * get uncategorised category */ private function getFirstCats($type){ $objAddons = new UniteCreatorAddons(); $filterActive = UniteCreatorAddons::getStateFilterActive(); $numAddonsZero = $objAddons->getNumAddons(0, $filterActive, $type); //all $arrCatAll = array(); $arrCatAll["id"] = "all"; $arrCatAll["title"] = HelperUC::getText("all_addons"); $arrCatAll["alias"] = ""; $arrCatAll["ordering"] = 0; $arrCatAll["parent_id"] = ""; $arrCatAll["params"] = ""; $arrCatAll["type"] = ""; $arrCatAll["num_addons"] = "set"; //uncategorized $arrCatZero = array(); $arrCatZero["id"] = 0; $arrCatZero["title"] = HelperUC::getText("uncategorized"); $arrCatZero["alias"] = ""; $arrCatZero["ordering"] = 0; $arrCatZero["parent_id"] = ""; $arrCatZero["params"] = ""; $arrCatZero["type"] = ""; $arrCatZero["num_addons"] = $numAddonsZero; $arrCats = array(); $arrCats[] = $arrCatAll; $arrCats[] = $arrCatZero; return($arrCats); } /** * get category list simple */ private function getListSimple($type=""){ if(empty($type)) $type = UniteCreatorDB::ISNULL; $where = array(); $where["type"] = $type; $response = $this->db->fetch(GlobalsUC::$table_categories, $where); return($response); } /** * get list extra where ending */ private function getListExtra_WhereEnding($type, $filterTitle="", $ordering=""){ $whereFilterActive = ""; if($type != self::TYPE_LAYOUT) $whereFilterActive = UniteCreatorAddons::getFilterActiveWhere(null, " and addons"); $type = $this->db->escape($type); if(empty($type)) $where = "where cats.type is null or cats.type=''"; else $where = "where cats.type='$type'"; //add filter by title if(!empty($filterTitle)){ $filterTitle = $this->db->escape($filterTitle); $where .= " and title like %$filterTitle%"; } //add ordering $ordering = strtolower($ordering); switch($ordering){ case "asc": $ordering = "title asc"; break; case "desc": $ordering = "title desc"; break; default: $ordering = "ordering"; break; } $whereEnding = "$where $whereFilterActive GROUP BY cats.id order by $ordering"; return($whereEnding); } /** * get layouts list extra */ private function getListExtraLayouts($filterTitle="", $ordering=""){ $type = self::TYPE_LAYOUT; $whereEnding = $this->getListExtra_WhereEnding($type, $filterTitle, $ordering); $tableCats = GlobalsUC::$table_categories; $tableLayouts = GlobalsUC::$table_layouts; $query = "select cats.*, count(layouts.id) as num_layouts from {$tableCats} as cats"; $query .= " left join $tableLayouts as layouts on layouts.catid=cats.id $whereEnding"; $arrCats = $this->db->fetchSql($query); //make short output $arrCatsNew = array(); //add uncategorised $arrCatsNew[] = array( "id" => 0, "title" => __("Uncategorized", ADDONLIBRARY_TEXTDOMAIN), "num_layouts" => 0 ); foreach($arrCats as $key=>$cat){ $arr = array(); $arr["id"] = $cat["id"]; $arr["title"] = $cat["title"]; $arr["num_layouts"] = $cat["num_layouts"]; $arrCatsNew[] = $arr; } return($arrCatsNew); } /** * get categories list with "all" and "uncategorised" and num addons * ordering = asc / desc / empty */ public function getListExtra($type, $filterTitle="", $ordering=""){ $whereEnding = $this->getListExtra_WhereEnding($type, $filterTitle, $ordering); $tableCats = GlobalsUC::$table_categories; $tableAddons = GlobalsUC::$table_addons; $query = "select cats.*, count(addons.id) as num_addons from {$tableCats} as cats"; $query .= " left join $tableAddons as addons on addons.catid=cats.id $whereEnding"; $arrCats = $this->db->fetchSql($query); if(empty($arrCats)) $arrCats = array(); $arrFirstCats = $this->getFirstCats($type); $arrCats = array_merge($arrFirstCats, $arrCats); //set number of all addons $numAddons = 0; foreach($arrCats as $cat){ $numCatAddons = $cat["num_addons"]; if(!is_numeric($numCatAddons)) continue; $numAddons += $numCatAddons; } $arrCats[0]["num_addons"] = $numAddons; return($arrCats); } /** * * get category records simple without num items */ public function getCatRecords($type){ if(empty($type)) $type = UniteCreatorDB::ISNULL; $where = array(); if($type != "all"){ $where["type"] = $type; } $arrCats = $this->db->fetch(GlobalsUC::$table_categories, $where, "ordering"); return($arrCats); } /** * * get categories list short * addtype: empty (empty category), new (craete new category) */ public function getCatsShort($addType = "", $type){ $arrCats = $this->getCatRecords($type); $arrCatsOutput = array(); switch($addType){ case "empty": $arrCatsOutput[""] = __("[Not Selected]", ADDONLIBRARY_TEXTDOMAIN); break; case "new": $arrCatsOutput["new"] = __("[Add New Category]", ADDONLIBRARY_TEXTDOMAIN); break; case "component": $arrCatsOutput[""] = __("[From Gallery Settings]", ADDONLIBRARY_TEXTDOMAIN); break; case "all_uncat": $arrCatsOutput["all"] = HelperUC::getText("all_addons"); $arrCatsOutput[0] = HelperUC::getText("uncategorized"); break; case "uncategorized": $arrCatsOutput[0] = HelperUC::getText("uncategorized"); break; case "all_uncat_layouts": $arrCatsOutput["all"] = HelperUC::getText("all_layouts"); $arrCatsOutput[0] = HelperUC::getText("uncategorized"); break; } foreach($arrCats as $cat){ $catID = UniteFunctionsUC::getVal($cat, "id"); $title = UniteFunctionsUC::getVal($cat, "title"); $arrCatsOutput[$catID] = $title; } return($arrCatsOutput); } /** * * get assoc value of category name */ private function getArrCatTitlesAssoc($type=""){ $arrCats = $this->getListSimple($type); $arrAssoc = array(); foreach($arrCats as $cat){ $arrAssoc[$cat["title"]] = true; } return($arrAssoc); } /** * * get max order from categories list */ private function getMaxOrder($type=""){ $type = $this->db->escape($type); if(empty($type)) $where = "where type='' or type is null"; else $where = "where type='$type'"; $query = "select MAX(ordering) as maxorder from ".GlobalsUC::$table_categories." $where"; ///$query = "select * from ".self::TABLE_CATEGORIES; $rows = $this->db->fetchSql($query); $maxOrder = 0; if(count($rows)>0) $maxOrder = $rows[0]["maxorder"]; if(!is_numeric($maxOrder)) $maxOrder = 0; return($maxOrder); } /** * get true/false if some category exists */ public function isCatExists($catID){ $arrCat = null; try{ $arrCat = $this->db->fetchSingle(GlobalsUC::$table_categories,"id=$catID"); }catch(Exception $e){ } return !empty($arrCat); } /** * check if category exists by title * check in all cats except the current category id */ private function isCatExistsByTitle($title, $type = "", $catID = null){ if(empty($type)) $type = UniteCreatorDB::ISNULL; $arrWhere = array(); $arrWhere["title"] = $title; $arrWhere["type"] = $type; $response = $this->db->fetch(GlobalsUC::$table_categories, $arrWhere); if(empty($response)) return(false); //check by catID if(empty($catID)) return(true); $cat = $response[0]; if($cat["id"] == $catID) return(false); else return(true); } /** * * get category */ public function getCat($catID){ $catID = (int)$catID; $arrCat = $this->db->fetchSingle(GlobalsUC::$table_categories,"id=$catID"); if(empty($arrCat)) UniteFunctionsUC::throwError("Category with id: $catID not found"); return($arrCat); } /** * get category type by id */ public function getCatType($catID){ $arrCat = $this->getCat($catID); $type = UniteFunctionsUC::getVal($arrCat, "type"); return($type); } /** * get category by title * if not found - return null */ public function getCatByTitle($title, $type=""){ if(empty($type)) $type = UniteCreatorDB::ISNULL; $arrWhere = array(); $arrWhere["title"] = $title; $arrWhere["type"] = $type; try{ $arrCat = $this->db->fetchSingle(GlobalsUC::$table_categories, $arrWhere); if(empty($arrCat)) return(null); return($arrCat); }catch(Exception $e){ return(null); } } /** * * get html of category */ private function getCatHTML($cat, $class = ""){ $id = $cat["id"]; $title = $cat["title"]; $numAddons = $cat["num_addons"]; $title = $cat["title"]; $numAddons = $cat["num_addons"]; $showTitle = $title; if(!empty($numAddons)) $showTitle .= " ($numAddons)"; $html = ""; $html .= "