| [ 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_checkin 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 defined('_JEXEC') or die; 10 11 jimport('joomla.application.component.modellist'); 12 13 /** 14 * Checkin Model 15 * 16 * @package Joomla.Administrator 17 * @subpackage com_checkin 18 * @since 1.6 19 */ 20 class CheckinModelCheckin extends JModelList 21 { 22 protected $total; 23 protected $tables; 24 /** 25 * Method to auto-populate the model state. 26 * 27 * Note. Calling getState in this method will result in recursion. 28 * 29 * @since 1.6 30 */ 31 protected function populateState($ordering = null, $direction = null) 32 { 33 $app = JFactory::getApplication(); 34 $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search'); 35 $this->setState('filter.search', $search); 36 37 // List state information. 38 parent::populateState('table', 'asc'); 39 } 40 /** 41 * Checks in requested tables 42 * 43 * @param array An array of table names. Optional. 44 * @return int Checked in item count 45 * @since 1.6 46 */ 47 public function checkin($ids = array()) 48 { 49 $app = JFactory::getApplication(); 50 $db = $this->_db; 51 $nullDate = $db->getNullDate(); 52 53 if (!is_array($ids)) { 54 return; 55 } 56 57 // this int will hold the checked item count 58 $results = 0; 59 60 foreach ($ids as $tn) { 61 // make sure we get the right tables based on prefix 62 if (stripos($tn, $app->getCfg('dbprefix')) !== 0) { 63 continue; 64 } 65 66 $fields = $db->getTableColumns($tn); 67 68 if (!(isset($fields['checked_out']) && isset($fields['checked_out_time']))) { 69 continue; 70 } 71 72 $query = $db->getQuery(true) 73 ->update($db->quoteName($tn)) 74 ->set('checked_out = 0') 75 ->set('checked_out_time = '.$db->Quote($nullDate)) 76 ->where('checked_out > 0'); 77 if (isset($fields[$tn]['editor'])) { 78 $query->set('editor = NULL'); 79 } 80 81 $db->setQuery($query); 82 if ($db->query()) { 83 $results = $results + $db->getAffectedRows(); 84 } 85 } 86 return $results; 87 } 88 89 /** 90 * Get total of tables 91 * 92 * @return int Total to check-in tables 93 * @since 1.6 94 */ 95 public function getTotal() 96 { 97 if (!isset($this->total)) 98 { 99 $this->getItems(); 100 } 101 return $this->total; 102 } 103 /** 104 * Get tables 105 * 106 * @return array Checked in table names as keys and checked in item count as values 107 * @since 1.6 108 */ 109 public function getItems() 110 { 111 if (!isset($this->items)) 112 { 113 $app = JFactory::getApplication(); 114 $db = $this->_db; 115 $nullDate = $db->getNullDate(); 116 $tables = $db->getTableList(); 117 118 // this array will hold table name as key and checked in item count as value 119 $results = array(); 120 121 foreach ($tables as $i => $tn) 122 { 123 // make sure we get the right tables based on prefix 124 if (stripos($tn, $app->getCfg('dbprefix')) !== 0) 125 { 126 unset($tables[$i]); 127 continue; 128 } 129 130 if ($this->getState('filter.search') && stripos($tn, $this->getState('filter.search')) === false) 131 { 132 unset($tables[$i]); 133 continue; 134 } 135 136 $fields = $db->getTableColumns($tn); 137 138 if (!(isset($fields['checked_out']) && isset($fields['checked_out_time']))) 139 { 140 unset($tables[$i]); 141 continue; 142 } 143 } 144 foreach ($tables as $tn) 145 { 146 $query=$db->getQuery(true) 147 ->select('COUNT(*)') 148 ->from($db->quoteName($tn)) 149 ->where('checked_out > 0'); 150 151 $db->setQuery($query); 152 if ($db->query()) { 153 $results[$tn] = $db->loadResult(); 154 } else { 155 continue; 156 } 157 } 158 $this->total = count($results); 159 if ($this->getState('list.ordering')=='table') 160 { 161 if ($this->getState('list.direction')=='asc') { 162 ksort($results); 163 } 164 else { 165 krsort($results); 166 } 167 } 168 else 169 { 170 if ($this->getState('list.direction')=='asc') { 171 asort($results); 172 } 173 else { 174 arsort($results); 175 } 176 } 177 $results = array_slice($results, $this->getState('list.start'), $this->getState('list.limit') ? $this->getState('list.limit') : null); 178 $this->items = $results; 179 } 180 return $this->items; 181 } 182 }
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 |