public function run($id) { $id = (int) $id; $userId = Adver::getUserIdFromAdver($id); $output = []; if ($userId != Yii::$app->getUser()->id) { $output = ['error' => true, 'message' => '<div class="alert alert-danger">' . Yii::t('app', 'The requested page does not exist.') . '</div>']; } if (empty($output) && !Gallery::checkLimitation($id)) { $output = ['error' => true, 'message' => '<div class="alert alert-danger">' . Yii::t('app', 'Image limitation per advertisement reached!') . '</div>']; } if (empty($output)) { $model = new Gallery(['scenario' => 'new']); if ($model->load(Yii::$app->request->post())) { $model->image = UploadedFile::getInstance($model, 'image'); if ($model->image) { $model->name = Yii::$app->helper->safeFile($model->image->baseName) . '-' . Yii::$app->getSecurity()->generateRandomString(6) . '-' . time() . '.' . $model->image->extension; $path = $model->getImagePath($id) . DIRECTORY_SEPARATOR . $model->name; $path = FileHelper::normalizePath($path); $model->adver_id = $id; if ($model->validate() && $model->image->saveAs($path, false)) { if ($model->save()) { $output = ['error' => false, 'message' => '<div class="alert alert-success">' . Yii::t('app', 'Image saved!') . '</div>']; } else { $output = ['error' => true, 'message' => '<div class="alert alert-danger">' . Yii::t('app', 'Error on saving image.') . '</div>']; } } } } if (empty($output)) { $output = ['error' => true, 'message' => \yii\helpers\Html::errorSummary($model, ["class" => "alert alert-danger"])]; } } return \yii\helpers\Json::encode($output); }
public function run($cat = 0) { $cat = (int) $cat; Yii::$app->response->format = \yii\web\Response::FORMAT_RAW; $headers = Yii::$app->response->headers; $headers->add('Content-Type', 'application/xml'); $content = '<?xml version="1.0" encoding="UTF-8"?>'; if ($cat <= 0) { $categories = Categories::find()->where(['status' => Categories::STATUS_ACTIVE])->select(['id'])->asArray()->all(); $content .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; foreach ($categories as $category) { $content .= '<sitemap>'; $content .= '<loc>' . Url::to(['/feed/sitemap', 'cat' => $category['id']], true) . '</loc>'; $content .= '</sitemap>'; } $content .= '</sitemapindex>'; } else { $advers = $this->controller->getModel(null, $cat); $content .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'; foreach ($advers as $adver) { $url = urldecode(Adver::generateLink($adver['id'], $adver['title'], $adver['category']['name'], $adver['country']['name'], $adver['province']['name'], $adver['city']['name'], $adver['address'], $adver['lang'], true)); $content .= '<url>'; $content .= "<loc>{$url}</loc>"; $content .= "<changefreq>daily</changefreq>"; $content .= '<priority>0.5</priority>'; $content .= '<lastmod>' . date(DATE_W3C, $adver['updated_at']) . '</lastmod>'; foreach ($adver['gallery'] as $gallery) { $content .= '<image:image><image:loc>' . Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 0, 0, 70, true) . '</image:loc></image:image>'; } $content .= '</url>'; } $content .= '</urlset>'; } return $content; }
public static function deleteDependentFiles($adverId, $fileName) { $galleryPath = Gallery::getImagePath($adverId) . DIRECTORY_SEPARATOR . $fileName; if (file_exists($galleryPath)) { @unlink($galleryPath); } }
public function run($ids) { $cacheKey = __NAMESPACE__ . __CLASS__ . 'infowindow' . $ids; $ids = explode('-', $ids); $makeCacheParam = []; foreach ($ids as $id) { $makeCacheParam[':p' . $id] = $id; } $makeCacheParam[':status'] = Adver::STATUS_ACTIVE; $cacheWhere = implode(',', array_keys($makeCacheParam)); $cache = Yii::$app->getCache(); if (!($model = $cache->get($cacheKey))) { $model = Adver::find()->select(['id', 'category_id', 'country_id', 'province_id', 'city_id', 'city_id', 'user_id', 'title', 'address', 'lang'])->with(['gallery' => function ($query) { $query->select(['id', 'adver_id', 'name', 'title']); }, 'category' => function ($query) { $query->select(['id', 'name']); }, 'country' => function ($query) { $query->select(['id', 'name']); }, 'province' => function ($query) { $query->select(['id', 'name']); }, 'city' => function ($query) { $query->select(['id', 'name']); }])->andWhere(['id' => $ids])->andWhere(['status' => Adver::STATUS_ACTIVE])->asArray()->all(); $cache->set($cacheKey, $model, 2592000, new \yii\caching\DbDependency(['sql' => "SELECT MAX([[updated_at]]) FROM {{%adver}} WHERE [[id]] IN ({$cacheWhere})", 'params' => $makeCacheParam])); } $newModel = []; foreach ($model as $key => $value) { $address = ''; if (isset($model[$key]['country']['name']) && $model[$key]['country']['name'] != '') { $address .= $model[$key]['country']['name'] . ', '; } if (isset($model[$key]['province']['name']) && $model[$key]['province']['name'] != '') { $address .= $model[$key]['province']['name'] . ', '; } if (isset($model[$key]['city']['name']) && $model[$key]['city']['name'] != '') { $address .= $model[$key]['city']['name'] . ', '; } $address = rtrim($address, ', '); $newModel[$key]['full_address'] = Html::encode($address); $newModel[$key]['address'] = Html::encode($model[$key]['address']); $newModel[$key]['title'] = Html::encode($model[$key]['title']); $newModel[$key]['category'] = Html::encode($model[$key]['category']['name']); $newModel[$key]['url'] = Adver::generateLink($model[$key]['id'], $model[$key]['title'], $model[$key]['category']['name'], $model[$key]['country']['name'], $model[$key]['province']['name'], $model[$key]['city']['name'], $model[$key]['address'], $model[$key]['lang']); $newGallery = []; foreach ($value['gallery'] as $gallery) { $newGallery[] = ['url' => Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 160, 105), 'title' => Html::encode($gallery['title']), 'adver_id' => $gallery['adver_id']]; } $newModel[$key]['gallery'] = $newGallery; } return Json::encode($newModel); }
public function run($id) { $id = (int) $id; $output = []; if (($model = Gallery::findOne($id)) !== null) { if ($model->delete()) { $output = ['error' => false, 'message' => Yii::t('app', 'Successfully deleted!')]; } } if (empty($output)) { $output = ['error' => true, 'message' => Yii::t('app', 'The requested page does not exist.')]; } return \yii\helpers\Json::encode($output); }
public function search($params, $adverId) { $query = Gallery::find(); $query->andWhere(['adver_id' => $adverId]); if (!Yii::$app->getUser()->can('AttachmentList')) { $query->andWhere(['user_id' => Yii::$app->getUser()->id]); } $dataProvider = new ActiveDataProvider(['query' => $query]); //$dataProvider->sort->defaultOrder = ['updated_at' => SORT_DESC]; // load the seach form data and validate if (!($this->load($params) && $this->validate())) { return $dataProvider; } // adjust the query by adding the filters $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
?> <?php $this->registerMetaTag(['name' => 'og:image', 'content' => Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 0, 0, 70, true)]); ?> <a class="fancyGallery" rel="gallery<?php echo $gallery['adver_id']; ?> " href="<?php echo Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id']); ?> " title="<?php echo Html::encode($gallery['title']); ?> "> <img class="img-thumbnail img-responsive" src="<?php echo Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 160, 105); ?> " alt="<?php echo Html::encode($gallery['title']); ?> " /> </a> <?php } ?> </div> <?php } ?> <?php if (!empty($model['attachment'])) {
use yii\helpers\Html; //use yii\helpers\HtmlPurifier; //use yii\widgets\DetailView; use yii\helpers\StringHelper; use common\models\adver\Adver; use common\models\gallery\Gallery; /* @var $model common\models\adver\Adver */ ?> <div class="col-sm-6 col-md-3"> <div class="thumbnail"> <?php $imageIndex = 0; $galleryCount = count($model->gallery); foreach ($model->gallery as $key => $gallery) { $imageUrl = Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 242, 200); $imageIndex = $key + 1; $galleryStyle = ($galleryCount !== 1 ? 'cursor: pointer;' : '') . ($imageIndex !== 1 ? 'display: none;' : ''); $imageScript = $galleryCount !== 1 ? "jQuery('#adversListImage" . $gallery->adver_id . $imageIndex . "').hide();" : ''; $imageScript .= $galleryCount === $imageIndex ? "jQuery('#adversListImage" . $gallery->adver_id . "1').show();" : "jQuery('#adversListImage" . $gallery->adver_id . ($imageIndex + 1) . "').show();"; echo '<img class="img-thumbnail img-responsive" id="adversListImage' . $gallery->adver_id . $imageIndex . '" onclick="' . $imageScript . '" alt="' . $gallery->title . '" style="' . $galleryStyle . '" src="' . $imageUrl . '"/>'; } $address = ''; if (isset($model['country']['name']) && $model['country']['name'] != '') { $address .= $model['country']['name'] . ', '; } if (isset($model['province']['name']) && $model['province']['name'] != '') { $address .= $model['province']['name'] . ', '; } if (isset($model['city']['name']) && $model['city']['name'] != '') { $address .= $model['city']['name'] . ', ';
public static function deleteDependentFiles($adverId) { $galleryPath = Gallery::getImagePath($adverId); $attachmentPath = Attachment::getAttachmentPath($adverId); if (is_dir($galleryPath)) { FileHelper::removeDirectory($galleryPath); } if (is_dir($attachmentPath)) { FileHelper::removeDirectory($attachmentPath); } }