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: $cfg["tab"]["workflow"] = $cfg['sql']['sqlprefix'] . "_piwf_workflow";
19: $cfg["tab"]["workflow_allocation"] = $cfg['sql']['sqlprefix'] . "_piwf_allocation";
20: $cfg["tab"]["workflow_art_allocation"] = $cfg['sql']['sqlprefix'] . "_piwf_art_allocation";
21: $cfg["tab"]["workflow_items"] = $cfg['sql']['sqlprefix'] . "_piwf_items";
22: $cfg["tab"]["workflow_tasks"] = $cfg['sql']['sqlprefix'] . "_piwf_tasks";
23: $cfg["tab"]["workflow_user_sequences"] = $cfg['sql']['sqlprefix'] . "_piwf_user_sequences";
24: $cfg["tab"]["workflow_actions"] = $cfg['sql']['sqlprefix'] . "_piwf_actions";
25:
26: plugin_include('workflow', 'classes/class.workflowactions.php');
27: plugin_include('workflow', 'classes/class.workflowallocation.php');
28: plugin_include('workflow', 'classes/class.workflowartallocation.php');
29: plugin_include('workflow', 'classes/class.workflowitems.php');
30: plugin_include('workflow', 'classes/class.workflowusersequence.php');
31:
32: 33: 34: 35: 36: 37:
38: class Workflows extends ItemCollection {
39:
40: 41: 42: 43: 44:
45: public function __construct() {
46: global $cfg;
47: parent::__construct($cfg["tab"]["workflow"], "idworkflow");
48: $this->_setItemClass("Workflow");
49: }
50:
51: public function create() {
52: global $auth, $client, $lang;
53: $newitem = parent::createNewItem();
54: $newitem->setField("created", date('Y-m-d H:i:s'));
55: $newitem->setField("idauthor", $auth->auth["uid"]);
56: $newitem->setField("idclient", $client);
57: $newitem->setField("idlang", $lang);
58: $newitem->store();
59:
60: return $newitem;
61: }
62:
63: 64: 65: 66: 67: 68:
69: public function delete($idWorkflow) {
70: global $cfg;
71: $oDb = cRegistry::getDb();
72:
73: $aItemIdsDelete = array();
74: $sSql = 'SELECT idworkflowitem FROM ' . $cfg["tab"]["workflow_items"] . ' WHERE idworkflow = ' . cSecurity::toInteger($idWorkflow) . ';';
75: $oDb->query($sSql);
76: while ($oDb->nextRecord()) {
77: $aItemIdsDelete[] = cSecurity::escapeDB($oDb->f('idworkflowitem'), $oDb);
78: }
79:
80: if (!empty($aItemIdsDelete)) {
81: $aUserSequencesDelete = array();
82: $sSql = 'SELECT idusersequence FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idworkflowitem in (' . implode(',', $aItemIdsDelete) . ');';
83: $oDb->query($sSql);
84: while ($oDb->nextRecord()) {
85: $aUserSequencesDelete[] = cSecurity::escapeDB($oDb->f('idusersequence'), $oDb);
86: }
87:
88: $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idworkflowitem in (' . implode(',', $aItemIdsDelete) . ');';
89: $oDb->query($sSql);
90:
91: $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_actions"] . ' WHERE idworkflowitem in (' . implode(',', $aItemIdsDelete) . ');';
92: $oDb->query($sSql);
93: }
94:
95: if (!empty($aUserSequencesDelete)) {
96: $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence in (' . implode(',', $aUserSequencesDelete) . ');';
97: $oDb->query($sSql);
98: }
99:
100: $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_items"] . ' WHERE idworkflow = ' . cSecurity::toInteger($idWorkflow) . ';';
101: $oDb->query($sSql);
102:
103: $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_allocation"] . ' WHERE idworkflow = ' . cSecurity::toInteger($idWorkflow) . ';';
104: $oDb->query($sSql);
105:
106: parent::delete($idWorkflow);
107: }
108:
109: }
110:
111: 112: 113: 114: 115: 116: 117: 118: 119: 120:
121: class Workflow extends Item {
122:
123: 124: 125: 126: 127:
128: public function __construct() {
129: global $cfg;
130:
131: parent::__construct($cfg["tab"]["workflow"], "idworkflow");
132: }
133:
134: }
135:
136:
137: function getWorkflowForCat($idcat) {
138: global $lang;
139:
140: $idcatlang = getCatLang($idcat, $lang);
141: if (!$idcatlang) {
142: return 0;
143: }
144: $workflows = new WorkflowAllocations();
145: $workflows->select('idcatlang = ' . (int) $idcatlang);
146: if (($obj = $workflows->next()) !== false) {
147:
148: $workflow = new Workflow();
149: $res = $workflow->loadByPrimaryKey($obj->get('idworkflow'));
150: return ($res == true)? $obj->get('idworkflow') : 0;
151: }
152: }
153:
154: function getCatLang($idcat, $idlang) {
155:
156: $oCatLangColl = new cApiCategoryLanguageCollection();
157: $aIds = $oCatLangColl->getIdsByWhereClause('idlang = ' . (int) $idlang . ' AND idcat = ' . (int) $idcat);
158: return (count($aIds) > 0)? $aIds[0] : 0;
159: }
160:
161: ?>