예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionAjaxAdd($id)
 {
     $albumPhoto = CUploadedFile::getInstanceByName('namaFile');
     $album_path = "public/album/" . $id;
     $fileName = time() . '_' . $id . '_' . Utility::getUrlTitle(Albums::getInfo($id, 'title')) . '.' . strtolower($albumPhoto->extensionName);
     if ($albumPhoto->saveAs($album_path . '/' . $fileName)) {
         $model = new AlbumPhoto();
         $model->album_id = $id;
         $model->media = $fileName;
         if ($model->save()) {
             $url = Yii::app()->controller->createUrl('ajaxmanage', array('id' => $model->album_id));
             echo CJSON::encode(array('id' => 'media-render', 'get' => $url));
         }
     }
 }
예제 #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)));
         }
     }
 }