|
@@ -0,0 +1,39 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace v1\controllers;
|
|
|
+
|
|
|
+use common\data\Respuesta;
|
|
|
+use common\rest\JsonController;
|
|
|
+use yii\db\Expression;
|
|
|
+use yii\web\NotFoundHttpException;
|
|
|
+
|
|
|
+class BannerPublicoController extends JsonController {
|
|
|
+
|
|
|
+ public $modelClass = "v1\models\Banner";
|
|
|
+
|
|
|
+ public function actionIndex() {
|
|
|
+ $id = trim($this->req->get("id", ""));
|
|
|
+
|
|
|
+ $query = $this->queryInicial;
|
|
|
+
|
|
|
+ if($id !== "") {
|
|
|
+ $query->andWhere(["id" => $id]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $modelo = $query->one();
|
|
|
+ if($modelo === null) {
|
|
|
+ throw new NotFoundHttpException('No se encontró el registro');
|
|
|
+ }
|
|
|
+ $media = $modelo->media;
|
|
|
+ /** @var \v1\models\Media $media */
|
|
|
+ if($media === null) {
|
|
|
+ throw new NotFoundHttpException('No se encontró la imagen');
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$media->ruta) {
|
|
|
+ throw new NotFoundHttpException('No se encontró la imagen');
|
|
|
+ }
|
|
|
+ return $this->redirect($media->ruta);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|