summaryrefslogtreecommitdiff
path: root/demos/blog-tutorial/samples/day5/blog/protected/pages/posts
diff options
context:
space:
mode:
authorctrlaltca <>2012-07-12 11:21:01 +0000
committerctrlaltca <>2012-07-12 11:21:01 +0000
commit903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 (patch)
treee08bf04f0823650a231227ac3499121270172a23 /demos/blog-tutorial/samples/day5/blog/protected/pages/posts
parent3e4e6e66aeb3f8fea4e1eb4237498ef9d2358f63 (diff)
standardize the use of unix eol; use svn properties to enforce native eol
Diffstat (limited to 'demos/blog-tutorial/samples/day5/blog/protected/pages/posts')
-rw-r--r--demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php142
-rw-r--r--demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php126
-rw-r--r--demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php66
-rw-r--r--demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php12
-rw-r--r--demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php116
5 files changed, 231 insertions, 231 deletions
diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php
index e137b85e..1b0f82b6 100644
--- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php
+++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php
@@ -1,72 +1,72 @@
-<?php
-
-class EditPost extends TPage
-{
- /**
- * Initializes the inputs with existing post data.
- * This method is invoked by the framework when the page is being initialized.
- * @param mixed event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- // Retrieves the existing user data. This is equivalent to:
- // $postRecord=$this->getPost();
- $postRecord=$this->Post;
- // Authorization check: only the author or the administrator can edit the post
- if($postRecord->author_id!==$this->User->Name && !$this->User->IsAdmin)
- throw new THttpException(500,'You are not allowed to edit this post.');
-
- if(!$this->IsPostBack) // if the page is initially requested
- {
- // Populates the input controls with the existing post data
- $this->TitleEdit->Text=$postRecord->title;
- $this->ContentEdit->Text=$postRecord->content;
- }
- }
-
- /**
- * Saves the post 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:
- // $postRecord=$this->getPost();
- $postRecord=$this->Post;
-
- // Fetches the input data
- $postRecord->title=$this->TitleEdit->SafeText;
- $postRecord->content=$this->ContentEdit->SafeText;
-
- // saves to the database via Active Record mechanism
- $postRecord->save();
-
- // redirects the browser to the ReadPost page
- $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id));
- $this->Response->redirect($url);
- }
- }
-
- /**
- * Returns the post data to be editted.
- * @return PostRecord the post data to be editted.
- * @throws THttpException if the post data is not found.
- */
- protected function getPost()
- {
- // the ID of the post to be editted is passed via GET parameter 'id'
- $postID=(int)$this->Request['id'];
- // use Active Record to look for the specified post ID
- $postRecord=PostRecord::finder()->findByPk($postID);
- if($postRecord===null)
- throw new THttpException(500,'Post is not found.');
- return $postRecord;
- }
-}
-
+<?php
+
+class EditPost extends TPage
+{
+ /**
+ * Initializes the inputs with existing post data.
+ * This method is invoked by the framework when the page is being initialized.
+ * @param mixed event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ // Retrieves the existing user data. This is equivalent to:
+ // $postRecord=$this->getPost();
+ $postRecord=$this->Post;
+ // Authorization check: only the author or the administrator can edit the post
+ if($postRecord->author_id!==$this->User->Name && !$this->User->IsAdmin)
+ throw new THttpException(500,'You are not allowed to edit this post.');
+
+ if(!$this->IsPostBack) // if the page is initially requested
+ {
+ // Populates the input controls with the existing post data
+ $this->TitleEdit->Text=$postRecord->title;
+ $this->ContentEdit->Text=$postRecord->content;
+ }
+ }
+
+ /**
+ * Saves the post 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:
+ // $postRecord=$this->getPost();
+ $postRecord=$this->Post;
+
+ // Fetches the input data
+ $postRecord->title=$this->TitleEdit->SafeText;
+ $postRecord->content=$this->ContentEdit->SafeText;
+
+ // saves to the database via Active Record mechanism
+ $postRecord->save();
+
+ // redirects the browser to the ReadPost page
+ $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id));
+ $this->Response->redirect($url);
+ }
+ }
+
+ /**
+ * Returns the post data to be editted.
+ * @return PostRecord the post data to be editted.
+ * @throws THttpException if the post data is not found.
+ */
+ protected function getPost()
+ {
+ // the ID of the post to be editted is passed via GET parameter 'id'
+ $postID=(int)$this->Request['id'];
+ // use Active Record to look for the specified post ID
+ $postRecord=PostRecord::finder()->findByPk($postID);
+ if($postRecord===null)
+ throw new THttpException(500,'Post is not found.');
+ return $postRecord;
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php
index 7402dace..ae5a7eeb 100644
--- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php
+++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php
@@ -1,64 +1,64 @@
-<?php
-
-class ListPost extends TPage
-{
- /**
- * Initializes the repeater.
- * This method is invoked by the framework when initializing the page
- * @param mixed event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- if(!$this->IsPostBack) // if the page is requested the first time
- {
- // get the total number of posts available
- $this->Repeater->VirtualItemCount=PostRecord::finder()->count();
- // populates post data into the repeater
- $this->populateData();
- }
- }
-
- /**
- * Event handler to the OnPageIndexChanged event of the pager.
- * This method is invoked when the user clicks on a page button
- * and thus changes the page of posts to display.
- */
- public function pageChanged($sender,$param)
- {
- // change the current page index to the new one
- $this->Repeater->CurrentPageIndex=$param->NewPageIndex;
- // re-populate data into the repeater
- $this->populateData();
- }
-
- /**
- * Determines which page of posts to be displayed and
- * populates the repeater with the fetched data.
- */
- protected function populateData()
- {
- $offset=$this->Repeater->CurrentPageIndex*$this->Repeater->PageSize;
- $limit=$this->Repeater->PageSize;
- if($offset+$limit>$this->Repeater->VirtualItemCount)
- $limit=$this->Repeater->VirtualItemCount-$offset;
- $this->Repeater->DataSource=$this->getPosts($offset,$limit);
- $this->Repeater->dataBind();
- }
-
- /**
- * Fetches posts from database with offset and limit.
- */
- protected function getPosts($offset, $limit)
- {
- // Construts a query criteria
- $criteria=new TActiveRecordCriteria;
- $criteria->OrdersBy['create_time']='desc';
- $criteria->Limit=$limit;
- $criteria->Offset=$offset;
- // query for the posts with the above criteria and with author information
- return PostRecord::finder()->withAuthor()->findAll($criteria);
- }
-}
-
+<?php
+
+class ListPost extends TPage
+{
+ /**
+ * Initializes the repeater.
+ * This method is invoked by the framework when initializing the page
+ * @param mixed event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ if(!$this->IsPostBack) // if the page is requested the first time
+ {
+ // get the total number of posts available
+ $this->Repeater->VirtualItemCount=PostRecord::finder()->count();
+ // populates post data into the repeater
+ $this->populateData();
+ }
+ }
+
+ /**
+ * Event handler to the OnPageIndexChanged event of the pager.
+ * This method is invoked when the user clicks on a page button
+ * and thus changes the page of posts to display.
+ */
+ public function pageChanged($sender,$param)
+ {
+ // change the current page index to the new one
+ $this->Repeater->CurrentPageIndex=$param->NewPageIndex;
+ // re-populate data into the repeater
+ $this->populateData();
+ }
+
+ /**
+ * Determines which page of posts to be displayed and
+ * populates the repeater with the fetched data.
+ */
+ protected function populateData()
+ {
+ $offset=$this->Repeater->CurrentPageIndex*$this->Repeater->PageSize;
+ $limit=$this->Repeater->PageSize;
+ if($offset+$limit>$this->Repeater->VirtualItemCount)
+ $limit=$this->Repeater->VirtualItemCount-$offset;
+ $this->Repeater->DataSource=$this->getPosts($offset,$limit);
+ $this->Repeater->dataBind();
+ }
+
+ /**
+ * Fetches posts from database with offset and limit.
+ */
+ protected function getPosts($offset, $limit)
+ {
+ // Construts a query criteria
+ $criteria=new TActiveRecordCriteria;
+ $criteria->OrdersBy['create_time']='desc';
+ $criteria->Limit=$limit;
+ $criteria->Offset=$offset;
+ // query for the posts with the above criteria and with author information
+ return PostRecord::finder()->withAuthor()->findAll($criteria);
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php
index a5e3ea4d..d3a36133 100644
--- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php
+++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php
@@ -1,34 +1,34 @@
-<?php
-
-class NewPost extends TPage
-{
- /**
- * Creates a new post 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 PostRecord object with user inputs
- $postRecord=new PostRecord;
- // using SafeText instead of Text avoids Cross Site Scripting attack
- $postRecord->title=$this->TitleEdit->SafeText;
- $postRecord->content=$this->ContentEdit->SafeText;
- $postRecord->author_id=$this->User->Name;
- $postRecord->create_time=time();
- $postRecord->status=0;
-
- // saves to the database via Active Record mechanism
- $postRecord->save();
-
- // redirects the browser to the newly created post page
- $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id));
- $this->Response->redirect($url);
- }
- }
-}
-
+<?php
+
+class NewPost extends TPage
+{
+ /**
+ * Creates a new post 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 PostRecord object with user inputs
+ $postRecord=new PostRecord;
+ // using SafeText instead of Text avoids Cross Site Scripting attack
+ $postRecord->title=$this->TitleEdit->SafeText;
+ $postRecord->content=$this->ContentEdit->SafeText;
+ $postRecord->author_id=$this->User->Name;
+ $postRecord->create_time=time();
+ $postRecord->status=0;
+
+ // saves to the database via Active Record mechanism
+ $postRecord->save();
+
+ // redirects the browser to the newly created post page
+ $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id));
+ $this->Response->redirect($url);
+ }
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php
index cf0539a1..ed80f10c 100644
--- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php
+++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php
@@ -1,7 +1,7 @@
-<?php
-
-class PostRenderer extends TRepeaterItemRenderer
-{
-}
-
+<?php
+
+class PostRenderer extends TRepeaterItemRenderer
+{
+}
+
?> \ No newline at end of file
diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php
index 0c120824..ab7429c3 100644
--- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php
+++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php
@@ -1,59 +1,59 @@
-<?php
-
-Prado::using('Application.BlogException');
-
-class ReadPost extends TPage
-{
- private $_post;
- /**
- * Fetches the post data.
- * This method is invoked by the framework when initializing the page
- * @param mixed event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- // post id is passed via the 'id' GET parameter
- $postID=(int)$this->Request['id'];
- // retrieves PostRecord with author information filled in
- $this->_post=PostRecord::finder()->withAuthor()->findByPk($postID);
- if($this->_post===null) // if post id is invalid
- throw new BlogException(500,'Unable to find the specified post.');
- // set the page title as the post title
- $this->Title=$this->_post->title;
- }
-
- /**
- * @return PostRecord the PostRecord currently being viewed
- */
- public function getPost()
- {
- return $this->_post;
- }
-
- /**
- * Deletes the post currently being viewed
- * This method is invoked when the user clicks on the "Delete" button
- */
- public function deletePost($sender,$param)
- {
- // only the author or the administrator can delete a post
- if(!$this->canEdit())
- throw new THttpException('You are not allowed to perform this action.');
- // delete it from DB
- $this->_post->delete();
- // redirect the browser to the homepage
- $this->Response->redirect($this->Service->DefaultPageUrl);
- }
-
- /**
- * @return boolean whether the current user can edit/delete the post being viewed
- */
- public function canEdit()
- {
- // only the author or the administrator can edit/delete a post
- return $this->User->Name===$this->Post->author_id || $this->User->IsAdmin;
- }
-}
-
+<?php
+
+Prado::using('Application.BlogException');
+
+class ReadPost extends TPage
+{
+ private $_post;
+ /**
+ * Fetches the post data.
+ * This method is invoked by the framework when initializing the page
+ * @param mixed event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ // post id is passed via the 'id' GET parameter
+ $postID=(int)$this->Request['id'];
+ // retrieves PostRecord with author information filled in
+ $this->_post=PostRecord::finder()->withAuthor()->findByPk($postID);
+ if($this->_post===null) // if post id is invalid
+ throw new BlogException(500,'Unable to find the specified post.');
+ // set the page title as the post title
+ $this->Title=$this->_post->title;
+ }
+
+ /**
+ * @return PostRecord the PostRecord currently being viewed
+ */
+ public function getPost()
+ {
+ return $this->_post;
+ }
+
+ /**
+ * Deletes the post currently being viewed
+ * This method is invoked when the user clicks on the "Delete" button
+ */
+ public function deletePost($sender,$param)
+ {
+ // only the author or the administrator can delete a post
+ if(!$this->canEdit())
+ throw new THttpException('You are not allowed to perform this action.');
+ // delete it from DB
+ $this->_post->delete();
+ // redirect the browser to the homepage
+ $this->Response->redirect($this->Service->DefaultPageUrl);
+ }
+
+ /**
+ * @return boolean whether the current user can edit/delete the post being viewed
+ */
+ public function canEdit()
+ {
+ // only the author or the administrator can edit/delete a post
+ return $this->User->Name===$this->Post->author_id || $this->User->IsAdmin;
+ }
+}
+
?> \ No newline at end of file