public function createInstance(CEvent $event)
 {
     $objectId = HU::get('ownerObjectId');
     $instanceId = HU::get('ownerInstanceId');
     if (!($objectId && $instanceId)) {
         throw new CHttpException(400, 'Bad request.');
     }
     $formModel = $event->sender->getFormModel();
     $ownerModel = $this->loadOwnerObjectModel($objectId, $instanceId);
     $photo = new PhotogalleryPhoto('backendInsert');
     $photo->id_photogallery_object = $ownerModel->getIdObject();
     $photo->id_photogallery_instance = $ownerModel->getIdInstance();
     $photo->save(false);
     $formModel->instanceId = $photo->id_photogallery_photo;
     $formModel->objectId = $photo->getIdObject();
     $formModel->tmpId = null;
 }
Esempio n. 2
0
 public function init()
 {
     $arrayOfId = $this->grid->dataProvider->getKeys();
     $whereConfig = array('and', 'id_photogallery_object=:id_photogallery_object', array('in', 'id_photogallery_instance', $arrayOfId));
     $data = Yii::app()->db->createCommand()->select('id_photogallery_instance AS id, count(*) AS cnt')->from(PhotogalleryPhoto::model()->tableName())->where($whereConfig)->group('id_photogallery_instance')->queryAll(true, array(':id_photogallery_object' => $this->object->id_object));
     foreach ($data as $row) {
         $this->photoCountList[$row['id']] = $row['cnt'];
     }
 }
Esempio n. 3
0
 public function run()
 {
     $model = PhotogalleryPhoto::model()->find(array('order' => 'RAND()'));
     //если фоток нет, то выходим
     if ($model == null) {
         return;
     }
     $preview = null;
     if ($model->image) {
         $preview = $model->image->getPreview($this->width, $this->height, $this->postfix, $this->cropType, $this->quality, $this->resize);
     }
     $galleryLink = $photoLink = '#';
     if (Photogallery::model()->count() > 1) {
         $galleryLink = Yii::app()->createUrl(PhotogalleryModule::ROUTE_GALLERY_LIST);
     } else {
         $galleryLink = Yii::app()->createUrl(PhotogalleryModule::ROUTE_GALLERY_VIEW, array('idGallery' => $model->id_photogallery_instance));
     }
     if ($preview !== null) {
         $photoLink = Yii::app()->createUrl(PhotogalleryModule::ROUTE_GALLERY_VIEW, array('idGallery' => $model->id_photogallery_instance));
     }
     $this->render('randomPhoto', array('photo' => $preview, 'galleryLink' => $galleryLink, 'photoLink' => $photoLink));
 }