From 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Thu, 12 Jul 2012 11:21:01 +0000 Subject: standardize the use of unix eol; use svn properties to enforce native eol --- .../day5/blog/protected/pages/users/AdminUser.php | 70 ++++----- .../day5/blog/protected/pages/users/EditUser.php | 164 ++++++++++----------- .../day5/blog/protected/pages/users/LoginUser.php | 72 ++++----- .../day5/blog/protected/pages/users/NewUser.php | 88 +++++------ 4 files changed, 197 insertions(+), 197 deletions(-) (limited to 'demos/blog-tutorial/samples/day5/blog/protected/pages/users') diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php index ad8f6e3d..ad668e1a 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php @@ -1,36 +1,36 @@ -UserGrid->DataSource=UserRecord::finder()->findAll(); - // binds the data to interface components - $this->UserGrid->dataBind(); - } - - /** - * Deletes a specified user record. - * This method responds to the datagrid's OnDeleteCommand event. - * @param TDataGrid the event sender - * @param TDataGridCommandEventParameter the event parameter - */ - public function deleteButtonClicked($sender,$param) - { - // obtains the datagrid item that contains the clicked delete button - $item=$param->Item; - // obtains the primary key corresponding to the datagrid item - $username=$this->UserGrid->DataKeys[$item->ItemIndex]; - // deletes the user record with the specified username primary key - UserRecord::finder()->deleteByPk($username); - } -} - +UserGrid->DataSource=UserRecord::finder()->findAll(); + // binds the data to interface components + $this->UserGrid->dataBind(); + } + + /** + * Deletes a specified user record. + * This method responds to the datagrid's OnDeleteCommand event. + * @param TDataGrid the event sender + * @param TDataGridCommandEventParameter the event parameter + */ + public function deleteButtonClicked($sender,$param) + { + // obtains the datagrid item that contains the clicked delete button + $item=$param->Item; + // obtains the primary key corresponding to the datagrid item + $username=$this->UserGrid->DataKeys[$item->ItemIndex]; + // deletes the user record with the specified username primary key + UserRecord::finder()->deleteByPk($username); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php index 81538c33..f8c61463 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php @@ -1,83 +1,83 @@ -IsPostBack) // if the page is initially requested - { - // Retrieves the existing user data. This is equivalent to: - // $userRecord=$this->getUserRecord(); - $userRecord=$this->UserRecord; - - // Populates the input controls with the existing user data - $this->Username->Text=$userRecord->username; - $this->Email->Text=$userRecord->email; - $this->Role->SelectedValue=$userRecord->role; - $this->FirstName->Text=$userRecord->first_name; - $this->LastName->Text=$userRecord->last_name; - } - } - - /** - * Saves the user account if all inputs are valid. - * This method responds to the OnClick event of the "save" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // Retrieves the existing user data. This is equivalent to: - $userRecord=$this->UserRecord; - - // Fetches the input data - $userRecord->username=$this->Username->Text; - // update password when the input is not empty - if(!empty($this->Password->Text)) - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - // update the role if the current user is an administrator - if($this->User->IsAdmin) - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } - - /** - * Returns the user data to be editted. - * @return UserRecord the user data to be editted. - * @throws THttpException if the user data is not found. - */ - protected function getUserRecord() - { - // the user to be editted is the currently logged-in user - $username=$this->User->Name; - // if the 'username' GET var is not empty and the current user - // is an administrator, we use the GET var value instead. - if($this->User->IsAdmin && $this->Request['username']!==null) - $username=$this->Request['username']; - - // use Active Record to look for the specified username - $userRecord=UserRecord::finder()->findByPk($username); - if(!($userRecord instanceof UserRecord)) - throw new THttpException(500,'Username is invalid.'); - return $userRecord; - } -} - +IsPostBack) // if the page is initially requested + { + // Retrieves the existing user data. This is equivalent to: + // $userRecord=$this->getUserRecord(); + $userRecord=$this->UserRecord; + + // Populates the input controls with the existing user data + $this->Username->Text=$userRecord->username; + $this->Email->Text=$userRecord->email; + $this->Role->SelectedValue=$userRecord->role; + $this->FirstName->Text=$userRecord->first_name; + $this->LastName->Text=$userRecord->last_name; + } + } + + /** + * Saves the user account if all inputs are valid. + * This method responds to the OnClick event of the "save" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // Retrieves the existing user data. This is equivalent to: + $userRecord=$this->UserRecord; + + // Fetches the input data + $userRecord->username=$this->Username->Text; + // update password when the input is not empty + if(!empty($this->Password->Text)) + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + // update the role if the current user is an administrator + if($this->User->IsAdmin) + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } + + /** + * Returns the user data to be editted. + * @return UserRecord the user data to be editted. + * @throws THttpException if the user data is not found. + */ + protected function getUserRecord() + { + // the user to be editted is the currently logged-in user + $username=$this->User->Name; + // if the 'username' GET var is not empty and the current user + // is an administrator, we use the GET var value instead. + if($this->User->IsAdmin && $this->Request['username']!==null) + $username=$this->Request['username']; + + // use Active Record to look for the specified username + $userRecord=UserRecord::finder()->findByPk($username); + if(!($userRecord instanceof UserRecord)) + throw new THttpException(500,'Username is invalid.'); + return $userRecord; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php index a0955490..407906ae 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php @@ -1,37 +1,37 @@ -Application->getModule('auth'); - if(!$authManager->login($this->Username->Text,$this->Password->Text)) - $param->IsValid=false; // tell the validator that validation fails - } - - /** - * Redirects the user's browser to appropriate URL if login succeeds. - * This method responds to the login button's OnClick event. - * @param mixed event sender - * @param mixed event parameter - */ - public function loginButtonClicked($sender,$param) - { - if($this->Page->IsValid) // all validations succeed - { - // obtain the URL of the privileged page that the user wanted to visit originally - $url=$this->Application->getModule('auth')->ReturnUrl; - if(empty($url)) // the user accesses the login page directly - $url=$this->Service->DefaultPageUrl; - $this->Response->redirect($url); - } - } -} - +Application->getModule('auth'); + if(!$authManager->login($this->Username->Text,$this->Password->Text)) + $param->IsValid=false; // tell the validator that validation fails + } + + /** + * Redirects the user's browser to appropriate URL if login succeeds. + * This method responds to the login button's OnClick event. + * @param mixed event sender + * @param mixed event parameter + */ + public function loginButtonClicked($sender,$param) + { + if($this->Page->IsValid) // all validations succeed + { + // obtain the URL of the privileged page that the user wanted to visit originally + $url=$this->Application->getModule('auth')->ReturnUrl; + if(empty($url)) // the user accesses the login page directly + $url=$this->Service->DefaultPageUrl; + $this->Response->redirect($url); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php index 76e8cb88..3bf6768a 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php @@ -1,45 +1,45 @@ -IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; - } - - /** - * Creates a new user account if all inputs are valid. - * This method responds to the OnClick event of the "create" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function createButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // populates a UserRecord object with user inputs - $userRecord=new UserRecord; - $userRecord->username=$this->Username->Text; - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } -} - +IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; + } + + /** + * Creates a new user account if all inputs are valid. + * This method responds to the OnClick event of the "create" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function createButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // populates a UserRecord object with user inputs + $userRecord=new UserRecord; + $userRecord->username=$this->Username->Text; + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } +} + ?> \ No newline at end of file -- cgit v1.2.3