/
Feature.php
177 lines (157 loc) · 4.93 KB
/
Feature.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
namespace Concrete\Core\Feature;
use Concrete\Core\Foundation\ConcreteObject;
use Loader;
use Concrete\Core\Package\PackageList;
use Core;
class Feature extends ConcreteObject
{
public function getFeatureDetailObject($mixed)
{
if ($this->feHasCustomClass) {
$class = '\\Concrete\\Core\\Feature\\Detail\\' . Loader::helper('text')->camelcase($this->feHandle) . 'Detail';
} else {
$class = '\\Concrete\\Core\\Feature\\Detail\\Detail';
}
$o = Core::make($class, array($mixed));
return $o;
}
public static function getByID($feID)
{
$db = Loader::db();
$row = $db->GetRow('select feID, feScore, feHasCustomClass, feHandle, pkgID from Features where feID = ?', array($feID));
if (isset($row['feID'])) {
$class = 'Feature';
if ($row['feHasCustomClass']) {
$class = Loader::helper('text')->camelcase($row['feHandle']) . $class;
}
$class = '\\Concrete\\Core\\Feature\\' . $class;
$fe = Core::make($class);
$fe->setPropertiesFromArray($row);
return $fe;
}
}
public static function getByHandle($feHandle)
{
$db = Loader::db();
$row = $db->GetRow('select feID, feScore, feHandle, feHasCustomClass, pkgID from Features where feHandle = ?', array($feHandle));
if (isset($row['feID'])) {
$class = 'Feature';
if ($row['feHasCustomClass']) {
$class = Loader::helper('text')->camelcase($row['feHandle']) . $class;
}
$class = '\\Concrete\\Core\\Feature\\' . $class;
$fe = Core::make($class);
$fe->setPropertiesFromArray($row);
return $fe;
}
}
public static function getListByPackage($pkg)
{
$db = Loader::db();
$list = array();
$r = $db->Execute('select feID from Features where pkgID = ? order by feID asc', array($pkg->getPackageID()));
while ($row = $r->FetchRow()) {
$fe = static::getByID($row['feID']);
if (is_object($fe)) {
$list[] = $fe;
}
}
$r->Close();
return $list;
}
public static function getList()
{
$db = Loader::db();
$list = array();
$r = $db->Execute('select feID from Features order by feID asc');
while ($row = $r->FetchRow()) {
$fe = static::getByID($row['feID']);
if (is_object($fe)) {
$list[] = $fe;
}
}
$r->Close();
return $list;
}
public function getFeatureID()
{
return $this->feID;
}
public function getFeatureHandle()
{
return $this->feHandle;
}
public function getFeatureName()
{
return Loader::helper('text')->unhandle($this->feHandle);
}
public function getFeatureScore()
{
return $this->feScore;
}
public function hasFeatureCustomClass()
{
return $this->feHasCustomClass;
}
public function getPackageID()
{
return $this->pkgID;
}
public function getPackageHandle()
{
return PackageList::getHandle($this->pkgID);
}
public static function add($feHandle, $feScore = 1, $feHasCustomClass = false, $pkg = false)
{
$db = Loader::db();
$pkgID = 0;
if (is_object($pkg)) {
$pkgID = $pkg->getPackageID();
}
if (!$feScore) {
$feScore = 1;
}
if ($feHasCustomClass) {
$feHasCustomClass = 1;
} else {
$feHasCustomClass = 0;
}
$db->Execute('insert into Features (feHandle, feScore, feHasCustomClass, pkgID) values (?, ?, ?, ?)', array($feHandle, $feScore, $feHasCustomClass, $pkgID));
$id = $db->Insert_ID();
$fe = static::getByID($id);
return $fe;
}
public function export($fxml, $full = true)
{
$fe = $fxml->addChild('feature');
$fe->addAttribute('handle', $this->getFeatureHandle());
if ($full) {
$fe->addAttribute('score', $this->getFeatureScore());
$fe->addAttribute('has-custom-class', $this->hasFeatureCustomClass());
$fe->addAttribute('package', $this->getPackageHandle());
}
return $fe;
}
public static function exportList($xml)
{
$fxml = $xml->addChild('features');
$db = Loader::db();
$r = $db->Execute('select feID from Features order by feID asc');
$list = array();
while ($row = $r->FetchRow()) {
$fe = static::getByID($row['feID']);
if (is_object($fe)) {
$list[] = $fe;
}
}
foreach ($list as $fe) {
$fe->export($fxml);
}
}
public function delete()
{
$db = Loader::db();
$db->Execute('delete from Features where feID = ?', array($this->feID));
}
}