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 /**
13 * Viewlevels table class.
14 *
15 * @since 11.1
16 */
17 class JTableViewlevel extends JTable
18 {
19 /**
20 * Constructor
21 *
22 * @param JDatabaseDriver $db Database driver object.
23 *
24 * @since 11.1
25 */
26 public function __construct($db)
27 {
28 parent::__construct('#__viewlevels', 'id', $db);
29 }
30
31 /**
32 * Method to bind the data.
33 *
34 * @param array $array The data to bind.
35 * @param mixed $ignore An array or space separated list of fields to ignore.
36 *
37 * @return boolean True on success, false on failure.
38 *
39 * @since 11.1
40 */
41 public function bind($array, $ignore = '')
42 {
43 // Bind the rules as appropriate.
44 if (isset($array['rules']))
45 {
46 if (is_array($array['rules']))
47 {
48 $array['rules'] = json_encode($array['rules']);
49 }
50 }
51
52 return parent::bind($array, $ignore);
53 }
54
55 /**
56 * Method to check the current record to save
57 *
58 * @return boolean True on success
59 *
60 * @since 11.1
61 */
62 public function check()
63 {
64 // Validate the title.
65 if ((trim($this->title)) == '')
66 {
67 $this->setError(JText::_('JLIB_DATABASE_ERROR_VIEWLEVEL'));
68
69 return false;
70 }
71
72 // Check for a duplicate title.
73 $db = $this->_db;
74 $query = $db->getQuery(true)
75 ->select('COUNT(title)')
76 ->from($db->quoteName('#__viewlevels'))
77 ->where($db->quoteName('title') . ' = ' . $db->quote($this->title))
78 ->where($db->quoteName('id') . ' != ' . (int) $this->id);
79 $db->setQuery($query);
80
81 if ($db->loadResult() > 0)
82 {
83 $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_USERLEVEL_NAME_EXISTS', $this->title));
84
85 return false;
86 }
87
88 return true;
89 }
90 }
91