/** * Displays a single Picture model. * @param integer $id * @return mixed */ public function actionPicture($id, $size = 'full') { if (($model = Picture::findOne($id)) === null) { throw new NotFoundHttpException('The requested page does not exist.'); } if (!$model) { $model = new Picture(); } $this->redirect($model->directlink($size), 301); }
/** * @inheritdoc * * FIXME hide input */ public function run() { $folderurl = \yii\helpers\Url::to($this->folderurl); // $this->options['data-url'] = \yii\helpers\Url::to($this->uploadurl); $picid = $this->model->{$this->attribute}; $picture = null; if ($picid) { $picture = Picture::find()->where(['id' => $picid])->one(); } if (!$picture) { $picture = new Picture(); } $id = $this->options['id']; $js = []; $view = $this->getView(); /* CKEditorWidgetAsset::register($view); $id = $this->options['id']; $options = $this->clientOptions !== false && !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '{}'; $js[] = "CKEDITOR.replace('$id', $options);";*/ $js[] = <<<JS \tjQuery('#{$id}-select').fileselect({ \t\ttitle:\t\t"Выбор изображения", \t\tcallback:\tfunction(id){alert(id)} \t}); \t JS; $this->registerClientScript(); $view->registerJs(implode("\n", $js)); return $this->render('picSelect', ['widget' => $this, 'picture' => $picture]); }
/** * Load picture by id * * If picture not found returned default picture * * Default picture * @param integer $id * @param array|id|null $default * @return \simplator\medialib\models\Picture */ public static function getPicture($id, $default = 'id') { $pic = Picture::find()->where(['id' => $id])->one(); if (!$pic) { $pic = Picture::find()->where(['id' => \Yii::$app->settings->get('default.' . $default, 'medialib')])->one(); } if (!$pic) { $pic = Picture::find()->where(['id' => \Yii::$app->settings->get('default.id', 'medialib')])->one(); } if (!$pic) { $pic = new Picture(); } return $pic; }
/** * Finds the Picture model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Picture the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Picture::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }