summaryrefslogtreecommitdiff
path: root/demos/blog/protected/Pages/Posts/ViewPost.php
blob: 309bedc137c3714a4bd8a0edba73b28d4f0f7118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php

class ViewPost extends BlogPage
{
	private $_postID=null;
	private $_post=null;

	public function getPostID()
	{
		if($this->_postID===null)
			$this->_postID=TPropertyValue::ensureInteger($this->Request['id']);
		return $this->_postID;
	}

	public function getCurrentPost()
	{
		if($this->_post===null)
		{
			if(($this->_post=$this->DataAccess->queryPostByID($this->getPostID()))===null)
				$this->reportError(BlogErrors::ERROR_POST_NOT_FOUND);
		}
		return $this->_post;
	}

	public function getCanEditPost()
	{
		$user=$this->getUser();
		$authorID=$this->getCurrentPost()->AuthorID;
		return $authorID===$user->getID() || $user->isInRole('admin');
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->getPostID());
		$this->CategoryList->dataBind();
		$this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->getPostID());
		$this->CommentList->dataBind();
	}

	public function submitCommentButtonClicked($sender,$param)
	{
		if($this->IsValid)
		{
			$commentRecord=new CommentRecord;
			$commentRecord->PostID=$this->CurrentPost->ID;
			$commentRecord->AuthorName=$this->CommentAuthor->Text;
			$commentRecord->AuthorEmail=$this->CommentEmail->Text;
			$commentRecord->AuthorWebsite=$this->CommentWebsite->Text;
			$commentRecord->AuthorIP=$this->Request->UserHostAddress;
			$commentRecord->Content=$this->CommentContent->Text;
			$commentRecord->CreateTime=time();
			$commentRecord->Status=0;
			$this->DataAccess->insertComment($commentRecord);
			$this->Response->reload();
		}
	}

	public function deleteButtonClicked($sender,$param)
	{
		$this->DataAccess->deletePost($this->PostID);
		$this->gotoDefaultPage();
	}

	public function repeaterItemCommand($sender,$param)
	{
		$id=TPropertyValue::ensureInteger($param->CommandParameter);
		$this->DataAccess->deleteComment($id);
		$this->Response->reload();
	}
}

?>