This repository has been archived by the owner on Nov 26, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
/
asset.php
132 lines (116 loc) · 2.6 KB
/
asset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* @package Joomla.Platform
* @subpackage Table
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Table class supporting modified pre-order tree traversal behavior.
*
* @package Joomla.Platform
* @subpackage Table
* @link http://docs.joomla.org/JTableAsset
* @since 11.1
*/
class JTableAsset extends JTableNested
{
/**
* The primary key of the asset.
*
* @var integer
* @since 11.1
*/
public $id = null;
/**
* The unique name of the asset.
*
* @var string
* @since 11.1
*/
public $name = null;
/**
* The human readable title of the asset.
*
* @var string
* @since 11.1
*/
public $title = null;
/**
* The rules for the asset stored in a JSON string
*
* @var string
* @since 11.1
*/
public $rules = null;
/**
* Constructor
*
* @param JDatabaseDriver $db Database driver object.
*
* @since 11.1
*/
public function __construct(JDatabaseDriver $db)
{
parent::__construct('#__assets', 'id', $db);
}
/**
* Method to load an asset by its name.
*
* @param string $name The name of the asset.
*
* @return integer
*
* @since 11.1
*/
public function loadByName($name)
{
// Get the JDatabaseQuery object
$query = $this->_db->getQuery(true);
// Get the asset id for the asset.
$query->select($this->_db->quoteName('id'));
$query->from($this->_db->quoteName('#__assets'));
$query->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote($name));
$this->_db->setQuery($query);
$assetId = (int) $this->_db->loadResult();
if (empty($assetId))
{
return false;
}
return $this->load($assetId);
}
/**
* Assert that the nested set data is valid.
*
* @return boolean True if the instance is sane and able to be stored in the database.
*
* @link http://docs.joomla.org/JTable/check
* @since 11.1
*/
public function check()
{
$this->parent_id = (int) $this->parent_id;
// JTableNested does not allow parent_id = 0, override this.
if ($this->parent_id > 0)
{
// Get the JDatabaseQuery object
$query = $this->_db->getQuery(true);
$query->select('COUNT(id)');
$query->from($this->_db->quoteName($this->_tbl));
$query->where($this->_db->quoteName('id') . ' = ' . $this->parent_id);
$this->_db->setQuery($query);
if ($this->_db->loadResult())
{
return true;
}
else
{
$this->setError('Invalid Parent ID');
return false;
}
}
return true;
}
}