예제 #1
0
 public function run()
 {
     $model = new Adver();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'Advertisement successfully saved.'));
             return $this->controller->redirect(['/adver/adver-list']);
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Error on saving advertisement.'));
         }
     }
     return $this->controller->render('@common/views/adver/manage', ['adverModel' => $model]);
 }
예제 #2
0
파일: View.php 프로젝트: rocketyang/admap
 public function run($id, $title)
 {
     $id = (int) $id;
     $cacheKey = __NAMESPACE__ . __CLASS__ . 'adver.view' . $id;
     $cache = Yii::$app->getCache();
     if (!($model = $cache->get($cacheKey))) {
         $model = Adver::find()->with(['attachment' => function ($query) {
             $query->select(['id', 'adver_id', 'name', 'title']);
         }, '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']);
         }])->where(['id' => $id, 'status' => Adver::STATUS_ACTIVE, 'lang' => ['*', Yii::$app->language]])->asArray()->one();
         if (!$model) {
             throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
         }
         $model['description'] = HtmlPurifier::process($model['description']);
         $cache->set($cacheKey, $model, 2592000, new \yii\caching\DbDependency(['sql' => "SELECT [[updated_at]] FROM {{%adver}} WHERE [[id]] = :id AND [[status]] = :status", 'params' => [':id' => $id, ':status' => Adver::STATUS_ACTIVE]]));
     }
     return $this->controller->render('view', ['model' => $model]);
 }
예제 #3
0
 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;
 }
예제 #4
0
 public function search($params)
 {
     $query = Adver::find();
     $query->joinWith(['category' => function ($query) {
         $query->from(['c' => 'categories']);
     }, 'country' => function ($query) {
         $query->from(['co' => 'country']);
     }, 'province' => function ($query) {
         $query->from(['p' => 'province']);
     }, 'city' => function ($query) {
         $query->from(['ci' => 'city']);
     }]);
     $query->from(['a' => $this->tableName()]);
     $query->andWhere(['a.user_id' => Yii::$app->getUser()->id]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['category.name'] = ['asc' => ['c.name' => SORT_ASC], 'desc' => ['c.name' => SORT_DESC]];
     $dataProvider->sort->attributes['country.name'] = ['asc' => ['co.name' => SORT_ASC], 'desc' => ['co.name' => SORT_DESC]];
     $dataProvider->sort->attributes['province.name'] = ['asc' => ['p.name' => SORT_ASC], 'desc' => ['p.name' => SORT_DESC]];
     $dataProvider->sort->attributes['city.name'] = ['asc' => ['ci.name' => SORT_ASC], 'desc' => ['ci.name' => SORT_DESC]];
     $dataProvider->sort->defaultOrder = ['status' => SORT_ASC, 'id' => 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(['a.id' => $this->id]);
     $query->andFilterWhere(['like', 'a.title', $this->title])->andFilterWhere(['a.status' => $this->status])->andFilterWhere(['like', 'a.lang', $this->lang]);
     $query->andFilterWhere(['LIKE', 'c.name', $this->getAttribute('category.name')]);
     $query->andFilterWhere(['LIKE', 'co.name', $this->getAttribute('country.name')]);
     $query->andFilterWhere(['LIKE', 'p.name', $this->getAttribute('province.name')]);
     $query->andFilterWhere(['LIKE', 'ci.name', $this->getAttribute('city.name')]);
     return $dataProvider;
 }
예제 #5
0
 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);
 }
예제 #6
0
 public function findModel($id)
 {
     if (($model = Adver::findOne($id)) !== null) {
         return $model;
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
예제 #7
0
 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);
 }
예제 #8
0
파일: Delete.php 프로젝트: rocketyang/admap
 public function run($id)
 {
     $id = (int) $id;
     $output = [];
     if (($model = Adver::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);
 }
예제 #9
0
 public function getModel($limit = null, $cat = 0)
 {
     $advers = Adver::find()->with(['gallery' => function ($query) {
         $query->select(['id', 'adver_id', 'name']);
     }, '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']);
     }])->where(['status' => Adver::STATUS_ACTIVE, 'lang' => ['*', Yii::$app->language]])->orderBy(['id' => SORT_DESC])->limit($limit);
     if ($cat > 0) {
         $advers->andWhere(['category_id' => $cat]);
     }
     return $advers->asArray()->all();
 }
