示例#1
0
文件: Add.php 项目: rocketyang/admap
 public function run()
 {
     $model = new Categories();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'New category successfully saved.'));
             $model = new Categories();
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Error on saving category.'));
         }
     }
     return Yii::$app->request->isAjax ? $this->controller->renderAjax('manage', ['model' => $model]) : $this->controller->render('manage', ['model' => $model]);
 }
示例#2
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;
 }
示例#3
0
 public function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
示例#4
0
 public function run($id)
 {
     $id = (int) $id;
     $output = [];
     if (($model = \common\models\categories\Categories::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);
 }
示例#5
0
 public function run($search = null, $id = null)
 {
     $out = ['more' => false];
     if (!is_null($search)) {
         $query = new Query();
         $query->select('[[id]], [[name]] AS [[text]]')->from('{{%categories}}')->filterWhere(['like', '[[name]]', $search])->andWhere(['[[status]]' => Categories::STATUS_ACTIVE])->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $cat = Categories::findOne(['id' => $id, 'status' => Categories::STATUS_ACTIVE]);
         $out['results'] = ['id' => $id, 'text' => $cat->name];
     } else {
         $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')];
     }
     return Json::encode($out);
 }
示例#6
0
 public function run($id)
 {
     $id = (int) $id;
     $output = [];
     if (($model = Categories::findOne($id)) !== null) {
         if ($model->status == Categories::STATUS_ACTIVE) {
             $model->status = Categories::STATUS_DISABLE;
         } else {
             $model->status = Categories::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);
 }
示例#7
0
 public function search($params)
 {
     $query = Categories::find();
     // join with relation `author` that is a relation to the table `users`
     // and set the table alias to be `author`
     $query->joinWith(['user' => function ($query) {
         $query->from(['u' => 'user']);
     }]);
     $query->from(['c' => $this->tableName()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['user.username'] = ['asc' => ['u.username' => SORT_ASC], 'desc' => ['u.username' => SORT_DESC]];
     //$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(['c.id' => $this->id]);
     $query->andFilterWhere(['like', 'c.name', $this->name])->andFilterWhere(['c.status' => $this->status]);
     $query->andFilterWhere(['LIKE', 'u.username', $this->getAttribute('user.username')]);
     return $dataProvider;
 }
示例#8
0
文件: User.php 项目: rocketyang/admap
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategories()
 {
     return $this->hasMany(Categories::className(), ['user_id' => 'id']);
 }
示例#9
0
</h3>
                </div>
                <div class="panel-body">
                    <?php 
$form = ActiveForm::begin(['id' => $model->formName(), 'enableClientValidation' => true]);
?>
                    <?php 
echo Html::activeHiddenInput($model, 'id');
?>
                    <?php 
echo $form->field($model, 'name')->textInput();
?>

                    <?php 
if (Yii::$app->getUser()->can('CategoryDisable')) {
    echo $form->field($model, 'status')->dropDownList(Categories::getStatusList());
}
?>
                    <?php 
if (!$model->isNewRecord) {
    echo $form->field($model, 'user_id')->widget(Select2::classname(), ['language' => Yii::$app->helper->getTwoCharLanguage(), 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 2, 'ajax' => ['url' => $userListUrl, 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {search:params.term}; }'), 'results' => new JsExpression('function(data,page) { return {results:data.results}; }')], 'initSelection' => new JsExpression($initScript)]]);
}
?>
                    <div class="form-group">
                        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Add') : Yii::t('app', 'Update'), ['class' => 'btn btn-primary btn-block']);
?>
                    </div>
<?php 
ActiveForm::end();
?>
示例#10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Categories::className(), ['id' => 'category_id']);
 }