1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class WorkflowAllocations extends ItemCollection {
25:
26: 27: 28: 29: 30:
31: public function __construct() {
32: global $cfg;
33: parent::__construct($cfg["tab"]["workflow_allocation"], "idallocation");
34: $this->_setItemClass("WorkflowAllocation");
35: }
36:
37: public function delete($idallocation) {
38: global $cfg, $lang;
39:
40: $obj = new WorkflowAllocation();
41: $obj->loadByPrimaryKey($idallocation);
42:
43: $idcatlang = $obj->get("idcatlang");
44:
45: $db = cRegistry::getDb();
46: $sql = "SELECT idcat FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcatlang = '" . cSecurity::toInteger($idcatlang) . "'";
47: $db->query($sql);
48: $db->nextRecord();
49: $idcat = $db->f("idcat");
50:
51: $sql = "SELECT idart FROM " . $cfg["tab"]["cat_art"] . " WHERE idcat = '" . cSecurity::toInteger($idcat) . "'";
52: $db->query($sql);
53:
54: while ($db->nextRecord()) {
55: $idarts[] = $db->f("idart");
56: }
57:
58: $idartlangs = array();
59:
60: if (is_array($idarts)) {
61: foreach ($idarts as $idart) {
62: $sql = "SELECT idartlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idart = '" . cSecurity::toInteger($idart) . "' and idlang = '" . cSecurity::toInteger($lang) . "'";
63: $db->query($sql);
64: if ($db->nextRecord()) {
65: $idartlangs[] = $db->f("idartlang");
66: }
67: }
68: }
69:
70: $workflowArtAllocation = new WorkflowArtAllocation();
71: $workflowArtAllocations = new WorkflowArtAllocations();
72:
73: foreach ($idartlangs as $idartlang) {
74: $workflowArtAllocation->loadBy("idartlang", $idartlang);
75: $workflowArtAllocations->delete($workflowArtAllocation->get("idartallocation"));
76: }
77:
78: parent::delete($idallocation);
79: }
80:
81: public function create($idworkflow, $idcatlang) {
82: $this->select("idcatlang = '$idcatlang'");
83:
84: if ($this->next() !== false) {
85: $this->lasterror = i18n("Category already has a workflow assigned", "workflow");
86: return false;
87: }
88:
89: $workflows = new Workflows();
90: $workflows->select("idworkflow = '$idworkflow'");
91:
92: if ($workflows->next() === false) {
93: $this->lasterror = i18n("Workflow doesn't exist", "workflow");
94: return false;
95: }
96: $newitem = parent::createNewItem();
97: if (!$newitem->setWorkflow($idworkflow)) {
98: $this->lasterror = $newitem->lasterror;
99: $workflows->delete($newitem->getField("idallocation"));
100: return false;
101: }
102:
103: if (!$newitem->setCatLang($idcatlang)) {
104: $this->lasterror = $newitem->lasterror;
105: $workflows->delete($newitem->getField("idallocation"));
106: return false;
107: }
108:
109: $newitem->store();
110:
111: return ($newitem);
112: }
113:
114: }
115:
116: 117: 118: 119: 120: 121: 122: 123: 124: 125:
126: class WorkflowAllocation extends Item {
127:
128: 129: 130: 131: 132:
133: public function __construct() {
134: global $cfg;
135:
136: parent::__construct($cfg["tab"]["workflow_allocation"], "idallocation");
137: }
138:
139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149:
150: public function setField($field, $value, $safe = true) {
151: throw new cBadMethodCallException("Don't use setField for WorkflowAllocation items! Use setWorkflow instead!");
152: }
153:
154: 155: 156: 157: 158:
159: public function setWorkflow($idworkflow) {
160: $workflows = new Workflows();
161:
162: $workflows->select("idworkflow = '$idworkflow'");
163:
164: if ($workflows->next() === false) {
165: $this->lasterror = i18n("Workflow doesn't exist", "workflow");
166: return false;
167: }
168:
169: parent::setField("idworkflow", $idworkflow);
170: parent::store();
171: return true;
172: }
173:
174: 175: 176: 177: 178: 179: 180:
181: public function setCatLang($idcatlang) {
182: global $cfg;
183:
184: $allocations = new WorkflowAllocations();
185:
186: $allocations->select("idcatlang = '$idcatlang'");
187:
188: if ($allocations->next() !== false) {
189: $this->lasterror = i18n("Category already has a workflow assigned", "workflow");
190: return false;
191: }
192:
193: $db = cRegistry::getDb();
194: $sql = "SELECT idcatlang FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcatlang = '" . cSecurity::toInteger($idcatlang) . "'";
195: $db->query($sql);
196:
197: if (!$db->nextRecord()) {
198: $this->lasterror = i18n("Category doesn't exist, assignment failed", "workflow");
199: return false;
200: }
201:
202: parent::setField("idcatlang", $idcatlang);
203: parent::store();
204: return true;
205: }
206:
207: }
208:
209: ?>