/** * 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 = FImage::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionNext() { Yii::import('application.extensions.FBGallery.GalleryConfig'); //return json data: {'images':[{'id':'41','src':'galleries/1/thumb/12345678_test.jpg'},{'id':'47','src':'galleries/1/thumb/99856_test777.jpg'}]} $imageId = $_REQUEST['imageId']; if (isset($imageId)) { $criteria = new CDbCriteria(); $criteria->condition = "state=0"; $criteria->order = "votes desc"; $models = FImage::model()->findAll($criteria); $prev = 0; $actu = $imageId; $next = 0; $thPrev = ''; $thActu = ''; $thNext = ''; $galleryConfig = self::config("gallery"); $siteUrlBase = Yii::app()->request->hostInfo . Yii::app()->baseUrl . '/'; $gUrl = $siteUrlBase . $galleryConfig['gFolder'] . '/1'; $thUrl = $gUrl . '/' . $galleryConfig['thumbsDir'] . '/'; if ($models[0]->id == $imageId) { //first $next = $models[1]->id; $res = array('images' => array(array('id' => $prev, 'src' => ''), array('id' => $imageId, 'src' => $thUrl . $models[0]->name), array('id' => $next, 'src' => $thUrl . $models[1]->name))); echo json_encode($res); Yii::app()->end(); } $last = count($models) - 1; if ($models[$last]->id == $imageId) { //last $prev = $prev = $models[$last - 1]->id; $res = array('images' => array(array('id' => $prev, 'src' => $thUrl . $models[$last - 1]->name), array('id' => $imageId, 'src' => $thUrl . $models[$last]->name), array('id' => $next, 'src' => ''))); echo json_encode($res); Yii::app()->end(); } for ($i = 0; $i < count($models); $i++) { $model = $models[$i]; if ($model->id == $imageId) { $prev = $models[$i - 1]->id; $next = $models[$i + 1]->id; break; } } $res = array('images' => array(array('id' => $prev, 'src' => $thUrl . $models[$i - 1]->name), array('id' => $imageId, 'src' => $thUrl . $models[$i]->name), array('id' => $next, 'src' => $thUrl . $models[$i + 1]->name))); echo json_encode($res); Yii::app()->end(); } $res = array('error' => 'Obrázek nebyl nalezen.'); echo json_encode($res); Yii::app()->end(); }
/** * Sets @var $this->arrFiles with existing pictures * Render according to userType */ private function renderer() { //$this->arrFiles(); //$this->render('view'); //$this->render('uploader', array('max'=>Uploader::maxLenghtUploader())); $images = FImage::model()->findAll(array('order' => 'votes DESC')); //$order = $this->imgsOrder; $rel = preg_replace('!\\-+!', '-', preg_replace("/[^a-z0-9-_.]/", "-", strtolower($this->pageTitle))); $text_field = ' text_field'; $thTitleShow = true; $deleteIcon = ''; if ($this->userType === 'admin') { $deleteIcon = '<img src="' . $this->assetUrl . 'delete16x16.png" alt="X" />'; } $thUrl = $this->gUrl . '/' . $this->galleryConfig['thumbsDir'] . '/'; $imgsUrl = $this->gUrl . '/' . $this->galleryConfig['picturesDir'] . '/'; if (Yii::app()->user->isGuest) { $text_field = ''; $thTitleShow = $this->galleryConfig['thTitleShow']; $deleteIcon = ''; } foreach ($images as $img) { $this->item = array('id' => $img->id, 'votes' => $img->votes, 'fbid' => $img->fbid, 'thTitleShow' => $thTitleShow, 'title' => $img->caption, 'text_field' => $text_field, 'deleteIcon' => $deleteIcon, 'rel' => $rel, 'urlImg' => $imgsUrl . $img->name, 'imgSrc' => $thUrl . $img->name, 'fileName' => $img->name); $this->arrItems[$img->name] = $this->render('_item', array(), true); } if ($this->userType === 'visitor') { if ($this->pageName == "gallery") { $this->render('view'); } } if ($this->userType === 'editor' || $this->userType === 'admin') { if ($this->pageName == "gallery") { $this->render('viewEditor'); } if ($this->pageName == "newfoto") { $this->render('uploader', array('max' => Uploader::maxLenghtUploader())); } //$this->renderEditor(); } if ($this->userType === 'admin') { FBAdmin::cpanel(); } }