public function doAction()
 {
     $this->parseIDSegment();
     //get Job Infos
     $job_data = getJobData((int) $this->id_job);
     $pCheck = new AjaxPasswordCheck();
     if (!$pCheck->grantJobAccessByJobData($job_data, $this->password)) {
         $this->result['errors'][] = array("code" => -10, "message" => "wrong password");
     }
     if (empty($this->id_segment)) {
         $this->result['errors'][] = array("code" => -1, "message" => "missing segment id");
     }
     if (empty($this->id_job)) {
         $this->result['errors'][] = array("code" => -2, "message" => "missing Job id");
     }
     if (!empty($this->result['errors'])) {
         //no action on errors
         return;
     }
     $segmentStruct = TranslationsSplit_SplitStruct::getStruct();
     $segmentStruct->id_segment = $this->id_segment;
     $segmentStruct->id_job = $this->id_job;
     $translationDao = new TranslationsSplit_SplitDAO(Database::obtain());
     $currSegmentInfo = $translationDao->read($segmentStruct);
     /**
      * Split check control
      */
     $isASplittedSegment = false;
     $isLastSegmentChunk = true;
     if (count($currSegmentInfo) > 0) {
         $isASplittedSegment = true;
         $currSegmentInfo = array_shift($currSegmentInfo);
         //get the chunk number and check whether it is the last one or not
         $isLastSegmentChunk = $this->split_num == count($currSegmentInfo->source_chunk_lengths) - 1;
         if (!$isLastSegmentChunk) {
             $nextSegmentId = $this->id_segment . "-" . ($this->split_num + 1);
         }
     }
     /**
      * End Split check control
      */
     if (!$isASplittedSegment || $isLastSegmentChunk) {
         $segmentList = getNextSegment($this->id_segment, $this->id_job, $this->password, !self::isRevision() ? false : true);
         if (!self::isRevision()) {
             $nextSegmentId = fetchStatus($this->id_segment, $segmentList);
         } else {
             $nextSegmentId = fetchStatus($this->id_segment, $segmentList, Constants_TranslationStatus::STATUS_TRANSLATED);
             if (!$nextSegmentId) {
                 $nextSegmentId = fetchStatus($this->id_segment, $segmentList, Constants_TranslationStatus::STATUS_APPROVED);
             }
         }
     }
     $insertRes = setCurrentSegmentInsert($this->id_segment, $this->id_job, $this->password);
     $this->result['code'] = 1;
     $this->result['data'] = array();
     //get segment revision informations
     $reviseDao = new Revise_ReviseDAO(Database::obtain());
     $searchReviseStruct = Revise_ReviseStruct::getStruct();
     $searchReviseStruct->id_job = $this->id_job;
     $searchReviseStruct->id_segment = $this->id_segment;
     $_dbReviseStruct = $reviseDao->read($searchReviseStruct);
     if (count($_dbReviseStruct) > 0) {
         $_dbReviseStruct = $_dbReviseStruct[0];
     } else {
         $_dbReviseStruct = Revise_ReviseStruct::getStruct();
     }
     $_dbReviseStruct = Revise_ReviseStruct::setDefaultValues($_dbReviseStruct);
     $dbReviseStruct = self::prepareReviseStructReturnValues($_dbReviseStruct);
     $this->result['nextSegmentId'] = $nextSegmentId;
     $this->result['error_data'] = $dbReviseStruct;
     $this->result['original'] = CatUtils::rawxliff2view($_dbReviseStruct->original_translation);
 }
 /**
  * When Called it perform the controller action to retrieve/manipulate data
  *
  * @throws Exception
  */
 public function doAction()
 {
     if (!empty($this->result['errors'])) {
         return;
     }
     $job_data = getJobData((int) $this->id_job, $this->password_job);
     if (empty($job_data)) {
         $msg = "Error : empty job data \n\n " . var_export($_POST, true) . "\n";
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
     }
     //add check for job status archived.
     if (strtolower($job_data['status']) == Constants_JobStatus::STATUS_ARCHIVED) {
         $this->result['errors'][] = array("code" => -6, "message" => "job archived");
     }
     $this->parseIDSegment();
     $pCheck = new AjaxPasswordCheck();
     //check for Password correctness
     if (empty($job_data) || !$pCheck->grantJobAccessByJobData($job_data, $this->password_job, $this->id_segment)) {
         $this->result['errors'][] = array("code" => -7, "message" => "wrong password");
     }
     $wStruct = new WordCount_Struct();
     $wStruct->setIdJob($this->id_job);
     $wStruct->setJobPassword($this->password_job);
     $wStruct->setNewWords($job_data['new_words']);
     $wStruct->setDraftWords($job_data['draft_words']);
     $wStruct->setTranslatedWords($job_data['translated_words']);
     $wStruct->setApprovedWords($job_data['approved_words']);
     $wStruct->setRejectedWords($job_data['rejected_words']);
     $reviseDAO = new Revise_ReviseDAO(Database::obtain());
     //store segment revision in DB
     $revisionStruct = Revise_ReviseStruct::getStruct();
     $revisionStruct->id_job = $this->id_job;
     $revisionStruct->id_segment = $this->id_segment;
     //check if an old revision exists. If it does, retrieve it and save it.
     $oldRevision = $reviseDAO->read($revisionStruct);
     $oldRevision = isset($oldRevision[0]) ? $oldRevision[0] : Revise_ReviseStruct::setDefaultValues(Revise_ReviseStruct::getStruct());
     $revisionStruct->err_typing = $this->err_typing;
     $revisionStruct->err_translation = $this->err_translation;
     $revisionStruct->err_terminology = $this->err_terminology;
     $revisionStruct->err_language = $this->err_language;
     $revisionStruct->err_style = $this->err_style;
     $revisionStruct->original_translation = $this->original_translation;
     //save the new revision in the database.
     try {
         $reviseDAO->create($revisionStruct);
     } catch (Exception $e) {
         Log::doLog(__METHOD__ . " -> " . $e->getMessage());
         $this->result['errors'][] = array('code' => -4, 'message' => "Insert failed");
         return;
     }
     /**
      * Refresh error counters in the job table
      */
     $errorCountStruct = new ErrorCount_DiffStruct($oldRevision, $revisionStruct);
     $errorCountStruct->setIdJob($this->id_job);
     $errorCountStruct->setJobPassword($this->password_job);
     $errorCountDao = new ErrorCount_ErrorCountDAO(Database::obtain());
     try {
         $errorCountDao->update($errorCountStruct);
     } catch (Exception $e) {
         Log::doLog(__METHOD__ . " -> " . $e->getMessage());
         $this->result['errors'][] = array('code' => -5, 'message' => "Did not update job error counters.");
         return;
     }
     /**
      * Retrieve information about job errors
      * ( Note: these information are fed by the revision process )
      * @see setRevisionController
      */
     $jobQA = new Revise_JobQA($this->id_job, $this->password_job, $wStruct->getTotal());
     $jobQA->retrieveJobErrorTotals();
     $jobVote = $jobQA->evalJobVote();
     $this->result['data']['message'] = 'OK';
     $this->result['data']['stat_quality'] = $jobQA->getQaData();
     $this->result['data']['overall_quality'] = $jobVote['minText'];
     $this->result['data']['overall_quality_class'] = strtolower(str_replace(' ', '', $jobVote['minText']));
 }