public function doAction() { $this->generateAuthURL(); //pay a little query to avoid to fetch 5000 rows $this->data = $jobData = getJobData($this->jid, $this->password); $wStruct = new WordCount_Struct(); $wStruct->setIdJob($this->jid); $wStruct->setJobPassword($this->password); $wStruct->setNewWords($jobData['new_words']); $wStruct->setDraftWords($jobData['draft_words']); $wStruct->setTranslatedWords($jobData['translated_words']); $wStruct->setApprovedWords($jobData['approved_words']); $wStruct->setRejectedWords($jobData['rejected_words']); if ($jobData['status'] == Constants_JobStatus::STATUS_ARCHIVED || $jobData['status'] == Constants_JobStatus::STATUS_CANCELLED) { //this job has been archived $this->job_archived = true; $this->job_owner_email = $jobData['job_owner']; } $this->job_stats = CatUtils::getFastStatsForJob($wStruct); $proj = getProject($jobData['id_project']); $this->project_status = $proj[0]; /** * Retrieve information about job errors * ( Note: these information are fed by the revision process ) * @see setRevisionController */ $jobQA = new Revise_JobQA($this->jid, $this->password, $wStruct->getTotal()); $jobQA->retrieveJobErrorTotals(); $jobVote = $jobQA->evalJobVote(); $this->totalJobWords = $wStruct->getTotal(); $this->qa_data = $jobQA->getQaData(); $this->qa_overall_text = $jobVote['minText']; $this->qa_overall_avg = $jobVote['avg']; $this->qa_equivalent_class = $jobVote['equivalent_class']; }
public function getData($job_id, $password, $options = array()) { $data = getJobData($job_id, $password); $wCounter = new WordCount_Counter(); $wStruct = $wCounter->initializeJobWordCount($job_id, $password); $jobQA = new Revise_JobQA($job_id, $password, $wStruct->getTotal()); $jobQA->retrieveJobErrorTotals(); $jobQA->evalJobVote(); $jobVote = $jobQA->getJobVote(); return array('job_id' => $job_id, 'quality_details' => $jobQA->getQaData(), 'quality_overall' => $jobVote['minText']); }
public function getResult() { switch ($this->_globals['STATUS_PROJECT']) { case 'NEW': case 'FAST_OK': case 'NOT_READY_FOR_ANALYSIS': $this->result['status'] = 'ANALYZING'; break; case 'EMPTY': $this->result['status'] = 'NO_SEGMENTS_FOUND'; break; case 'NOT_TO_ANALYZE': $this->result['status'] = 'ANALYSIS_NOT_ENABLED'; break; case 'DONE': $this->result['status'] = 'DONE'; break; default: //this can not be $this->result['status'] = 'FAIL'; break; } $this->result['analyze'] = "/analyze/" . $this->_project_data[0]['pname'] . "/" . $this->_project_data[0]['pid'] . "-" . $this->_project_data[0]['ppassword']; $this->result['jobs'] = array(); foreach ($this->_project_data as $job) { $this->result['jobs']['langpairs'][$job['jid_jpassword']] = $job['lang_pair']; $this->result['jobs']['job-url'][$job['jid_jpassword']] = "/translate/" . $job['job_url']; //set the total for the job $jobQA = new Revise_JobQA($job['jid'], $job['jpassword'], $this->result['data']['jobs'][$job['jid']]['totals'][$job['jpassword']]["TOTAL_PAYABLE"][0]); $jobQA->retrieveJobErrorTotals(); $jobVote = $jobQA->evalJobVote(); $this->result['jobs']['job-quality-details'][$job['jid_jpassword']] = $jobQA->getQaData(); $this->result['jobs']['quality-overall'][$job['jid_jpassword']] = $jobVote['minText']; } return $this->result; }
/** * 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'])); }
public function doAction() { $files_found = array(); $lang_handler = Langs_Languages::getInstance(); $data = getSegmentsInfo($this->jid, $this->password); if (empty($data) or $data < 0) { $this->job_not_found = true; //stop execution return; } //retrieve job owner. It will be useful also if the job is archived or cancelled $this->job_owner = $data[0]['job_owner'] != "" ? $data[0]['job_owner'] : "*****@*****.**"; if ($data[0]['status'] == Constants_JobStatus::STATUS_CANCELLED) { $this->job_cancelled = true; //stop execution return; } if ($data[0]['status'] == Constants_JobStatus::STATUS_ARCHIVED) { $this->job_archived = true; //stop execution return; } /* * I prefer to use a programmatic approach to the check for the archive date instead of a pure query * because the query to check "Utils::getArchivableJobs($this->jid)" should be * executed every time a job is loaded ( F5 or CTRL+R on browser ) and it cost some milliseconds ( ~0.1s ) * and it is little heavy for the database. * We use the data we already have from last query and perform * the check on the last translation only if the job is older than 30 days * */ $lastUpdate = new DateTime($data[0]['last_update']); $oneMonthAgo = new DateTime(); $oneMonthAgo->modify('-' . INIT::JOB_ARCHIVABILITY_THRESHOLD . ' days'); if ($lastUpdate < $oneMonthAgo && !$this->job_cancelled) { $lastTranslationInJob = new Datetime(getLastTranslationDate($this->jid)); if ($lastTranslationInJob < $oneMonthAgo) { $res = "job"; $new_status = Constants_JobStatus::STATUS_ARCHIVED; updateJobsStatus($res, $this->jid, $new_status, null, null, $this->password); $this->job_archived = true; } } foreach ($data as $i => $job) { $this->project_status = $job; // get one row values for the project are the same for every row if (empty($this->pname)) { $this->pname = $job['pname']; $this->downloadFileName = $job['pname'] . ".zip"; // will be overwritten below in case of one file job } if (empty($this->last_opened_segment)) { $this->last_opened_segment = $job['last_opened_segment']; } if (empty($this->cid)) { $this->cid = $job['cid']; } if (empty($this->pid)) { $this->pid = $job['pid']; } if (empty($this->create_date)) { $this->create_date = $job['create_date']; } if (empty($this->source_code)) { $this->source_code = $job['source']; } if (empty($this->target_code)) { $this->target_code = $job['target']; } if (empty($this->source)) { $s = explode("-", $job['source']); $source = strtoupper($s[0]); $this->source = $source; $this->source_rtl = $lang_handler->isRTL(strtolower($this->source)) ? ' rtl-source' : ''; } if (empty($this->target)) { $t = explode("-", $job['target']); $target = strtoupper($t[0]); $this->target = $target; $this->target_rtl = $lang_handler->isRTL(strtolower($this->target)) ? ' rtl-target' : ''; } //check if language belongs to supported right-to-left languages if ($job['status'] == Constants_JobStatus::STATUS_ARCHIVED) { $this->job_archived = true; $this->job_owner = $data[0]['job_owner']; } $id_file = $job['id_file']; if (!isset($this->data["{$id_file}"])) { $files_found[] = $job['filename']; } $wStruct = new WordCount_Struct(); $wStruct->setIdJob($this->jid); $wStruct->setJobPassword($this->password); $wStruct->setNewWords($job['new_words']); $wStruct->setDraftWords($job['draft_words']); $wStruct->setTranslatedWords($job['translated_words']); $wStruct->setApprovedWords($job['approved_words']); $wStruct->setRejectedWords($job['rejected_words']); unset($job['id_file']); unset($job['source']); unset($job['target']); unset($job['source_code']); unset($job['target_code']); unset($job['mime_type']); unset($job['filename']); unset($job['jid']); unset($job['pid']); unset($job['cid']); unset($job['tid']); unset($job['pname']); unset($job['create_date']); unset($job['owner']); unset($job['last_opened_segment']); unset($job['new_words']); unset($job['draft_words']); unset($job['translated_words']); unset($job['approved_words']); unset($job['rejected_words']); //For projects created with No tm analysis enabled if ($wStruct->getTotal() == 0 && ($job['status_analysis'] == Constants_ProjectStatus::STATUS_DONE || $job['status_analysis'] == Constants_ProjectStatus::STATUS_NOT_TO_ANALYZE)) { $wCounter = new WordCount_Counter(); $wStruct = $wCounter->initializeJobWordCount($this->jid, $this->password); Log::doLog("BackWard compatibility set Counter."); } $this->job_stats = CatUtils::getFastStatsForJob($wStruct); } //Needed because a just created job has last_opened segment NULL if (empty($this->last_opened_segment)) { $this->last_opened_segment = getFirstSegmentId($this->jid, $this->password); } $this->first_job_segment = $this->project_status['job_first_segment']; $this->last_job_segment = $this->project_status['job_last_segment']; if (count($files_found) == 1) { $this->downloadFileName = $files_found[0]; } /** * get first segment of every file */ $fileInfo = getFirstSegmentOfFilesInJob($this->jid); $TotalPayable = array(); foreach ($fileInfo as &$file) { $file['file_name'] = ZipArchiveExtended::getFileName($file['file_name']); $TotalPayable[$file['id_file']]['TOTAL_FORMATTED'] = $file['TOTAL_FORMATTED']; } $this->firstSegmentOfFiles = json_encode($fileInfo); $this->fileCounter = json_encode($TotalPayable); list($uid, $user_email) = $this->getLoginUserParams(); if (self::isRevision()) { $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR; } elseif ($user_email == $data[0]['job_owner']) { $this->userRole = TmKeyManagement_Filter::OWNER; } else { $this->userRole = TmKeyManagement_Filter::ROLE_TRANSLATOR; } /* * Take the keys of the user */ try { $_keyList = new TmKeyManagement_MemoryKeyDao(Database::obtain()); $dh = new TmKeyManagement_MemoryKeyStruct(array('uid' => $uid)); $keyList = $_keyList->read($dh); } catch (Exception $e) { $keyList = array(); Log::doLog($e->getMessage()); } $reverse_lookup_user_personal_keys = array('pos' => array(), 'elements' => array()); /** * Set these keys as editable for the client * * @var $keyList TmKeyManagement_MemoryKeyStruct[] */ foreach ($keyList as $_j => $key) { /** * @var $_client_tm_key TmKeyManagement_TmKeyStruct */ //create a reverse lookup $reverse_lookup_user_personal_keys['pos'][$_j] = $key->tm_key->key; $reverse_lookup_user_personal_keys['elements'][$_j] = $key; $this->_keyList['totals'][$_j] = new TmKeyManagement_ClientTmKeyStruct($key->tm_key); } /* * Now take the JOB keys */ $job_keyList = json_decode($data[0]['tm_keys'], true); $this->tid = count($job_keyList) > 0; /** * Start this N^2 cycle from keys of the job, * these should be statistically lesser than the keys of the user * * @var $keyList array */ foreach ($job_keyList as $jobKey) { $jobKey = new TmKeyManagement_ClientTmKeyStruct($jobKey); if ($this->isLoggedIn() && count($reverse_lookup_user_personal_keys['pos'])) { /* * If user has some personal keys, check for the job keys if they are present, and obfuscate * when they are not */ $_index_position = array_search($jobKey->key, $reverse_lookup_user_personal_keys['pos']); if ($_index_position !== false) { //i found a key in the job that is present in my database //i'm owner?? and the key is an owner type key? if (!$jobKey->owner && $this->userRole != TmKeyManagement_Filter::OWNER) { $jobKey->r = $jobKey->{TmKeyManagement_Filter::$GRANTS_MAP[$this->userRole]['r']}; $jobKey->w = $jobKey->{TmKeyManagement_Filter::$GRANTS_MAP[$this->userRole]['w']}; $jobKey = $jobKey->hideKey($uid); } else { if ($jobKey->owner && $this->userRole != TmKeyManagement_Filter::OWNER) { // I'm not the job owner, but i know the key because it is in my keyring // so, i can upload and download TMX, but i don't want it to be removed from job // in tm.html relaxed the control to "key.edit" to enable buttons // $jobKey = $jobKey->hideKey( $uid ); // enable editing } else { if ($jobKey->owner && $this->userRole == TmKeyManagement_Filter::OWNER) { //do Nothing } } } unset($this->_keyList['totals'][$_index_position]); } else { /* * This is not a key of that user, set right and obfuscate */ $jobKey->r = true; $jobKey->w = true; $jobKey = $jobKey->hideKey(-1); } $this->_keyList['job_keys'][] = $jobKey; } else { /* * This user is anonymous or it has no keys in its keyring, obfuscate all */ $jobKey->r = true; $jobKey->w = true; $this->_keyList['job_keys'][] = $jobKey->hideKey(-1); } } //clean unordered keys $this->_keyList['totals'] = array_values($this->_keyList['totals']); /** * Retrieve information about job errors * ( Note: these information are fed by the revision process ) * @see setRevisionController */ $jobQA = new Revise_JobQA($this->jid, $this->password, $wStruct->getTotal()); $jobQA->retrieveJobErrorTotals(); $jobVote = $jobQA->evalJobVote(); $this->qa_data = json_encode($jobQA->getQaData()); $this->qa_overall = $jobVote['minText']; $engine = new EnginesModel_EngineDAO(Database::obtain()); //this gets all engines of the user if ($this->isLoggedIn()) { $engineQuery = new EnginesModel_EngineStruct(); $engineQuery->type = 'MT'; $engineQuery->uid = $uid; $engineQuery->active = 1; $mt_engines = $engine->read($engineQuery); } else { $mt_engines = array(); } // this gets MyMemory $engineQuery = new EnginesModel_EngineStruct(); $engineQuery->type = 'TM'; $engineQuery->active = 1; $tms_engine = $engine->setCacheTTL(3600 * 24 * 30)->read($engineQuery); //this gets MT engine active for the job $engineQuery = new EnginesModel_EngineStruct(); $engineQuery->id = $this->project_status['id_mt_engine']; $engineQuery->active = 1; $active_mt_engine = $engine->setCacheTTL(60 * 10)->read($engineQuery); /* * array_unique cast EnginesModel_EngineStruct to string * * EnginesModel_EngineStruct implements __toString method * */ $this->translation_engines = array_unique(array_merge($active_mt_engine, $tms_engine, $mt_engines)); }