Ejemplo n.º 1
0
 function sync_from_API($mode = '')
 {
     global $beanFiles;
     require_once $beanFiles['TILKEE_PROJECTS'];
     $associated_project = new TILKEE_PROJECTS();
     $projects_array = $this->get_linked_beans('tilkee_projects_tilkee_tilks', 'TILKEE_PROJECTS');
     $tilkee_project_id = 0;
     foreach ($projects_array as $project) {
         $tilkee_project_id = $project->tilkee_id;
     }
     if (!empty($tilkee_project_id)) {
         require_once 'custom/include/externalAPI/Tilkee/ExtAPITilkee.php';
         $tilkee = new ExtAPITilkee();
         $result = $tilkee->infos_tilk($tilkee_project_id, $this->tilkee_id);
         if ($result != -1 && !empty($result)) {
             // project updated : init bean
             $this->name = $result->title;
             $this->tilk_url = $result->url;
             $this->won = $result->won == 1 ? 'true' : 'false';
             $this->archived = !empty($result->archived_at) ? 'true' : 'false';
             $this->created_at = !empty($result->created_at) ? date('Y-m-d H:i:s', strtotime($result->created_at)) : '';
             $this->archived_at = !empty($result->archived_at) ? date('Y-m-d H:i:s', strtotime($result->archived_at)) : '';
             $this->last_sign_in_at = !empty($result->last_sign_in_at) ? date('Y-m-d H:i:s', strtotime($result->last_sign_in_at)) : '';
             $this->total_time = $this->convert_time($result->total_time);
             $this->total_connexion = $result->total_connexion;
             $this->save();
             // UPDATE LINKED CONNEXIONS
             if ($mode == 'update_connexions') {
                 global $beanFiles;
                 require_once $beanFiles['TILKEE_CONNEXIONS'];
                 $cur_connexions = new TILKEE_CONNEXIONS();
                 $cur_connexions->updateFromArray($this->id, $result->connexions);
             }
         } else {
             global $mod_strings;
             SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_SYNC_ON_TILKEE']);
             $GLOBALS['log']->fatal('TILKS sync_from_API -> ERROR RETRIEVE TILK INFOS FOR TILK : ' . $this->tilkee_id . ' - PROJECT : ' . $associated_project->tilkee_id);
         }
     }
     return 0;
 }
Ejemplo n.º 2
0
     if ($_REQUEST['project_id_update'] != '') {
         $result = $tilkee->update_project($_REQUEST['project_id_update'], $_REQUEST['project_name_update'], $_REQUEST['project_kind'], $_REQUEST['project_won'], $_REQUEST['project_archived']);
         $display_result = print_r($result, true);
         $display_title = "Update Project";
     }
     break;
 case 'delete_project':
     if ($_REQUEST['project_id_delete'] != '') {
         $result = $tilkee->delete_project($_REQUEST['project_id_delete']);
         $display_result = print_r($result, true);
         $display_title = "Delete Project";
     }
     break;
 case 'infos_tilk':
     if ($_REQUEST['project_id_infos_tilk'] != '' && $_REQUEST['tilk_id_infos_tilk'] != '') {
         $result = $tilkee->infos_tilk($_REQUEST['project_id_infos_tilk'], $_REQUEST['tilk_id_infos_tilk']);
         $display_result = print_r($result, true);
         $display_title = "Infos Tillk";
     }
     break;
 case 'create_tilk':
     if ($_REQUEST['project_id_create_tilk'] != '') {
         $result = $tilkee->create_tilk($_REQUEST['project_id_create_tilk'], $_REQUEST['tilk_name_create']);
         $display_result = print_r($result, true);
         $display_title = "Create Tillk";
     }
     break;
 case 'update_tilk':
     if ($_REQUEST['project_id_update_tilk'] != '' && $_REQUEST['tilk_id_update_tilk'] != '') {
         $result = $tilkee->update_tilk($_REQUEST['project_id_update_tilk'], $_REQUEST['tilk_id_update_tilk'], $_REQUEST['tilk_name_update'], $_REQUEST['tilk_won'], $_REQUEST['tilk_archived']);
         $display_result = print_r($result, true);