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