You are here

function tmgmt_local_update_7001 in Translation Management Tool 7

Create local task items.

File

translators/tmgmt_local/tmgmt_local.install, line 271
Installation hooks for tmgmt_local module.

Code

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();
}