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