Пример #1
0
 /**
  * Function is only called when sendToAllReceivers is 1.
  * This function creates an array that contains all Decissions according to an WorkflowSlot and its WorkflowUsers
  */
 public function checkCurrentSlot() {
     $result = array();
     foreach($this->workflowSlotUser as $user) {
         $processUser = WorkflowProcessUserTable::instance()->getProcessUserByWorkflowSlotUserId($user->getId())->toArray();
         $this->decission[] = $this->checkProcessState($processUser);
     }
 }
Пример #2
0
 /**
  * Load all stations, which are running
  *
  * @param sfWebRequest $request
  * @return <type>
  */
 public function executeLoadStation(sfWebRequest $request) {
     $filter = new FilterManagement();
     $data = WorkflowProcessUserTable::instance()->getWaitingProcess();
     $json_data = $filter->getRunningStation($data);
     $this->renderText('{"result":'.json_encode($json_data).'}');
     return sfView::NONE;
 }
Пример #3
0
 /**
  *
  * @param array $data, contains reason for deny
  * @param int $workflowid, workflow id
  * @param int $userId, user id
  * @param int $versionId, version id
  * @return <type>
  */
 public function denyWorkflow(array $data, $workflowid, $userId, $versionId) {
     WorkflowTemplateTable::instance()->stopWorkflow($workflowid, $userId);
     WorkflowVersionTable::instance()->setEndReason($versionId, $data['workfloweditAcceptWorkflow_reason']);
     $workflowToStop = WorkflowProcessUserTable::instance()->getWaitingStationToStopByUser($versionId);
     foreach($workflowToStop as $itemToChange) {
         $pdoObj = Doctrine::getTable('WorkflowProcessUser')->find($itemToChange->getId());
         $pdoObj->setDecissionstate('STOPPEDBYUSER');
         $pdoObj->setDateofdecission(time());
         $pdoObj->save();
     }
     return true;
 }
    protected function execute($arguments = array(), $options = array()) {
        // initialize the database connection
        $databaseManager = new sfDatabaseManager($this->configuration);
        $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
        $context = sfContext::createInstance($this->configuration);
        $context->getConfiguration()->loadHelpers('Partial', 'I18N', 'Url', 'Date', 'CalculateDate', 'ColorBuilder', 'Icon', 'EndAction');
        $serverUrl = $options['setenvironment'] == '' ? $serverUrl = $options['host'] : $serverUrl = $options['host'] . '/' . $options['setenvironment'];

        $system = SystemConfigurationTable::instance()->getSystemConfiguration()->toArray();
        if($system[0]['individualcronjob'] == 1) {
            $systemConifg = new CheckSubstituteRun($context);
            if($systemConifg->checkRun($system[0]['cronjobdays'],$system[0]['cronjobfrom'],$system[0]['cronjobto']) == true) {
                $process = WorkflowProcessUserTable::instance()->getWaitingProcess(); // load all waiting processes
                $sub = new CheckSubstitute($process, $context, $serverUrl, $system[0]['setuseragenttype']);
            }
        }
        else {
            $process = WorkflowProcessUserTable::instance()->getWaitingProcess(); // load all waiting processes
            $sub = new CheckSubstitute($process, $context, $serverUrl, $system[0]['setuseragenttype']);
        }
    }
    protected function execute($arguments = array(), $options = array()) {
    // initialize the database connection
        $databaseManager = new sfDatabaseManager($this->configuration);
        $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
        $context = sfContext::createInstance($this->configuration);
        sfProjectConfiguration::getActive()->loadHelpers('Partial', 'I18N', 'Url');
        $serverUrl = $options['setenvironment'] == '' ? $serverUrl = $options['host'] : $serverUrl = $options['host'] . '/' . $options['setenvironment'];
        


        $wfSettings = SystemConfigurationTable::instance()->getSystemConfiguration()->toArray();
        if($wfSettings[0]['sendremindermail'] == 1) {
            $sendMail = new PrepareReminderEmail();
            $stillOpenWorkflows = array();
            $a = 0;
            $openWorkflows = WorkflowTemplateTable::instance()->getAllRunningWorkflows();
            foreach($openWorkflows as $workflow) {
                $openStations = WorkflowProcessUserTable::instance()->getWaitingStationByVersionId($workflow['WorkflowVersion']['id'])->toArray();
                $data = $sendMail->prepareData($openStations);
                $stillOpenWorkflows[$a]['workflow_id'] = $workflow['id'];
                $stillOpenWorkflows[$a]['name'] = $workflow['name'];
                $stillOpenWorkflows[$a]['workflowversion_id'] = $workflow['WorkflowVersion']['id'];
                $stillOpenWorkflows[$a++]['users'] = $data;
            }
            $stillOpenWorkflows = $sendMail->sortByUser($stillOpenWorkflows);
            foreach($stillOpenWorkflows as $userToSend) {
                $umSettings = new UserMailSettings($userToSend['user_id']);
                $reminder = new SendReminderEmail($umSettings,$context, $userToSend, $serverUrl);
            }

        }


        

    // add your code here
    }
 /**
  * Function checks if the WAITING process is a substitute of an process.
  * If Yes, the StartProcess is loaded, and all substitutes were merged into the StartProcess
  * If No, nothing happens
  * @param Doctrine_Collection $openProcesses, WAITING processes
  * @return array $result, merged Array
  */
 public function checkForSubstitute($openProcesses) {
     $result = array();
     $b = 0;
     foreach($openProcesses as $process) {
         if($process['isuseragentof'] != '' AND is_numeric($process['isuseragentof']) == true) {
             $processAndSubstitutes = WorkflowProcessUserTable::instance()->getProcessAndSubstituteProcessByProcessId($process->getIsuseragentof())->toArray();
             $theProcessWithSubstitute = array();
             $theProcessWithSubstitute = $processAndSubstitutes[0];
             // add substitutes to the Process
             $counter = 0;
             for($a=1;$a<count($processAndSubstitutes);$a++) {
                 $theProcessWithSubstitute['hasSubstitute'] = 1;
                 $theProcessWithSubstitute['substitutes'][$counter++] = $processAndSubstitutes[$a];
             }
             $result[$b++] = $theProcessWithSubstitute;
         }
         else {
             $result[$b] = $process->toArray();
             $result[$b]['hasSubstitute'] = 0;
             $b++;
         }
     }
     return $result;
 }
 /**
  * Load all Workflowproecsses and Workflowprcessuser entries
  *
  * @param array $wfProcess, processdata
  * @return array $result
  */
 public function addWorkflowProcessUser(array $wfProcess) {
     $result = array();
     $userprocess = WorkflowProcessUserTable::instance()->getWorkflowProcessUserByWorklflowProcessId($wfProcess['id'])->toArray();
     $a = 0;
     foreach ($userprocess as $process) {
         $result[$a]['decissionstate'] = $process['decissionstate'];
         $result[$a]['isuseragentof'] = $process['isuseragentof'];
         $result[$a++]['user_id'] = $process['user_id'];
     }
     return $result;
 }
