/** * @param Event $event * @param CUploadedFile $image */ public function __construct(Event $event, CUploadedFile $image) { $name = EventsUploadedImage::createName($event, $image); $fullPath = EventsUploadedImage::getSavePath() . '/' . $name; $image->saveAs($fullPath); @chmod($fullPath, 0666); // Check if event has main image $is_main = (int) EventImage::model()->countByAttributes(array('event_id' => $event->id)); $imageModel = new EventImage(); $imageModel->event_id = $event->id; $imageModel->image = $name; $imageModel->save(); $this->resize($fullPath); $this->watermark($fullPath); }
/** * @param Event $model */ public function handleUploadedVideos(Event $model) { $videos = isset($_POST['video']) ? $_POST['video'] : false; if ($videos) { foreach ($model->video as $v) { if (!array_key_exists($v->id, $videos)) { $v->delete(); } } foreach ($videos as $key => $video) { $NewVideo = EventVideo::model()->findByPk($key); if (!$NewVideo) { $NewVideo = new EventVideo(); } if ($video['video']) { $NewVideo->video = $video['video']; $NewVideo->event_id = $model->id; $NewVideo->save(); } $image = CUploadedFile::getInstanceByName('videoImage[' . $key . ']'); if (!$image) { continue; } if (!EventsUploadedImage::hasErrors($image)) { $NewVideo->addImage($image); $NewVideo->save(); } else { $this->setFlashMessage(Yii::t('EventsModule.admin', 'Ошибка загрузки изображения {name}', array('{name}' => $image->getName()))); } } } }