Ejemplo n.º 1
0
    /**
     * Fill the users
     *
     * @param bool $sendToAllReceiverFlag
     * @param id $workflowslotUser
     * @param String $decission, skipped or waiting
     */
    public function checkSendToAllReceiverAtOnce($sendToAllReceiverFlag, $workflowslotUser, $decission) {
        if($sendToAllReceiverFlag == 1) {
            $station = WorkflowSlotUserTable::instance()->getUserBySlotId($workflowslotUser->getWorkflowslotId())->toArray();
            foreach($station as $item) {
                WorkflowProcessUserTable::instance()->deleteWorkflowProcessUserByWorkfloSlotUserId($item['id']);
            }
            WorkflowProcessTable::instance()->deleteWorkflowProcessByWorkflowSlotId($workflowslotUser->getWorkflowslotId());
            foreach($station as $item) {
                 $wfp = new WorkflowProcess();
                 $wfp->setWorkflowtemplateId($this->station->workflowtemplate_id);
                 $wfp->setWorkflowversionId($this->station->version_id);
                 $wfp->setWorkflowslotId($workflowslotUser->getWorkflowslotId());
                 $wfp->save();
                 $wfoId = $wfp->getId();

                 $wfpu = new WorkflowProcessUser();
                 $wfpu->setWorkflowprocessId($wfoId);
                 $wfpu->setWorkflowslotuserId($item['id']);
                 $wfpu->setUserId($item['user_id']);
                 $wfpu->setInprogresssince(time());
                 $wfpu->setDecissionstate($decission);
                 $wfpu->setResendet(0);
                 $wfpu->save();
                 if($decission == 'WAITING') {
                     $mail = new PrepareStationEmail($this->station->version_id, $this->station->workflowtemplate_id, $item['user_id'], $this->station->context, $this->station->serverUrl);
                 }
            }
        }
        
    }
    /**
     * Get the workflowprocess and workflowprocessuser entries of an old version, to rebuild the structure
     * when workflow will start at current station
     *
     * @param int $version_id, old id of the workflow
     * @return array $result
     */
    public function getRestartData($version_id) {
        $result = array();
        $a = 0;
        // load the slots
        $slots = WorkflowSlotTable::instance()->getSlotByVersionId($version_id);
        foreach($slots as $slot) {
            $documentSlot = $slot->getDocumenttemplateSlot()->toArray();
            $b = 0;
            $result[$a]['slot_id'] = $slot->getId();
            $result[$a]['sendtoallreceivers'] = $documentSlot[0]['sendtoallreceivers'];
            $result[$a]['version_id'] = $slot->getWorkflowversionId();
            // load the processtable
            $wfProcess = WorkflowProcessTable::instance()->getWorkflowProcessBySlotId($slot->getId())->toArray();
            if(!empty($wfProcess)) {
                foreach($wfProcess as $process) {
                    $result[$a]['userprocess'][$b]  = $process;
                    // add its processes for a user
                    $result[$a]['userprocess'][$b]['process'] = $this->addWorkflowProcessUser($process);
                    $b++;
                }

            }
            else {
                $result[$a]['userprocess'][$b] = '';
                $b++;
            }
            $a++;
        }
        return $result;
    }
Ejemplo n.º 3
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);
     }
 }
    public function getCurrentStation($activeversion_id, $sender_id) {
        $result = array();
        $activeVersion = WorkflowProcessTable::instance()->getCurrentStation($activeversion_id);
        $user = $activeVersion[0]->getWorkflowProcessUser()->toArray();
        $workflowslot = $activeVersion[0]->getWorkflowSlot()->toArray();
        if(!empty($workflowslot)) {
            $slot = DocumenttemplateSlotTable::instance()->getSlotById($workflowslot[0]['slot_id'])->toArray();
            $currentStation = $slot[0]['name'];
            $userdata = UserLoginTable::instance()->findActiveUserById($user['user_id'])->toArray();
            $username = $userdata[0]['username'];
            $currentStation .= ' <i>(' . $username . ')</i>';
            $result[0] = $currentStation;
            $result[1] = $workflowslot[0]['updated_at'];
            return $result;
        }

        return $result;
    }
    /**
     * 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);
        }
    
    }