public function post() { if (!$this->input->is_ajax_request()) { $this->_403(); } $user = new Influencer($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'); $valid->is('City', $this->input->post('city'))->required()->push('city'); $valid->is('Genre', $this->input->post('genre'))->required()->transform(function ($d) { return explode(',', $d); })->push('genre'); 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('Date of Birth', $this->input->post('date_of_birth'))->optional()->custom(function ($key, $value) { $d = \DateTime::createFromFormat('Y-m-d', $value); if (!($d && $d->format('Y-m-d') == $value)) { throw new \Exception($key . ' must be a valid date of the format yyyy-mm-dd'); } })->push('date_of_birth'); $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone'); $valid->is('Picture', $this->input->post('picture'))->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('picture'); $valid->is('Interest', $this->input->post('interest'))->push('interest'); $data = $valid->data(); $user->update($data); if ($password) { (new NotifyInfluencerAccount())->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()); } }
protected function _walk_social($u) { $user = new Influencer(null); $update = array(); printf("%-15s %-30s\n", 'BEGIN', $u['_id']); $this->_compute_social($u, $update); if ($update) { $this->_compute_fluenz_score($u, $update); printf("%-15s %-30s\n", 'UPDATE', $u['_id']); $user->modify(array('_id' => $u['_id']), array('$set' => $update)); } printf("%-15s %-30s\n", 'END', $u['_id']); }
protected function _remove() { try { $influencer = new Influencer(UserSession::get('user._id')); $iinfo = $influencer->get(); if ($social = MongoDoc::get($iinfo, 'social')) { unset($social['instagram']); $influencer->update(array('social' => $social)); } } catch (\Exception $e) { Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('influencer/social')); } Alert::once('success', 'Account remove successfully', Url::base('influencer/social')); }
protected function _activation() { $influencer = new InfluencerModel($this->input->post('id')); if (!($binfo = $influencer->get())) { Json::error('Invalid influencer!'); } try { $active = $this->input->post('active') ? true : false; $influencer->update(array('active' => $active)); (new NotifyInfluencerAccount())->activation($binfo['_id'], UserSession::get('user._id')); Json::success('Influencer status updated!', null); } catch (\Exception $e) { Json::error($e->getMessage()); } }
public function get() { if (UserSession::get('user.type') !== 'influencer') { $this->_403(); } $influencer = new Influencer(UserSession::get('user._id')); $iinfo = $influencer->get(); $brand = new Brand(null); $favorites = array(); $lists = array(); if ($l = MongoDoc::get($iinfo, 'favorites', null)) { $favorites = $brand->filter(array('_id' => array('$in' => $l)), array('_id' => true, 'name' => true, 'username' => true)); } $this->_display->view(array('main/app/influencer/favorite.php'), array('favorites' => $favorites)); }
public function get($brand_id = null) { $user = new Influencer(UserSession::get('user._id')); $uinfo = $user->get(); $brands = array(); $bmodel = new Brand(null); foreach (MongoDoc::get($uinfo, 'favorites', array()) as $b) { $brands[] = $bmodel->filter_one(array('_id' => $b), array('_id' => true, 'name' => true, 'username' => true)); } $river = array(); if ($brands && !$brand_id) { $brand_id = $brands[0]['_id']; } if ($brand_id) { $river = MongoDoc::get((new Brand($brand_id))->get(), 'social_river', array()); } $this->_display->view(array('main/app/influencer/river.php'), array('brands' => $brands, 'brand_id' => $brand_id, 'river' => $river)); }
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 _favorite() { if (UserSession::get('user.type') !== 'influencer') { $this->_403(); } if (!($id = $this->input->post('id'))) { Json::error('Invalid brand id'); } $id = new \MongoId($id); $influencer = new Influencer(UserSession::get('user._id')); $iinfo = $influencer->get(); $favorites = MongoDoc::get($iinfo, 'favorites', array()); if ($reset = in_array($id, $favorites)) { $favorites = array_values(array_diff($favorites, array($id))); } else { $favorites[] = $id; } $influencer->update(array('favorites' => $favorites)); Json::success('Success', null, array('set' => !$reset)); }