/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate() { $model = new Follow(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $flag = 0; if (isset($_POST['product_id'], $_POST['follow_flag'])) { $model = $model->loadFollowModel($_POST['product_id']); //$model->attributes=$_POST['Wishlist']; if ($model == null) { $model = new Follow(); $model->setIsNewRecord(TRUE); } // echo "</pre>"; echo "post"; //var_dump($model); // die(); $model->follow_flag = $_POST['follow_flag'] ? 0 : 1; $model->product_id = $_POST['product_id']; // echo "</pre>"; echo "post"; var_dump($model); die(); if ($model->save()) { echo "saved"; // echo "</pre>"; echo "post"; var_dump($model); die(); //$this->redirect(array('view','id'=>$model->follow_id)); } else { var_dump($model->getErrors()); } } $this->render('update', array('model' => $model, 'productId' => $model->product_id, 'follow_flag' => $flag)); }
public function setUp() { parent::setUp(); $this->setUpData(); $this->setUpRating(); $this->setUpProfile(); $user = new User(); $user->email = '*****@*****.**'; $user->password = '******'; $user->save(); $follow_id = User::where('email', '*****@*****.**')->first()->user_id; $profile = new Profile(); $profile->user_id = $follow_id; $profile->follower_count = '13'; $profile->following_count = '2'; $profile->rate_count = '32'; $profile->comment_count = '12'; $profile->scan_count = '8'; $profile->last_name = 'pro3'; $profile->first_name = 'user login'; $profile->save(); $follow = new Follow(); $follow->id = 1; $follow->from_id = $this->_user_id; $follow->to_id = $follow_id; $follow->save(); }
public function setUp() { parent::setUp(); $this->setUpData(); $this->setUpProfile(); $user = new User(); $user->email = '*****@*****.**'; $user->password = '******'; $user->save(); $other_user = User::where('email', '*****@*****.**')->first()->user_id; $profile = new Profile(); $profile->user_id = $other_user; $profile->follower_count = '4'; $profile->following_count = '7'; $profile->rate_count = '6'; $profile->comment_count = '9'; $profile->scan_count = '15'; $profile->last_name = 'pro2'; $profile->first_name = 'user other 1'; $profile->save(); $follow = new Follow(); $follow->from_id = $this->_user_id; $follow->to_id = $other_user; $follow->save(); }
public function add($user_follow, $user_followed, $type) { $check = Relationship::model()->findAllByAttributes(array('user_id_1' => $user_follow, 'user_id_2' => $user_followed)); $check_2 = Relationship::model()->findAllByAttributes(array('user_id_2' => $user_follow, 'user_id_1' => $user_followed)); $check_3 = Follow::model()->findByAttributes(array('user_follow' => $user_follow, 'user_followed' => $user_followed)); if ($check || $check_2 || $check_3 || $user_followed == Yii::app()->session['user_id']) { return FALSE; } $model = new Follow(); $model->user_follow = $user_follow; $model->user_followed = $user_followed; $model->created_at = time(); $model->update_at = time(); $model->type = $type; $user_follow_data = User::model()->findByPk($user_follow); $user_followed_data = User::model()->findByPk($user_followed); if ($user_follow != Yii::app()->session['user_id']) { $arr_noti = array('user_id' => $user_follow, 'content' => "{$user_follow_data->username} vừa theo dõi bạn", 'type' => 'follow', 'recipient_id' => $user_followed_data->id, 'url' => Yii::app()->createAbsoulteUrl('user/profile', array('user_id' => $user_follow_data->id, 'ref' => 'noti'))); Notifications::model()->add($arr_noti); } if ($model->save(FALSE)) { return TRUE; } return FALSE; }
public function actionAdd() { $id = Yii::app()->request->getParam('id'); //被访问的用户id,此时视图能看见加好友功能 $model = new Follow(); $model->uid = Yii::app()->user->id; $model->touid = $id; $model->time = time(); if ($model->save()) { //$this->redirect(array('user/home', 'uid' => $id)); $this->redirect_message('关注成功!', 'success', '3'); } }
/** * @todo rewrite as proper SQL (or many-to-many once it works) */ function add_follower(User $follower) { $f = Follow::find_by_user_id_and_follower_id($this->id, $follower->id); if (!$f) { $f = new Follow(); $f->user_id = $this->id; $f->follower_id = $follower->id; $f->save(); } // foreach($this->follows as $f) { // echo $f->follower_id."\n<br>"; // } }
public function setUp() { parent::setUp(); $this->setUpData(); $wine_note = new Winenote(); $wine_note->wine_unique_id = "1_2009"; $wine_note->user_id = $this->_user_id; $wine_note->note = "this is note test"; $wine_note->save(); $follow = new Follow(); $follow->from_id = $this->_user_id; $follow->to_id = "3620a42d-fcbb-45eb-b3a5-36cada1b77b7"; $follow->save(); }
public function register($aid, $name, $gender, $age, $type, $u_name, $u_gender, $u_city, $inviter) { $user = new User(); $user->name = $u_name; $user->gender = $u_gender; $user->city = $u_city; $user->code = $this->createInviteCode(); $user->inviter = $inviter; $user->gold = 500; $reward_items = array(1101 => 3, 1102 => 3, 1103 => 3, 1104 => 3, 1105 => 3, 1106 => 3, 1107 => 3, 1201 => 2, 1202 => 2, 1203 => 2, 1204 => 2, 1205 => 2, 1206 => 2, 1207 => 2, 1301 => 1, 1302 => 1, 1303 => 1, 1304 => 1, 1305 => 1, 2101 => 3, 2102 => 3, 2103 => 3, 2104 => 3); $user->items = serialize($reward_items); $user->save(); if (!isset($aid)) { $animal = new Animal(); $animal->name = $name; $animal->gender = $gender; $animal->age = $age; $animal->type = $type; $animal->from = substr($type, 0, 1); $animal->master_id = $user->usr_id; $animal->save(); $aid = $animal->aid; $circle = new Circle(); $circle->aid = $aid; $circle->usr_id = $user->usr_id; $circle->rank = 0; $circle->save(); } else { $circle = new Circle(); $circle->aid = $aid; $circle->usr_id = $user->usr_id; $circle->save(); } $f = new Follow(); $f->usr_id = $user->usr_id; $f->aid = $aid; $f->create_time = time(); $f->save(); $user->aid = $aid; $user->saveAttributes(array('aid')); $user->initialize(); $user->rewardInviter(); //$this->onRegister = array($user, 'initialize'); //$this->onRegister = array($user, 'rewardInviter'); $this->owner->usr_id = $user->usr_id; $this->owner->saveAttributes(array('usr_id')); $this->onRegister(new CEvent()); return $user; }
/** * Let current user follow user $target_id * * @return Response */ public function store() { $target_id = Input::get('target'); $user_id = Auth::id(); $params = array('user_id' => Auth::id(), 'target_id' => $target_id); $follow = Follow::withTrashed($params)->where($params)->first(); if ($follow === null) { $follow = new Follow($params); $follow->save(); FeedManager::followUser($follow->user_id, $follow->target_id); } elseif ($follow->trashed()) { $follow->restore(); FeedManager::followUser($follow->user_id, $follow->target_id); } return Redirect::to(Input::get('next')); }
public function setUp() { parent::setUp(); $this->setUpData(); $this->setUpRating(); $user = new User(); $user->email = '*****@*****.**'; $user->password = '******'; $user->save(); $follow_id = User::where('email', '*****@*****.**')->first()->user_id; $follow = new Follow(); $follow->id = 1; $follow->from_id = $this->_user_id; $follow->to_id = $follow_id; $follow->save(); }
public function store() { $follower_id = Input::get('follower_id'); $followed_id = Input::get('followed_id'); $follow_id = FEFollowsHelper::getId($follower_id, $followed_id, false); if (!$follow_id) { $follow = new Follow(); $follow->follower_id = $follower_id; $follow->followed_id = $followed_id; $follow->save(); echo $follow->id; } else { $follow = Follow::find($follow_id); $follow->is_deleted = 0; $follow->save(); echo $follow->id; } }
/** * 添加或取消关注 */ public function toggleFollow($userId) { $owner = $this->getOwner(); $follow = Follow::model()->findByAttributes(array('userId' => $userId, 'followableEntityId' => $owner->entityId)); if ($follow) { $follow->delete(); $result = false; } else { $follow = new Follow(); $follow->userId = $userId; $follow->followableEntityId = $owner->entityId; $follow->addTime = time(); $follow->save(); $result = true; } if ($follow->isNewRecord) { $this->onAdded(new Event($this, array('follow' => $follow))); } return $result; }
public function follow($slug) { $hub = Hub::where('slug', '=', $slug)->first(); $user = Auth::user(); if (!is_null($hub)) { $f = Follow::where('user', '=', $user->id)->where('hub', '=', $hub->id)->first(); if (is_null($f)) { $f = new Follow(); $f->hub = $hub->id; $f->user = $user->id; $f->save(); return Redirect::to('hubs/' . $hub->slug); } else { $f->delete(); return Redirect::to('hubs/' . $hub->slug); } } else { App::abort('404'); } }
/** * @param $model * @return Follow */ public function processRequest($model) { Yii::import('application.modules.users.models.User'); Yii::import('application.modules.catalog.models.Objects'); $follow = new Follow; if((Yii::app()->request->isPostRequest) && (Yii::app()->request->getPost('Follow'))) { $follow->attributes = Yii::app()->request->getPost('Follow'); if(!Yii::app()->user->isGuest) { $follow->name = Yii::app()->user->username; $follow->email = Yii::app()->user->email; } if($follow->validate()) { $pkAttr = $model->getObjectPkAttribute(); $follow->class_name = $model->getClassName(); $follow->object_pk = $model->$pkAttr; $follow->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id; $follow->save(); $url = Yii::app()->getRequest()->getUrl(); if($follow->status==Follow::STATUS_WAITING) { $url.='#'; Yii::app()->user->setFlash('messages', 'Успешно подписаны'); } elseif($follow->status==Follow::STATUS_APPROVED) $url.='#follow_'.$follow->id; // Refresh page Yii::app()->request->redirect($url, true); } } return $follow; }
public static function createNewFollow($input) { $follow = new Follow(); $error_code = ApiResponse::OK; $follow->from_id = Session::get('user_id'); if (!empty($input['follow_id'])) { if ($input['follow_id'] == $follow->from_id) { $error_code = ApiResponse::SELF_FOLLOW_ERROR; $data = ApiResponse::getErrorContent(ApiResponse::SELF_FOLLOW_ERROR); } else { $follow->to_id = $input['follow_id']; $user = User::where('user_id', $follow->to_id)->first(); if ($user) { if (Follow::where('from_id', $follow->from_id)->where('to_id', '=', $follow->to_id)->first()) { $error_code = ApiResponse::DUPLICATED_FOLLOW; $data = ApiResponse::getErrorContent(ApiResponse::DUPLICATED_FOLLOW); } else { $following_profile = Profile::where('user_id', $follow->from_id)->first(); if ($following_profile != null) { $following_profile->following_count = $following_profile->following_count + 1; $following_profile->save(); } $follower_profile = Profile::where('user_id', $follow->to_id)->first(); if ($follower_profile) { $follower_profile->follower_count = $follower_profile->follower_count + 1; $follower_profile->save(); } $follow->save(); $data = $follow->toArray(); } } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } } } else { $error_code = ApiResponse::MISSING_PARAMS; $data = $input; } return array("code" => $error_code, "data" => $data); }
/** * Follows the owner object * * @param int $userId * @return boolean */ public function follow($userId = "") { if ($userId == "") { $userId = Yii::app()->user->id; } // User cannot follow himself if (get_class($this->getOwner()) == 'User' && $this->getOwner()->getPrimaryKey() == $userId) { return false; } $record = $this->getFollowRecord($userId); if ($record === null) { $follow = new Follow(); $follow->user_id = $userId; $follow->object_id = $this->getOwner()->getPrimaryKey(); $follow->object_model = get_class($this->getOwner()); if (!$follow->save()) { return false; } } else { // Already follows this object return false; } return true; }
public function actionJoinApi($aid) { $transaction = Yii::app()->db->beginTransaction(); try { $circle = new Circle(); $circle->aid = $aid; $circle->usr_id = $this->usr_id; $circle->save(); $f = Follow::model()->findByPk(array('usr_id' => $this->usr_id, 'aid' => $aid)); if (!isset($f)) { $f = new Follow(); $f->usr_id = $this->usr_id; $f->aid = $aid; $f->create_time = time(); $f->save(); } $news = new News(); $news->aid = $aid; $news->type = 2; $news->create_time = time(); $user = User::model()->findByPk($this->usr_id); $news->content = serialize(array('usr_id' => $user->usr_id, 'u_name' => $user->name)); $news->save(); $transaction->commit(); $this->echoJsonData(array('isSuccess' => TRUE)); } catch (Exception $e) { $transaction->rollback(); throw $e; } }
public function follow() { $value = Session::get('key'); if ($value == "") { return Redirect::to('login'); } $follow = Input::get('follow'); $memberID = Input::get('memberID'); if ($follow == 0) { //eğer kullanıcı takip etmiyorsa $f = new Follow(); $f->memberID = $value; $f->followMemberID = $memberID; $f->save(); return Redirect::to('m-profile-' . $memberID); } $f = DB::table('follow')->where('memberID', $value)->where('followMemberID', $memberID)->select('followID')->get(); $f2 = Follow::find($f[0]->followID); $f2->delete(); return Redirect::to('m-profile-' . $memberID); }
public function follow($followed_user_id) { $user_id = Auth::id(); $follow = new Follow(); $follow->user_following = $user_id; $follow->user_followed = $followed_user_id; $follow->save(); }
public function follow($artist) { $artist = User::where('profile_url', '=', $artist)->first(); $user = Auth::user(); if (!is_null($artist)) { $f = Follow::where('user', '=', $user->id)->where('artist', '=', $artist->id)->first(); if (is_null($f)) { $f = new Follow(); $f->artist = $artist->id; $f->user = $user->id; $f->save(); return Redirect::to('artist/' . $artist->profile_url); } else { $f->delete(); return Redirect::to('artist/' . $artist->profile_url); } } else { App::abort('404'); } }