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