public static function decorateNewJob(SweteSite $site, Dataface_Record $rec) { require_once 'modules/tm/lib/XFTranslationMemory.php'; try { SweteDb::q('start transaction'); // First we need to create a translation memory for this job. $tm = XFTranslationMemory::createTranslationMemory('Job translation memory for site ' . $site->getRecord()->val('website_id') . ' ' . $site->getSourceLanguage() . '->' . $site->getDestinationLanguage(), $site->getSourceLanguage(), $site->getDestinationLanguage()); $status = SweteJob::JOB_STATUS_NEW; if ($rec->val('assigned_to')) { $status = SweteJob::JOB_STATUS_ASSIGNED; } $rec->setValues(array('website_id' => $site->getRecord()->val('website_id'), 'date_created' => date('Y-m-d H:i:s'), 'job_status' => $status, 'translation_memory_id' => $tm->getRecord()->val('translation_memory_id'), 'source_language' => $site->getSourceLanguage(), 'destination_language' => $site->getDestinationLanguage())); //print_r($rec->vals()); $res = $rec->save(); if (PEAR::isError($res)) { //print_r($res); throw new Exception($res->getMessage(), $res->getCode()); } if ($rec->val('posted_by')) { $res = df_q("insert ignore into job_roles (job_id, username, access_level) values ('" . addslashes($rec->val('job_id')) . "','" . addslashes($rec->val('posted_by')) . "','" . self::JOB_ROLE_OWNER . "')"); } if ($rec->val('assigned_to')) { $res = df_q("insert ignore into job_roles (job_id, username, access_level) values ('" . addslashes($rec->val('job_id')) . "','" . addslashes($rec->val('assigned_to')) . "','" . self::JOB_ROLE_TRANSLATOR . "')"); } SweteDb::q('commit'); $out = new SweteJob($rec); $out->setTranslationMemory($tm); return $out; } catch (Exception $ex) { SweteDb::q('rollback'); throw $ex; } }