Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • Workflow
  • WorkflowAction
  • WorkflowActions
  • WorkflowAllocation
  • WorkflowAllocations
  • WorkflowArtAllocation
  • WorkflowArtAllocations
  • WorkflowItem
  • WorkflowItems
  • Workflows
  • WorkflowTask
  • WorkflowTasks
  • WorkflowUserSequence
  • WorkflowUserSequences

Functions

  • createNewWorkflow
  • doWorkflowAction
  • editWorkflowStep
  • getActionSelect
  • getCatLang
  • getCurrentUserSequence
  • getLastWorkflowStatus
  • getTimeUnitSelector
  • getUsers
  • getWorkflowForCat
  • getWorkflowForUserSequence
  • getWorkflowList
  • getWorkflowUsers
  • isCurrentEditor
  • piworkflowAllowArticleEdit
  • piworkflowCategoryColumns
  • piworkflowCategoryRenderColumn
  • piworkflowCreateTasksFolder
  • piworkflowProcessActions
  • piworkflowProcessArticleColumns
  • piworkflowRenderAction
  • piworkflowRenderColumn
  • prepareWorkflowItems
  • setUserSequence
  • workflowInherit
  • workflowSelect
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the class for workflow item management.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage Workflow
  7:  * @author Timo Hummel
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Class for workflow item management.
 18:  *
 19:  * @package Plugin
 20:  * @subpackage Workflow
 21:  * @method WorkflowItem createNewItem
 22:  * @method WorkflowItem next
 23:  */
 24: class WorkflowItems extends ItemCollection {
 25:     /**
 26:      * Constructor Function
 27:      *
 28:      * @throws cInvalidArgumentException
 29:      */
 30:     public function __construct() {
 31:         global $cfg;
 32:         parent::__construct($cfg["tab"]["workflow_items"], "idworkflowitem");
 33:         $this->_setItemClass("WorkflowItem");
 34:     }
 35: 
 36:     /**
 37:      * @param mixed $id
 38:      *
 39:      * @return bool|void
 40:      * @throws cDbException
 41:      * @throws cException
 42:      */
 43:     public function delete($id) {
 44:         global $cfg;
 45:         $item = new WorkflowItem();
 46:         $item->loadByPrimaryKey($id);
 47:         $pos = (int) $item->get("position");
 48:         $idworkflow = (int) $item->get("idworkflow");
 49:         $oDb = cRegistry::getDb();
 50: 
 51:         $this->select("position > {$pos} AND idworkflow = {$idworkflow}");
 52:         while (($obj = $this->next()) !== false) {
 53:             $obj->setPosition($obj->get("position") - 1);
 54:             $obj->store();
 55:         }
 56: 
 57:         $aUserSequencesDelete = array();
 58:         $sSql = 'SELECT idusersequence FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idworkflowitem = ' . (int) $id;
 59:         $oDb->query($sSql);
 60:         while ($oDb->nextRecord()) {
 61:             $aUserSequencesDelete[] = (int) $oDb->f('idusersequence');
 62:         }
 63: 
 64:         $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_actions"] . ' WHERE idworkflowitem = ' . (int) $id;
 65:         $oDb->query($sSql);
 66: 
 67:         $this->updateArtAllocation($id, 1);
 68: 
 69:         if (count($aUserSequencesDelete) > 0) {
 70:             $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idusersequence in (' . implode(',', $aUserSequencesDelete) . ')';
 71:             $oDb->query($sSql);
 72:         }
 73:     }
 74: 
 75:     /**
 76:      * @param      $idworkflowitem
 77:      * @param bool $delete
 78:      *
 79:      * @throws cDbException
 80:      * @throws cException
 81:      * @throws cInvalidArgumentException
 82:      */
 83:     public function updateArtAllocation($idworkflowitem, $delete = false) {
 84:         global $idworkflow, $cfg;
 85:         $oDb = cRegistry::getDb();
 86: 
 87:         $aUserSequences = array();
 88:         $sSql = 'SELECT idusersequence FROM ' . $cfg["tab"]["workflow_user_sequences"] . ' WHERE idworkflowitem = ' . (int) $idworkflowitem;
 89: 
 90:         $oDb->query($sSql);
 91:         while ($oDb->nextRecord()) {
 92:             $aUserSequences[] = (int) $oDb->f('idusersequence');
 93:         }
 94: 
 95:         $aIdArtLang = array();
 96:         if (count($aUserSequences) > 0) {
 97:             $sSql = 'SELECT idartlang FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence in (' . implode(',', $aUserSequences) . ')';
 98:             $oDb->query($sSql);
 99:             while ($oDb->nextRecord()) {
100:                 $aIdArtLang[] = (int) $oDb->f('idartlang');
101:             }
102:             $sSql = 'DELETE FROM ' . $cfg["tab"]["workflow_art_allocation"] . ' WHERE idusersequence in (' . implode(',', $aUserSequences) . ')';
103:             $oDb->query($sSql);
104:         }
105: 
106:         if ($delete) {
107:             parent::delete($idworkflowitem);
108:         }
109: 
110:         foreach ($aIdArtLang as $iIdArtLang) {
111:             setUserSequence($iIdArtLang, $idworkflow);
112:         }
113:     }
114: 
115:     /**
116:      * @param $idworkflow
117:      * @param $pos1
118:      * @param $pos2
119:      *
120:      * @return bool
121:      * @throws cDbException
122:      * @throws cException
123:      * @throws cInvalidArgumentException
124:      */
125:     public function swap($idworkflow, $pos1, $pos2) {
126:         $idworkflow = (int) $idworkflow;
127:         $pos1 = (int) $pos1;
128:         $pos2 = (int) $pos2;
129: 
130:         $this->select("idworkflow = {$idworkflow} AND position = {$pos1}");
131:         if (($item = $this->next()) === false) {
132:             $this->lasterror = i18n("Swapping items failed: Item doesn't exist", "workflow");
133:             return false;
134:         }
135: 
136:         $pos1ID = $item->getField("idworkflowitem");
137: 
138:         $this->select("idworkflow = {$idworkflow} AND position = {$pos2}");
139:         if (($item = $this->next()) === false) {
140:             $this->lasterror = i18n("Swapping items failed: Item doesn't exist", "workflow");
141:             return false;
142:         }
143: 
144:         $pos2ID = $item->getField("idworkflowitem");
145: 
146:         $item = new WorkflowItem();
147:         $item->loadByPrimaryKey($pos1ID);
148:         $item->setPosition($pos2);
149:         $item->store();
150:         $item->loadByPrimaryKey($pos2ID);
151:         $item->setPosition($pos1);
152:         $item->store();
153: 
154:         $this->updateArtAllocation($pos1ID);
155:         $this->updateArtAllocation($pos2ID);
156:         return (true);
157:     }
158: 
159:     /**
160:      * @param $idworkflow
161:      *
162:      * @return bool|Item
163:      * @throws cDbException
164:      * @throws cException
165:      * @throws cInvalidArgumentException
166:      */
167:     public function create($idworkflow) {
168:         $idworkflow = (int) $idworkflow;
169: 
170:         $workflows = new Workflows();
171:         $workflows->select("idworkflow = {$idworkflow}");
172: 
173:         if ($workflows->next() === false) {
174:             $this->lasterror = i18n("Can't add item to workflow: Workflow doesn't exist", "workflow");
175:             return false;
176:         }
177: 
178:         $this->select("idworkflow = {$idworkflow}", "", "position DESC", "1");
179: 
180:         $item = $this->next();
181: 
182:         if ($item === false) {
183:             $lastPos = 1;
184:         } else {
185:             $lastPos = $item->getField("position") + 1;
186:         }
187: 
188:         $newItem = $this->createNewItem();
189:         if ($newItem->init($idworkflow, $lastPos) === false) {
190:             $this->delete($newItem->getField("idworkflowitem"));
191:             $this->lasterror = $newItem->lasterror;
192:             return false;
193:         }
194: 
195:         if ($item === false) {
196:             $this->updateArtAllocation(0);
197:         }
198: 
199:         return ($newItem);
200:     }
201: 
202: }
203: 
204: /**
205:  * Class WorkflowItem
206:  * Class for a single workflow item
207:  *
208:  * @package Plugin
209:  * @subpackage Workflow
210:  * @author Timo A. Hummel <Timo.Hummel@4fb.de>
211:  * @version 0.1
212:  * @copyright four for business 2003
213:  */
214: class WorkflowItem extends Item {
215: 
216:     /**
217:      * Constructor Function
218:      */
219:     public function __construct() {
220:         global $cfg;
221: 
222:         parent::__construct($cfg["tab"]["workflow_items"], "idworkflowitem");
223:     }
224: 
225:     /**
226:      * @return mixed
227:      * @throws cDbException
228:      * @throws cException
229:      */
230:     public function getStepRights() {
231:         $idwfi = $this->values["idworkflowitem"];
232:         $workflowActions = new WorkflowActions();
233: 
234:         $actions = $workflowActions->getAvailableWorkflowActions();
235: 
236:         foreach ($actions as $key => $value) {
237:             $rights[$key] = $workflowActions->get($idwfi, $key);
238:         }
239: 
240:         return $rights;
241:     }
242: 
243:     /**
244:      * Overridden setField function.
245:      *
246:      * @param string $field Void field since we override the usual setField
247:      *                      function
248:      * @param string $value Void field since we override the usual setField
249:      *                      function
250:      * @param bool   $safe
251:      *
252:      * @return bool
253:      * @throws cInvalidArgumentException if the field is idsequence, idworkflow
254:      *         or position
255:      */
256:     public function setField($field, $value, $safe = true) {
257:         if (true !== $this->isLoaded()) {
258:             $this->lasterror = i18n("No item loaded", "workflow");
259:             return false;
260:         }
261: 
262:         if ($field == "idsequence") {
263:             throw new cInvalidArgumentException("You can't set the idsequence field using this method. Use 'create' in the WorkflowItems class.");
264:         }
265: 
266:         if ($field == "idworkflow") {
267:             throw new cInvalidArgumentException("You can't set the workflow ID using this method. Use 'create' in the WorkflowItems class!");
268:         }
269: 
270:         if ($field == "position") {
271:             throw new cInvalidArgumentException("You can't set the position ID using this method. Use 'create' or 'swap' to create or move items!");
272:         }
273: 
274:         if ($field == "idtask" && $value != 0) {
275:             $taskCollection = new WorkflowTasks();
276:             $taskCollection->select("idtask = '$value'");
277:             if ($taskCollection->next() === false) {
278:                 $this->lasterror = i18n("Requested task doesn't exist, can't assign", "workflow");
279:                 return false;
280:             }
281:         }
282: 
283:         parent::setField($field, $value, $safe);
284:     }
285: 
286:     /**
287:      * init initializes a new wf_items entry.
288:      * Should
289:      * only be called by the create function.
290:      *
291:      * @param int $idworkflow The workflow to set the item to
292:      * @param int $idposition Position of workflow item
293:      *
294:      * @return bool
295:      * @throws cDbException
296:      * @throws cException
297:      * @throws cInvalidArgumentException
298:      */
299:     public function init($idworkflow, $idposition) {
300:         global $cfg;
301: 
302:         $workflows = new Workflows();
303: 
304:         $workflows->select("idworkflow = '$idworkflow'");
305: 
306:         if ($workflows->next() === false) {
307:             $this->lasterror = i18n("Workflow doesn't exist", "workflow");
308:             return false;
309:         }
310: 
311:         $workflowItems = new WorkflowItems();
312:         $workflowItems->select("position = '$idposition' AND idworkflow = '$idworkflow'");
313:         if ($workflowItems->next()) {
314:             $this->lasterror = i18n("Position in this workflow already exists.", "workflow");
315:             return false;
316:         }
317: 
318:         parent::setField("idworkflow", $idworkflow);
319:         parent::setField("position", $idposition);
320:         $this->store();
321:         return true;
322:     }
323: 
324:     /**
325:      * setPosition Sets the position for an item.
326:      * Should only be
327:      * called by the "swap" function
328:      *
329:      * @param int $idposition The new position ID
330:      *
331:      * @return bool
332:      * @throws cDbException
333:      * @throws cInvalidArgumentException
334:      */
335:     public function setPosition($idposition) {
336:         parent::setField("position", $idposition);
337:         $this->store();
338:         return true;
339:     }
340: 
341: }
342: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0