PATH:
home
/
letacommog
/
letaweb
/
admin
/
models
/
subsite_models
/
forms
<?php class NewsCommentForm extends CFormModel { public $id,$email,$news_id,$user_id,$name,$url,$content,$parent_id,$approved; public $module_id,$status,$viewed,$is_spam,$date_approved,$type; public function rules() { return array( array('id', 'numerical'), array('email,name', 'required','on' => 'guest_comment'), array('email', 'email','on' => 'guest_comment'), array('content', 'required'), array('module_id,status,viewed,is_spam,date_approved,type', 'safe'), array('id,email,news_id,user_id,name,url,content,parent_id,approved', 'safe'), ); } protected function preProcess() { if (!isset($this->approved)) { $this->approved=0; } $this->user_id = 0; if (!Yii::app()->user->isGuest) { $this->user_id = Yii::app()->user->id; } $this->status = 1; $this->viewed = 0; $this->type = 1; $this->is_spam = 0; } public function save($item = null) { if ($this->validate()) { $this->preProcess(); if ($this->id == 0) { $model = new BNews_Comments(); $model->setIsNewRecord(true); $model->id = $model->getMaxId() + 1; $model->user_id = $this->user_id; } else { $model = BNews_Comments::model()->findByPk($this->id); $model->setIsNewRecord(false); } $model->email = $this->email; $news = BNews::model()->findByPk($this->news_id); if(isset($news)) $model->news_id = $news->inline_id; else { $model->news_id = 0; $this->addError('news_id', Language::term('LBL_NEWS_NOT_EXISTS', 'News doesn\'t exists')); return false; } $model->user_id = $this->user_id; $model->name = $this->name; $model->url = $this->url; $model->content = $this->content; $parent = BNews_Comments::model()->findByPk($this->parent_id); if(isset($parent)) $model->parent_id = $parent->inline_id; else $model->parent_id = 0; $model->status = $this->status; $model->type = $this->type; $model->viewed = $this->viewed; $model->approved = $this->approved; if ($this->approved) { $model->date_approved = date('Y-m-d H:i:s'); } else $model->date_approved = NULL; $model->is_spam = $this->is_spam; if ($model->save()) { return $model; } else { // $errors = $newsForm->getErrors(); //print_r($model->getErrors()); return false; } } else { return false; } } public function city_required($attribute_name, $params) { if (empty($this->city) && empty($this->city_text) ) { $this->addError($attribute_name, Yii::t('user', 'At least 1 of the field must be filled up properly')); return false; } return true; } public function state_required($attribute_name, $params) { if (empty($this->state) && empty($this->state_text) ) { $this->addError($attribute_name, Yii::t('user', 'At least 1 of the field must be filled up properly')); return false; } return true; } }
[+]
..
[-] ColorForm.php
[edit]
[-] ProfileResetPassForm.php
[edit]
[-] NewsCommentForm.php
[edit]
[-] SkinForm.php
[edit]
[-] PageForm.php
[edit]
[-] BLoginForm.php
[edit]
[-] UserResetPassForm.php
[edit]
[-] ModuleForm.php
[edit]
[-] NewsForm.php
[edit]
[-] ContributorForm.php
[edit]
[-] News_CategoriesForm.php
[edit]
[-] InviteForm.php
[edit]
[-] NewsTagForm.php
[edit]
[-] DomainForm.php
[edit]