示例#1
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;
    }
    /**
     * 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);
        }
    
    }