예제 #10
0
 public function run($id)
 {
     $id = (int) $id;
     $output = [];
     if (($model = Adver::findOne($id)) !== null) {
         if ($model->status == Adver::STATUS_ACTIVE) {
             $model->status = Adver::STATUS_DISABLE;
         } else {
             $model->status = Adver::STATUS_ACTIVE;
         }
         if ($model->save()) {
             $output = ['error' => false, 'message' => Yii::t('app', 'Successfully status changed!')];
         }
     }
     if (empty($output)) {
         $output = ['error' => true, 'message' => Yii::t('app', 'The requested page does not exist.')];
     }
     return \yii\helpers\Json::encode($output);
 }
예제 #11
0
파일: Search.php 프로젝트: rocketyang/admap
 public function search($params)
 {
     $query = Adver::find()->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']);
     }])->where(['status' => Adver::STATUS_ACTIVE, 'lang' => ['*', Yii::$app->language]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => array('pageSize' => 10)]);
     /*$dataProvider->setSort([
     			'attributes' => [
     				'id' => [
     					'asc' => ['id' => SORT_ASC],
     					'desc' => ['id' => SORT_DESC],
     					'label' => Yii::t('app', 'ID'),
     					//'default' => SORT_ASC
     				],
     			]
     		]);*/
     // load the seach form data and validate
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['category_id' => $this->category_id]);
     $query->andFilterWhere(['country_id' => $this->country_id]);
     $query->andFilterWhere(['province_id' => $this->province_id]);
     $query->andFilterWhere(['city_id' => $this->city_id]);
     $query->andFilterWhere(['title' => $this->title]);
     $query->andFilterWhere(['address' => $this->address]);
     return $dataProvider;
 }
예제 #12
0
$this->title = Yii::t('app', 'My advertisement');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
    <div class="col-md-12">
        <div class="table table-responsive">
		<div id="adver-message-container"></div>
		<?php 
echo Alert::widget();
?>
        <?php 
Pjax::begin(['id' => 'adverList-pjax', 'enablePushState' => true, 'timeout' => '20000']);
?>
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'title', 'format' => 'raw', 'value' => function ($data) {
    return Html::a(Html::encode($data->title), Adver::generateLink($data['id'], $data['title'], $data['category']['name'], $data['country']['name'], $data['province']['name'], $data['city']['name'], $data['address'], $data['lang']), ['data-pjax' => '0', 'target' => '_blank']);
}], 'category.name', 'country.name', 'province.name', 'city.name', 'lang', ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'created_at', 'value' => function ($data) {
    return Yii::$app->dateTimeAction->timeToDate('l j F Y H:i', $data->created_at);
}], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'updated_at', 'value' => function ($data) {
    return Yii::$app->dateTimeAction->timeToDate('l j F Y H:i', $data->updated_at);
}], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'status', 'filter' => $searchModel->getStatusList(), 'format' => 'html', 'value' => function ($data) {
    return $data->getStatusImage($data->status);
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}', 'buttons' => ['update' => function ($url, $model, $key) {
    return Yii::$app->helper->createUpdateButton($url);
}]], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
    return Yii::$app->helper->createDeleteButton(Url::to(['/adver/delete', 'id' => $model->id]), '', 'adverList-pjax', 'adver-message-container');
}]]]]);
?>
        <?php 
Pjax::end();
?>
예제 #13
0
파일: User.php 프로젝트: rocketyang/admap
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdvers()
 {
     return $this->hasMany(Adver::className(), ['user_id' => 'id']);
 }
예제 #14
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdver()
 {
     return $this->hasOne(Adver::className(), ['id' => 'adver_id']);
 }
예제 #15
0
파일: _index.php 프로젝트: rocketyang/admap
		<?php 
}
?>
		<div class="caption">
			<h3><?php 
echo Html::encode($model->title);
?>
</h3>
			<p><?php 
echo StringHelper::truncateWords($model->description, 40, '...', false);
?>
</p>
			<p><span class="label label-success"><?php 
echo Html::encode($model['category']['name']);
?>
</span>
			<span class="label label-success"><?php 
echo Html::encode($address);
?>
</span></p>
			<p><a target="_blank" data-pjax="0" class="btn btn-info" href="<?php 
echo Adver::generateLink($model['id'], $model['title'], $model['category']['name'], $model['country']['name'], $model['province']['name'], $model['city']['name'], $model['address'], $model['lang']);
?>
"><?php 
echo Yii::t('app', 'Detail');
?>
</a></p>
		</div>
	</div>
</div>
예제 #16
0
 public function actionIndex()
 {
     return new ActiveDataProvider(['query' => Adver::find()]);
 }