Пример #8
0
 public function stopWorkflow($workflow_id, $version_id, $user_id, $endreason) {
     WorkflowTemplateTable::instance()->stopWorkflow($workflow_id, $user_id);
     WorkflowVersionTable::instance()->setEndReason($version_id, $endreason);
     WorkflowProcessUserTable::instance()->setWaitingStationToStoppedByUser($version_id);
 }
Пример #9
0
 /**
  * Now the slots / stations between the old id and the new id must be filled.
  * This function calculates the slots and users and fills it
  *
  * @param int $workflowslot_id, id of the slot
  * @param int $position, SLot position
  */
 public function calculateStation($workflowslot_id, $position) {
     $nextUser = $this->getNextUser($workflowslot_id, $position);
     if(!empty($nextUser)) { // user has been found
         $currentWorkflowProcessUser = WorkflowProcessUserTable::instance()->getProcessUserByWorkflowSlotUserId($nextUser[0]['id'])->toArray();
         if(!empty($currentWorkflowProcessUser)) { // user has a process, then remove it
             WorkflowProcessUserTable::instance()->deleteWorkflowProcessUserByWorkfloSlotUserId($currentWorkflowProcessUser[0]['workflowslotuser_id']);
             WorkflowProcessTable::instance()->deleteWorkflowProcessById($currentWorkflowProcessUser[0]['workflowprocess_id']);
             $this->calculateStation($nextUser[0]['workflowslot_id'], $nextUser[0]['position']+1);
         }
         else {
             $this->calculateStation($nextUser[0]['workflowslot_id'], $nextUser[0]['position']+1); // user has no process running, the search for next user
         }
     }
     else {
         $this->calculateSlot($workflowslot_id);
     }
 }
