| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 4 * @license GNU General Public License version 2 or later; see LICENSE.txt 5 */ 6 7 // No direct access. 8 defined('_JEXEC') or die; 9 10 jimport('joomla.application.component.modeladmin'); 11 12 /** 13 * User view level model. 14 * 15 * @package Joomla.Administrator 16 * @subpackage com_users 17 * @since 1.6 18 */ 19 class UsersModelLevel extends JModelAdmin 20 { 21 /** 22 * @var array A list of the access levels in use. 23 * @since 1.6 24 */ 25 protected $levelsInUse = null; 26 27 /** 28 * Method to test whether a record can be deleted. 29 * 30 * @param object $record A record object. 31 * 32 * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. 33 * @since 1.6 34 */ 35 protected function canDelete($record) 36 { 37 // Check if the access level is being used by any content. 38 if ($this->levelsInUse === null) { 39 // Populate the list once. 40 $this->levelsInUse = array(); 41 42 $db = $this->getDbo(); 43 $query = $db->getQuery(true) 44 ->select('DISTINCT access'); 45 // from is added dynamically 46 47 // Get all the tables and the prefix 48 $tables = $db->getTableList(); 49 //$fields = $db->getTableFields($tables); 50 $prefix = $db->getPrefix(); 51 52 foreach ($tables as $table) 53 { 54 // Get all of the columns in the table 55 $fields = $db->getTableColumns($table); 56 57 // We are looking for the access field. If custom tables are using something other 58 // than the 'access' field they are on their own unfortunately. 59 // Also make sure the table prefix matches the live db prefix (eg, it is not a "bak_" table) 60 if ((strpos($table, $prefix) === 0) && (isset($fields['access']))) { 61 // Lookup the distinct values of the field. 62 $query->clear('from') 63 ->from($db->quoteName($table)); 64 $db->setQuery($query); 65 66 $values = $db->loadColumn(); 67 $error = $db->getErrorMsg(); 68 69 // Check for DB error. 70 if ($error) { 71 $this->setError($error); 72 73 return false; 74 } 75 76 $this->levelsInUse = array_merge($this->levelsInUse, $values); 77 78 // TODO Could assemble an array of the tables used by each view level list those, 79 // giving the user a clue in the error where to look. 80 } 81 } 82 83 // Get uniques. 84 $this->levelsInUse = array_unique($this->levelsInUse); 85 86 // Ok, after all that we are ready to check the record :) 87 } 88 89 if (in_array($record->id, $this->levelsInUse)) { 90 $this->setError(JText::sprintf('COM_USERS_ERROR_VIEW_LEVEL_IN_USE', $record->id, $record->title)); 91 92 return false; 93 } 94 95 return parent::canDelete($record); 96 } 97 98 /** 99 * Returns a reference to the a Table object, always creating it. 100 * 101 * @param type The table type to instantiate 102 * @param string A prefix for the table class name. Optional. 103 * @param array Configuration array for model. Optional. 104 * @return JTable A database object 105 * @since 1.6 106 */ 107 public function getTable($type = 'Viewlevel', $prefix = 'JTable', $config = array()) 108 { 109 $return = JTable::getInstance($type, $prefix, $config); 110 111 return $return; 112 } 113 114 /** 115 * Method to get a single record. 116 * 117 * @param integer The id of the primary key. 118 * @return mixed Object on success, false on failure. 119 * @since 1.6 120 */ 121 public function getItem($pk = null) 122 { 123 $result = parent::getItem($pk); 124 125 // Convert the params field to an array. 126 $result->rules = json_decode($result->rules); 127 128 return $result; 129 } 130 131 /** 132 * Method to get the record form. 133 * 134 * @param array $data An optional array of data for the form to interogate. 135 * @param boolean $loadData True if the form is to load its own data (default case), false if not. 136 * @return JForm A JForm object on success, false on failure 137 * @since 1.6 138 */ 139 public function getForm($data = array(), $loadData = true) 140 { 141 // Initialise variables. 142 $app = JFactory::getApplication(); 143 144 // Get the form. 145 $form = $this->loadForm('com_users.level', 'level', array('control' => 'jform', 'load_data' => $loadData)); 146 147 if (empty($form)) { 148 return false; 149 } 150 151 return $form; 152 } 153 154 /** 155 * Method to get the data that should be injected in the form. 156 * 157 * @return mixed The data for the form. 158 * @since 1.6 159 */ 160 protected function loadFormData() 161 { 162 // Check the session for previously entered form data. 163 $data = JFactory::getApplication()->getUserState('com_users.edit.level.data', array()); 164 165 if (empty($data)) { 166 $data = $this->getItem(); 167 } 168 169 return $data; 170 } 171 172 /** 173 * Override preprocessForm to load the user plugin group instead of content. 174 * 175 * @param object A form object. 176 * @param mixed The data expected for the form. 177 * @throws Exception if there is an error in the form event. 178 * @since 1.6 179 */ 180 protected function preprocessForm(JForm $form, $data, $groups = '') 181 { 182 parent::preprocessForm($form, $data, 'user'); 183 } 184 185 /** 186 * Method to save the form data. 187 * 188 * @param array The form data. 189 * @return boolean True on success. 190 * @since 1.6 191 */ 192 public function save($data) 193 { 194 if (!isset($data['rules'])) { 195 $data['rules']=array(); 196 } 197 198 return parent::save($data); 199 } 200 }
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 |