128), array('email','email'), array('url','url'), ); } /** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'post' => array(self::BELONGS_TO, 'Post', 'post_id'), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'Id', 'content' => 'Comment', 'status' => 'Status', 'create_time' => 'Create Time', 'author' => 'Name', 'email' => 'Email', 'url' => 'Website', 'post_id' => 'Post', ); } /** * Approves a comment. */ public function approve() { $this->status=Comment::STATUS_APPROVED; $this->update(array('status')); } /** * @param Post the post that this comment belongs to. If null, the method * will query for the post. * @return string the permalink URL for this comment */ public function getUrl($post=null) { if($post===null) $post=$this->post; return $post->url.'#c'.$this->id; } /** * @return string the hyperlink display for the current comment's author */ public function getAuthorLink() { if(!empty($this->url)) return CHtml::link(CHtml::encode($this->author),$this->url); else return CHtml::encode($this->author); } /** * @return integer the number of comments that are pending approval */ public function getPendingCommentCount() { return $this->count('status='.self::STATUS_PENDING); } /** * @param integer the maximum number of comments that should be returned * @return array the most recently added comments */ public function findRecentComments($limit=10) { return $this->with('post')->findAll(array( 'condition'=>'t.status='.self::STATUS_APPROVED, 'order'=>'t.create_time DESC', 'limit'=>$limit, )); } /** * This is invoked before the record is saved. * @return boolean whether the record should be saved. */ protected function beforeSave() { if(parent::beforeSave()) { if($this->isNewRecord) $this->create_time=time(); return true; } else return false; } }