AAAAhome/academiac/www/administrator/components/com_virtuemart/models/category.php000060400000071437151372174460024147 0ustar00setMainTable('categories'); $this->addvalidOrderingFieldName(self::$_validOrderingFields); $toCheck = VmConfig::get('browse_cat_orderby_field','category_name'); if(!in_array($toCheck, $this->_validOrderingFieldName)){ $toCheck = 'category_name'; } $this->_selectedOrdering = $toCheck; $this->_selectedOrderingDir = VmConfig::get('cat_brws_orderby_dir', 'ASC'); $this->setToggleName('shared'); } /** * Retrieve the detail record for the current $id if the data has not already been loaded. * * @author RickG, jseros, RolandD, Max Milbers */ public function getCategory($virtuemart_category_id=0,$childs=TRUE){ if(!empty($virtuemart_category_id)) $this->setId((int)$virtuemart_category_id); if (empty($this->_data)) { $this->_data = $this->getTable('categories'); $this->_data->load((int)$this->_id); $xrefTable = $this->getTable('category_medias'); $this->_data->virtuemart_media_id = $xrefTable->load((int)$this->_id); if($xrefTable->getError()) vmError($xrefTable->getError()); if(empty($this->_data->category_template)){ $this->_data->category_template = VmConfig::get('categorytemplate'); } if(empty($this->_data->category_layout)){ $this->_data->category_layout = VmConfig::get('categorylayout'); } if($childs){ $this->_data->haschildren = $this->hasChildren($this->_id); /* Get children if they exist */ if ($this->_data->haschildren) $this->_data->children = $this->getCategories(true,$this->_id); else $this->_data->children = null; /* Get the product count */ $this->_data->productcount = $this->countProducts($this->_id); /* Get parent for breatcrumb */ $this->_data->parents = $this->getParentsList($this->_id); } if($errs = $this->getErrors()){ $app = JFactory::getApplication(); foreach($errs as $err){ $app->enqueueMessage($err); } } } return $this->_data; } /** * Get the list of child categories for a given category, is cached * * @param int $virtuemart_category_id Category id to check for child categories * @return object List of objects containing the child categories * */ public function getChildCategoryList($vendorId, $virtuemart_category_id,$selectedOrdering = null, $orderDir = null, $cache = true) { $useCache = true; if(empty($this) or get_class($this)!='VirtueMartModelCategory'){ $useCache = false; } if($selectedOrdering===null){ if($useCache){ $selectedOrdering = $this->_selectedOrdering; } else { $selectedOrdering = VmConfig::get('browse_cat_orderby_field','category_name'); } } if(!in_array($selectedOrdering, self::$_validOrderingFields)){ $selectedOrdering = 'category_name'; } if($orderDir===null){ if($useCache){ $orderDir = $this->_selectedOrderingDir; } else { $orderDir = VmConfig::get('cat_brws_orderby_dir', 'ASC'); } } $validOrderingDir = array('ASC','DESC'); if(!in_array(strtoupper($orderDir), $validOrderingDir)){ $orderDir = 'ASC'; } static $_childCategoryList = array (); $key = (int)$vendorId.'_'.(int)$virtuemart_category_id.$selectedOrdering.$orderDir.VMLANG ; //We have here our internal key to preven calling of the cache if (! array_key_exists ($key,$_childCategoryList)){ if($useCache){ $cache = JFactory::getCache('com_virtuemart_cats','callback'); $cache->setCaching(true); $_childCategoryList[$key] = $cache->call( array( 'VirtueMartModelCategory', 'getChildCategoryListObject' ),$vendorId, $virtuemart_category_id, $selectedOrdering, $orderDir); } else { $_childCategoryList[$key] = VirtueMartModelCategory::getChildCategoryListObject($vendorId, $virtuemart_category_id, $selectedOrdering, $orderDir); } } return $_childCategoryList[$key]; } /** * Be aware we need the lang to assure that the cache works properly. The cache needs all paraemeters * in the function call to use the right hash * * @author Max Milbers * @param $vendorId * @param $virtuemart_category_id * @param null $selectedOrdering * @param null $orderDir * @param $lang * @return mixed */ static public function getChildCategoryListObject($vendorId, $virtuemart_category_id,$selectedOrdering = null, $orderDir = null,$lang = VMLANG) { $query = 'SELECT L.* FROM `#__virtuemart_categories_'.$lang.'` as L JOIN `#__virtuemart_categories` as c using (`virtuemart_category_id`)'; $query .= ' LEFT JOIN `#__virtuemart_category_categories` as cx on c.`virtuemart_category_id` = cx.`category_child_id` '; $query .= 'WHERE cx.`category_parent_id` = ' . (int)$virtuemart_category_id . ' '; $query .= 'AND c.`virtuemart_vendor_id` = ' . (int)$vendorId . ' '; $query .= 'AND c.`published` = 1 '; $query .= ' ORDER BY '.$selectedOrdering.' '.$orderDir; $db = JFactory::getDBO(); $db->setQuery( $query); $childList = $db->loadObjectList(); if(!empty($childList)){ if(!class_exists('TableCategory_medias'))require(JPATH_VM_ADMINISTRATOR.DS.'tables'.DS.'category_medias.php'); foreach($childList as $child){ $xrefTable = new TableCategory_medias($db); $child->virtuemart_media_id = $xrefTable->load($child->virtuemart_category_id); } } return $childList; } // public sortArraysPerXref(){ // $q = 'SELECT * FROM ' // } public function getCategoryTree($parentId=0, $level = 0, $onlyPublished = true,$keyword = ''){ $sortedCats = array(); $limits = $this->setPaginationLimits(); $limitStart = $limits[0]; $limit = $limits[1]; // vmRam('What take the cats?'); $this->_noLimit = true; if($keyword!=''){ $sortedCats = self::getCategories($onlyPublished, false, false, $keyword); } else { $this->rekurseCats($parentId,$level,$onlyPublished,$keyword,$sortedCats); } $this->_noLimit = false; $this->_total = count($sortedCats); $this->_limitStart = $limitStart; $this->_limit = $limit; $this->getPagination(); if(empty($limit)){ return $sortedCats; } else { $sortedCats = array_slice($sortedCats, $limitStart,$limit); return $sortedCats; } } public function rekurseCats($virtuemart_category_id,$level,$onlyPublished,$keyword,&$sortedCats){ $level++; if($this->hasChildren($virtuemart_category_id)){ $childCats = self::getCategories($onlyPublished, $virtuemart_category_id, false, $keyword); if(!empty($childCats)){ foreach ($childCats as $key => $category) { $category->level = $level; $sortedCats[] = $category; $this->rekurseCats($category->virtuemart_category_id,$level,$onlyPublished,$keyword,$sortedCats); } } } } public function getCategories($onlyPublished = true, $parentId = false, $childId = false, $keyword = "") { $vendorId = 1; $select = ' c.`virtuemart_category_id`, l.`category_description`, l.`category_name`, c.`ordering`, c.`published`, cx.`category_child_id`, cx.`category_parent_id`, c.`shared` '; $joinedTables = ' FROM `#__virtuemart_categories_'.VMLANG.'` l JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`) LEFT JOIN `#__virtuemart_category_categories` AS cx ON l.`virtuemart_category_id` = cx.`category_child_id` '; $where = array(); if( $onlyPublished ) { $where[] = " c.`published` = 1 "; } if( $parentId !== false ){ $where[] = ' cx.`category_parent_id` = '. (int)$parentId; } if( $childId !== false ){ $where[] = ' cx.`category_child_id` = '. (int)$childId; } if(!class_exists('Permissions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'permissions.php'); if( !Permissions::getInstance()->check('admin') ){ $where[] = ' (c.`virtuemart_vendor_id` = "'. (int)$vendorId. '" OR c.`shared` = "1") '; } if( !empty( $keyword ) ) { $keyword = '"%' . $this->_db->getEscaped( $keyword, true ) . '%"' ; //$keyword = $this->_db->Quote($keyword, false); $where[] = ' ( l.`category_name` LIKE '.$keyword.' OR l.`category_description` LIKE '.$keyword.') '; } $whereString = ''; if (count($where) > 0){ $whereString = ' WHERE '.implode(' AND ', $where) ; } else { $whereString = 'WHERE 1 '; } $ordering = $this->_getOrdering(); $this->_category_tree = $this->exeSortSearchListQuery(0,$select,$joinedTables,$whereString,'',$ordering ); return $this->_category_tree; } /** * count the products in a category * * @author Max Milbers * @return array list of categories product is in */ public function countProducts($cat_id=0) { if(!empty($this->_db))$this->_db = JFactory::getDBO(); $vendorId = 1; if ($cat_id > 0) { $q = 'SELECT count(#__virtuemart_products.virtuemart_product_id) AS total FROM `#__virtuemart_products`, `#__virtuemart_product_categories` WHERE `#__virtuemart_products`.`virtuemart_vendor_id` = "'.(int)$vendorId.'" AND `#__virtuemart_product_categories`.`virtuemart_category_id` = '.(int)$cat_id.' AND `#__virtuemart_products`.`virtuemart_product_id` = `#__virtuemart_product_categories`.`virtuemart_product_id` AND `#__virtuemart_products`.`published` = "1" '; $this->_db->setQuery($q); $count = $this->_db->loadResult(); } else $count=0 ; return $count; } /** * Order any category * * @author jseros * @param int $id category id * @param int $movement movement number * @return bool */ public function orderCategory($id, $movement){ //retrieving the category table object //and loading data $row = $this->getTable('categories'); $row->load($id); $query = 'SELECT `category_parent_id` FROM `#__virtuemart_category_categories` WHERE `category_child_id` = '. (int)$row->virtuemart_category_id ; $this->_db->setQuery($query); $parent = $this->_db->loadObject(); if (!$row->move( $movement, $parent->category_parent_id)) { vmError($row->getError()); return false; } return true; } /** * Order category group * * @author jseros * @param array $cats categories to order * @return bool */ public function setOrder($cats, $order){ $total = count( $cats ); $groupings = array(); $row = $this->getTable('categories'); $query = 'SELECT `category_parent_id` FROM `#__virtuemart_categories` c LEFT JOIN `#__virtuemart_category_categories` cx ON c.`virtuemart_category_id` = cx.`category_child_id` WHERE c.`virtuemart_category_id` = %s'; // update ordering values for( $i=0; $i < $total; $i++ ) { $row->load( $cats[$i] ); $this->_db->setQuery( sprintf($query, (int)$cats[$i] ), 0 ,1 ); $parent = $this->_db->loadObject(); $groupings[] = $parent->category_parent_id; if ($row->ordering != $order[$i]) { $row->ordering = $order[$i]; if (!$row->toggle('ordering',$row->ordering)) { vmError($row->getError()); return false; } } } // execute reorder for each parent group $groupings = array_unique( $groupings ); foreach ($groupings as $group){ $row->reorder($group); } $cache = JFactory::getCache('com_virtuemart_cats','callback'); $cache->clean(); return true; } /** * Retrieve the detail record for the parent category of $categoryd * * @author jseros * * @param int $categoryId Child category id * @return JTable parent category data */ public function getParentCategory( $categoryId = 0 ){ $data = $this->getRelationInfo( $categoryId ); $parentId = isset($data->category_parent_id) ? $data->category_parent_id : 0; $parent = $this->getTable('categories'); $parent->load((int) $parentId); return $parent; } /** * Retrieve category child-parent relation record * * @author jseros * * @param int $virtuemart_category_id * @return object Record of parent relation */ public function getRelationInfo( $virtuemart_category_id = 0 ){ $virtuemart_category_id = (int) $virtuemart_category_id; $query = 'SELECT `category_parent_id`, `ordering` FROM `#__virtuemart_category_categories` WHERE `category_child_id` = '. $this->_db->Quote($virtuemart_category_id); $this->_db->setQuery($query); return $this->_db->loadObject(); } /** * Bind the post data to the category table and save it * * @author jseros, RolandD, Max Milbers * @return int category id stored */ public function store(&$data) { JRequest::checkToken() or jexit( 'Invalid Token, in store category'); $table = $this->getTable('categories'); /* vmdebug('categorytemplate to null',VmConfig::get('categorytemplate'),$data['category_template']); * VmConfig::get('categorytemplate') = default * $data['category_template'] = 0 */ if ( !array_key_exists ('category_template' , $data ) ){ $data['category_template'] = $data['category_layout'] = $data['category_product_layout'] = 0 ; } if(VmConfig::get('categorytemplate') == $data['category_template'] ){ $data['category_template'] = 0; } if(VmConfig::get('categorylayout') == $data['category_layout']){ $data['category_layout'] = 0; } if(VmConfig::get('productlayout') == $data['category_product_layout']){ $data['category_product_layout'] = 0; } // vmdebug('category store ',$data); $table->bindChecknStore($data); $errors = $table->getErrors(); foreach($errors as $error){ vmError($error); } if(!empty($data['virtuemart_category_id'])){ $xdata['category_child_id'] = (int)$data['virtuemart_category_id']; $xdata['category_parent_id'] = empty($data['category_parent_id'])? 0:(int)$data['category_parent_id']; $xdata['ordering'] = empty($data['ordering'])? 0: (int)$data['ordering']; $table = $this->getTable('category_categories'); $table->bindChecknStore($xdata); $errors = $table->getErrors(); foreach($errors as $error){ vmError($error); } } // Process the images $mediaModel = VmModel::getModel('Media'); $file_id = $mediaModel->storeMedia($data,'category'); $errors = $mediaModel->getErrors(); foreach($errors as $error){ vmError($error); } $cache = JFactory::getCache('com_virtuemart_cats','callback'); $cache->clean(); return $data['virtuemart_category_id'] ; } /** * Delete all categories selected * * @author jseros * @param array $cids categories to remove * @return boolean if the item remove was successful */ public function remove($cids) { JRequest::checkToken() or jexit( 'Invalid Token, in remove category'); $table = $this->getTable('categories'); foreach($cids as &$cid) { if (!$table->delete($cid)) { vmError($table->getError()); return false; } $db = JFactory::getDbo(); $q = 'SELECT `virtuemart_customfield_id` FROM `#__virtuemart_product_customfields` as pc '; $q .= 'LEFT JOIN `#__virtuemart_customs`as c using (`virtuemart_custom_id`) WHERE pc.`custom_value` = "' . $cid . '" AND `field_type`= "Z"'; $db->setQuery($q); $list = $db->loadResultArray(); if ($list) { $listInString = implode(',',$list); //Delete media xref $query = 'DELETE FROM `#__virtuemart_product_customfields` WHERE `virtuemart_customfield_id` IN ('. $listInString .') '; $this->_db->setQuery($query); if(!$this->_db->query()){ vmError( $this->_db->getErrorMsg() ); } } } $cidInString = implode(',',$cids); //Delete media xref $query = 'DELETE FROM `#__virtuemart_category_medias` WHERE `virtuemart_category_id` IN ('. $cidInString .') '; $this->_db->setQuery($query); if(!$this->_db->query()){ vmError( $this->_db->getErrorMsg() ); } //deleting product relations $query = 'DELETE FROM `#__virtuemart_product_categories` WHERE `virtuemart_category_id` IN ('. $cidInString .') '; $this->_db->setQuery($query); if(!$this->_db->query()){ vmError( $this->_db->getErrorMsg() ); } //deleting category relations $query = 'DELETE FROM `#__virtuemart_category_categories` WHERE `category_child_id` IN ('. $cidInString .') '; $this->_db->setQuery($query); if(!$this->_db->query()){ vmError( $this->_db->getErrorMsg() ); } //updating parent relations $query = 'UPDATE `#__virtuemart_category_categories` SET `category_parent_id` = 0 WHERE `category_parent_id` IN ('. $cidInString .') '; $this->_db->setQuery($query); if(!$this->_db->query()){ vmError( $this->_db->getErrorMsg() ); } $cache = JFactory::getCache('com_virtuemart_cats','callback'); $cache->clean(); return true; } /** * Checks for children of the category $virtuemart_category_id * * @author RolandD * @param int $virtuemart_category_id the category ID to check * @return boolean true when the category has childs, false when not */ public function hasChildren($virtuemart_category_id) { // vmSetStartTime('hasChildren'); $db = JFactory::getDBO(); $q = "SELECT `category_child_id` FROM `#__virtuemart_category_categories` WHERE `category_parent_id` = ".(int)$virtuemart_category_id; $db->setQuery($q); $db->query(); if ($db->getAffectedRows() > 0){ // vmTime('hasChildren YES','hasChildren'); return true; } else { // vmTime('hasChildren NO','hasChildren'); return false; } } /** * Creates a bulleted of the childen of this category if they exist * * @author RolandD * @todo Add vendor ID * @param int $virtuemart_category_id the category ID to create the list of * @return array containing the child categories */ public function getParentsList($virtuemart_category_id) { $db = JFactory::getDBO(); $menu = JFactory::getApplication()->getMenu(); $parents = array(); if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); } else { $menuItem = $menu->getItem($query['Itemid']); } $menuCatid = (empty($menuItem->query['virtuemart_category_id'])) ? 0 : $menuItem->query['virtuemart_category_id']; if ($menuCatid == $virtuemart_category_id) return ; $parents_id = array_reverse($this->getCategoryRecurse($virtuemart_category_id,$menuCatid)); foreach ($parents_id as $id ) { $q = 'SELECT `category_name`,`virtuemart_category_id` FROM `#__virtuemart_categories_'.VMLANG.'` WHERE `virtuemart_category_id`='.(int)$id; $db->setQuery($q); $parents[] = $db->loadObject(); } return $parents; } var $categoryRecursed = 0; function getCategoryRecurse($virtuemart_category_id,$catMenuId,$first=true ) { static $idsArr = array(); if($first) { $idsArr = array(); $this->categoryRecursed = 0; } else if($this->categoryRecursed>10){ vmWarn('Stopped getCategoryRecurse after 10 rekursions'); return $idsArr; } $db = JFactory::getDBO(); $q = "SELECT `category_child_id` AS `child`, `category_parent_id` AS `parent` FROM `#__virtuemart_category_categories` AS `xref` WHERE `xref`.`category_child_id`= ".(int)$virtuemart_category_id; $db->setQuery($q); if (!$ids = $db->loadObject()) { return $idsArr; } if ($ids->child) $idsArr[] = $ids->child; if($ids->child != 0 and $catMenuId != $virtuemart_category_id and $catMenuId != $ids->parent) { $this->categoryRecursed++; $this->getCategoryRecurse($ids->parent,$catMenuId,false); } return $idsArr; } /** * Stuff of categorydetails */ /* array container for category tree ID*/ var $container = array(); /** * Sorts an array with categories so the order of the categories is the same as in a tree. * * @author jseros * * @param array $this->_category_tree * @return associative array ordering categories * @deprecated */ public function sortCategoryTree($categoryArr){ /** FIRST STEP * Order the Category Array and build a Tree of it **/ $idList = array(); $rowList = array(); $depthList = array(); $children = array(); $parentIds = array(); $parentIdsHash = array(); $parentId = 0; for( $i = 0, $nrows = count($categoryArr); $i < $nrows; $i++ ) { $parentIds[$i] = $categoryArr[$i]->category_parent_id; if($categoryArr[$i]->category_parent_id == 0){ array_push($idList, $categoryArr[$i]->category_child_id); array_push($rowList, $i); array_push($depthList, 0); } $parentId = $parentIds[$i]; if( isset($parentIdsHash[$parentId] )){ $parentIdsHash[$parentId][$categoryArr[$i]->category_child_id] = $i; } else{ $parentIdsHash[$parentId] = array($categoryArr[$i]->category_child_id => $i); } } $loopCount = 0; $watch = array(); // Hash to store children while( count($idList) < $nrows ){ if( $loopCount > $nrows ) break; $idTemp = array(); $rowTemp = array(); $depthTemp = array(); for($i = 0, $cIdlist = count($idList); $i < $cIdlist ; $i++) { $id = $idList[$i]; $row = $rowList[$i]; $depth = $depthList[$i]; array_push($idTemp, $id); array_push($rowTemp, $row); array_push($depthTemp, $depth); $children = @$parentIdsHash[$id]; if( !empty($children) ){ foreach($children as $key => $value) { if( !isset($watch[$id][$key]) ){ $watch[$id][$key] = 1; array_push($idTemp, $key); array_push($rowTemp, $value); array_push($depthTemp, $depth + 1); } } } } $idList = $idTemp; $rowList = $rowTemp; $depthList = $depthTemp; $loopCount++; } return array('id_list' => $idList, 'row_list' => $rowList, 'depth_list' => $depthList, 'categories' => $categoryArr ); } /* * Returns an array of the categories recursively for a given category * @author Kohl Patrick * @param int $id * @param int $maxLevel * @Object $this->container * @deprecated */ function treeCat($id=0,$maxLevel =1000) { static $level = 0; static $num = -1 ; $db = JFactory::getDBO(); $q = 'SELECT `category_child_id`,`category_name` FROM `#__virtuemart_categories_'.VMLANG.'` LEFT JOIN `#__virtuemart_category_categories` on `#__virtuemart_categories`.`virtuemart_category_id`=`#__virtuemart_category_categories`.`category_child_id` WHERE `category_parent_id`='.(int)$id; $db->setQuery($q); $num ++; // if it is a leaf (no data underneath it) then return $childs = $db->loadObjectList(); if ($level==$maxLevel) return; if ($childs) { $level++; foreach ($childs as $child) { $this->container[$num]->id = $child->category_child_id; $this->container[$num]->name = $child->category_name; $this->container[$num]->level = $level; self::treeCat($child->category_child_id,$maxLevel ); } $level--; } } /** * @author Kohl Patrick * @param $maxlevel the number of level * @param $id the root category id * @Object $this->container * @ return categories id, name and level in container * if you set Maxlevel to 0, then you see nothing * max level =1 for simple category,2 for category and child cat .... * don't set it for all (1000 levels) * @deprecated */ function GetTreeCat($id=0,$maxLevel = 1000) { self::treeCat($id ,$maxLevel) ; return $this->container ; } /** * This function is repsonsible for returning an array containing category information * @param boolean Show only published products? * @param string the keyword to filter categories * @deprecated */ function getCategoryTreeArray( $only_published=true, $keyword = "" ) { $db = JFactory::getDBO(); if( empty( $this->_category_tree)) { // Get only published categories $query = "SELECT `virtuemart_category_id`, `category_description`, `category_name`,`category_child_id`, `category_parent_id`,`#__virtuemart_categories`.`ordering`, `published` as category_publish FROM `#__virtuemart_category_categories`, `#__virtuemart_categories_".VMLANG."` as L JOIN `#__virtuemart_categories` using (`virtuemart_category_id`) WHERE "; if( $only_published ) { $query .= "`#__virtuemart_categories`.`published`=1 AND "; } $query .= " L.`virtuemart_category_id`=`#__virtuemart_category_categories`.`category_child_id` "; if( !empty( $keyword ) ) { $keyword = '"%' . $this->_db->getEscaped( $keyword, true ) . '%"' ; //$keyword = $this->_db->Quote($keyword, false); $query .= 'AND ( `category_name` LIKE '.$keyword.' OR `category_description` LIKE '.$keyword.') '; } /* if( !empty( $keyword )) { $query .= "AND ( `category_name` LIKE '%$keyword%' "; $query .= "OR `category_description` LIKE '%$keyword%' "; $query .= ") "; }*/ $query .= " ORDER BY `#__virtuemart_categories`.`ordering` ASC, L.`category_name` ASC"; // initialise the query in the $database connector $db->setQuery($query); // Transfer the Result into a searchable Array $dbCategories = $db->loadAssocList(); //if (!$ids = $db->loadObject()) foreach( $dbCategories as $Cat ) { $this->_category_tree[$Cat['category_child_id']] = $Cat; } } } /** * Sorts an array with categories so the order of the categories is the same as in a tree, just as a flat list. * The Tree Depth is * * @deprecated * @param array $categoryArr */ function sortCategoryTreeArray() { // Copy the Array into an Array with auto_incrementing Indexes $key = array_keys($this->_category_tree); // Array of category table primary keys $nrows = $size = sizeOf($key); // Category count /** FIRST STEP * Order the Category Array and build a Tree of it **/ $id_list = array(); $row_list = array(); $depth_list = array(); $children = array(); $parent_ids = array(); $parent_ids_hash = array(); //Build an array of category references $category_tmp = Array(); for ($i=0; $i<$size; $i++) { $category_tmp[$i] = $this->_category_tree[$key[$i]]; $parent_ids[$i] = $category_tmp[$i]['category_parent_id']; if($category_tmp[$i]["category_parent_id"] == 0) { array_push($id_list,$category_tmp[$i]["category_child_id"]); array_push($row_list,$i); array_push($depth_list,0); } $parent_id = $parent_ids[$i]; if (isset($parent_ids_hash[$parent_id])) { $parent_ids_hash[$parent_id][$i] = $parent_id; } else { $parent_ids_hash[$parent_id] = array($i => $parent_id); } } $loop_count = 0; $watch = array(); // Hash to store children while(count($id_list) < $nrows) { if( $loop_count > $nrows ) break; $id_temp = array(); $row_temp = array(); $depth_temp = array(); for($i = 0 ; $i < count($id_list) ; $i++) { $id = $id_list[$i]; $row = $row_list[$i]; $depth = $depth_list[$i]; array_push($id_temp,$id); array_push($row_temp,$row); array_push($depth_temp,$depth); $children = @$parent_ids_hash[$id]; if (!empty($children)) { foreach($children as $key => $value) { if( !isset($watch[$id][$category_tmp[$key]["category_child_id"]])) { $watch[$id][$category_tmp[$key]["category_child_id"]] = 1; array_push($id_temp,$category_tmp[$key]["category_child_id"]); array_push($row_temp,$key); array_push($depth_temp,$depth + 1); } } } } $id_list = $id_temp; $row_list = $row_temp; $depth_list = $depth_temp; $loop_count++; } return array('id_list' => $id_list, 'row_list' => $row_list, 'depth_list' => $depth_list, 'category_tmp' => $category_tmp); } }home/academiac/www/administrator/components/com_virtuemart/controllers/category.php000060400000011046151372431140025207 0ustar00authorise('vm.category.edit', 'com_virtuemart')) { JFactory::getApplication()->redirect( 'index.php?option=com_virtuemart', JText::_('JERROR_ALERTNOAUTHOR'), 'error'); } $data = JRequest::get('post'); $data['category_name'] = JRequest::getVar('category_name','','post','STRING',JREQUEST_ALLOWHTML); $data['category_description'] = JRequest::getVar('category_description','','post','STRING',JREQUEST_ALLOWHTML); parent::save($data); } /** * Save the category order * * @author jseros */ public function orderUp() { //ACL if (!JFactory::getUser()->authorise('vm.category.edit', 'com_virtuemart')) { JFactory::getApplication()->redirect( 'index.php?option=com_virtuemart', JText::_('JERROR_ALERTNOAUTHOR'), 'error'); } // Check token JRequest::checkToken() or jexit( 'Invalid Token' ); //capturing virtuemart_category_id $id = 0; $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); if (isset($cid[0]) && $cid[0]) { $id = $cid[0]; } else { $this->setRedirect( 'index.php?option=com_virtuemart&view=category', JText::_('COM_VIRTUEMART_NO_ITEMS_SELECTED') ); return false; } //getting the model $model = VmModel::getModel('category'); if ($model->orderCategory($id, -1)) { $msg = JText::_('COM_VIRTUEMART_ITEM_MOVED_UP'); } else { $msg = $model->getError(); } $this->setRedirect( 'index.php?option=com_virtuemart&view=category', $msg ); } /** * Save the category order * * @author jseros */ public function orderDown() { //ACL if (!JFactory::getUser()->authorise('vm.category.edit', 'com_virtuemart')) { JFactory::getApplication()->redirect( 'index.php?option=com_virtuemart', JText::_('JERROR_ALERTNOAUTHOR'), 'error'); } // Check token JRequest::checkToken() or jexit( 'Invalid Token' ); //capturing virtuemart_category_id $id = 0; $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); if (isset($cid[0]) && $cid[0]) { $id = $cid[0]; } else { $this->setRedirect( 'index.php?option=com_virtuemart&view=category', JText::_('COM_VIRTUEMART_NO_ITEMS_SELECTED') ); return false; } //getting the model $model = VmModel::getModel('category'); if ($model->orderCategory($id, 1)) { $msg = JText::_('COM_VIRTUEMART_ITEM_MOVED_DOWN'); } else { $msg = $model->getError(); } $this->setRedirect( 'index.php?option=com_virtuemart&view=category', $msg ); } /** * Save the categories order */ public function saveOrder() { //ACL if (!JFactory::getUser()->authorise('vm.category.edit', 'com_virtuemart')) { JFactory::getApplication()->redirect( 'index.php?option=com_virtuemart', JText::_('JERROR_ALERTNOAUTHOR'), 'error'); } // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); //is sanitized JArrayHelper::toInteger($cid); $model = VmModel::getModel('category'); $order = JRequest::getVar('order', array(), 'post', 'array'); JArrayHelper::toInteger($order); if ($model->setOrder($cid,$order)) { $msg = JText::_('COM_VIRTUEMART_NEW_ORDERING_SAVED'); } else { $msg = $model->getError(); } $this->setRedirect('index.php?option=com_virtuemart&view=category', $msg ); } } home/academiac/www/libraries/joomla/html/html/category.php000064400000010052151372603700017704 0ustar00 array(0, 1))) { $hash = md5($extension . '.' . serialize($config)); if (!isset(self::$items[$hash])) { $config = (array) $config; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.title, a.level'); $query->from('#__categories AS a'); $query->where('a.parent_id > 0'); // Filter on extension. $query->where('extension = ' . $db->quote($extension)); // Filter on the published state if (isset($config['filter.published'])) { if (is_numeric($config['filter.published'])) { $query->where('a.published = ' . (int) $config['filter.published']); } elseif (is_array($config['filter.published'])) { JArrayHelper::toInteger($config['filter.published']); $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')'); } } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Assemble the list options. self::$items[$hash] = array(); foreach ($items as &$item) { $repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0; $item->title = str_repeat('- ', $repeat) . $item->title; self::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title); } } return self::$items[$hash]; } /** * Returns an array of categories for the given extension. * * @param string $extension The extension option. * @param array $config An array of configuration options. By default, only published and unpublished categories are returned. * * @return array Categories for the extension * * @since 11.1 */ public static function categories($extension, $config = array('filter.published' => array(0, 1))) { $hash = md5($extension . '.' . serialize($config)); if (!isset(self::$items[$hash])) { $config = (array) $config; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.title, a.level, a.parent_id'); $query->from('#__categories AS a'); $query->where('a.parent_id > 0'); // Filter on extension. $query->where('extension = ' . $db->quote($extension)); // Filter on the published state if (isset($config['filter.published'])) { if (is_numeric($config['filter.published'])) { $query->where('a.published = ' . (int) $config['filter.published']); } elseif (is_array($config['filter.published'])) { JArrayHelper::toInteger($config['filter.published']); $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')'); } } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Assemble the list options. self::$items[$hash] = array(); foreach ($items as &$item) { $repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0; $item->title = str_repeat('- ', $repeat) . $item->title; self::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title); } // Special "Add to root" option: self::$items[$hash][] = JHtml::_('select.option', '1', JText::_('JLIB_HTML_ADD_TO_ROOT')); } return self::$items[$hash]; } } home/academiac/www/libraries/joomla/html/parameter/element/category.php000064400000003366151372624040022363 0ustar00attributes('extension'); $class = $node->attributes('class'); $filter = explode(',', $node->attributes('filter')); if (!isset($extension)) { // Alias for extension $extension = $node->attributes('scope'); if (!isset($extension)) { $extension = 'com_content'; } } if (!$class) { $class = "inputbox"; } if (count($filter) < 1) { $filter = null; } return JHtml::_( 'list.category', $control_name . '[' . $name . ']', $extension, $extension . '.view', $filter, (int) $value, $class, null, 1, $control_name . $name ); } } home/academiac/www/libraries/joomla/database/table/category.php000064400000012537151372717450020651 0ustar00access = (int) JFactory::getConfig()->get('access'); } /** * Method to compute the default name of the asset. * The default name is in the form table_name.id * where id is the value of the primary key of the table. * * @return string * * @since 11.1 */ protected function _getAssetName() { $k = $this->_tbl_key; return $this->extension . '.category.' . (int) $this->$k; } /** * Method to return the title to use for the asset table. * * @return string * * @since 11.1 */ protected function _getAssetTitle() { return $this->title; } /** * Get the parent asset id for the record * * @param JTable $table A JTable object for the asset parent. * @param integer $id The id for the asset * * @return integer The id of the asset's parent * * @since 11.1 */ protected function _getAssetParentId($table = null, $id = null) { // Initialise variables. $assetId = null; // This is a category under a category. if ($this->parent_id > 1) { // Build the query to get the asset id for the parent category. $query = $this->_db->getQuery(true); $query->select($this->_db->quoteName('asset_id')); $query->from($this->_db->quoteName('#__categories')); $query->where($this->_db->quoteName('id') . ' = ' . $this->parent_id); // Get the asset id from the database. $this->_db->setQuery($query); if ($result = $this->_db->loadResult()) { $assetId = (int) $result; } } // This is a category that needs to parent with the extension. elseif ($assetId === null) { // Build the query to get the asset id for the parent category. $query = $this->_db->getQuery(true); $query->select($this->_db->quoteName('id')); $query->from($this->_db->quoteName('#__assets')); $query->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote($this->extension)); // Get the asset id from the database. $this->_db->setQuery($query); if ($result = $this->_db->loadResult()) { $assetId = (int) $result; } } // Return the asset id. if ($assetId) { return $assetId; } else { return parent::_getAssetParentId($table, $id); } } /** * Override check function * * @return boolean * * @see JTable::check * @since 11.1 */ public function check() { // Check for a title. if (trim($this->title) == '') { $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_CATEGORY')); return false; } $this->alias = trim($this->alias); if (empty($this->alias)) { $this->alias = $this->title; } $this->alias = JApplication::stringURLSafe($this->alias); if (trim(str_replace('-', '', $this->alias)) == '') { $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s'); } return true; } /** * Overloaded bind function. * * @param array $array named array * @param string $ignore An optional array or space separated list of properties * to ignore while binding. * * @return mixed Null if operation was satisfactory, otherwise returns an error * * @see JTable::bind * @since 11.1 */ public function bind($array, $ignore = '') { if (isset($array['params']) && is_array($array['params'])) { $registry = new JRegistry; $registry->loadArray($array['params']); $array['params'] = (string) $registry; } if (isset($array['metadata']) && is_array($array['metadata'])) { $registry = new JRegistry; $registry->loadArray($array['metadata']); $array['metadata'] = (string) $registry; } // Bind the rules. if (isset($array['rules']) && is_array($array['rules'])) { $rules = new JAccessRules($array['rules']); $this->setRules($rules); } return parent::bind($array, $ignore); } /** * Overridden JTable::store to set created/modified and user id. * * @param boolean $updateNulls True to update fields even if they are null. * * @return boolean True on success. * * @since 11.1 */ public function store($updateNulls = false) { $date = JFactory::getDate(); $user = JFactory::getUser(); if ($this->id) { // Existing category $this->modified_time = $date->toSql(); $this->modified_user_id = $user->get('id'); } else { // New category $this->created_time = $date->toSql(); $this->created_user_id = $user->get('id'); } // Verify that the alias is unique $table = JTable::getInstance('Category', 'JTable', array('dbo' => $this->getDbo())); if ($table->load(array('alias' => $this->alias, 'parent_id' => $this->parent_id, 'extension' => $this->extension)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('JLIB_DATABASE_ERROR_CATEGORY_UNIQUE_ALIAS')); return false; } return parent::store($updateNulls); } } home/academiac/www/administrator/components/com_virtuemart/models/fields/category.php000060400000003606151372770550025410 0ustar00element['key_field'] ? $this->element['key_field'] : 'value'); $val = ($this->element['value_field'] ? $this->element['value_field'] : $this->name); VmConfig::loadJLang('com_virtuemart'); $categorylist = ShopFunctions::categoryListTree(array($this->value)); $html = '"; return $html; } }home/academiac/www/administrator/components/com_categories/tables/category.php000064400000001766151373623510024057 0ustar00extension)) { $this->extension = JRequest::getCmd('extension', 'com_content'); } } /** * Method to check if you can add a new record. * * @param array $data An array of input data. * * @return boolean * * @since 1.6 */ protected function allowAdd($data = array()) { $user = JFactory::getUser(); return ($user->authorise('core.create', $this->extension) || count($user->getAuthorisedCategories($this->extension, 'core.create'))); } /** * Method to check if you can edit a record. * * @param array $data An array of input data. * @param string $key The name of the key for the primary key. * * @return boolean * * @since 1.6 */ protected function allowEdit($data = array(), $key = 'parent_id') { // Initialise variables. $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $user = JFactory::getUser(); $userId = $user->get('id'); // Check general edit permission first. if ($user->authorise('core.edit', $this->extension)) { return true; } // Check specific edit permission. if ($user->authorise('core.edit', $this->extension . '.category.' . $recordId)) { return true; } // Fallback on edit.own. // First test if the permission is available. if ($user->authorise('core.edit.own', $this->extension . '.category.' . $recordId) || $user->authorise('core.edit.own', $this->extension)) { // Now test the owner is the user. $ownerId = (int) isset($data['created_user_id']) ? $data['created_user_id'] : 0; if (empty($ownerId) && $recordId) { // Need to do a lookup from the model. $record = $this->getModel()->getItem($recordId); if (empty($record)) { return false; } $ownerId = $record->created_user_id; } // If the owner matches 'me' then do the test. if ($ownerId == $userId) { return true; } } return false; } /** * Method to run batch operations. * * @param object $model The model. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 1.6 */ public function batch($model = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Set the model $model = $this->getModel('Category'); // Preset the redirect $this->setRedirect('index.php?option=com_categories&view=categories&extension=' . $this->extension); return parent::batch($model); } /** * Gets the URL arguments to append to an item redirect. * * @param integer $recordId The primary key id for the item. * @param string $urlVar The name of the URL variable for the id. * * @return string The arguments to append to the redirect URL. * * @since 1.6 */ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') { $append = parent::getRedirectToItemAppend($recordId); $append .= '&extension=' . $this->extension; return $append; } /** * Gets the URL arguments to append to a list redirect. * * @return string The arguments to append to the redirect URL. * * @since 1.6 */ protected function getRedirectToListAppend() { $append = parent::getRedirectToListAppend(); $append .= '&extension=' . $this->extension; return $append; } }