0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: category.php.tar
home/academiac/www/administrator/components/com_virtuemart/models/category.php 0000604 00000071437 15137217446 0024147 0 ustar 00 <?php /** * * Category Model * * @package VirtueMart * @subpackage Category * @author jseros, RickG * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id: category.php 6396 2012-09-05 17:35:36Z Milbo $ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); if(!class_exists('VmModel'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmmodel.php'); /** * Model for product categories * @author jseros */ class VirtueMartModelCategory extends VmModel { private $_category_tree; public $_cleanCache = true ; static $_validOrderingFields = array('category_name','category_description','c.ordering','c.category_shared','c.published'); /** * constructs a VmModel * setMainTable defines the maintable of the model * @author Max Milbers */ function __construct() { parent::__construct(); $this->setMainTable('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.php 0000604 00000011046 15137243114 0025207 0 ustar 00 <?php /** * * Category controller * * @package VirtueMart * @subpackage Category * @author RickG, jseros * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id: category.php 6071 2012-06-06 15:33:04Z Milbo $ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); // Load the controller framework jimport('joomla.application.component.controller'); if(!class_exists('VmController'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmcontroller.php'); /** * Category Controller * * @package VirtueMart * @subpackage Category * @author jseros, Max Milbers */ class VirtuemartControllerCategory extends VmController { public function __construct() { parent::__construct(); } /** * We want to allow html so we need to overwrite some request data * * @author Max Milbers */ function save($data = 0){ //ACL if (!JFactory::getUser()->authorise('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.php 0000644 00000010052 15137260370 0017704 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage HTML * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; /** * Utility class for categories * * @package Joomla.Platform * @subpackage HTML * @since 11.1 */ abstract class JHtmlCategory { /** * Cached array of the category items. * * @var array * @since 11.1 */ protected static $items = array(); /** * Returns an array of categories for the given extension. * * @param string $extension The extension option e.g. com_something. * @param array $config An array of configuration options. By default, only * published and unpublished categories are returned. * * @return array * * @since 11.1 */ public static function options($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'); $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.php 0000644 00000003366 15137262404 0022363 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage HTML * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; /** * Renders a category element * * @package Joomla.Platform * @subpackage Parameter * @since 11.1 * @deprecated Use JFormFieldCategory instead. */ class JElementCategory extends JElement { /** * Element name * * @var string */ protected $_name = 'Category'; /** * Fetch the element * * @param string $name Element name * @param string $value Element value * @param JXMLElement &$node JXMLElement node object containing the settings for the element * @param string $control_name Control name * * @return string * * @since 11.1 * @deprecated 12.1 */ public function fetchElement($name, $value, &$node, $control_name) { // Deprecation warning. JLog::add('JElementCategory::fetchElement() is deprecated.', JLog::WARNING, 'deprecated'); $db = JFactory::getDbo(); $extension = $node->attributes('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.php 0000644 00000012537 15137271745 0020651 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Database * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.database.tablenested'); /** * Category table * * @package Joomla.Platform * @subpackage Table * @since 11.1 */ class JTableCategory extends JTableNested { /** * Constructor * * @param JDatabase &$db A database connector object * * @since 11.1 */ public function __construct(&$db) { parent::__construct('#__categories', 'id', $db); $this->access = (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.php 0000604 00000003606 15137277055 0025410 0 ustar 00 <?php /** * * @package VirtueMart * @subpackage Models Fields * @author Valérie Isaksen * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2011 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id: $ */ defined('JPATH_BASE') or die; if (!class_exists('VmConfig')) require(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php'); if (!class_exists('ShopFunctions')) require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php'); if (!class_exists('TableCategories')) require(JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'categories.php'); jimport('joomla.form.formfield'); /** * Supports a modal product picker. * * */ class JFormFieldCategory extends JFormField { protected $type = 'category'; /** * Method to get the field input markup. * * @author Valerie Cartan Isaksen * @return string The field input markup. * @since 1.6 */ function getInput() { $key = ($this->element['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 = '<select class="inputbox" name="' . $this->name . '" >'; $html .= '<option value="0">' . JText::_('COM_VIRTUEMART_CATEGORY_FORM_TOP_LEVEL') . '</option>'; $html .= $categorylist; $html .="</select>"; return $html; } } home/academiac/www/administrator/components/com_categories/tables/category.php 0000644 00000001766 15137362351 0024057 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_categories * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; // Import JTableCategory JLoader::register('JTableCategory', JPATH_PLATFORM . '/joomla/database/table/category.php'); /** * @package Joomla.Administrator * @subpackage com_categories */ class CategoriesTableCategory extends JTableCategory { /** * Method to delete a node and, optionally, its child nodes from the table. * * @param integer $pk The primary key of the node to delete. * @param boolean $children True to delete child nodes, false to move them up a level. * * @return boolean True on success. * * @see http://docs.joomla.org/JTableNested/delete * @since 2.5 */ public function delete($pk = null, $children = false) { return parent::delete($pk, $children); } } home/academiac/www/administrator/components/com_categories/controllers/category.php 0000644 00000010210 15137364713 0025137 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_categories * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.component.controllerform'); /** * The Category Controller * * @package Joomla.Administrator * @subpackage com_categories * @since 1.6 */ class CategoriesControllerCategory extends JControllerForm { /** * The extension for which the categories apply. * * @var string * @since 1.6 */ protected $extension; /** * Constructor. * * @param array $config An optional associative array of configuration settings. * * @since 1.6 * @see JController */ public function __construct($config = array()) { parent::__construct($config); // Guess the JText message prefix. Defaults to the option. if (empty($this->extension)) { $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; } } home/academiac/www/components/com_contact/models/category.php 0000644 00000022446 15137424023 0020507 0 ustar 00 <?php /** bv * @package Joomla.Site * @subpackage com_contact * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modellist'); /** * @package Joomla.Site * @subpackage com_contact */ class ContactModelCategory extends JModelList { /** * Category items data * * @var array */ protected $_item = null; protected $_articles = null; protected $_siblings = null; protected $_children = null; protected $_parent = null; /** * The category that applies. * * @access protected * @var object */ protected $_category = null; /** * The list of other newfeed categories. * * @access protected * @var array */ protected $_categories = null; /** * Constructor. * * @param array An optional associative array of configuration settings. * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( 'id', 'a.id', 'name', 'a.name', 'con_position', 'a.con_position', 'suburb', 'a.suburb', 'state', 'a.state', 'country', 'a.country', 'ordering', 'a.ordering', 'sortname', 'sortname1', 'a.sortname1', 'sortname2', 'a.sortname2', 'sortname3', 'a.sortname3' ); } parent::__construct($config); } /** * Method to get a list of items. * * @return mixed An array of objects on success, false on failure. */ public function getItems() { // Invoke the parent getItems method to get the main list $items = parent::getItems(); // Convert the params field into an object, saving original in _params for ($i = 0, $n = count($items); $i < $n; $i++) { $item = &$items[$i]; if (!isset($this->_params)) { $params = new JRegistry(); $params->loadString($item->params); $item->params = $params; } } return $items; } /** * Method to build an SQL query to load the list data. * * @return string An SQL query * @since 1.6 */ protected function getListQuery() { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select required fields from the categories. //sqlsrv changes $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id.' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('c.alias'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id.' END as catslug'; $query->select($this->getState('list.select', 'a.*') . ','.$case_when.','.$case_when1); // . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' // . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug '); $query->from($db->quoteName('#__contact_details').' AS a'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); $query->where('a.access IN ('.$groups.')'); // Filter by category. if ($categoryId = $this->getState('category.id')) { $query->where('a.catid = '.(int) $categoryId); $query->where('c.access IN ('.$groups.')'); } // Join over the users for the author and modified_by names. $query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author"); $query->select("ua.email AS author_email"); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); $query->join('LEFT', '#__users AS uam ON uam.id = a.modified_by'); // Filter by state $state = $this->getState('filter.published'); if (is_numeric($state)) { $query->where('a.published = '.(int) $state); } // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(JFactory::getDate()->toSql()); if ($this->getState('filter.publish_date')){ $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } // Filter by language if ($this->getState('filter.language')) { $query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')'); } // Set sortname ordering if selected if ($this->getState('list.ordering') == 'sortname') { $query->order($db->escape('a.sortname1').' '.$db->escape($this->getState('list.direction', 'ASC'))); $query->order($db->escape('a.sortname2').' '.$db->escape($this->getState('list.direction', 'ASC'))); $query->order($db->escape('a.sortname3').' '.$db->escape($this->getState('list.direction', 'ASC'))); } else { $query->order($db->escape($this->getState('list.ordering', 'a.ordering')).' '.$db->escape($this->getState('list.direction', 'ASC'))); } return $query; } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState($ordering = null, $direction = null) { // Initialise variables. $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_contact'); $db = $this->getDbo(); // List state information $format = JRequest::getWord('format'); if ($format=='feed') { $limit = $app->getCfg('feed_limit'); } else { $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'uint'); } $this->setState('list.limit', $limit); $limitstart = JRequest::getUInt('limitstart', 0); $this->setState('list.start', $limitstart); // Get list ordering default from the parameters $menuParams = new JRegistry(); if ($menu = $app->getMenu()->getActive()) { $menuParams->loadString($menu->params); } $mergedParams = clone $params; $mergedParams->merge($menuParams); $orderCol = JRequest::getCmd('filter_order', $mergedParams->get('initial_sort', 'ordering')); if (!in_array($orderCol, $this->filter_fields)) { $orderCol = 'ordering'; } $this->setState('list.ordering', $orderCol); $listOrder = JRequest::getCmd('filter_order_Dir', 'ASC'); if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { $listOrder = 'ASC'; } $this->setState('list.direction', $listOrder); $id = JRequest::getVar('id', 0, '', 'int'); $this->setState('category.id', $id); $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))){ // limit to published for people who can't edit or edit.state. $this->setState('filter.published', 1); // Filter by start and end dates. $this->setState('filter.publish_date', true); } $this->setState('filter.language', $app->getLanguageFilter()); // Load the parameters. $this->setState('params', $params); } /** * Method to get category data for the current category * * @param int An optional ID * * @return object * @since 1.5 */ public function getCategory() { if(!is_object($this->_item)) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); $params = new JRegistry(); if($active) { $params->loadString($active->params); } $options = array(); $options['countItems'] = $params->get('show_cat_items', 1) || $params->get('show_empty_categories', 0); $categories = JCategories::getInstance('Contact', $options); $this->_item = $categories->get($this->getState('category.id', 'root')); if(is_object($this->_item)) { $this->_children = $this->_item->getChildren(); $this->_parent = false; if($this->_item->getParent()) { $this->_parent = $this->_item->getParent(); } $this->_rightsibling = $this->_item->getSibling(); $this->_leftsibling = $this->_item->getSibling(false); } else { $this->_children = false; $this->_parent = false; } } return $this->_item; } /** * Get the parent category. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. */ public function getParent() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_parent; } /** * Get the sibling (adjacent) categories. * * @return mixed An array of categories or false if an error occurs. */ function &getLeftSibling() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_leftsibling; } function &getRightSibling() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_rightsibling; } /** * Get the child categories. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. */ function &getChildren() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_children; } } home/academiac/www/components/com_virtuemart/controllers/category.php 0000604 00000004012 15137425147 0022332 0 ustar 00 <?php /** * * Description * * @package VirtueMart * @subpackage * @author RolandD * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id: category.php 6383 2012-08-27 16:53:06Z alatak $ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); // Load the controller framework jimport('joomla.application.component.controller'); /** * Class Description * * @package VirtueMart * @author RolandD */ class VirtueMartControllerCategory extends JController { /** * Method Description * * @access public * @author RolandD */ public function __construct() { parent::__construct(); $this->registerTask('browse','category'); } /** * Function Description * * @author RolandD * @author George * @access public */ public function display($cachable = false, $urlparams = false) { if (JRequest::getvar('search')) { $view = $this->getView('category', 'html'); $view->display(); } else { // Display it all $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->default_view); $viewLayout = JRequest::getCmd('layout', 'default'); $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout)); $view->assignRef('document', $document); $view->display(); } if($categoryId = JRequest::getInt('virtuemart_category_id',0)){ shopFunctionsF::setLastVisitedCategoryId($categoryId); } return $this; } } // pure php no closing tag home/academiac/www/administrator/components/com_categories/models/category.php 0000644 00000056240 15137441621 0024063 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_categories * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access. defined('_JEXEC') or die; jimport('joomla.application.component.modeladmin'); /** * Categories Component Category Model * * @package Joomla.Administrator * @subpackage com_categories * @since 1.6 */ class CategoriesModelCategory extends JModelAdmin { /** * @var string The prefix to use with controller messages. * @since 1.6 */ protected $text_prefix = 'COM_CATEGORIES'; /** * Method to test whether a record can be deleted. * * @param object $record A record object. * * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. * * @since 1.6 */ protected function canDelete($record) { if (!empty($record->id)) { if ($record->published != -2) { return; } $user = JFactory::getUser(); return $user->authorise('core.delete', $record->extension . '.category.' . (int) $record->id); } } /** * Method to test whether a record can have its state changed. * * @param object $record A record object. * * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. * * @since 1.6 */ protected function canEditState($record) { $user = JFactory::getUser(); // Check for existing category. if (!empty($record->id)) { return $user->authorise('core.edit.state', $record->extension . '.category.' . (int) $record->id); } // New category, so check against the parent. elseif (!empty($record->parent_id)) { return $user->authorise('core.edit.state', $record->extension . '.category.' . (int) $record->parent_id); } // Default to component settings if neither category nor parent known. else { return $user->authorise('core.edit.state', $record->extension); } } /** * Method to get a table object, load it if necessary. * * @param string $type The table name. Optional. * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * * @return JTable A JTable object * * @since 1.6 */ public function getTable($type = 'Category', $prefix = 'CategoriesTable', $config = array()) { return JTable::getInstance($type, $prefix, $config); } /** * Auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication('administrator'); $parentId = JRequest::getInt('parent_id'); $this->setState('category.parent_id', $parentId); // Load the User state. $pk = (int) JRequest::getInt('id'); $this->setState($this->getName() . '.id', $pk); $extension = JRequest::getCmd('extension', 'com_content'); $this->setState('category.extension', $extension); $parts = explode('.', $extension); // Extract the component name $this->setState('category.component', $parts[0]); // Extract the optional section name $this->setState('category.section', (count($parts) > 1) ? $parts[1] : null); // Load the parameters. $params = JComponentHelper::getParams('com_categories'); $this->setState('params', $params); } /** * Method to get a category. * * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used. * * @return mixed Category data object on success, false on failure. * * @since 1.6 */ public function getItem($pk = null) { if ($result = parent::getItem($pk)) { // Prime required properties. if (empty($result->id)) { $result->parent_id = $this->getState('category.parent_id'); $result->extension = $this->getState('category.extension'); } // Convert the metadata field to an array. $registry = new JRegistry(); $registry->loadString($result->metadata); $result->metadata = $registry->toArray(); // Convert the created and modified dates to local user time for display in the form. jimport('joomla.utilities.date'); $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); if (intval($result->created_time)) { $date = new JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); } else { $result->created_time = null; } if (intval($result->modified_time)) { $date = new JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); } else { $result->modified_time = null; } } return $result; } /** * Method to get the row form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return mixed A JForm object on success, false on failure * * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Initialise variables. $extension = $this->getState('category.extension'); $jinput = JFactory::getApplication()->input; // A workaround to get the extension into the model for save requests. if (empty($extension) && isset($data['extension'])) { $extension = $data['extension']; $parts = explode('.', $extension); $this->setState('category.extension', $extension); $this->setState('category.component', $parts[0]); $this->setState('category.section', @$parts[1]); } // Get the form. $form = $this->loadForm('com_categories.category' . $extension, 'category', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Modify the form based on Edit State access controls. if (empty($data['extension'])) { $data['extension'] = $extension; } $user = JFactory::getUser(); if (!$user->authorise('core.edit.state', $extension . '.category.' . $jinput->get('id'))) { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('published', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is a record you can edit. $form->setFieldAttribute('ordering', 'filter', 'unset'); $form->setFieldAttribute('published', 'filter', 'unset'); } return $form; } /** * A protected method to get the where clause for the reorder * This ensures that the row will be moved relative to a row with the same extension * * @param JCategoryTable $table Current table instance * * @return array An array of conditions to add to add to ordering queries. * * @since 1.6 */ protected function getReorderConditions($table) { return 'extension = ' . $this->_db->Quote($table->extension); } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_categories.edit.' . $this->getName() . '.data', array()); if (empty($data)) { $data = $this->getItem(); } return $data; } /** * Method to preprocess the form. * * @param JForm $form A JForm object. * @param mixed $data The data expected for the form. * @param string $groups The name of the plugin group to import. * * @return void * * @see JFormField * @since 1.6 * @throws Exception if there is an error in the form event. */ protected function preprocessForm(JForm $form, $data, $group = 'content') { jimport('joomla.filesystem.path'); // Initialise variables. $lang = JFactory::getLanguage(); $extension = $this->getState('category.extension'); $component = $this->getState('category.component'); $section = $this->getState('category.section'); // Get the component form if it exists jimport('joomla.filesystem.path'); $name = 'category' . ($section ? ('.' . $section) : ''); // Looking first in the component models/forms folder $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/models/forms/$name.xml"); // Old way: looking in the component folder if (!file_exists($path)) { $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/$name.xml"); } if (file_exists($path)) { $lang->load($component, JPATH_BASE, null, false, true); $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, true); if (!$form->loadFile($path, false)) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } } // Try to find the component helper. $eName = str_replace('com_', '', $component); $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/helpers/category.php"); if (file_exists($path)) { require_once $path; $cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory'; if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) { $lang->load($component, JPATH_BASE, null, false, true) || $lang->load($component, JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component), null, false, true); call_user_func_array(array($cName, 'onPrepareForm'), array(&$form)); // Check for an error. if ($form instanceof Exception) { $this->setError($form->getMessage()); return false; } } } // Set the access control rules field component value. $form->setFieldAttribute('rules', 'component', $component); $form->setFieldAttribute('rules', 'section', $name); // Trigger the default form events. parent::preprocessForm($form, $data, $group); } /** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { // Initialise variables; $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState($this->getName() . '.id'); $isNew = true; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); // Load the row if saving an existing category. if ($pk > 0) { $table->load($pk); $isNew = false; } // Set the new parent id if parent id not matched OR while New/Save as Copy . if ($table->parent_id != $data['parent_id'] || $data['id'] == 0) { $table->setLocation($data['parent_id'], 'last-child'); } // Alter the title for save as copy if (JRequest::getVar('task') == 'save2copy') { list($title, $alias) = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Bind the rules. if (isset($data['rules'])) { $rules = new JAccessRules($data['rules']); $table->setRules($rules); } // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // Trigger the onContentAfterSave event. $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew)); // Rebuild the path for the category: if (!$table->rebuildPath($table->id)) { $this->setError($table->getError()); return false; } // Rebuild the paths of the category's children: if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path)) { $this->setError($table->getError()); return false; } $this->setState($this->getName() . '.id', $table->id); // Clear the cache $this->cleanCache(); return true; } /** * Method to change the published state of one or more records. * * @param array $pks A list of the primary keys to change. * @param integer $value The value of the published state. * * @return boolean True on success. * * @since 2.5 */ function publish(&$pks, $value = 1) { if (parent::publish($pks, $value)) { // Initialise variables. $dispatcher = JDispatcher::getInstance(); $extension = JRequest::getCmd('extension'); // Include the content plugins for the change of category state event. JPluginHelper::importPlugin('content'); // Trigger the onCategoryChangeState event. $dispatcher->trigger('onCategoryChangeState', array($extension, $pks, $value)); return true; } } /** * Method rebuild the entire nested set tree. * * @return boolean False on failure or error, true otherwise. * * @since 1.6 */ public function rebuild() { // Get an instance of the table object. $table = $this->getTable(); if (!$table->rebuild()) { $this->setError($table->getError()); return false; } // Clear the cache $this->cleanCache(); return true; } /** * Method to save the reordered nested set tree. * First we save the new order values in the lft values of the changed ids. * Then we invoke the table rebuild to implement the new ordering. * * @param array $idArray An array of primary key ids. * @param integer $lft_array The lft value * * @return boolean False on failure or error, True otherwise * * @since 1.6 */ public function saveorder($idArray = null, $lft_array = null) { // Get an instance of the table object. $table = $this->getTable(); if (!$table->saveorder($idArray, $lft_array)) { $this->setError($table->getError()); return false; } // Clear the cache $this->cleanCache(); return true; } /** * Batch copy categories to a new category. * * @param integer $value The new category. * @param array $pks An array of row IDs. * @param array $contexts An array of item contexts. * * @return mixed An array of new IDs on success, boolean false on failure. * * @since 1.6 */ protected function batchCopy($value, $pks, $contexts) { // $value comes as {parent_id}.{extension} $parts = explode('.', $value); $parentId = (int) JArrayHelper::getValue($parts, 0, 1); $table = $this->getTable(); $db = $this->getDbo(); $user = JFactory::getUser(); $extension = JFactory::getApplication()->input->get('extension', '', 'word'); $i = 0; // Check that the parent exists if ($parentId) { if (!$table->load($parentId)) { if ($error = $table->getError()) { // Fatal error $this->setError($error); return false; } else { // Non-fatal error $this->setError(JText::_('JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND')); $parentId = 0; } } // Check that user has create permission for parent category $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : $user->authorise('core.create', $extension . '.category.' . $parentId); if (!$canCreate) { // Error since user cannot create in parent category $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; } } // If the parent is 0, set it to the ID of the root item in the tree if (empty($parentId)) { if (!$parentId = $table->getRootId()) { $this->setError($db->getErrorMsg()); return false; } // Make sure we can create in root elseif (!$user->authorise('core.create', $extension)) { $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; } } // We need to log the parent ID $parents = array(); // Calculate the emergency stop count as a precaution against a runaway loop bug $query = $db->getQuery(true); $query->select('COUNT(id)'); $query->from($db->quoteName('#__categories')); $db->setQuery($query); $count = $db->loadResult(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } // Parent exists so we let's proceed while (!empty($pks) && $count > 0) { // Pop the first id off the stack $pk = array_shift($pks); $table->reset(); // Check that the row actually exists if (!$table->load($pk)) { if ($error = $table->getError()) { // Fatal error $this->setError($error); return false; } else { // Not fatal error $this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk)); continue; } } // Copy is a bit tricky, because we also need to copy the children $query->clear(); $query->select('id'); $query->from($db->quoteName('#__categories')); $query->where('lft > ' . (int) $table->lft); $query->where('rgt < ' . (int) $table->rgt); $db->setQuery($query); $childIds = $db->loadColumn(); // Add child ID's to the array only if they aren't already there. foreach ($childIds as $childId) { if (!in_array($childId, $pks)) { array_push($pks, $childId); } } // Make a copy of the old ID and Parent ID $oldId = $table->id; $oldParentId = $table->parent_id; // Reset the id because we are making a copy. $table->id = 0; // If we a copying children, the Old ID will turn up in the parents list // otherwise it's a new top level item $table->parent_id = isset($parents[$oldParentId]) ? $parents[$oldParentId] : $parentId; // Set the new location in the tree for the node. $table->setLocation($table->parent_id, 'last-child'); // TODO: Deal with ordering? //$table->ordering = 1; $table->level = null; $table->asset_id = null; $table->lft = null; $table->rgt = null; // Alter the title & alias list($title, $alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title); $table->title = $title; $table->alias = $alias; // Store the row. if (!$table->store()) { $this->setError($table->getError()); return false; } // Get the new item ID $newId = $table->get('id'); // Add the new ID to the array $newIds[$i] = $newId; $i++; // Now we log the old 'parent' to the new 'parent' $parents[$oldId] = $table->id; $count--; } // Rebuild the hierarchy. if (!$table->rebuild()) { $this->setError($table->getError()); return false; } // Rebuild the tree path. if (!$table->rebuildPath($table->id)) { $this->setError($table->getError()); return false; } return $newIds; } /** * Batch move categories to a new category. * * @param integer $value The new category ID. * @param array $pks An array of row IDs. * @param array $contexts An array of item contexts. * * @return boolean True on success. * * @since 1.6 */ protected function batchMove($value, $pks, $contexts) { $parentId = (int) $value; $table = $this->getTable(); $db = $this->getDbo(); $query = $db->getQuery(true); $user = JFactory::getUser(); $extension = JFactory::getApplication()->input->get('extension', '', 'word'); // Check that the parent exists. if ($parentId) { if (!$table->load($parentId)) { if ($error = $table->getError()) { // Fatal error $this->setError($error); return false; } else { // Non-fatal error $this->setError(JText::_('JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND')); $parentId = 0; } } // Check that user has create permission for parent category $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : $user->authorise('core.create', $extension . '.category.' . $parentId); if (!$canCreate) { // Error since user cannot create in parent category $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; } // Check that user has edit permission for every category being moved // Note that the entire batch operation fails if any category lacks edit permission foreach ($pks as $pk) { if (!$user->authorise('core.edit', $extension . '.category.' . $pk)) { // Error since user cannot edit this category $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_EDIT')); return false; } } } // We are going to store all the children and just move the category $children = array(); // Parent exists so we let's proceed foreach ($pks as $pk) { // Check that the row actually exists if (!$table->load($pk)) { if ($error = $table->getError()) { // Fatal error $this->setError($error); return false; } else { // Not fatal error $this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk)); continue; } } // Set the new location in the tree for the node. $table->setLocation($parentId, 'last-child'); // Check if we are moving to a different parent if ($parentId != $table->parent_id) { // Add the child node ids to the children array. $query->clear(); $query->select('id'); $query->from($db->quoteName('#__categories')); $query->where($db->quoteName('lft' ) .' BETWEEN ' . (int) $table->lft . ' AND ' . (int) $table->rgt); $db->setQuery($query); $children = array_merge($children, (array) $db->loadColumn()); } // Store the row. if (!$table->store()) { $this->setError($table->getError()); return false; } // Rebuild the tree path. if (!$table->rebuildPath()) { $this->setError($table->getError()); return false; } } // Process the child rows if (!empty($children)) { // Remove any duplicates and sanitize ids. $children = array_unique($children); JArrayHelper::toInteger($children); // Check for a database error. if ($db->getErrorNum()) { $this->setError($db->getErrorMsg()); return false; } } return true; } /** * Custom clean the cache of com_content and content modules * * @since 1.6 */ protected function cleanCache($group = null, $client_id = 0) { $extension = JRequest::getCmd('extension'); switch ($extension) { case 'com_content': parent::cleanCache('com_content'); parent::cleanCache('mod_articles_archive'); parent::cleanCache('mod_articles_categories'); parent::cleanCache('mod_articles_category'); parent::cleanCache('mod_articles_latest'); parent::cleanCache('mod_articles_news'); parent::cleanCache('mod_articles_popular'); break; default: parent::cleanCache($extension); break; } } /** * Method to change the title & alias. * * @param integer $parent_id The id of the parent. * @param string $alias The alias. * @param string $title The title. * * @return array Contains the modified title and alias. * * @since 1.7 */ protected function generateNewTitle($parent_id, $alias, $title) { // Alter the title & alias $table = $this->getTable(); while ($table->load(array('alias' => $alias, 'parent_id' => $parent_id))) { $title = JString::increment($title); $alias = JString::increment($alias, 'dash'); } return array($title, $alias); } } home/academiac/www/components/com_newsfeeds/models/category.php 0000644 00000016344 15137455146 0021051 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modellist'); /** * Newsfeeds Component Category Model * * @package Joomla.Site * @subpackage com_newsfeeds * @since 1.5 */ class NewsfeedsModelCategory extends JModelList { /** * Category items data * * @var array */ protected $_item = null; protected $_articles = null; protected $_siblings = null; protected $_children = null; protected $_parent = null; /** * The category that applies. * * @access protected * @var object */ protected $_category = null; /** * The list of other newfeed categories. * * @access protected * @var array */ protected $_categories = null; /** * Constructor. * * @param array An optional associative array of configuration settings. * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( 'id', 'a.id', 'name', 'a.name', 'numarticles', 'a.numarticles', 'link', 'a.link', 'ordering', 'a.ordering', ); } parent::__construct($config); } /** * Method to get a list of items. * * @return mixed An array of objects on success, false on failure. */ public function getItems() { // Invoke the parent getItems method to get the main list $items = parent::getItems(); // Convert the params field into an object, saving original in _params for ($i = 0, $n = count($items); $i < $n; $i++) { $item = &$items[$i]; if (!isset($this->_params)) { $params = new JRegistry(); $item->params = $params; $params->loadString($item->params); } } return $items; } /** * Method to build an SQL query to load the list data. * * @return string An SQL query * @since 1.6 */ protected function getListQuery() { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select required fields from the categories. $query->select($this->getState('list.select', 'a.*')); $query->from($db->quoteName('#__newsfeeds').' AS a'); $query->where('a.access IN ('.$groups.')'); // Filter by category. if ($categoryId = $this->getState('category.id')) { $query->where('a.catid = '.(int) $categoryId); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); $query->where('c.access IN ('.$groups.')'); } // Filter by state $state = $this->getState('filter.published'); if (is_numeric($state)) { $query->where('a.published = '.(int) $state); } // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $date = JFactory::getDate(); $nowDate = $db->Quote($date->format($db->getDateFormat())); if ($this->getState('filter.publish_date')){ $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } // Filter by language if ($this->getState('filter.language')) { $query->where('a.language in ('.$db->Quote(JFactory::getLanguage()->getTag()).','.$db->Quote('*').')'); } // Add the list ordering clause. $query->order($db->escape($this->getState('list.ordering', 'a.ordering')).' '.$db->escape($this->getState('list.direction', 'ASC'))); return $query; } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState($ordering = null, $direction = null) { // Initialise variables. $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_newsfeeds'); // List state information $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'uint'); $this->setState('list.limit', $limit); $limitstart = JRequest::getUInt('limitstart', 0); $this->setState('list.start', $limitstart); $orderCol = JRequest::getCmd('filter_order', 'ordering'); if (!in_array($orderCol, $this->filter_fields)) { $orderCol = 'ordering'; } $this->setState('list.ordering', $orderCol); $listOrder = JRequest::getCmd('filter_order_Dir', 'ASC'); if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { $listOrder = 'ASC'; } $this->setState('list.direction', $listOrder); $id = JRequest::getVar('id', 0, '', 'int'); $this->setState('category.id', $id); $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_newsfeeds')) && (!$user->authorise('core.edit', 'com_newsfeeds'))){ // limit to published for people who can't edit or edit.state. $this->setState('filter.published', 1); // Filter by start and end dates. $this->setState('filter.publish_date', true); } $this->setState('filter.language', $app->getLanguageFilter()); // Load the parameters. $this->setState('params', $params); } /** * Method to get category data for the current category * * @param int An optional ID * * @return object * @since 1.5 */ public function getCategory() { if(!is_object($this->_item)) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); $params = new JRegistry(); if($active) { $params->loadString($active->params); } $options = array(); $options['countItems'] = $params->get('show_cat_items', 1) || $params->get('show_empty_categories', 0); $categories = JCategories::getInstance('Newsfeeds', $options); $this->_item = $categories->get($this->getState('category.id', 'root')); if(is_object($this->_item)) { $this->_children = $this->_item->getChildren(); $this->_parent = false; if($this->_item->getParent()) { $this->_parent = $this->_item->getParent(); } $this->_rightsibling = $this->_item->getSibling(); $this->_leftsibling = $this->_item->getSibling(false); } else { $this->_children = false; $this->_parent = false; } } return $this->_item; } /** * Get the parent category. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. */ public function getParent() { if (!is_object($this->_item)) { $this->getCategory(); } return $this->_parent; } /** * Get the sibling (adjacent) categories. * * @return mixed An array of categories or false if an error occurs. */ function &getLeftSibling() { if (!is_object($this->_item)) { $this->getCategory(); } return $this->_leftsibling; } function &getRightSibling() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_rightsibling; } /** * Get the child categories. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. */ function &getChildren() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_children; } } home/academiac/www/components/com_weblinks/models/category.php 0000644 00000017405 15137507243 0020677 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modellist'); /** * Weblinks Component Weblink Model * * @package Joomla.Site * @subpackage com_weblinks * @since 1.5 */ class WeblinksModelCategory extends JModelList { /** * Category items data * * @var array */ protected $_item = null; protected $_articles = null; protected $_siblings = null; protected $_children = null; protected $_parent = null; /** * Constructor. * * @param array An optional associative array of configuration settings. * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( 'id', 'a.id', 'title', 'a.title', 'hits', 'a.hits', 'ordering', 'a.ordering', ); } parent::__construct($config); } /** * The category that applies. * * @access protected * @var object */ protected $_category = null; /** * The list of other weblink categories. * * @access protected * @var array */ protected $_categories = null; /** * Method to get a list of items. * * @return mixed An array of objects on success, false on failure. */ public function getItems() { // Invoke the parent getItems method to get the main list $items = parent::getItems(); // Convert the params field into an object, saving original in _params for ($i = 0, $n = count($items); $i < $n; $i++) { if (!isset($this->_params)) { $params = new JRegistry; $params->loadString($items[$i]->params); $items[$i]->params = $params; } } return $items; } /** * Method to build an SQL query to load the list data. * * @return string An SQL query * @since 1.6 */ protected function getListQuery() { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select required fields from the categories. $query->select($this->getState('list.select', 'a.*')); $query->from($db->quoteName('#__weblinks').' AS a'); $query->where('a.access IN ('.$groups.')'); // Filter by category. if ($categoryId = $this->getState('category.id')) { $query->where('a.catid = '.(int) $categoryId); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); $query->where('c.access IN ('.$groups.')'); //Filter by published category $cpublished = $this->getState('filter.c.published'); if (is_numeric($cpublished)) { $query->where('c.published = '.(int) $cpublished); } } // Join over the users for the author and modified_by names. $query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author"); $query->select("ua.email AS author_email"); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); $query->join('LEFT', '#__users AS uam ON uam.id = a.modified_by'); // Filter by state $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.state = '.(int) $state); } // do not show trashed links on the front-end $query->where('a.state != -2'); // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $date = JFactory::getDate(); $nowDate = $db->Quote($date->toSql()); if ($this->getState('filter.publish_date')){ $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } // Filter by language if ($this->getState('filter.language')) { $query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')'); } // Add the list ordering clause. $query->order($db->escape($this->getState('list.ordering', 'a.ordering')).' '.$db->escape($this->getState('list.direction', 'ASC'))); return $query; } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState($ordering = null, $direction = null) { // Initialise variables. $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_weblinks'); // List state information $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'uint'); $this->setState('list.limit', $limit); $limitstart = JRequest::getUInt('limitstart', 0); $this->setState('list.start', $limitstart); $orderCol = JRequest::getCmd('filter_order', 'ordering'); if (!in_array($orderCol, $this->filter_fields)) { $orderCol = 'ordering'; } $this->setState('list.ordering', $orderCol); $listOrder = JRequest::getCmd('filter_order_Dir', 'ASC'); if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { $listOrder = 'ASC'; } $this->setState('list.direction', $listOrder); $id = JRequest::getVar('id', 0, '', 'int'); $this->setState('category.id', $id); $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks'))){ // limit to published for people who can't edit or edit.state. $this->setState('filter.state', 1); // Filter by start and end dates. $this->setState('filter.publish_date', true); } $this->setState('filter.language', $app->getLanguageFilter()); // Load the parameters. $this->setState('params', $params); } /** * Method to get category data for the current category * * @param int An optional ID * * @return object * @since 1.5 */ public function getCategory() { if(!is_object($this->_item)) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); $params = new JRegistry(); if($active) { $params->loadString($active->params); } $options = array(); $options['countItems'] = $params->get('show_cat_num_links_cat', 1) || $params->get('show_empty_categories', 0); $categories = JCategories::getInstance('Weblinks', $options); $this->_item = $categories->get($this->getState('category.id', 'root')); if(is_object($this->_item)) { $this->_children = $this->_item->getChildren(); $this->_parent = false; if($this->_item->getParent()) { $this->_parent = $this->_item->getParent(); } $this->_rightsibling = $this->_item->getSibling(); $this->_leftsibling = $this->_item->getSibling(false); } else { $this->_children = false; $this->_parent = false; } } return $this->_item; } /** * Get the parent categorie. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. */ public function getParent() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_parent; } /** * Get the sibling (adjacent) categories. * * @return mixed An array of categories or false if an error occurs. */ function &getLeftSibling() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_leftsibling; } function &getRightSibling() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_rightsibling; } /** * Get the child categories. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. */ function &getChildren() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_children; } } home/academiac/www/libraries/joomla/form/fields/category.php 0000644 00000007300 15137513522 0020207 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Form * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; JFormHelper::loadFieldClass('list'); /** * Form Field class for the Joomla Platform. * Supports an HTML select list of categories * * @package Joomla.Platform * @subpackage Form * @since 11.1 */ class JFormFieldCategory extends JFormFieldList { /** * The form field type. * * @var string * @since 11.1 */ public $type = 'Category'; /** * Method to get the field options for category * Use the extension attribute in a form to specify the.specific extension for * which categories should be displayed. * Use the show_root attribute to specify whether to show the global category root in the list. * * @return array The field option objects. * * @since 11.1 */ protected function getOptions() { // Initialise variables. $options = array(); $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $this->element['scope']; $published = (string) $this->element['published']; $name = (string) $this->element['name']; // Load the category options for a given extension. if (!empty($extension)) { // Filter over published state or not depending upon if it is present. if ($published) { $options = JHtml::_('category.options', $extension, array('filter.published' => explode(',', $published))); } else { $options = JHtml::_('category.options', $extension); } // Verify permissions. If the action attribute is set, then we scan the options. if ((string) $this->element['action']) { // Get the current user object. $user = JFactory::getUser(); // For new items we want a list of categories you are allowed to create in. if (!$this->form->getValue($name)) { foreach ($options as $i => $option) { // To take save or create in a category you need to have create rights for that category // unless the item is already in that category. // Unset the option if the user isn't authorised for it. In this field assets are always categories. if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true ) { unset($options[$i]); } } } // If you have an existing category id things are more complex. else { $categoryOld = $this->form->getValue($name); foreach ($options as $i => $option) { // If you are only allowed to edit in this category but not edit.state, you should not get any // option to change the category. if ($user->authorise('core.edit.state', $extension . '.category.' . $categoryOld) != true) { if ($option->value != $categoryOld) { unset($options[$i]); } } // However, if you can edit.state you can also move this to another category for which you have // create permission and you should also still be able to save in the current category. elseif (($user->authorise('core.create', $extension . '.category.' . $option->value) != true) && $option->value != $categoryOld) { unset($options[$i]); } } } } if (isset($this->element['show_root'])) { array_unshift($options, JHtml::_('select.option', '0', JText::_('JGLOBAL_ROOT'))); } } else { JError::raiseWarning(500, JText::_('JLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY')); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; } } home/academiac/www/components/com_content/models/category.php 0000644 00000027057 15137727164 0020545 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_content * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.component.modellist'); /** * This models supports retrieving a category, the articles associated with the category, * sibling, child and parent categories. * * @package Joomla.Site * @subpackage com_content * @since 1.5 */ class ContentModelCategory extends JModelList { /** * Category items data * * @var array */ protected $_item = null; protected $_articles = null; protected $_siblings = null; protected $_children = null; protected $_parent = null; /** * Model context string. * * @var string */ protected $_context = 'com_content.category'; /** * The category that applies. * * @access protected * @var object */ protected $_category = null; /** * The list of other newfeed categories. * * @access protected * @var array */ protected $_categories = null; /** * Constructor. * * @param array An optional associative array of configuration settings. * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( 'id', 'a.id', 'title', 'a.title', 'alias', 'a.alias', 'checked_out', 'a.checked_out', 'checked_out_time', 'a.checked_out_time', 'catid', 'a.catid', 'category_title', 'state', 'a.state', 'access', 'a.access', 'access_level', 'created', 'a.created', 'created_by', 'a.created_by', 'modified', 'a.modified', 'ordering', 'a.ordering', 'featured', 'a.featured', 'language', 'a.language', 'hits', 'a.hits', 'publish_up', 'a.publish_up', 'publish_down', 'a.publish_down', 'author', 'a.author' ); } parent::__construct($config); } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * return void * @since 1.6 */ protected function populateState($ordering = null, $direction = null) { // Initiliase variables. $app = JFactory::getApplication('site'); $pk = JRequest::getInt('id'); $this->setState('category.id', $pk); // Load the parameters. Merge Global and Menu Item params into new object $params = $app->getParams(); $menuParams = new JRegistry; if ($menu = $app->getMenu()->getActive()) { $menuParams->loadString($menu->params); } $mergedParams = clone $menuParams; $mergedParams->merge($params); $this->setState('params', $mergedParams); $user = JFactory::getUser(); // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); $groups = implode(',', $user->getAuthorisedViewLevels()); if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))){ // limit to published for people who can't edit or edit.state. $this->setState('filter.published', 1); // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(JFactory::getDate()->toSQL()); $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } else { $this->setState('filter.published', array(0, 1, 2)); } // process show_noauth parameter if (!$params->get('show_noauth')) { $this->setState('filter.access', true); } else { $this->setState('filter.access', false); } // Optional filter text $this->setState('list.filter', JRequest::getString('filter-search')); // filter.order $itemid = JRequest::getInt('id', 0) . ':' . JRequest::getInt('Itemid', 0); $orderCol = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order', 'filter_order', '', 'string'); if (!in_array($orderCol, $this->filter_fields)) { $orderCol = 'a.ordering'; } $this->setState('list.ordering', $orderCol); $listOrder = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order_Dir', 'filter_order_Dir', '', 'cmd'); if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { $listOrder = 'ASC'; } $this->setState('list.direction', $listOrder); $this->setState('list.start', JRequest::getUInt('limitstart', 0)); // set limit for query. If list, use parameter. If blog, add blog parameters for limit. if ((JRequest::getCmd('layout') == 'blog') || $params->get('layout_type') == 'blog') { $limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links'); $this->setState('list.links', $params->get('num_links')); } else { $limit = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.limit', 'limit', $params->get('display_num'), 'uint'); } $this->setState('list.limit', $limit); // set the depth of the category query based on parameter $showSubcategories = $params->get('show_subcategory_content', '0'); if ($showSubcategories) { $this->setState('filter.max_category_levels', $params->get('show_subcategory_content', '1')); $this->setState('filter.subcategories', true); } $this->setState('filter.language', $app->getLanguageFilter()); $this->setState('layout', JRequest::getCmd('layout')); } /** * Get the articles in the category * * @return mixed An array of articles or false if an error occurs. * @since 1.5 */ function getItems() { $params = $this->getState()->get('params'); $limit = $this->getState('list.limit'); if ($this->_articles === null && $category = $this->getCategory()) { $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); $model->setState('params', JFactory::getApplication()->getParams()); $model->setState('filter.category_id', $category->id); $model->setState('filter.published', $this->getState('filter.published')); $model->setState('filter.access', $this->getState('filter.access')); $model->setState('filter.language', $this->getState('filter.language')); $model->setState('list.ordering', $this->_buildContentOrderBy()); $model->setState('list.start', $this->getState('list.start')); $model->setState('list.limit', $limit); $model->setState('list.direction', $this->getState('list.direction')); $model->setState('list.filter', $this->getState('list.filter')); // filter.subcategories indicates whether to include articles from subcategories in the list or blog $model->setState('filter.subcategories', $this->getState('filter.subcategories')); $model->setState('filter.max_category_levels', $this->setState('filter.max_category_levels')); $model->setState('list.links', $this->getState('list.links')); if ($limit >= 0) { $this->_articles = $model->getItems(); if ($this->_articles === false) { $this->setError($model->getError()); } } else { $this->_articles=array(); } $this->_pagination = $model->getPagination(); } return $this->_articles; } /** * Build the orderby for the query * * @return string $orderby portion of query * @since 1.5 */ protected function _buildContentOrderBy() { $app = JFactory::getApplication('site'); $db = $this->getDbo(); $params = $this->state->params; $itemid = JRequest::getInt('id', 0) . ':' . JRequest::getInt('Itemid', 0); $orderCol = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order', 'filter_order', '', 'string'); $orderDirn = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order_Dir', 'filter_order_Dir', '', 'cmd'); $orderby = ' '; if (!in_array($orderCol, $this->filter_fields)) { $orderCol = null; } if (!in_array(strtoupper($orderDirn), array('ASC', 'DESC', ''))) { $orderDirn = 'ASC'; } if ($orderCol && $orderDirn) { $orderby .= $db->escape($orderCol) . ' ' . $db->escape($orderDirn) . ', '; } $articleOrderby = $params->get('orderby_sec', 'rdate'); $articleOrderDate = $params->get('order_date'); $categoryOrderby = $params->def('orderby_pri', ''); $secondary = ContentHelperQuery::orderbySecondary($articleOrderby, $articleOrderDate) . ', '; $primary = ContentHelperQuery::orderbyPrimary($categoryOrderby); $orderby .= $db->escape($primary) . ' ' . $db->escape($secondary) . ' a.created '; return $orderby; } public function getPagination() { if (empty($this->_pagination)) { return null; } return $this->_pagination; } /** * Method to get category data for the current category * * @param int An optional ID * * @return object * @since 1.5 */ public function getCategory() { if (!is_object($this->_item)) { if( isset( $this->state->params ) ) { $params = $this->state->params; $options = array(); $options['countItems'] = $params->get('show_cat_num_articles', 1) || !$params->get('show_empty_categories_cat', 0); } else { $options['countItems'] = 0; } $categories = JCategories::getInstance('Content', $options); $this->_item = $categories->get($this->getState('category.id', 'root')); // Compute selected asset permissions. if (is_object($this->_item)) { $user = JFactory::getUser(); $userId = $user->get('id'); $asset = 'com_content.category.'.$this->_item->id; // Check general create permission. if ($user->authorise('core.create', $asset)) { $this->_item->getParams()->set('access-create', true); } // TODO: Why aren't we lazy loading the children and siblings? $this->_children = $this->_item->getChildren(); $this->_parent = false; if ($this->_item->getParent()) { $this->_parent = $this->_item->getParent(); } $this->_rightsibling = $this->_item->getSibling(); $this->_leftsibling = $this->_item->getSibling(false); } else { $this->_children = false; $this->_parent = false; } } return $this->_item; } /** * Get the parent categorie. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. * @since 1.6 */ public function getParent() { if (!is_object($this->_item)) { $this->getCategory(); } return $this->_parent; } /** * Get the left sibling (adjacent) categories. * * @return mixed An array of categories or false if an error occurs. * @since 1.6 */ function &getLeftSibling() { if (!is_object($this->_item)) { $this->getCategory(); } return $this->_leftsibling; } /** * Get the right sibling (adjacent) categories. * * @return mixed An array of categories or false if an error occurs. * @since 1.6 */ function &getRightSibling() { if (!is_object($this->_item)) { $this->getCategory(); } return $this->_rightsibling; } /** * Get the child categories. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. * @since 1.6 */ function &getChildren() { if (!is_object($this->_item)) { $this->getCategory(); } // Order subcategories if (sizeof($this->_children)) { $params = $this->getState()->get('params'); if ($params->get('orderby_pri') == 'alpha' || $params->get('orderby_pri') == 'ralpha') { jimport('joomla.utilities.arrayhelper'); JArrayHelper::sortObjects($this->_children, 'title', ($params->get('orderby_pri') == 'alpha') ? 1 : -1); } } return $this->_children; } } home/academiac/www/components/com_weblinks/helpers/category.php 0000644 00000001332 15140013400 0021023 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_weblinks * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; // Component Helper jimport('joomla.application.component.helper'); jimport('joomla.application.categories'); /** * Weblinks Component Category Tree * * @static * @package Joomla.Site * @subpackage com_weblinks * @since 1.6 */ class WeblinksCategories extends JCategories { public function __construct($options = array()) { $options['table'] = '#__weblinks'; $options['extension'] = 'com_weblinks'; parent::__construct($options); } } home/academiac/www/components/com_newsfeeds/helpers/category.php 0000644 00000001406 15140244561 0021210 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_newsfeeds * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; // Component Helper jimport('joomla.application.component.helper'); jimport('joomla.application.categories'); /** * Content Component Category Tree * * @static * @package Joomla.Site * @subpackage com_newsfeeds * @since 1.6 */ class NewsfeedsCategories extends JCategories { public function __construct($options = array()) { $options['table'] = '#__newsfeeds'; $options['extension'] = 'com_newsfeeds'; $options['statefield'] = 'published'; parent::__construct($options); } } home/academiac/www/components/com_banners/helpers/category.php 0000644 00000001324 15140275760 0020661 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_banners * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; // Component Helper jimport('joomla.application.component.helper'); jimport('joomla.application.categories'); /** * Banners Component Category Tree * * @static * @package Joomla.Site * @subpackage com_banners * @since 1.6 */ class BannersCategories extends JCategories { public function __construct($options = array()) { $options['table'] = '#__banners'; $options['extension'] = 'com_banners'; parent::__construct($options); } } home/academiac/www/components/com_contact/helpers/category.php 0000644 00000001404 15140530400 0020644 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_content * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; // Component Helper jimport('joomla.application.component.helper'); jimport('joomla.application.categories'); /** * Contact Component Category Tree * * @static * @package Joomla.Site * @subpackage com_contact * @since 1.6 */ class ContactCategories extends JCategories { public function __construct($options = array()) { $options['table'] = '#__contact_details'; $options['extension'] = 'com_contact'; $options['statefield'] = 'published'; parent::__construct($options); } } home/academiac/www/components/com_content/helpers/category.php 0000644 00000001220 15140621231 0020662 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_content * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; jimport('joomla.application.categories'); /** * Content Component Category Tree * * @static * @package Joomla.Site * @subpackage com_content * @since 1.6 */ class ContentCategories extends JCategories { public function __construct($options = array()) { $options['table'] = '#__content'; $options['extension'] = 'com_content'; parent::__construct($options); } }
©
2018.