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