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:
169: public function setField($field, $value, $safe = true) {
170: global $cfg;
171:
172: switch ($field) {
173: case "idworkflowitem":
174: throw new cInvalidArgumentException("Please use create to modify idsequence. Direct modifications are not allowed");
175: case "idusersequence":
176: throw new cInvalidArgumentException("Please use create to modify idsequence. Direct modifications are not allowed");
177: case "position":
178: throw new cInvalidArgumentException("Please use create and swap to set the position. Direct modifications are not allowed");
179: case "iduser":
180: if ($value != 0) {
181: $db = cRegistry::getDb();
182: $sql = "SELECT user_id FROM " . $cfg['tab']['user'] . " WHERE user_id = '" . $db->escape($value) . "'";
183: $db->query($sql);
184:
185: if (!$db->nextRecord()) {
186: $sql = "SELECT group_id FROM " . $cfg["tab"]["groups"] . " WHERE group_id = '" . $db->escape($value) . "'";
187:
188: $db->query($sql);
189: if (!$db->nextRecord()) {
190: $this->lasterror = i18n("Can't set user_id: User or group doesn't exist", "workflow");
191: return false;
192: }
193: }
194: $idusersquence = parent::getField('idusersequence');
195: }
196: }
197:
198: parent::setField($field, $value, $safe);
199: if ($idusersquence) {
200: $workflowUserSequences = new WorkflowUserSequences();
201: $workflowUserSequences->updateArtAllocation(0);
202: }
203: }
204:
205: 206: 207: 208: 209:
210: public function getWorkflowItem() {
211: if (!$this->virgin) {
212: $workflowItem = new WorkflowItem();
213: $workflowItem->loadByPrimaryKey($this->values["idworkflowitem"]);
214: return ($workflowItem);
215: } else {
216: return false;
217: }
218: }
219:
220: 221: 222: 223: 224: 225:
226: public function setWorkflowItem($value) {
227: parent::setField("idworkflowitem", $value);
228: }
229:
230: 231: 232: 233: 234: 235:
236: public function setPosition($value) {
237: parent::setField("position", $value);
238: }
239:
240: }
241:
242: ?>