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 --- .../protected/controls/Comments/CommentBlock.php | 212 ++++++++++----------- 1 file changed, 106 insertions(+), 106 deletions(-) (limited to 'demos/quickstart/protected/controls/Comments/CommentBlock.php') diff --git a/demos/quickstart/protected/controls/Comments/CommentBlock.php b/demos/quickstart/protected/controls/Comments/CommentBlock.php index 9c008491..ebb82a0f 100644 --- a/demos/quickstart/protected/controls/Comments/CommentBlock.php +++ b/demos/quickstart/protected/controls/Comments/CommentBlock.php @@ -1,107 +1,107 @@ -setDbConnection($db); - -class CommentRecord extends TActiveRecord -{ - const TABLE='qs_comments'; - - public $id; - public $username; - public $date_added; - public $page; - public $block_id; - public $content; - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} - -class CommentBlock extends TTemplateControl -{ - private $_page; - - function onLoad($param) - { - if(!$this->Page->IsCallBack) - { - $count = array(); - $data = $this->getCommentData(); - foreach($data as $r) - { - if(!isset($count[$r->block_id])) - $count[$r->block_id]=0; - $count[$r->block_id]++; - } - $js = "var comment_count = ".TJavascript::encode($count).";\n"; - $this->Page->ClientScript->registerBeginScript('count',$js); - $this->comments->dataSource = $data; - $this->comments->dataBind(); - } - } - - function getCommentData() - { - return CommentRecord::finder()->findAllByPage($this->getCurrentPagePath()); - } - - function add_comment($sender, $param) - { - if(!$this->Page->IsValid) - return; - $record = new CommentRecord; - $record->username = $this->username->Text; - $record->date_added = date('Y-m-d h:i:s'); - $record->page = $this->getCurrentPagePath(); - $record->block_id = $this->block_id->Value; - $record->content = $this->content->Text; - $record->save(); - - $this->content->Text = ''; - $this->password->Text = ''; - $cc = $this->Page->CallbackClient; - $cc->appendContent('comment-list', $this->format_message($record)); - $cc->callClientFunction('hide_add_comment'); - $cc->callClientFunction('increment_count_tag', $record->block_id); - if(!$this->Page->IsCallBack) - { - $this->comments->dataSource = $this->getCommentData(); - $this->comments->dataBind(); - } - } - - protected function getCurrentPagePath() - { - if(is_null($this->_page)) - { - $page = str_replace($this->Service->BasePath, '', $this->Page->Template->TemplateFile); - $this->_page = str_replace('\\', '/', $page); - } - return $this->_page; - } - - function validate_credential($sender, $param) - { - $param->IsValid = $this->password->Text == 'Prado'; - } - - protected function format_message($record) - { - $username=htmlspecialchars($record->username); - $content=nl2br(htmlspecialchars($record->content)); - return << - {$username} on {$record->date_added}. -
{$content}
- -EOD; - } +setDbConnection($db); + +class CommentRecord extends TActiveRecord +{ + const TABLE='qs_comments'; + + public $id; + public $username; + public $date_added; + public $page; + public $block_id; + public $content; + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} + +class CommentBlock extends TTemplateControl +{ + private $_page; + + function onLoad($param) + { + if(!$this->Page->IsCallBack) + { + $count = array(); + $data = $this->getCommentData(); + foreach($data as $r) + { + if(!isset($count[$r->block_id])) + $count[$r->block_id]=0; + $count[$r->block_id]++; + } + $js = "var comment_count = ".TJavascript::encode($count).";\n"; + $this->Page->ClientScript->registerBeginScript('count',$js); + $this->comments->dataSource = $data; + $this->comments->dataBind(); + } + } + + function getCommentData() + { + return CommentRecord::finder()->findAllByPage($this->getCurrentPagePath()); + } + + function add_comment($sender, $param) + { + if(!$this->Page->IsValid) + return; + $record = new CommentRecord; + $record->username = $this->username->Text; + $record->date_added = date('Y-m-d h:i:s'); + $record->page = $this->getCurrentPagePath(); + $record->block_id = $this->block_id->Value; + $record->content = $this->content->Text; + $record->save(); + + $this->content->Text = ''; + $this->password->Text = ''; + $cc = $this->Page->CallbackClient; + $cc->appendContent('comment-list', $this->format_message($record)); + $cc->callClientFunction('hide_add_comment'); + $cc->callClientFunction('increment_count_tag', $record->block_id); + if(!$this->Page->IsCallBack) + { + $this->comments->dataSource = $this->getCommentData(); + $this->comments->dataBind(); + } + } + + protected function getCurrentPagePath() + { + if(is_null($this->_page)) + { + $page = str_replace($this->Service->BasePath, '', $this->Page->Template->TemplateFile); + $this->_page = str_replace('\\', '/', $page); + } + return $this->_page; + } + + function validate_credential($sender, $param) + { + $param->IsValid = $this->password->Text == 'Prado'; + } + + protected function format_message($record) + { + $username=htmlspecialchars($record->username); + $content=nl2br(htmlspecialchars($record->content)); + return << + {$username} on {$record->date_added}. +
{$content}
+ +EOD; + } } \ No newline at end of file -- cgit v1.2.3