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