/
GatheringItemAssignment.php
68 lines (60 loc) · 2.13 KB
/
GatheringItemAssignment.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
<?php
namespace Concrete\Core\Feature\Assignment;
use Concrete\Core\Feature\Feature;
use Concrete\Core\Feature\Category\Category as FeatureCategory;
use Concrete\Core\Feature\Detail\Detail as FeatureDetail;
class GatheringItemAssignment extends Assignment
{
protected $gaiID;
public function loadDetails($mixed)
{
$this->gaiID = $mixed->getGatheringItemID();
}
public static function add(Feature $fe, FeatureDetail $fd, $item)
{
$fc = FeatureCategory::getByHandle('gathering_item');
$fa = parent::addAssignment($fe, $fc, $fd, $item);
$db = Loader::db();
$db->Execute('insert into GatheringItemFeatureAssignments (gaiID, faID) values (?, ?)', array(
$item->getGatheringItemID(),
$fa->getFeatureAssignmentID(),
));
return $fa;
}
public static function getList($item)
{
$db = Loader::db();
$r = $db->Execute('select faID from GatheringItemFeatureAssignments where gaiID = ?', array(
$item->getGatheringItemID(),
));
$list = array();
while ($row = $r->FetchRow()) {
$fa = Assignment::getByID($row['faID'], $item);
if (is_object($fa)) {
$list[] = $fa;
}
}
return $list;
}
public static function getFeature($feHandle, $item)
{
$db = Loader::db();
$faID = $db->GetOne('select ca.faID from GatheringItemFeatureAssignments as inner join FeatureAssignments fa on as.faID = fa.faID inner join Features fe on fa.feID = fe.feID where gaiID = ? and fe.feHandle = ?', array(
$item->getGatheringItemID(), $feHandle,
));
if ($faID && $faID > 0) {
$fa = Assignment::getByID($faID, $item);
if (is_object($fa)) {
return $fa;
}
}
}
public function delete()
{
$db = Loader::db();
$db->Execute('delete from GatheringItemFeatureAssignments where faID = ? and gaiID = ?', array($this->getFeatureAssignmentID(), $this->gaiID));
if (!$this->assignmentIsInUse()) {
parent::delete();
}
}
}