예제 #1
0
 public function afterFind()
 {
     parent::afterFind();
     if (CMS::time() >= strtotime($this->date_end)) {
         $this->switch = 0;
         $this->save(false);
     }
 }
예제 #2
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         //create
         if ($this->isNewRecord) {
             if (isset($this->tableSchema->columns['ip_create'])) {
                 //Текущий IP адресс, автора добавление
                 $this->ip_create = Yii::app()->request->userHostAddress;
             }
             if (isset($this->tableSchema->columns['user_id'])) {
                 $this->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id;
             }
             if (isset($this->tableSchema->columns['user_agent'])) {
                 $this->user_agent = Yii::app()->request->userAgent;
             }
             if (isset($this->tableSchema->columns['date_create'])) {
                 // $this->date_create = date('Y-m-d H:i:s');
                 $this->date_create = date('Y-m-d H:i:s', CMS::time());
             }
             if (isset($this->tableSchema->columns['ordern'])) {
                 if (!isset($this->ordern)) {
                     $row = $this->model()->find(array('select' => 'max(ordern) AS maxOrdern'));
                     $this->ordern = $row['maxOrdern'] + 1;
                 }
             }
         } else {
             //update
             if (isset($this->tableSchema->columns['date_update'])) {
                 $this->date_update = date('Y-m-d H:i:s');
             }
         }
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * Определяет таймаут управление комментарием
  * @return bool
  */
 public function controlTimeout()
 {
     $stime = strtotime($this->date_create) + Yii::app()->settings->get('comments', 'control_timeout');
     return CMS::time() < $stime || Yii::app()->user->isSuperuser ? true : false;
 }
예제 #4
0
 public function actionCreate()
 {
     $owner_title = $_POST['owner_title'];
     $modelName = $_POST['model'];
     $objID = $_POST['object_id'];
     $comment = new Comments();
     $request = Yii::app()->request;
     if ($request->isPostRequest && $request->isAjaxRequest) {
         $comment->attributes = $request->getPost('Comments');
         $comment->model = $modelName;
         $comment->owner_title = $owner_title;
         $comment->object_id = $objID;
         if ($comment->validate()) {
             $comment->saveNode();
             echo CJSON::encode(array('success' => true, 'message' => 'Комментарий будет опубликован после проверки'));
             Yii::app()->end();
             Yii::app()->session['caf'] = CMS::time();
         }
     }
     return $comment;
 }