/
Category.php
128 lines (109 loc) · 3.74 KB
/
Category.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
<?php
namespace Concrete\Core\Workflow\Progress;
use Concrete\Core\Foundation\ConcreteObject;
use Loader;
use Concrete\Core\Package\PackageList;
class Category extends ConcreteObject
{
public static function getByID($wpCategoryID)
{
$db = Loader::db();
$row = $db->GetRow('select wpCategoryID, wpCategoryHandle, pkgID from WorkflowProgressCategories where wpCategoryID = ?', array($wpCategoryID));
if (isset($row['wpCategoryID'])) {
$pkc = new static();
$pkc->setPropertiesFromArray($row);
return $pkc;
}
}
public static function getByHandle($wpCategoryHandle)
{
$db = Loader::db();
$row = $db->GetRow('select wpCategoryID, wpCategoryHandle, pkgID from WorkflowProgressCategories where wpCategoryHandle = ?', array($wpCategoryHandle));
if (isset($row['wpCategoryID'])) {
$pkc = new static();
$pkc->setPropertiesFromArray($row);
return $pkc;
}
}
public static function exportList($xml)
{
$attribs = static::getList();
$axml = $xml->addChild('workflowprogresscategories');
foreach ($attribs as $pkc) {
$acat = $axml->addChild('category');
$acat->addAttribute('handle', $pkc->getWorkflowProgressCategoryHandle());
$acat->addAttribute('package', $pkc->getPackageHandle());
}
}
public static function getListByPackage($pkg)
{
$db = Loader::db();
$list = array();
$r = $db->Execute('select wpCategoryID from WorkflowProgressCategories where pkgID = ? order by wpCategoryID asc', array($pkg->getPackageID()));
while ($row = $r->fetch()) {
$list[] = static::getByID($row['wpCategoryID']);
}
$r->free();
return $list;
}
public function getWorkflowProgressCategoryID()
{
return $this->wpCategoryID;
}
public function getWorkflowProgressCategoryHandle()
{
return $this->wpCategoryHandle;
}
public function getPackageID()
{
return $this->pkgID;
}
public function getPackageHandle()
{
return PackageList::getHandle($this->pkgID);
}
public function getWorkflowProgressCategoryClass()
{
$className = '\\Core\\Workflow\\Progress\\' . Loader::helper('text')->camelcase($this->wpCategoryHandle) . 'Progress';
$pkHandle = $this->getPackageHandle();
$class = core_class($className, $pkHandle);
if (class_exists($class)) {
$c = new $class();
return $c;
}
}
public function __call($method, $arguments)
{
$class = $this->getWorkflowProgressCategoryClass();
if ($class) {
return call_user_func_array(array($class, $method), $arguments);
}
}
public function delete()
{
$db = Loader::db();
$db->Execute('delete from WorkflowProgressCategories where wpCategoryID = ?', array($this->wpCategoryID));
}
public static function getList()
{
$db = Loader::db();
$cats = array();
$r = $db->Execute('select wpCategoryID from WorkflowProgressCategories order by wpCategoryID asc');
while ($row = $r->fetch()) {
$cats[] = static::getByID($row['wpCategoryID']);
}
return $cats;
}
public static function add($wpCategoryHandle, $pkg = false)
{
$db = Loader::db();
if (is_object($pkg)) {
$pkgID = $pkg->getPackageID();
} else {
$pkgID = $pkg ?: null;
}
$db->Execute('insert into WorkflowProgressCategories (wpCategoryHandle, pkgID) values (?, ?)', array($wpCategoryHandle, $pkgID));
$id = $db->Insert_ID();
return static::getByID($id);
}
}