function syncTILKEE() { global $sugar_config; $GLOBALS['log']->info('Scheduled syncTILKEE -> START'); if (isset($sugar_config['tilkee']['user_scheduler']) && isset($sugar_config['tilkee']['user_scheduler'])) { require_once 'custom/include/externalAPI/Tilkee/ExtAPITilkee.php'; require_once 'modules/TILKEE_PROJECTS/TILKEE_PROJECTS.php'; require_once 'modules/Users/User.php'; global $current_user; //$scheduler_user = new User(); $current_user->retrieve($sugar_config['tilkee']['user_scheduler']); $tilkee = new ExtAPITilkee(); //$result_call = $tilkee->get_token_password($login, $mdp) ; // retrieve all TILKEE Projects $tilkee_projects_array = get_bean_select_array(false, 'TILKEE_PROJECTS', 'name', '', 'name', false); foreach ($tilkee_projects_array as $id => $project) { $current_project = new TILKEE_PROJECTS(); $current_project->retrieve($id); $current_project->sync_from_API('update_tilks'); // Retrieve list of TILKS and update connexion $tilks_array = $current_project->get_linked_beans('tilkee_projects_tilkee_tilks', 'TILKEE_TILKS'); foreach ($tilks_array as $tilkee_tilk) { $tilkee_tilk->sync_from_API('update_connexions'); } unset($current_project); } } else { $GLOBALS['log']->fatal('Scheduled syncTILKEE -> scheduler connexion information is not set'); } $GLOBALS['log']->info('Scheduled syncTILKEE -> END'); return true; }
function display() { global $mod_strings, $app_strings, $app_list_strings, $sugar_config, $beanFiles; $this->ss->assign("MOD", $mod_strings); $this->ss->assign("APP_LIST", $app_list_strings); // Init default name $this->bean->name = '[TILK] '; // IF THE TILK IS CREATED FROM AN CONTACT if (isset($_REQUEST['CreateFromContact']) && $_REQUEST['CreateFromContact'] == 'true') { // CREATE DEFAULT TILK LINK WITH CONTACT require_once $beanFiles['Contact']; $link_contact = new Contact(); $link_contact->retrieve($_REQUEST['return_id']); $this->bean->contacts_id = $link_contact->id; $this->bean->contacts_name = $link_contact->name; $this->bean->contact_email = $link_contact->emailAddress->getPrimaryAddress($link_contact); $this->bean->name = '[TILK] ' . $link_contact->name; //$this->bean->id = $this->bean->save(); $_REQUEST['record'] = $this->bean->id; // TILKEE API - CREATE PROJECT AND SYNCH IT } // IF THE TILK IS CREATED FROM AN LEAD if (isset($_REQUEST['CreateFromLead']) && $_REQUEST['CreateFromLead'] == 'true') { // CREATE DEFAULT TILK LINK WITH LEAD require_once $beanFiles['Lead']; $link_lead = new Lead(); $link_lead->retrieve($_REQUEST['return_id']); $this->bean->leads_name = $link_lead->name; $this->bean->leads_id = $link_lead->id; $this->bean->contact_email = $link_lead->emailAddress->getPrimaryAddress($link_lead); $this->bean->name = '[TILK] ' . $link_lead->name; //$this->bean->id = $this->bean->save(); $_REQUEST['record'] = $this->bean->id; // TILKEE API - CREATE PROJECT AND SYNCH IT } // IF THE TILK IS CREATED FROM AN PROJECT if (isset($_REQUEST['CreateFromProject']) && $_REQUEST['CreateFromProject'] == 'true') { // CREATE DEFAULT TILK LINK WITH PROJECT require_once $beanFiles['TILKEE_PROJECTS']; $link_tilkee_project = new TILKEE_PROJECTS(); $link_tilkee_project->retrieve($_REQUEST['return_id']); $this->bean->tilkee_projects_name = $link_tilkee_project->name; $this->bean->tilkee_projects_id = $link_tilkee_project->id; //$this->bean->id = $this->bean->save(); $_REQUEST['record'] = $this->bean->id; // TILKEE API - CREATE PROJECT AND SYNCH IT } parent::display(); }
function update_from_API($archived = '') { global $beanFiles; require_once $beanFiles['TILKEE_PROJECTS']; $associated_project = new TILKEE_PROJECTS(); if (!empty($this->tilkee_projects_id)) { $associated_project->retrieve($this->tilkee_projects_id); if (!empty($associated_project->tilkee_id)) { require_once 'custom/include/externalAPI/Tilkee/ExtAPITilkee.php'; $tilkee = new ExtAPITilkee(); $result = $tilkee->update_tilk($associated_project->tilkee_id, $this->tilkee_id, $this->name, $this->won, $this->archived); if ($result != -1 && !empty($result)) { // project updated : init bean $this->tilk_url = $result->url; $this->won = $result->won; $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->archived = !empty($result->archived_at) ? 'true' : 'false'; $this->total_time = $this->convert_time($result->total_time); $this->total_connexion = $result->total_connexion; // tilkee_contact_id // tilkee_contact $this->save(); // UPDATE LINKED CONNEXIONS $connexion_array = $result->connexions; } else { global $mod_strings; SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_UPDATE_ON_TILKEE']); } } else { // ERROR : Associated project is not created in TILKEE } } return 0; }