Example #1
0
 /**
  * Used to add new comment for instagram media
  *
  * @access public
  * @param null $mediaId
  * @param null $type
  */
 public function instagram_comment($mediaId = null, $type = null)
 {
     if ($this->template->is_ajax()) {
         $post = $this->input->post();
         if (isset($post['message']) && $mediaId != null) {
             try {
                 $this->load->library('Socializer/socializer');
                 $instagram = Socializer::factory('Instagram', $this->c_user->id);
                 $comment = $instagram->postMediaComment($mediaId, $post['message']);
                 if (empty($comment->meta->error_message)) {
                     if ($type == 'crm') {
                         Crm_directory_activity::inst()->update_other_field($mediaId, 'comments', 'inc');
                     } else {
                         Mention::inst()->update_other_field($mediaId, 'comments', 'inc');
                     }
                 } else {
                     throw new Exception($comment->meta->error_message);
                 }
                 $result['success'] = true;
                 $result['html'] = $this->template->block('_comment', 'social/activity/blocks/_one_instagram_comment', array('comment' => $comment, 'socializer' => $instagram, 'radar' => $this->radar));
             } catch (Exception $e) {
                 $result = array();
                 $result['success'] = false;
                 $result['error'] = $e->getMessage();
             }
             echo json_encode($result);
         }
     }
 }
Example #2
0
 /**
  * Check activities not related to anything
  * And move them to queue
  * 
  * minutely ?
  */
 public function queue_unrelated_crm_activities()
 {
     $activities = Crm_directory_activity::inst()->where('crm_directory_id IS NULL')->count();
     if (!$activities) {
         log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No unrelated activities');
         return;
     }
     $this->jobQueue->addJob('tasks/crm_directory_task/remove_unrelated', array('thread' => self::CRM_THREAD));
     log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Unrelated activities: ' . $activities);
     return;
 }
 /**
  * Remove single directory with all collected activities
  *
  * @param $directory_array (array) - crm directory model arrayed
  *
  * @throws Exception
  */
 public function remove_deleted($directory_array)
 {
     try {
         $directory_id = isset($directory_array['id']) ? $directory_array['id'] : null;
         $directory = new Crm_directory($directory_id);
         if (!$directory->exists()) {
             throw new Exception('mkwid: ' . $directory_id . ' doesn\'t exist.');
         }
         $directory_activities = Crm_directory_activity::inst()->get_by_directory_id($directory_id);
         $directory_activities->delete_all();
         $directory->delete();
         log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'Crm directory and activities for mkwid: ' . $directory_array['id'] . ' deleted');
     } catch (Exception $e) {
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
         return;
         // throw $e;
     }
 }