Пример #1
0
 protected function _add()
 {
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $lists = MongoDoc::get($binfo, 'lists', array());
     $list_idx = $this->input->post('list');
     $new_list = $this->input->post('new_list');
     if ($list_idx !== null && isset($lists[$list_idx])) {
         if (in_array($id, $lists[$list_idx]['influencers'])) {
             Json::success('Influencer is already preset in the list');
         }
         $lists[$list_idx]['influencers'][] = $id;
     } else {
         if (!empty($new_list)) {
             foreach ($lists as $l) {
                 if ($l['name'] === $new_list) {
                     Json::error(sprintf('List with name "%s" already exists', $new_list));
                 }
             }
             $lists[] = array('name' => $new_list, 'influencers' => array($id));
         } else {
             Json::error('Invalid list');
         }
     }
     $brand->update(array('lists' => $lists));
     Json::success('Success');
 }
Пример #2
0
 protected function _save_river($key)
 {
     try {
         $user = new Brand(UserSession::get('user._id'));
         $uinfo = $user->get();
         $auto = !!$this->input->post('auto');
         if ($auto) {
             if (($r = MongoDoc::get($uinfo, 'social_river.data_custom')) && isset($r[$key])) {
                 unset($r[$key]);
                 $user->update(array('social_river.data_custom' => (object) $r));
             }
         } else {
             if (($u = $this->input->post('url')) && !empty($u)) {
                 $user->update(array('social_river.data_custom.' . $key => trim($u)));
             }
         }
         Alert::once('success', 'URL updated successfully', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Пример #3
0
 protected function _remove()
 {
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $iinfo = $brand->get();
         if ($social = MongoDoc::get($iinfo, 'social')) {
             unset($social['twitter']);
             $brand->update(array('social' => $social));
         }
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Account remove successfully', Url::base('brand/social'));
 }
Пример #4
0
 protected function _activation()
 {
     $brand = new BrandModel($this->input->post('id'));
     if (!($binfo = $brand->get())) {
         Json::error('Invalid brand!');
     }
     try {
         $active = $this->input->post('active') ? true : false;
         $brand->update(array('active' => $active));
         (new NotifyBrandAccount())->activation($binfo['_id'], UserSession::get('user._id'));
         Json::success('Brand status updated!', null);
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Пример #5
0
 public function post()
 {
     if (UserSession::get('user.type') !== 'brand') {
         $this->_403();
     }
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $favorites = MongoDoc::get($binfo, 'favorites', array());
     if ($reset = in_array($id, $favorites)) {
         $favorites = array_values(array_diff($favorites, array($id)));
     } else {
         $favorites[] = $id;
     }
     $brand->update(array('favorites' => $favorites));
     Json::success('Success', null, array('set' => !$reset));
 }
Пример #6
0
 protected function _list_remove()
 {
     if (UserSession::get('user.type') !== 'brand') {
         $this->_403();
     }
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $binfo = $brand->get();
         $list_idx = $this->input->post('list');
         if (!($list = MongoDoc::get($binfo, 'lists.' . $list_idx))) {
             Json::error('Invalid list');
         }
         $list['influencers'] = array_values(array_diff($list['influencers'], array(new \MongoId($this->input->post('id')))));
         $redirect = null;
         if (count($list['influencers'])) {
             $binfo['lists'][$list_idx] = $list;
         } else {
             // Redirect if list is empty, cause we've removed it
             $redirect = Url::base(Url::current());
             unset($binfo['lists'][$list_idx]);
             $binfo['lists'] = array_values($binfo['lists']);
         }
         $brand->update(array('lists' => $binfo['lists']));
         $influencers = (new Influencer(null))->filter(array('_id' => array('$in' => $list['influencers'])), array('_id' => true, 'name' => true, 'username' => true));
         $body = $this->_display->view(array('main/app/brand/influencer.list.php'), array('influencers' => $influencers), true, false);
         Json::success('Success', $redirect, array('body' => $body));
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Пример #7
0
 /**
  * Update the specified product brand in storage.
  *
  * @param BrandFormRequest $request
  * @param Brand $brand
  * @return Response
  */
 public function update(BrandFormRequest $request, Brand $brand)
 {
     $this->data = $brand->update($request->all());
     return $this->handleRedirect($request);
 }
Пример #8
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     if ($this->input->post('action') == 'update-manager') {
         $user = new ExtraUser($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $data = $valid->data();
             $user->update($data);
             if ($password) {
                 (new NotifyBrandAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user.manager', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     } else {
         $user = new Brand($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
             $valid->is('Contact', $this->input->post('phone'))->required()->length(3, 100)->push('phone');
             if (UserSession::get('main_user.type') == 'admin') {
                 $valid->is('Package', $this->input->post('package'))->required()->push('package');
             }
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $valid->is('About', $this->input->post('about'))->optional()->length(20, 500)->push('about');
             $valid->is('Address', $this->input->post('address'))->optional()->length(10, 100)->push('address');
             $valid->is('Wesbite', $this->input->post('url'))->optional()->length(5)->custom(function ($key, $value) {
                 $d = get_headers($value, 1);
                 if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                     throw new \Exception($key . ' returned a response of : ' . $d[0]);
                 }
             })->push('url');
             $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone');
             $valid->is('Logo', $this->input->post('logo'))->optional()->length(5)->custom(function ($key, $value) {
                 $d = get_headers($value, 1);
                 if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                     throw new \Exception($key . ' returned a response of : ' . $d[0]);
                 }
             })->push('logo');
             $data = $valid->data();
             if (in_array(UserSession::get('main_user.type'), array('admin', 'partner'))) {
                 $data['social_river.enabled'] = !!$this->input->post('social_river');
             }
             $user->update($data);
             if ($password) {
                 (new NotifyBrandAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     }
 }