Пример #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());
     }
 }
Пример #2
0
 protected function _finish()
 {
     $id = $this->input->post('id');
     try {
         $selected = array();
         if ($s = $this->input->post('selected_influencers')) {
             $selected = explode(',', $s);
         }
         if (!$selected) {
             throw new \Exception('At least one influencer must be selected');
         }
         foreach ($selected as &$s) {
             $s = new \MongoId($s);
         }
         $campaign = new Campaign($id);
         $cinfo = $campaign->filter_one(array('_id' => $campaign->id, 'state' => array('$in' => array('pending', 'rejected'))));
         if (!$cinfo) {
             throw new \Exception('Invalid Campaign');
         }
         $campaign->update(array('state' => 'active', 'influencers_select' => $selected, 'points' => (int) $this->input->post('points'), 'global' => (bool) $this->input->post('global')));
         Alert::once('success', 'Campaign is now active', Url::base('admin/campaign/view/' . $id));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::base('admin/campaign/view/' . $id));
     }
 }