| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_cache 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // no direct access 10 defined('_JEXEC') or die; 11 12 jimport('joomla.application.component.modellist'); 13 14 /** 15 * Cache Model 16 * 17 * @package Joomla.Administrator 18 * @subpackage com_cache 19 * @since 1.6 20 */ 21 class CacheModelCache extends JModelList 22 { 23 /** 24 * An Array of CacheItems indexed by cache group ID 25 * 26 * @var Array 27 */ 28 protected $_data = array(); 29 30 /** 31 * Group total 32 * 33 * @var integer 34 */ 35 protected $_total = null; 36 37 /** 38 * Pagination object 39 * 40 * @var object 41 */ 42 protected $_pagination = null; 43 44 /** 45 * Method to auto-populate the model state. 46 * 47 * Note. Calling getState in this method will result in recursion. 48 * 49 * @since 1.6 50 */ 51 protected function populateState($ordering = null, $direction = null) 52 { 53 $app = JFactory::getApplication(); 54 55 $clientId = $this->getUserStateFromRequest($this->context.'.filter.client_id', 'filter_client_id', 0, 'int'); 56 $this->setState('clientId', $clientId == 1 ? 1 : 0); 57 58 $client = JApplicationHelper::getClientInfo($clientId); 59 $this->setState('client', $client); 60 61 parent::populateState('group', 'asc'); 62 } 63 64 65 /** 66 * Method to get cache data 67 * 68 * @return array 69 */ 70 public function getData() 71 { 72 if (empty($this->_data)) { 73 $cache = $this->getCache(); 74 $data = $cache->getAll(); 75 76 if ($data != false) { 77 $this->_data = $data; 78 $this->_total = count($data); 79 80 if ($this->_total) { 81 // Apply custom ordering 82 $ordering = $this->getState('list.ordering'); 83 $direction = ($this->getState('list.direction') == 'asc') ? 1 : -1; 84 85 jimport('joomla.utilities.arrayhelper'); 86 $this->_data = JArrayHelper::sortObjects($data, $ordering, $direction); 87 88 // Apply custom pagination 89 if ($this->_total > $this->getState('list.limit') && $this->getState('list.limit')) { 90 $this->_data = array_slice($this->_data, $this->getState('list.start'), $this->getState('list.limit')); 91 } 92 } 93 } else { 94 $this->_data = array(); 95 } 96 } 97 return $this->_data; 98 } 99 100 101 102 /** 103 * Method to get cache instance 104 * 105 * @return object 106 */ 107 public function getCache() 108 { 109 $conf = JFactory::getConfig(); 110 111 $options = array( 112 'defaultgroup' => '', 113 'storage' => $conf->get('cache_handler', ''), 114 'caching' => true, 115 'cachebase' => ($this->getState('clientId') == 1) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache') 116 ); 117 118 $cache = JCache::getInstance('', $options); 119 120 return $cache; 121 } 122 123 /** 124 * Method to get client data 125 * 126 * @return array 127 */ 128 public function getClient() 129 { 130 return $this->getState('client'); 131 } 132 133 /** 134 * Get the number of current Cache Groups 135 * 136 * @return int 137 */ 138 public function getTotal() 139 { 140 if (empty($this->_total)) { 141 $this->_total = count($this->getData()); 142 } 143 144 return $this->_total; 145 } 146 147 /** 148 * Method to get a pagination object for the cache 149 * 150 * @return integer 151 */ 152 public function getPagination() 153 { 154 if (empty($this->_pagination)) { 155 jimport('joomla.html.pagination'); 156 $this->_pagination = new JPagination($this->getTotal(), $this->getState('list.start'), $this->getState('list.limit')); 157 } 158 159 return $this->_pagination; 160 } 161 162 /** 163 * Clean out a cache group as named by param. 164 * If no param is passed clean all cache groups. 165 * 166 * @param String $group 167 */ 168 public function clean($group = '') 169 { 170 $cache = $this->getCache(); 171 $cache->clean($group); 172 } 173 174 public function cleanlist($array) 175 { 176 foreach ($array as $group) { 177 $this->clean($group); 178 } 179 } 180 181 public function purge() 182 { 183 $cache = JFactory::getCache(''); 184 return $cache->gc(); 185 } 186 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |