Beispiel #1
0
 protected function _channel_influencer()
 {
     try {
         $id = $this->input->post('id');
         $campaign = new Campaign($id);
         $cinfo = $campaign->get();
         if (!$cinfo) {
             throw new \Exception('Invalid campaign');
         }
         if (!($influencer = $this->input->post('influencer'))) {
             throw new \Exception('Invalid influencer');
         }
         $comment = $this->input->post('comment');
         if (empty($comment)) {
             throw new \Exception('Comment must not be empty');
         }
         $comments = MongoDoc::get($cinfo, 'comments.brand_influencer', array());
         if (!isset($comments[$influencer])) {
             $comments[$influencer] = array();
         }
         $comments[$influencer][] = array('from' => UserSession::get('user._id'), 'from_username' => UserSession::get('user.username'), 'user' => 'brand', 'created_at' => time(), 'text' => $comment);
         $comments[$influencer] = array_slice($comments[$influencer], -20);
         $campaign->update(array('comments.brand_influencer' => $comments));
         Alert::once('success', 'Comment added', Url::referrer());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Beispiel #2
0
 public function post()
 {
     try {
         $campaign = new Campaign(null);
         $cinfo = $campaign->find_modify_one(array('_id' => new \MongoId($this->input->post('id')), 'state' => array('$in' => array('pending', 'active'))), array('$set' => array('state' => 'rejected')));
         if (!$cinfo) {
             $this->_403();
         }
         Alert::once('success', 'Campaign has been removed', Url::base('admin/campaign/pending'));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Beispiel #3
0
 protected function _render_approval()
 {
     $id = $this->input->post('id');
     try {
         $campaign = new Campaign(null);
         $cinfo = $campaign->filter_one(array('_id' => new \MongoId($id), 'state' => array('$in' => array('pending', 'rejected'))));
         if (!$cinfo) {
             Alert::once('error', 'Invalid campaign', Url::referrer());
         }
         $i_sel = array();
         $influencer = new Influencer(null);
         $sel = array();
         foreach (MongoDoc::get($cinfo, 'influencers_select', array()) as $i) {
             $i_sel[] = $influencer->filter_one(array('_id' => $i), array('_id' => true, 'username' => true));
             $sel[] = (string) $i;
         }
         $cinfo['influencers_select'] = $i_sel;
         $this->_display->view(array('main/app/admin/campaign/approve.php'), array('campaign' => $cinfo, 'influencers_select_string' => implode(',', $sel), 'influencers' => (new Influencer(null))->filter(array('active' => true))));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::base('admin/campaign/view/' . $id));
     }
 }
 protected function _view($id)
 {
     $notify = new Notify();
     $n = $notify->get(new \MongoId($id), true, UserSession::get('user._id'));
     Url::redirect(empty($n['url']) ? Url::referrer() : $n['url']);
 }