/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Follower(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Follower'])) { $model->attributes = $_POST['Follower']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * post_follow is called when the "Follow" button is pressed on another user's profile, * creating a record in the DB in the form of a primary key (user_id, following_id) defining a relationship */ public function post_follow() { // get the id of the user to be followed $following_id = Input::get('id'); // get the id of the currently logged in user $follower_id = Auth::user()->id; // define a relationship $new_follower = array('user_id' => $follower_id, 'following_id' => $following_id); // save the follower reltionship $follower = new Follower($new_follower); $follower->save(); return Redirect::back(); }
/** * Allows one user to follow another * @param int $id The ID of the user to follow */ public function actionFollow($id = null) { if ($id == null) { throw new CHttpException(400, 'You must specify the user you wish to follow'); } if ($id == Yii::app()->user->id) { throw new CHttpException(400, 'You can not follow yourself'); } $follower = new Follower(); $follower->attributes = array('follower_id' => Yii::app()->user->id, 'followee_id' => $id); if ($follower->save()) { Yii::app()->user->setFlash('success', 'You are now following ' . User::model()->findByPk($id)->name); } // Redirect back to where they were before $this->redirect(Yii::app()->request->urlReferrer); }
/** * @transaction * @userCache * * @param int $userId リクエストされたユーザのID * @param int $requestorId リクエストしたユーザのID * * @return Logics_Result */ public function accept($userId, $requestorId) { $result = new Logics_Result(); $aUser = new User($userId); $requestor = new User($requestorId); if ($aUser->isActive() && $requestor->isActive()) { $follower = new Follower(); $follower->save(array("user_id" => $requestor->id, "follow_id" => $aUser->id, "created_at" => now())); $request = new Request(); $request->setCondition("user_id", $requestor->id); $request->setCondition("request_id", $aUser->id); $request->delete(); } else { $result->failure(); } return $result; }
/** * @transaction * * @param User $aUser * * @return Logics_Result */ public function updateSettings(User $aUser) { $result = new Logics_Result(); $result->aUser = $aUser; if ($errors = $this->validateModel($aUser)) { return $result->setErrors($errors); } $aUser->save(); if (!$aUser->private_flag) { $request = new Request(); if ($requests = $request->select("request_id", $aUser->id)) { foreach ($requests as $aRequest) { $aFollower = new Follower(); $aFollower->save(array("user_id" => $aRequest->user_id, "follow_id" => $aRequest->request_id, "created_at" => now())); $aRequest->delete(); } } } return $result; }
public static function createFollower($service, array $rawfollower, PropelPDO $con = null) { $crit = new Criteria(); $crit->add(self::SENDER_ID, $rawfollower['id']); $follower = self::doSelectOne($crit, $con); if (is_null($follower)) { if (!$service->existsFriendship(sfConfig::get('twitter_user_id'), $rawfollower['id'])) { $service->createFriendship($rawfollower['id']); } $follower = new Follower(); $follower->setFollowing(true); $follower->setSenderId($rawfollower['id']); $follower->setSenderName($rawfollower['name']); $follower->setSenderScreenName($rawfollower['screen_name']); $follower->setSenderLocation($rawfollower['location']); $follower->setSenderProfileImg($rawfollower['profile_image_url']); $follower->setSenderProtected($rawfollower['protected']); $follower->save(); } return $follower; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aFollower !== null) { if ($this->aFollower->isModified() || $this->aFollower->isNew()) { $affectedRows += $this->aFollower->save($con); } $this->setFollower($this->aFollower); } if ($this->isNew()) { $this->modifiedColumns[] = RawMessagePeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = RawMessagePeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += RawMessagePeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
public function accountStore($id) { $club = Club::find($id); switch ($club->sport) { case 'lacrosse': $validator = Validator::make(Input::all(), ClubPublic::$rules, ClubPublic::$messages); break; case 'coach': $validator = Validator::make(Input::all(), ClubPublic::$coach_rules, ClubPublic::$coach_messages); break; } $uuid = Uuid::generate(); if ($validator->passes()) { $repo = App::make('UserRepository'); $user = $repo->signup(Input::all()); $role = Role::find(4); $user->attachRole($role); if ($user->id) { $profile = new Profile(); $profile->user_id = $user->id; $profile->firstname = Input::get('firstname'); $profile->lastname = Input::get('lastname'); $profile->mobile = Input::get('mobile'); $profile->dob = Input::get('dob'); $profile->avatar = '/img/coach-avatar.jpg'; $profile->save(); $follower = new Follower(); $follower->user_id = $user->id; $follower->club_id = $club->id; $follower->save(); //implement here method for save different sport players fields switch ($club->sport) { case 'lacrosse': $player = new Player(); $player->id = $uuid; $player->firstname = Input::get('firstname_p'); $player->lastname = Input::get('lastname_p'); $player->email = Input::get('email_p'); $player->mobile = Input::get('mobile_p'); $player->position = Input::get('position'); $player->relation = Input::get('relation'); $player->dob = Input::get('dob_p'); $player->gender = Input::get('gender'); $player->year = Input::get('year'); $player->school = Input::get('school'); $player->laxid = Input::get('laxid'); $player->laxid_exp = Input::get('laxid_exp'); $player->uniform = Input::get('uniform'); $player->avatar = Input::get('avatar'); $player->address = Input::get('address'); $player->city = Input::get('city'); $player->state = Input::get('state'); $player->zip = Input::get('zip'); $player->user_id = $user->id; $player->save(); break; case 'coach': $player = new Player(); $player->id = $uuid; $player->firstname = Input::get('firstname_p'); $player->lastname = Input::get('lastname_p'); $player->email = Input::get('email_p'); $player->mobile = Input::get('mobile_p'); $player->position = ''; $player->relation = Input::get('relation'); $player->dob = Input::get('dob_p'); $player->gender = Input::get('gender'); $player->year = Input::get('year'); $player->school = Input::get('school'); $player->avatar = Input::get('avatar'); $player->user_id = $user->id; $player->save(); break; } if (Config::get('confide::signup_email')) { Mail::queueOn(Config::get('confide::email_queue'), Config::get('confide::email_account_confirmation'), compact('user'), function ($message) use($user) { $message->to($user->email, $user->username)->subject(Lang::get('confide::confide.email.account_confirmation.subject')); }); } return Redirect::action('ClubPublicController@accountLogin', array($club->id))->with('notice', Lang::get('confide::confide.alerts.account_created')); } else { $error = $user->errors()->all(':message'); return Redirect::back()->withInput(Input::except('password'))->withErrors($error); } } return Redirect::back()->withErrors($validator)->withInput(); }