Пример #10
0
 /**
  * Move workflow to archive, and stop it
  * 
  * @param sfWebRequest $request
  * @return <type>
  */
 public function executeArchiveWorkflow(sfWebRequest $request) {
     WorkflowTemplateTable::instance()->archiveAndStopWorkflow($request->getParameter('workflowtemplateid'), $this->getUser()->getAttribute('id'));
     $workflow = new WorkflowOverview($this->getContext(), $this->getUser());
     $workflow->setUserId($this->getUser()->getAttribute('id'));
     $workflow->setCulture($this->getUser()->getCulture());
     $data = WorkflowProcessUserTable::instance()->getWaitingStationToStopByUser($request->getParameter('versionid'));
     foreach($data as $itemToChange) {
             $pdoObj = Doctrine::getTable('WorkflowProcessUser')->find($itemToChange->getId());
             $pdoObj->setDecissionstate('ARCHIVED');
             $pdoObj->setDateofdecission(time());
             $pdoObj->save();
     }
     return sfView::NONE;
 }
 public function getDecission (WorkflowSlotUser $user, $templateversion_id) {
     $result = array();
     $a = 0;
     $processUsers = WorkflowProcessUserTable::instance()->getProcessUserByWorkflowSlotUserId($user->getId());
     foreach($processUsers as $processUser) {
         $result[$a] = $processUser->toArray();
         $result[$a]['received'] = format_date($result[$a]['inprogresssince'], 'g', $this->culture);
         $result[$a]['decission_id'] = $result[$a]['id'];
         $result[$a]['endreasion'] = '';
         $result[$a]['useragent_id'] = $result[$a]['user_id'];
         $result[$a]['isuseragentof'] = $result[$a]['isuseragentof'];
         $usersettings = $this->user->getAttribute('userSettings');
         $inProgress = createDayOutOfDateSince(date('Y-m-d', $result[$a]['inprogresssince']));
         $inProgress = addColor($inProgress, $usersettings['markred'],$usersettings['markorange'],$usersettings['markyellow']);
         $result[$a]['inprogresssince'] = '<table><tr><td width="20">' . $inProgress . ' </td><td>' . $this->context->getI18N()->__('Days' ,null,'workflowmanagement') . '</td></tr></table>';
         $result[$a]['decissioninwords'] = '<table><tr><td>'.AddStateIcon($result[$a]['decissionstate']).'</td><td>' . $this->context->getI18N()->__($result[$a]['decissionstate'],null,'workflowmanagement') . '</td></tr></table>';
         if($result[$a]['decissionstate'] == 'STOPPEDBYADMIN') {
             $result[$a]['inprogresssince'] = '-';
         }
         elseif($result[$a]['decissionstate'] == 'STOPPEDBYUSER') {
             $endReasion = WorkflowVersionTable::instance()->getWorkflowVersionById($templateversion_id);
             $result[$a]['endreasion'] = $endReasion[0]->getEndreason();
         }
         $a++;
     }
     return $result;
 }
    public function getProcess($version_id) {
        $slots = WorkflowSlotTable::instance()->getSlotByVersionId($version_id);
        $alreadyCompleted = 0;
        $toComplete = 0;
        foreach($slots as $slot) {
            $users = WorkflowSlotUserTable::instance()->getUserBySlotId($slot->getId());
            $toComplete += count($users);
            foreach($users as $user) {
                $processUser = WorkflowProcessUserTable::instance()->getProcessUserByWorkflowSlotUserId($user->getId())->toArray();
                if(!empty($processUser)) {
                    $waiting = true;
                    foreach($processUser as $process) {
                        if(count($processUser) == 1 AND $process['decissionstate'] != 'WAITING') {
                            $alreadyCompleted++;
                        }
                        else {
                            if($process['decissionstate'] != 'WAITING') {
                                $waiting = false;
                            }
                            else {
                                $waiting = true;
                            }
                        }
                    }
                    if(count($processUser) > 1 AND $waiting == false) {
                        $alreadyCompleted++;
                    }
                }
            }
        }
        $percentDone = ($toComplete/$toComplete);
        $fullPercentDone = 100 / $toComplete;
        $percentDone = $fullPercentDone * $alreadyCompleted;
        if($percentDone > 100) {
            $percentDone = 100;
        }
        $color = '';
        if($percentDone < 15) {

        }
        else if ($percentDone >= 15 AND $percentDone < 30) {
            $color = '#FF0000';
        }
        else if ($percentDone >= 30 AND $percentDone < 45) {
            $color = '#FF9933';
        }
        else if ($percentDone >= 45 AND $percentDone < 60) {
            $color = '#FFCC33';
        }
        else if ($percentDone >= 60 AND $percentDone < 75) {
            $color = '#FFFF33';
        }
        else if ($percentDone >= 75 AND $percentDone < 90) {
            $color = '#99FF99';
        }
        else {
            $color = '#00FF00';
        }
        return '<div style="background-color:'.$color.'; width:'.$percentDone.'px;">'.floor($percentDone) . ' %'.'</div>';
    }
