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 WorkflowUserSequences extends ItemCollection {
25: 26: 27: 28: 29:
30: public function __construct() {
31: global $cfg;
32: parent::__construct($cfg["tab"]["workflow_user_sequences"], "idusersequence");
33: $this->_setItemClass("WorkflowUserSequence");
34: }
35:
36: 37: 38: 39: 40: 41: 42:
43: public function delete($id) {
44: global $cfg, $idworkflow;
45:
46: $item = new WorkflowUserSequence();
47: $item->loadByPrimaryKey($id);
48:
49: $pos = $item->get("position");
50: $idworkflowitem = $item->get("idworkflowitem");
51: $this->select("position > $pos AND idworkflowitem = " . (int) $idworkflowitem);
52: while (($obj = $this->next()) !== false) {
53: $pos = $obj->get("position") - 1;
54: $obj->setPosition($pos);
55: $obj->store();
56: }
57:
58: parent::delete($id);
59:
60: $this->updateArtAllocation($id);
61: }
62:
63: 64: 65: 66: 67: 68: 69:
70: public function updateArtAllocation($idusersequence) {
71: global $idworkflow, $cfg;
72: $oDb = cRegistry::getDb();
73:
74: $aIdArtLang = array();
75: $sSql = 'SELECT idartlang FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence = ' . $oDb->escape($idusersequence) . ';';
76: $oDb->query($sSql);
77: while ($oDb->nextRecord()) {
78: array_push($aIdArtLang, $oDb->f('idartlang'));
79: }
80:
81: $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence = ' . $oDb->escape($idusersequence) . ';';
82: $oDb->query($sSql);
83:
84: foreach ($aIdArtLang as $iIdArtLang) {
85: setUserSequence($iIdArtLang, $idworkflow);
86: }
87: }
88:
89: 90: 91: 92: 93: 94: 95: 96:
97: public function create($idworkflowitem) {
98: global $auth, $client, $idworkflow;
99:
100: $workflowitems = new WorkflowItems();
101: if (!$workflowitems->exists($idworkflowitem)) {
102: $this->lasterror = i18n("Workflow item doesn't exist. Can't create entry.", "workflow");
103: return false;
104: }
105:
106: $this->select("idworkflowitem = " . (int) $idworkflowitem, "", "position DESC", "1");
107:
108: $item = $this->next();
109:
110: if ($item === false) {
111: $lastPos = 1;
112: } else {
113: $lastPos = $item->getField("position") + 1;
114: }
115:
116: $newitem = $this->createNewItem();
117: $newitem->setWorkflowItem($idworkflowitem);
118: $newitem->setPosition($lastPos);
119: $newitem->store();
120:
121: return $newitem;
122: }
123:
124: 125: 126: 127: 128: 129: 130: 131: 132: 133:
134: public function swap($idworkflowitem, $pos1, $pos2) {
135: $this->select("idworkflowitem = '$idworkflowitem' AND position = " . (int) $pos1);
136: if (($item = $this->next()) === false) {
137: $this->lasterror = i18n("Swapping items failed: Item doesn't exist", "workflow");
138: return false;
139: }
140:
141: $pos1ID = $item->getField("idusersequence");
142:
143: $this->select("idworkflowitem = '$idworkflowitem' AND position = " . (int) $pos2);
144: if (($item = $this->next()) === false) {
145: $this->lasterror(i18n("Swapping items failed: Item doesn't exist", "workflow"));
146: return false;
147: }
148:
149: $pos2ID = $item->getField("idusersequence");
150:
151: $item = new WorkflowUserSequence();
152: $item->loadByPrimaryKey($pos1ID);
153: $item->setPosition($pos2);
154: $item->store();
155: $item->loadByPrimaryKey($pos2ID);
156: $item->setPosition($pos1);
157: $item->store();
158:
159: $this->updateArtAllocation($pos2ID);
160: $this->updateArtAllocation($pos1ID);
161:
162: return true;
163: }
164:
165: }
166:
167: 168: 169: 170: 171: 172: 173: 174: 175: 176:
177: class WorkflowUserSequence extends Item {
178:
179: 180: 181:
182: public function __construct() {
183: global $cfg;
184: parent::__construct($cfg["tab"]["workflow_user_sequences"], "idusersequence");
185: }
186:
187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200:
201: public function setField($field, $value, $safe = true) {
202: global $cfg;
203:
204: switch ($field) {
205: case "idworkflowitem":
206: throw new cInvalidArgumentException("Please use create to modify idsequence. Direct modifications are not allowed");
207: case "idusersequence":
208: throw new cInvalidArgumentException("Please use create to modify idsequence. Direct modifications are not allowed");
209: case "position":
210: throw new cInvalidArgumentException("Please use create and swap to set the position. Direct modifications are not allowed");
211: case "iduser":
212: if ($value != 0) {
213: $db = cRegistry::getDb();
214: $sql = "SELECT user_id FROM " . $cfg['tab']['user'] . " WHERE user_id = '" . $db->escape($value) . "'";
215: $db->query($sql);
216:
217: if (!$db->nextRecord()) {
218: $sql = "SELECT group_id FROM " . $cfg["tab"]["groups"] . " WHERE group_id = '" . $db->escape($value) . "'";
219:
220: $db->query($sql);
221: if (!$db->nextRecord()) {
222: $this->lasterror = i18n("Can't set user_id: User or group doesn't exist", "workflow");
223: return false;
224: }
225: }
226: $idusersquence = parent::getField('idusersequence');
227: }
228: }
229:
230: parent::setField($field, $value, $safe);
231: if ($idusersquence) {
232: $workflowUserSequences = new WorkflowUserSequences();
233: $workflowUserSequences->updateArtAllocation(0);
234: }
235: }
236:
237: 238: 239: 240: 241: 242: 243:
244: public function getWorkflowItem() {
245: if ($this->isLoaded()) {
246: $workflowItem = new WorkflowItem();
247: $workflowItem->loadByPrimaryKey($this->values["idworkflowitem"]);
248: return ($workflowItem);
249: } else {
250: return false;
251: }
252: }
253:
254: 255: 256: 257: 258: 259:
260: public function setWorkflowItem($value) {
261: parent::setField("idworkflowitem", $value);
262: }
263:
264: 265: 266: 267: 268: 269:
270: public function setPosition($value) {
271: parent::setField("position", $value);
272: }
273:
274: }
275: