PATH:
home
/
letacommog
/
letaweb
/
admin
/
models
/
subsite_models
/
forms
<?php class NewsForm extends CFormModel { public $id; public $unique_name; public $subject_id; public $main_category_id; public $type; public $categories,$category; public $parent_id; public $title, $summary, $content, $status,$allow_comment,$tags,$image,$date_available,$last_modified; public $source,$comment_count,$headline_title,$author_id,$last_modify_id; public $featured; public $seo_keywords; public $seo_description; public $seo_title; public $og_image; public $og_title; public function NewsForm() { $this->type = BNews::PLAIN_TEXT_TYPE; } public function rules() { return array( array('id', 'numerical'), array('title', 'required'), array('unique_name', 'required','on' => 'create'), array('unique_name', 'length', 'max' => 500), array('unique_name', 'unique','className' => 'BNews','on' => 'create'), array('status, allow_comment,featured', 'in' , 'range' => array(0,1)), array('id,summary,seo_keywords,seo_description,seo_title,og_image,og_title,subject_id,content,parent_id,type,source,tags, image,comment_count, headline_title,author_id, last_modify_id,category,categories,main_category_id', 'safe'), ); } protected function preProcess() { $this->scenario = 'update'; if (!isset($this->id) || $this->id == 0) { $this->scenario = 'create'; $this->unique_name = $this->title; $name = Functions::stripUnicode($this->unique_name); $name = str_replace(' ', '-', $name); $temp_name = trim($name); while (BNews::model()->exists('unique_name=:name', array(':name' => $temp_name))) { $temp_name = rand(1, 1000).'-'.$name; } $this->unique_name = $temp_name; } $now = date('Y-m-d H:i:s'); if (isset($this->date_available)) { $this->date_available = $this->date_available; } else { $this->date_available = $now; } $this->author_id = Yii::app()->user->id; $this->last_modify_id = Yii::app()->user->id; } public function save($item = null) { $this->preProcess(); $now = date('Y-m-d H:i:s'); if ($this->validate()) { if ($this->scenario === 'create' || !isset($this->id) || $this->id == 0) { $news = new BNews(); $news->setIsNewRecord(true); $news->id = $news->getMaxId() + 1; $news->date_added = $now; $news->unique_name = $this->unique_name; $news->author_id = $this->author_id; } else { $news = BNews::model()->findByPk($this->id); $news->setIsNewRecord(false); if ($news->author_id == 0) { $news->author_id = $this->author_id; } } $news->title = $this->title; $news->summary = $this->summary; $news->content = $this->content; $news->status = $this->status; $news->allow_comment = $this->allow_comment; $news->tags = $this->tags; $news->image = $this->image; $news->categories = $this->categories; $category = BNewsCategory::model()->findByPk($this->main_category_id); if(isset($category)) $news->main_category_id = $category->inline_id; //$news->featured = $this->featured; //$news->comment_count = $this->comment_count; $news->last_modify_id = $this->last_modify_id; $news->date_available = $this->date_available; $news->date_modified = $now; $news->seo_keywords = $this->seo_keywords; $news->seo_description = $this->seo_description; $news->seo_title = $this->seo_title; $news->og_image = $this->og_image; $news->og_title = $this->og_title; if ($news->save()) { return $news; } else { return false; } } else { return false; } } }
[+]
..
[-] 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]