Пример #1
0
 function updateFromArray($project_id, $tilks_array)
 {
     if (empty($project_id) || !is_array($tilks_array) || count($tilks_array) == 0) {
         return;
     }
     foreach ($tilks_array as $tilks) {
         // retrive tilk by tilkee_id field
         $tilk_obj = new TILKEE_TILKS();
         $tilk_obj->retrieve_by_string_fields(array('tilkee_id' => $tilks->id));
         if (empty($tilk_obj->id)) {
             // Tilk does not exist so create it
             $tilk_obj->tilkee_id = $tilks->id;
         }
         $tilk_obj->name = $tilks->title;
         $tilk_obj->tilk_url = $tilks->url;
         $tilk_obj->won = $tilks->won == 1 ? 'true' : 'false';
         $tilk_obj->archived = !empty($tilks->archived_at) ? 'true' : 'false';
         $tilk_obj->created_at = !empty($tilks->created_at) ? date('Y-m-d H:i:s', strtotime($tilks->created_at)) : '';
         $tilk_obj->archived_at = !empty($tilks->archived_at) ? date('Y-m-d H:i:s', strtotime($tilks->archived_at)) : '';
         $tilk_obj->last_sign_in_at = !empty($tilks->last_sign_in_at) ? date('Y-m-d H:i:s', strtotime($tilks->last_sign_in_at)) : '';
         $tilk_obj->total_time = $this->convert_time($tilks->total_time);
         $tilk_obj->total_connexion = $tilks->total_connexion;
         $tilk_obj->save();
         // Init relationship with Tilkee project
         $tilk_obj->load_relationship('tilkee_projects_tilkee_tilks');
         $tilk_obj->tilkee_projects_tilkee_tilks->add($project_id);
         unset($tilk_obj);
     }
 }
Пример #2
0
 function sync_from_API($mode = '')
 {
     if (!empty($this->tilkee_id)) {
         require_once 'custom/include/externalAPI/Tilkee/ExtAPITilkee.php';
         $tilkee = new ExtAPITilkee();
         $result = $tilkee->infos_project($this->tilkee_id);
         if ($result != -1 && !empty($result)) {
             // project created : init bean
             $this->set_result_to_bean($result);
             // Create or update tilks from return data
             if ($mode == 'update_tilks') {
                 global $beanFiles;
                 require_once $beanFiles['TILKEE_TILKS'];
                 $cur_tilks = new TILKEE_TILKS();
                 $cur_tilks->updateFromArray($this->id, $result->tilks);
             }
             // TBD
         } else {
             global $mod_strings;
             SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_UPDATE_ON_TILKEE']);
         }
     }
 }