summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/Comments.php
blob: 7af70eceb92f4495fa2c17d467365103606874bb (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
74
75
76
<?php

Prado::using('System.I18N.*');

/**
 * Comments class.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @version : $  Sat May 27 20:23:00 AZOST 2006 $
 * @package Demo.Quickstart
 * @since 3.0
 */
class Comments extends TPage
{
	private $_quickstart;
	
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->_quickstart = new QuickStartComments;
		if(!$this->getIsPostBack())
			$this->refreshData();
	}
	
	protected function refreshData()
	{
		$this->comments->setDataSource($this->_quickstart->getQuequedComments());
		$this->comments->dataBind();		
	}
	
	public function approveComment($sender, $param)
	{
		$ID = $this->comments->DataKeys[$this->comments->SelectedItemIndex];
		$this->_quickstart->approveComment($ID);
		$this->refreshData();
		$this->comments->SelectedItemIndex=-1;
	}
	
	public function editComment($sender, $param)
	{
		$this->comments->SelectedItemIndex=-1;
		$this->comments->EditItemIndex=$param->Item->ItemIndex;
		$this->refreshData();	
	}
	
	public function cancelEdit($sender, $param)
	{
		$this->comments->SelectedItemIndex=-1;
		$this->comments->EditItemIndex=-1;
		$this->refreshData();
	}
	
	public function deleteComment($sender, $param)
	{
		$ID = $this->comments->DataKeys[$param->Item->ItemIndex];
		$this->_quickstart->deleteComment($ID);
		$this->comments->SelectedItemIndex=-1;
		$this->comments->EditItemIndex=-1;
		$this->refreshData();
	}
	
	public function updateComment($sender, $param)
	{
		$item=$param->Item;
		$this->_quickstart->updateComment(
			$this->comments->DataKeys[$item->ItemIndex],
			$item->page->Text,
			$item->email->Text,
			$item->content->Text);
			
		$this->comments->EditItemIndex=-1;
		$this->refreshData();
	}
}

?>