Ejemplo n.º 1
0
 public function set_community_resources($community_id, $update_first_project_callback = FALSE)
 {
     $client = new Lingotek_API();
     $refresh_success = array('projects' => FALSE, 'workflows' => FALSE);
     $api_data = $client->get_projects($community_id);
     $projects = array();
     if ($api_data !== FALSE) {
         foreach ($api_data->entities as $project) {
             $projects[$project->properties->id] = $project->properties->title;
         }
         if ($api_data->properties->total == 1) {
             if (!$project->properties->callback_url) {
                 $client->update_callback_url($project->properties->id);
             }
         }
         natcasesort($projects);
         //order by title (case-insensitive)
         $refresh_success['projects'] = TRUE;
     }
     $api_data = $client->get_workflows($community_id);
     $default_workflows = array('c675bd20-0688-11e2-892e-0800200c9a66' => 'Machine Translation', 'ddf6e3c0-0688-11e2-892e-0800200c9a66' => 'Machine Translation + Post-Edit', '6ff1b470-33fd-11e2-81c1-0800200c9a66' => 'Machine Translation + Translate', '2b5498e0-f3c7-4c49-9afa-cca4b3345af7' => 'Translation + 1 review', '814172a6-3744-4da7-b932-5857c1c20976' => 'Translation + 2 reviews', '2210b148-0c44-4ae2-91d0-ca2ee47c069e' => 'Translation + 3 reviews', '7993b4d7-4ada-46d0-93d5-858db46c4c7d' => 'Translation Only');
     $workflows = array();
     if ($api_data) {
         foreach ($api_data->entities as $workflow) {
             $workflows[$workflow->properties->id] = $workflow->properties->title;
         }
         $diff = array_diff_key($workflows, $default_workflows);
         if (empty($diff)) {
             $workflows = array('c675bd20-0688-11e2-892e-0800200c9a66' => 'Machine Translation');
         }
         natcasesort($workflows);
         //order by title (case-insensitive)
         $refresh_success['workflows'] = TRUE;
     }
     $api_data = $client->get_filters();
     $filters = array();
     if ($api_data && $api_data->properties->total > 0) {
         foreach ($api_data->entities as $filter) {
             if (!$filter->properties->is_public) {
                 $filters[$filter->properties->id] = $filter->properties->title;
             }
             if ($filter->properties->title == '*****@*****.**' || $filter->properties->title == '*****@*****.**') {
                 $filters[$filter->properties->id] = $filter->properties->title;
             }
         }
         $primary_filter_id = array_search('*****@*****.**', $filters);
         $secondary_filter_id = array_search('*****@*****.**', $filters);
         $defaults = get_option('lingotek_defaults');
         if ($defaults == NULL) {
             $defaults['primary_filter_id'] = $primary_filter_id;
             $defaults['secondary_filter_id'] = $secondary_filter_id;
             update_option('lingotek_defaults', $defaults);
         }
     }
     $resources = array('projects' => $projects, 'workflows' => $workflows, 'filters' => $filters);
     if ($refresh_success['projects'] == TRUE || $refresh_success['workflows'] == TRUE) {
         update_option('lingotek_community_resources', $resources);
         $this->ensure_valid_defaults();
     }
     return $refresh_success;
 }