'A tmgmt local task connects translator user with assigned job items and provide additional workflow data.', 'fields' => array( 'tltid' => array( 'description' => 'The identifier of the task.', 'type' => 'serial', 'not null' => TRUE, ), 'uid' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => "User's {users}.uid for task creator.", ), 'created' => array( 'description' => 'The Unix timestamp when the task was created.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'changed' => array( 'description' => 'The Unix timestamp when the task was most recently saved.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'title' => array( 'description' => 'Task title.', 'type' => 'varchar', 'length' => 128, ), 'tuid' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Assigned translator user {users}.uid.', ), 'tjid' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => "Translation job {tmgmt_job}.tjid that belongs to task.", ), 'status' => array( 'description' => 'The status of the task.', 'type' => 'int', 'not null' => TRUE, ), 'loop_count' => array( 'description' => 'Counter for how many times this task was returned to translator.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('tltid'), 'indexes' => array( 'tuid' => array('tuid'), ), 'foreign keys' => array( 'author' => array( 'table' => 'users', 'columns' => array('uid' => 'uid'), ), 'translator' => array( 'table' => 'users', 'columns' => array('tuid' => 'uid'), ), 'job' => array( 'table' => 'tmgmt_job', 'columns' => array('tjid' => 'tjid'), ), ), ); $schema['tmgmt_local_task_item'] = array( 'description' => 'A tmgmt local task item contains additional workflow data for a job item.', 'fields' => array( 'tltiid' => array( 'description' => 'The identifier of the task item.', 'type' => 'serial', 'not null' => TRUE, ), 'tltid' => array( 'description' => 'Translation job task {tmgmt_local_task}.tltid that belongs to task.', 'type' => 'int', 'not null' => TRUE, ), 'tjiid' => array( 'type' => 'int', 'not null' => TRUE, 'description' => "Translation job item {tmgmt_job_item}.tjiid that belongs to task.", ), 'status' => array( 'description' => 'The status of the task.', 'type' => 'int', 'not null' => TRUE, ), 'data' => array( 'description' => 'Stores translations and translation statuses', 'type' => 'text', 'not null' => TRUE, 'size' => 'big', 'serialize' => TRUE, ), 'count_untranslated' => array( 'description' => 'Counter for all untranslated data items.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'count_translated' => array( 'description' => 'Counter for all translated data items.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'count_completed' => array( 'description' => 'Counter for all completed data items.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('tltiid'), 'indexes' => array( 'tltid' => array('tltid'), ), 'foreign keys' => array( 'task' => array( 'table' => 'tmgmt_local_task', 'columns' => array('tltid' => 'tltid'), ), 'job_item' => array( 'table' => 'tmgmt_job_item', 'columns' => array('tjiid' => 'tjiid'), ), ), ); return $schema; } /** * Adds the {tmgmt_local_task_item} table. */ function tmgmt_local_update_7000() { $schema = array( 'description' => 'A tmgmt local task item contains additional workflow data for a job item.', 'fields' => array( 'tltiid' => array( 'description' => 'The identifier of the task item.', 'type' => 'serial', 'not null' => TRUE, ), 'tltid' => array( 'description' => 'Translation job task {tmgmt_local_task}.tltid that belongs to task.', 'type' => 'int', 'not null' => TRUE, ), 'tjiid' => array( 'type' => 'int', 'not null' => TRUE, 'description' => "Translation job item {tmgmt_job_item}.tjiid that belongs to task.", ), 'status' => array( 'description' => 'The status of the task.', 'type' => 'int', 'not null' => TRUE, ), 'data' => array( 'description' => 'Stores translations and translation statuses', 'type' => 'text', 'not null' => TRUE, 'size' => 'big', 'serialize' => TRUE, ), 'count_untranslated' => array( 'description' => 'Counter for all untranslated data items.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'count_translated' => array( 'description' => 'Counter for all translated data items.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'count_completed' => array( 'description' => 'Counter for all completed data items.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('tltiid'), 'indexes' => array( 'tltid' => array('tltid'), ), 'foreign keys' => array( 'task' => array( 'table' => 'tmgmt_local_task', 'columns' => array('tltid' => 'tltid'), ), 'job_item' => array( 'table' => 'tmgmt_job_item', 'columns' => array('tjiid' => 'tjiid'), ), ), ); db_create_table('tmgmt_local_task_item', $schema); } /** * Implements hook_enable(). */ function tmgmt_local_enable() { // If our field type is not found rebuild the cache. if (!field_info_field_types('tmgmt_language_combination')) { field_cache_clear(); } // Create the language combination field if it doesn't exist yet. if (!field_info_field('tmgmt_translation_skills')) { $field = array( 'type' => 'tmgmt_language_combination', 'field_name' => 'tmgmt_translation_skills', 'translatable' => FALSE, 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'locked' => FALSE, ); field_create_field($field); } // Attach the language skills field collection to the user entity. if (!field_info_instance('user', 'tmgmt_translation_skills', 'user')) { $instance = array( 'field_name' => 'tmgmt_translation_skills', 'entity_type' => 'user', 'bundle' => 'user', 'label' => t('Translation skills'), ); field_create_instance($instance); } } /** * Implements hook_uninstall(). */ function tmgmt_local_uninstall() { field_delete_field('tmgmt_translation_skills'); } /** * Create local task items. */ function tmgmt_local_update_7001() { $result = db_query('SELECT lt.tltid, ji.tjiid, ji.state, ji.data from {tmgmt_local_task} lt INNER JOIN {tmgmt_job} j ON j.tjid = lt.tjid INNER JOIN {tmgmt_job_item} ji ON ji.tjid = j.tjid'); $insert = db_insert('tmgmt_local_task_item') ->fields(array('tltid', 'tjiid', 'status', 'data')); module_load_include('module', 'tmgmt'); foreach ($result as $row) { $data = unserialize($row->data); $data_count = count(array_filter(tmgmt_flatten_data($data), '_tmgmt_filter_data')); $translation = (array)_tmgmt_local_translated_data_7001($data); $values =array( 'tltid' => $row->tltid, 'tjiid' => $row->tjiid, 'count_untranslated' => 0, 'count_translated' => 0, 'count_translated' => 0, 'status' => 0, 'data' => serialize($translation), ); switch ($row->state) { case 2: // Job item state needs review is task item status translated. $values['status'] = 1; $values['count_translated'] = $data_count; break; case 3: // Job item state accepted is task item status completed. $values['status'] = 3; $values['count_completed'] = $data_count; break; case 1: default: // Job item state active is task item status untranslated. $values['status'] = 0; $values['count_untranslated'] = $data_count; break; } $insert->values($values); } $insert->execute(); } /** * Data parsing helper function for tmgmt_local_update_7001(). * * Copies #translation texts from the source data array to the translation * data array. * * @param array $source * The original source data array of the job item. * * @return array * The filled translation data array. */ function _tmgmt_local_translated_data_7001($source) { if (!empty($source['#translation']['#text'])) { $translation['#text'] = $source['#translation']['#text']; if ((!empty($source['#status']))) { $translation['#status'] = $source['#status']; } return $translation; } else { $translation = array(); foreach (element_children($source) as $key) { if ($return = _tmgmt_local_translated_data_7001($source[$key])) { $translation[$key] = $return; } } if (!empty($translation)) { return $translation; } } } /** * Ensures that the tmgmt_language_combination module is enabled. */ function tmgmt_local_update_7002() { // Enable the tmgmt_language_combionation module. module_enable(array('tmgmt_language_combination')); // Remove the tmgmt_skills module. db_delete('system') ->condition('name', 'tmgmt_skills') ->condition('type', 'module') ->execute(); // Create the field if it doesn't exist yet. if (!field_info_field_types('tmgmt_language_combination')) { field_cache_clear(); } // Create the language combination field if it doesn't exist yet. if (!field_info_field('tmgmt_translation_skills')) { $field = array( 'type' => 'tmgmt_language_combination', 'field_name' => 'tmgmt_translation_skills', 'translatable' => FALSE, 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'locked' => FALSE, ); field_create_field($field); } // Attach the language skills field collection to the user entity. if (!field_info_instance('user', 'tmgmt_translation_skills', 'user')) { $instance = array( 'field_name' => 'tmgmt_translation_skills', 'entity_type' => 'user', 'bundle' => 'user', 'label' => t('Translation skills'), ); field_create_instance($instance); } }