Пример #13
0
 /**
  * Set current station inactive
  *
  * @param int $workflowslotuser_id, Workflowslot userid
  */
 public function setStationInactive($workflowslotuser_id) {
     WorkflowProcessUserTable::instance()->skipAllStation($workflowslotuser_id);
 }
Пример #14
0
    /**
     * Add a useragent manually
     *
     * @param sfWebRequest $request
     * @return <type>
     */
    public function executeSetUseragent(sfWebRequest $request) {
        sfLoader::loadHelpers('Url');
        $useragent_id = $request->getParameter('userid');
        $workflowprocess_id = $request->getParameter('workflowprocessuserid');
        $version_id = $request->getParameter('versionid');
        $currentVersion = WorkflowProcessUserTable::instance()->getProcessById($workflowprocess_id)->toArray();
        $workflowId = WorkflowVersionTable::instance()->getWorkflowVersionById($version_id)->toArray();
        $context = sfContext::getInstance();
        $context->getConfiguration()->loadHelpers('Partial', 'I18N', 'Url', 'Date', 'CalculateDate', 'ColorBuilder', 'Icon', 'EndAction');

        $processObj = new WorkflowProcessUser();
        $processObj->setWorkflowprocessId($currentVersion[0]['workflowprocess_id']);
        $processObj->setWorkflowslotuserId($currentVersion[0]['workflowslotuser_id']);
        $processObj->setUserId($useragent_id);
        $processObj->setInprogresssince(time());
        $processObj->setDecissionstate('WAITING');
        $processObj->setUseragentsetbycronjob(0);
        $processObj->setIsuseragentof($workflowprocess_id);
        $processObj->setResendet(0);
        $processObj->save();
        WorkflowProcessUserTable::instance()->setProcessToUseragentSet($workflowprocess_id);

        $mailObj = new PrepareStationEmail($version_id, $workflowId[0]['workflowtemplate_id'], $useragent_id, $context,str_replace('/layout', '', url_for('layout/index',true)));


        $detailsObj = new WorkflowDetail();
        $detailsObj->setUser($this->getUser());
        $detailsObj->setCulture($this->getUser()->getCulture());
        $detailsObj->setContext($this->getContext());

        $workflowsettings = WorkflowVersionTable::instance()->getWorkflowVersionById($version_id);
        $userData = $detailsObj->buildUserData($workflowsettings, $version_id);
        $this->renderText('{"detailData" : '.json_encode($userData).'}');
        return sfView::NONE;
    }
 /**
  * Function is needed, when a worklow is sendet to all slots at once.
  * This function checks if each Entry from WorkflowProcessUser is != WAITING
  *
  * If no user needs to fill out the workflow, the workflow is completed and flag will be set
  */
 public function checkSendToAllAtOnce() {
     if($this->sendToAllAtOnce == 1) {
         $slots = WorkflowSlotTable::instance()->getSlotByVersionId($this->version_id);
         $isCompleted = true;
         foreach($slots as $slot) {
             $users = WorkflowSlotUserTable::instance()->getUserBySlotId($slot->getId());
             foreach($users as $user) {
                 $processUsers = WorkflowProcessUserTable::instance()->getProcessUserByWorkflowSlotUserId($user->getId());
                 foreach($processUsers as $singleUser) {
                     $userArray = $singleUser->toArray();
                     if($userArray['decissionstate'] == 'WAITING') {
                         $isCompleted = false;
                     }
                 }
             }
         }
         if($isCompleted == true) {
             WorkflowTemplateTable::instance()->setWorkflowFinished($this->workflowtemplate_id);
             $this->checkEndAction();
         }
     }
 }
    /**
     * Recursive function, which calculates and creates a useragent.
     * The Function calculates out of an timestamp the next useragent
     *
     * The $sumUseragenttime variable is summed up by each set useragent.
     * $sumUseragenttime = $sumUseragenttime + (mountofUseragents * userUserSetinngsUserAgenttime)
     *
     * @param array $userAgent, current Useragent
     * @param int $sumUseragenttime, useragent time which is summed up by each written useragent
     * @param int $userAgentOffset, offset for the array
     */
    public function setNewUserAgent(array $userAgent, $sumUseragenttime, $userAgentOffset) {
        
        if($this->checkSubObj->cronJobSetting == 1){
            if($this->currentTime > ($sumUseragenttime + $this->process['inprogresssince'])) {
                $decissionstate = 'USERAGENTSET';
                $userAgentOffset++;
                $nextUserAgent = $this->getNextUserAgent($userAgentOffset);
                if(is_array($nextUserAgent) == true) { // a useragent was found
                    $sumUseragenttime = $sumUseragenttime + $this->process['useragenttime'];
                    WorkflowProcessUserTable::instance()->setProcessToUseragentSet($this->process['id']);
                    $processObj = new WorkflowProcessUser();
                    $processObj->setWorkflowprocessId($this->process['workflowprocess_id']);
                    $processObj->setWorkflowslotuserId($this->process['workflowslotuser_id']);
                    $processObj->setUserId($userAgent['useragent_id']);
                    $processObj->setInprogresssince(time());
                    $processObj->setDateofdecission(time());
                    $processObj->setDecissionstate('USERAGENTSET');
                    $processObj->setUseragentsetbycronjob(1);
                    $processObj->setIsuseragentof($this->process['id']);
                    $processObj->setResendet(0);
                    $processObj->save();
                    $this->setNewUserAgent($nextUserAgent, $sumUseragenttime, $userAgentOffset);
                }
                else { // last Useragent in list is selected
                    $decissionstate = 'WAITING';
                }
            }
            else {
                $decissionstate = 'WAITING';
            }
        }
        else {
            $decissionstate = 'WAITING';
        }

        if($decissionstate == 'WAITING') {
            WorkflowProcessUserTable::instance()->setProcessToUseragentSet($this->process['id']);
            $processObj = new WorkflowProcessUser();
            $processObj->setWorkflowprocessId($this->process['workflowprocess_id']);
            $processObj->setWorkflowslotuserId($this->process['workflowslotuser_id']);
            $processObj->setUserId($userAgent['useragent_id']);
            $processObj->setInprogresssince(time());
            $processObj->setDateofdecission(time());
            $processObj->setDecissionstate('WAITING');
            $processObj->setUseragentsetbycronjob(1);
            $processObj->setIsuseragentof($this->process['id']);
            $processObj->setResendet(0);
            $processObj->save();
            // get Additional Data, to send an email
            $workflowSettings = WorkflowProcessTable::instance()->getWorkflowProcessById($this->process['id']);
            $workflowVersionTable = WorkflowVersionTable::instance()->getWorkflowVersionById($workflowSettings[0]->getWorkflowversionId())->toArray();

            // sendmail
            $mailObj = new PrepareStationEmail($workflowVersionTable[0]['id'], $workflowVersionTable[0]['workflowtemplate_id'], $userAgent['useragent_id'], $this->checkSubObj->context, $this->checkSubObj->serverUrl);
        }
    
    }