/
Assignment.php
137 lines (119 loc) · 3.67 KB
/
Assignment.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
<?php
namespace Concrete\Core\Feature\Assignment;
use Concrete\Core\Foundation\ConcreteObject;
use Core;
use Concrete\Core\Feature\Feature;
use Concrete\Core\Feature\Category\Category as FeatureCategory;
use Concrete\Core\Feature\Detail\Detail as FeatureDetail;
use Database;
use RuntimeException;
abstract class Assignment extends ConcreteObject
{
abstract public function loadDetails($mixed);
/**
* @param mixed $mixed
*
* @return Assignment[]
* @abstract
*/
public static function getList($mixed)
{
throw new RuntimeException('This method has not yet been implemented.');
}
/**
* @param string $feHandle
* @param mixes $mixed
*
* @return Assignment|null
* @abstract
*/
public static function getFeature($feHandle, $mixed)
{
throw new RuntimeException('This method has not yet been implemented.');
}
/**
* @param Feature $fe
* @param FeatureDetail $fd
* @param mixed $mixed
*
* @return Assignment
* @abstract
*/
public static function add(Feature $fe, FeatureDetail $fd, $mixed)
{
throw new RuntimeException('This method has not yet been implemented.');
}
public static function addAssignment(Feature $fe, FeatureCategory $fc, FeatureDetail $fd, $mixed)
{
$db = Database::connection();
$db->Execute(
'insert into FeatureAssignments (fcID, feID, fdObject) values (?, ?, ?)',
array(
$fc->getFeatureCategoryID(),
$fe->getFeatureID(),
serialize($fd),
)
);
$faID = $db->Insert_ID();
// sometimes feature detail objects need to do more with the feature assignments, so we do that here.
$fa = static::getByID($faID, $mixed);
$fd->handleFeatureAssignment($fa);
return $fa;
}
protected function assignmentIsInUse()
{
$categories = FeatureCategory::getList();
foreach ($categories as $cat) {
if ($cat->assignmentIsInUse($this)) {
return true;
break;
}
}
return false;
}
public function getFeatureAssignmentID()
{
return $this->faID;
}
public function getFeatureID()
{
return $this->feID;
}
public function getFeatureObject()
{
return Feature::getByID($this->feID);
}
public function getFeatureDetailObject()
{
return $this->fdObject;
}
public function getFeatureDetailHandle()
{
return $this->feHandle;
}
public static function getByID($faID, $mixed)
{
$db = Database::connection();
$r = $db->GetRow(
'select faID, fa.fcID, fdObject, fa.feID, fe.feHandle, fc.fcHandle from FeatureAssignments fa inner join FeatureCategories fc on fa.fcID = fc.fcID inner join Features fe on fa.feID = fe.feID where faID = ?',
array($faID)
);
if (is_array($r) && $r['faID'] == $faID) {
$class = '\\Concrete\\Core\\Feature\\Assignment\\' . Core::make('helper/text')->camelcase($r['fcHandle']) . 'Assignment';
$fa = Core::make($class);
$fa->setPropertiesFromArray($r);
$fa->fdObject = @unserialize($r['fdObject']);
$fa->loadDetails($mixed);
return $fa;
}
}
public function delete()
{
$detail = $this->getFeatureDetailObject();
if (is_object($detail)) {
$detail->deleteFeatureAssignment($this);
}
$db = Database::connection();
$db->Execute('delete from FeatureAssignments where faID = ?', array($this->getFeatureAssignmentID()));
}
}