1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Table
5 *
6 * @copyright Copyright (C) 2005 - 2017 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 use Joomla\Registry\Registry;
13
14 /**
15 * Update table
16 * Stores updates temporarily
17 *
18 * @since 11.1
19 */
20 class JTableUpdate extends JTable
21 {
22 /**
23 * Constructor
24 *
25 * @param JDatabaseDriver $db Database driver object.
26 *
27 * @since 11.1
28 */
29 public function __construct($db)
30 {
31 parent::__construct('#__updates', 'update_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
52 if (!$this->update_id && !$this->data)
53 {
54 $this->data = '';
55 }
56
57 return true;
58 }
59
60 /**
61 * Overloaded bind function
62 *
63 * @param array $array Named array
64 * @param mixed $ignore An optional array or space separated list of properties
65 * to ignore while binding.
66 *
67 * @return mixed Null if operation was satisfactory, otherwise returns an error
68 *
69 * @see JTable::bind()
70 * @since 11.1
71 */
72 public function bind($array, $ignore = '')
73 {
74 if (isset($array['params']) && is_array($array['params']))
75 {
76 $registry = new Registry($array['params']);
77 $array['params'] = (string) $registry;
78 }
79
80 if (isset($array['control']) && is_array($array['control']))
81 {
82 $registry = new Registry($array['control']);
83 $array['control'] = (string) $registry;
84 }
85
86 return parent::bind($array, $ignore);
87 }
88
89 /**
90 * Method to create and execute a SELECT WHERE query.
91 *
92 * @param array $options Array of options
93 *
94 * @return string Results of query
95 *
96 * @since 11.1
97 */
98 public function find($options = array())
99 {
100 $where = array();
101
102 foreach ($options as $col => $val)
103 {
104 $where[] = $col . ' = ' . $this->_db->quote($val);
105 }
106
107 $query = $this->_db->getQuery(true)
108 ->select($this->_db->quoteName($this->_tbl_key))
109 ->from($this->_db->quoteName($this->_tbl))
110 ->where(implode(' AND ', $where));
111 $this->_db->setQuery($query);
112
113 return $this->_db->loadResult();
114 }
115 }
116