コード例 #1
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = OmmuTags::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.'));
     }
     return $model;
 }
コード例 #2
0
 /**
  * After save attributes
  */
 protected function afterSave()
 {
     parent::afterSave();
     if ($this->isNewRecord) {
         // Add album directory
         $album_path = "public/album/" . $this->album_id;
         if (!file_exists($album_path)) {
             @mkdir($album_path, 0777, true);
             // Add file in album directory (index.php)
             $newFile = $album_path . '/index.php';
             $FileHandle = fopen($newFile, 'w');
         }
         $this->media = CUploadedFile::getInstance($this, 'media');
         if ($this->media instanceof CUploadedFile) {
             $fileName = time() . '_' . $this->album_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->media->extensionName);
             if ($this->media->saveAs($album_path . '/' . $fileName)) {
                 $images = new AlbumPhoto();
                 $images->album_id = $this->album_id;
                 $images->cover = '1';
                 $images->media = $fileName;
                 $images->save();
             }
         }
     } else {
         // Add Tags
         if ($this->keyword != '') {
             $model = OmmuTags::model()->find(array('select' => 'tag_id, body', 'condition' => 'publish = 1 AND body = :body', 'params' => array(':body' => $this->keyword)));
             $tag = new AlbumTag();
             $tag->album_id = $this->album_id;
             if ($model != null) {
                 $tag->tag_id = $model->tag_id;
             } else {
                 $data = new OmmuTags();
                 $data->body = $this->keyword;
                 if ($data->save()) {
                     $tag->tag_id = $data->tag_id;
                 }
             }
             $tag->save();
         }
     }
     if (AlbumSetting::getInfo('headline') == 1) {
         if ($this->headline == 1) {
             self::model()->updateAll(array('headline' => 0), array('condition' => 'album_id != :id AND cat_id = :cat', 'params' => array(':id' => $this->album_id, ':cat' => $this->cat_id)));
         }
     }
 }
コード例 #3
0
 /**
  * before save attributes
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             if ($this->tag_id == 0) {
                 $tag = OmmuTags::model()->find(array('select' => 'tag_id, body', 'condition' => 'publish = 1 AND body = :body', 'params' => array(':body' => $this->body)));
                 if ($tag != null) {
                     $this->tag_id = $tag->tag_id;
                 } else {
                     $data = new OmmuTags();
                     $data->body = $this->body;
                     if ($data->save()) {
                         $this->tag_id = $data->tag_id;
                     }
                 }
             }
         }
         $this->creation_id = Yii::app()->user->id;
     }
     return true;
 }
コード例 #4
0
 /**
  * After save attributes
  */
 protected function afterSave()
 {
     parent::afterSave();
     $article_path = "public/article/" . $this->article_id;
     if ($this->isNewRecord && in_array($this->article_type, array(1, 3))) {
         // Add article directory
         if (!file_exists($article_path)) {
             @mkdir($article_path, 0777, true);
             // Add file in article directory (index.php)
             $newFile = $article_path . '/index.php';
             $FileHandle = fopen($newFile, 'w');
         }
     }
     if ($this->article_type == 1) {
         if ($this->isNewRecord || !$this->isNewRecord && ArticleSetting::getInfo('media_limit') == 1) {
             $this->media = CUploadedFile::getInstance($this, 'media');
             if ($this->media instanceof CUploadedFile) {
                 $fileName = time() . '_' . $this->article_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->media->extensionName);
                 if ($this->media->saveAs($article_path . '/' . $fileName)) {
                     if ($this->isNewRecord || !$this->isNewRecord && $this->media_id == 0) {
                         $images = new ArticleMedia();
                         $images->article_id = $this->article_id;
                         $images->cover = 1;
                         $images->media = $fileName;
                         $images->save();
                     } else {
                         if ($this->old_media != '' && file_exists($article_path . '/' . $this->old_media)) {
                             rename($article_path . '/' . $this->old_media, 'public/article/verwijderen/' . $this->article_id . '_' . $this->old_media);
                         }
                         $images = ArticleMedia::model()->findByPk($this->media_id);
                         $images->media = $fileName;
                         $images->update();
                     }
                 }
             }
         }
     } else {
         if ($this->article_type == 2) {
             if ($this->isNewRecord) {
                 $video = new ArticleMedia();
                 $video->article_id = $this->article_id;
                 $video->cover = 1;
                 $video->media = $this->video;
                 $video->save();
             } else {
                 if ($this->media_id == 0) {
                     $video = new ArticleMedia();
                     $video->article_id = $this->article_id;
                     $video->cover = 1;
                     $video->media = $this->video;
                     if ($video->save()) {
                         $data = Articles::model()->findByPk($this->article_id);
                         $data->media_id = $video->media_id;
                         $data->update();
                     }
                 } else {
                     $video = ArticleMedia::model()->findByPk($this->media_id);
                     $video->media = $this->video;
                     $video->update();
                 }
             }
         }
     }
     $this->file = CUploadedFile::getInstance($this, 'file');
     if ($this->file instanceof CUploadedFile) {
         $fileName = time() . '_' . $this->article_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->file->extensionName);
         if ($this->file->saveAs($article_path . '/' . $fileName)) {
             if (!$this->isNewRecord && $this->media_file != '' && file_exists($article_path . '/' . $this->old_file)) {
                 rename($article_path . '/' . $this->old_file, 'public/article/verwijderen/' . $this->article_id . '_' . $this->old_file);
             }
             $article = Articles::model()->findByPk($this->article_id);
             $article->media_file = $fileName;
             $article->update();
         }
     }
     // Add Keyword
     if (!$this->isNewRecord) {
         if ($this->keyword != '') {
             $model = OmmuTags::model()->find(array('select' => 'tag_id, body', 'condition' => 'publish = 1 AND body = :body', 'params' => array(':body' => $this->keyword)));
             $tag = new ArticleTag();
             $tag->article_id = $this->article_id;
             if ($model != null) {
                 $tag->tag_id = $model->tag_id;
             } else {
                 $data = new OmmuTags();
                 $data->body = $this->keyword;
                 if ($data->save()) {
                     $tag->tag_id = $data->tag_id;
                 }
             }
             $tag->save();
         }
     }
     // Reset headline
     if (ArticleSetting::getInfo('headline') == 1) {
         if ($this->headline == 1) {
             self::model()->updateAll(array('headline' => 0), array('condition' => 'article_id != :id AND cat_id = :cat', 'params' => array(':id' => $this->article_id, ':cat' => $this->cat_id)));
         }
     } else {
     }
 }