Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
extension.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Table
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Extension table
14  * Replaces plugins table
15  *
16  * @package Joomla.Platform
17  * @subpackage Table
18  * @since 11.1
19  */
20 class JTableExtension extends JTable
21 {
22  /**
23  * Constructor
24  *
25  * @param JDatabaseDriver $db Database driver object.
26  *
27  * @since 11.1
28  */
29  public function __construct(JDatabaseDriver $db)
30  {
31  parent::__construct('#__extensions', 'extension_id', $db);
32  }
33 
34  /**
35  * Overloaded check function
36  *
37  * @return boolean True if the object is ok
38  *
39  * @see JTable::check()
40  * @since 11.1
41  */
42  public function check()
43  {
44  // Check for valid name
45  if (trim($this->name) == '' || trim($this->element) == '')
46  {
47  $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_EXTENSION'));
48 
49  return false;
50  }
51  return true;
52  }
53 
54  /**
55  * Overloaded bind function
56  *
57  * @param array $array Named array
58  * @param mixed $ignore An optional array or space separated list of properties
59  * to ignore while binding.
60  *
61  * @return mixed Null if operation was satisfactory, otherwise returns an error
62  *
63  * @see JTable::bind()
64  * @since 11.1
65  */
66  public function bind($array, $ignore = '')
67  {
68  if (isset($array['params']) && is_array($array['params']))
69  {
70  $registry = new JRegistry;
71  $registry->loadArray($array['params']);
72  $array['params'] = (string) $registry;
73  }
74 
75  if (isset($array['control']) && is_array($array['control']))
76  {
77  $registry = new JRegistry;
78  $registry->loadArray($array['control']);
79  $array['control'] = (string) $registry;
80  }
81 
82  return parent::bind($array, $ignore);
83  }
84 
85  /**
86  * Method to create and execute a SELECT WHERE query.
87  *
88  * @param array $options Array of options
89  *
90  * @return string The database query result
91  *
92  * @since 11.1
93  */
94  public function find($options = array())
95  {
96  // Get the JDatabaseQuery object
97  $query = $this->_db->getQuery(true);
98 
99  foreach ($options as $col => $val)
100  {
101  $query->where($col . ' = ' . $this->_db->quote($val));
102  }
103 
104  $query->select($this->_db->quoteName('extension_id'))
105  ->from($this->_db->quoteName('#__extensions'));
106  $this->_db->setQuery($query);
107 
108  return $this->_db->loadResult();
109  }
110 
111  /**
112  * Method to set the publishing state for a row or list of rows in the database
113  * table. The method respects checked out rows by other users and will attempt
114  * to checkin rows that it can after adjustments are made.
115  *
116  * @param mixed $pks An optional array of primary key values to update. If not
117  * set the instance property value is used.
118  * @param integer $state The publishing state. eg. [0 = unpublished, 1 = published]
119  * @param integer $userId The user id of the user performing the operation.
120  *
121  * @return boolean True on success.
122  *
123  * @since 11.1
124  */
125  public function publish($pks = null, $state = 1, $userId = 0)
126  {
127  $k = $this->_tbl_key;
128 
129  // Sanitize input.
131  $userId = (int) $userId;
132  $state = (int) $state;
133 
134  // If there are no primary keys set check to see if the instance key is set.
135  if (empty($pks))
136  {
137  if ($this->$k)
138  {
139  $pks = array($this->$k);
140  }
141  // Nothing to set publishing state on, return false.
142  else
143  {
144  $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
145 
146  return false;
147  }
148  }
149 
150  // Build the WHERE clause for the primary keys.
151  $where = $k . '=' . implode(' OR ' . $k . '=', $pks);
152 
153  // Determine if there is checkin support for the table.
154  if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time'))
155  {
156  $checkin = '';
157  }
158  else
159  {
160  $checkin = ' AND (checked_out = 0 OR checked_out = ' . (int) $userId . ')';
161  }
162 
163  // Update the publishing state for rows with the given primary keys.
164  $query = $this->_db->getQuery(true)
165  ->update($this->_db->quoteName($this->_tbl))
166  ->set($this->_db->quoteName('enabled') . ' = ' . (int) $state)
167  ->where('(' . $where . ')' . $checkin);
168  $this->_db->setQuery($query);
169  $this->_db->execute();
170 
171  // If checkin is supported and all rows were adjusted, check them in.
172  if ($checkin && (count($pks) == $this->_db->getAffectedRows()))
173  {
174  // Checkin the rows.
175  foreach ($pks as $pk)
176  {
177  $this->checkin($pk);
178  }
179  }
180 
181  // If the JTable instance value is in the list of primary keys that were set, set the instance.
182  if (in_array($this->$k, $pks))
183  {
184  $this->enabled = $state;
185  }
186 
187  $this->setError('');
188 
189  return true;
190  }
191 }