public function actionEdit($id) { $categoryModel = Category::findOne(['id' => $id]); if ($categoryModel->load(Yii::$app->request->post()) && $categoryModel->save()) { } return $this->render('edit', ['model' => $categoryModel]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $this->scenario = ''; $query = Product::find()->where(['active' => 1]); $this->scenario = 'default'; $this->load($params, ''); $order_arr = !empty($this->order_by) ? explode(':', $this->order_by) : ['id', 'desc']; $orderField = count($order_arr) > 0 ? $order_arr[0] : 'id'; $orderSort = count($order_arr) > 1 && $order_arr[1] == 'desc' ? SORT_DESC : SORT_ASC; $this->order_by = $orderField . ':' . ($orderSort == SORT_DESC ? 'desc' : 'asc'); /** @var Category $category */ if (isset($params['code']) && !empty($params['code'])) { $this->_category = Category::find()->where(['url_code' => $params['code']])->one(); } if (is_null($this->_category) && isset($params['id']) && !empty($params['id'])) { $this->_category = Category::findOne($params['id']); } if (!is_null($this->_category)) { $arr_cats = $this->_category->fillSubCategoryArray(); $query->andFilterWhere(['in', 'category_id', $arr_cats]); } $per_page = isset($params['per-page']) ? $params['per-page'] : 12; $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $per_page], 'sort' => ['defaultOrder' => ['new' => SORT_DESC], 'attributes' => ['new' => ['desc' => ['id' => SORT_DESC], 'asc' => false, 'default' => SORT_DESC, 'label' => Yii::t('app', 'Newest Arrivals')], 'featured' => ['asc' => false, 'desc' => ['featured' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Featured')], 'price_asc' => ['desc' => false, 'asc' => ['price_custom' => SORT_ASC], 'default' => SORT_ASC, 'label' => Yii::t('app', 'Price: Low to High')], 'price_desc' => ['asc' => false, 'desc' => ['price_custom' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Price: High to Low')]]]]); return $dataProvider; }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $alias * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelByAlias($alias) { if (($model = Category::findOne(['alias' => $alias])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Возвращает модель категории. * @param int $id идентификатор категории * @throws NotFoundHttpException в случае, когда категория не найдена * @return Category */ public function getCategory($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested post does not exist.'); } }
/** * @param string $id * @return Category|bool * @throws NotFoundHttpException */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { return false; } }
protected function findModel($id) { if (($model = Category::findOne($id)) !== null && $model->user_id == Yii::$app->user->id) { return $model; } else { throw new NotFoundHttpException('The page you requested is not available or does not exist.'); } }
/** * Finds the Users model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Users the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getParentName() { if ($this->parent != 0) { $data = Category::findOne($this->parent); return Html::a($data->name, ['view', 'id' => $data->id]); } else { return "Главная категория"; } }
/** * @param $node * @return string * @throws NotFoundHttpException */ public function actionList($node) { $category = Category::findOne($node); if (!$category) { throw new NotFoundHttpException(); } $model = new ProductSearch(); $dataProvider = $model->search(\Yii::$app->request->queryParams); return $this->render('list', ['dataProvider' => $dataProvider, 'searchModel' => $model, 'category' => $category]); }
public function actionCategory($categories = null) { if ($categories) { $category = Category::findOne(['categories' => $categories]); if ($category) { return $this->render('category', ['model' => $category]); } } else { $this->goHome(); } }
static function loadCategory() { $categories = \app\models\Category::find()->asArray()->all(); for ($i = 0; $i <= count($categories) - 1; $i++) { if ($categories[$i]['parent'] != 0) { $categories[$i]['name'] = $categories[$i]['name'] . "(" . \app\models\Category::findOne(['id' => $categories[$i]['parent']])->name . ")"; } } $categories = ArrayHelper::map($categories, 'id', 'name'); return $categories; }
public function actionFixCategory() { $catGoogle = \app\models\CategoryGoogle::find()->all(); foreach ($catGoogle as $cat) { if (isset($cat->parent_id)) { $mCat = \app\models\Category::findOne($cat->parent_id); $mGoogleCat = \app\models\CategoryGoogle::findOne(['nombre' => $mCat->nombre_categoria]); $cat->parent_id = $mGoogleCat->id; $cat->save(); } } }
public function init() { parent::init(); $category = Category::findOne(83); $descendants = $category->children()->all(); $menuItems = []; foreach ($descendants as $key => $value) { $menuItems[] = ['label' => $value->name, 'url' => ['post/index', 'id' => $value->id]]; } $menuItems[] = ['label' => '未分类', 'url' => ['post/index', 'id' => 0]]; echo '<h4 class="text-right">分类</h4>'; echo Menu::widget(['options' => ['class' => 'side-menu list-unstyled'], 'items' => $menuItems, 'encodeLabels' => false]); }
public function actionIndex() { $queryParams = Yii::$app->request->getQueryParams(); $query = Post::find()->where(['status' => 1]); $category = ""; if (isset($queryParams['id'])) { $category = Category::findOne($queryParams['id']); $query = $query->andWhere(['category_id' => $queryParams['id']]); } if (isset($queryParams['tag'])) { $query = $query->andWhere(['like', 'tags', $queryParams['tag']]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]); return $this->render('index', ['dataProvider' => $dataProvider, 'category' => $category]); }
public function actionCategory($id) { $cur_category = Category::findOne($id); if ($cur_category === null) { throw new NotFoundHttpException(); } elseif ($cur_category->status === Category::STATUS_INACTIVE) { return $this->redirect(['index']); } $categories = Category::find()->where(['status' => Category::STATUS_ACTIVE])->orderBy('caption')->all(); $query = $cur_category->getNews()->where(['status' => News::STATUS_ACTIVE])->orderBy('date DESC'); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => NewsController::DEFAULT_PAGE_SIZE]); $news = $query->offset($pagination->offset)->orderBy('date')->limit($pagination->limit)->all(); return $this->render('index', ['categories' => $categories, 'news' => $news, 'pagination' => $pagination, 'cur_category' => $cur_category]); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if (!$insert) { // Delete all categories from Post on update $this->unlinkAll('categories', true); } if (!empty($this->assignedCategories)) { // Add selected categories to Post foreach ($this->assignedCategories as $category) { /** @var $model \yii\db\ActiveRecord */ $model = Category::findOne($category); $this->link('categories', $model); } } parent::afterSave($insert, $changedAttributes); }
public function createCategory($cat) { $category = Category::findOne(['name' => $cat]); if ($category == null) { $cat_row = new Category(); $cat_row->name = $cat; if ($cat_row->save()) { //echo \yii\helpers\Json::encode($cat_row); $cat = $cat_row->id; } else { echo 'failed to create row'; //echo $logo->errors(); } } else { $cat = $category->id; } return $cat; }
private function ImportCategory($array) { foreach ($array as $category) { // Skip inactive categories if (!$category['active']) { continue; } $model = Category::findOne($category['id']); $save = false; // Checking is this ID free for use if ($model !== null) { // Asking user what he wants $question = 'Category with the same id alredy exists in data base:' . PHP_EOL . 'Data from database:' . PHP_EOL . $this->CategoryObjToString($model) . 'New data from file:' . PHP_EOL . $this->CategoryArrToString($category); $this->stdout($question); $answer = $this->select('What you want to do?' . PHP_EOL . '(a - assign new id and save data, s - keep database data, d - keep id and save data)' . PHP_EOL, ['a' => 'assign new id and save data', 's' => 'keep database data', 'd' => 'keep id and save data']); switch ($answer) { case 'a': $model = new Category(); case 'd': $save = true; break; case 's': break; } } else { $model = new Category(); $model->id = $category['id']; $save = true; } // Saving data if it is needed if ($save) { $model->caption = $category['name']; $model->status = $category['active'] ? Category::STATUS_ACTIVE : Category::STATUS_INACTIVE; if ($model->save()) { $this->stdout('Category: ' . PHP_EOL . $this->CategoryObjToString($model) . ' saved sucesfully' . PHP_EOL); } } $this->ImportNews($category['news'], $model); if (isset($category['subcategories'])) { $this->ImportCategory($category['subcategories']); } } }
echo Html::encode($this->title); ?> </h4> <div class="toolbar"> <p> <?php echo Html::a('Tạo kỹ năng', ['create'], ['class' => 'btn btn-success']); ?> </p> </div> </header> <div class="body"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', ['attribute' => 'title', 'content' => function ($data) { return Html::a($data->title, ['view', 'id' => $data->id]); }], ['attribute' => 'cat_id', 'content' => function ($data) { $categoryName = Category::findOne($data->cat_id)->title; return $categoryName ? $categoryName : '<span style="color:red">Không tìm danh mục</span>'; }], ['attribute' => 'Số câu quiz', 'content' => function ($data) { $quizs = Quiz::findAll(['skill_id' => $data->id]); return '<a href="' . Url::toRoute(['quiz/index', 'skill_id' => $data->id]) . '">' . count($quizs) . '</a>'; }, 'format' => 'raw'], ['attribute' => 'state', 'content' => function ($data) { return Skill::findOne($data['id'])->state == 1 ? '<span class="label-success label label-default">Kích hoạt</span>' : '<span class="label-default label">Không kích hoạt</span>'; }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'header' => 'Thao tác', 'buttons' => ['delete' => function ($url, $model) { return '<a class="btn btn-danger" aria-label="Delete" data-confirm="Bạn có chắc muốn xóa danh mục này?" data-method="post" data-pjax="0" href="' . $url . '"><i class="icon icon-trash icon-white"></i></a>'; }]]]]); ?> </div> </div> </div>
public function getCategoryTitle() { return Category::findOne(['id' => $this->category_id])->title; }
public static function countInc($cid, $point = 1) { $category = Category::findOne(['cid' => $cid, 'uid' => \Yii::$app->user->getId()]); $category->count = $category->count + 1; $category->save(); }
public function get_view($id) { return Category::findOne($id)->parent_id; }
<div class="row-fluid"> <div class="box"> <header> <h4><?php echo Html::encode($this->title); ?> </h4> <div class="toolbar"> <?php echo Html::a('Tạo danh mục', ['create'], ['class' => 'btn btn-success']); ?> </div> </header> <div class="body"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', ['attribute' => 'title', 'content' => function ($data) { return Html::a($data->title, ['view', 'id' => $data->id]); }], ['attribute' => 'parent_id', 'label' => 'Danh mục cha', 'content' => function ($data) { return $data['parent_id'] != NULL ? Category::findOne($data['parent_id'])->title : 'Danh mục gốc'; }], ['attribute' => 'state', 'label' => 'Trạng thái', 'content' => function ($data) { return Category::findOne($data['id'])->state == 1 ? '<span class="label-success label label-default">Kích hoạt</span>' : '<span class="label-default label">Không kích hoạt</span>'; }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'header' => 'Thao tác', 'buttons' => ['delete' => function ($url, $model) { return '<a class="btn btn-danger" aria-label="Delete" data-confirm="Bạn có chắc muốn xóa danh mục này?" data-method="post" data-pjax="0" href="' . $url . '"><i class="icon icon-trash icon-white"></i></a>'; }]]]]); ?> </div> </div> </div>
<div class="product-index"> <h1> <?php echo Html::encode($this->title); ?> <?php echo Html::a("<span class='glyphicon glyphicon-plus'>", ['create'], ['class' => 'btn btn-success', 'data-toggle' => "tooltip", 'data-placement' => "top", 'title' => "Добавить товар"]); ?> </h1> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'name', 'vAlign' => 'middle', 'width' => '210px', 'editableOptions' => function ($model, $key, $index) { return ['header' => 'названия', 'size' => 'md']; }], ['attribute' => 'sum', 'content' => function ($data) { return "{$data->sum}<span class='glyphicon glyphicon-ruble'></span>"; }], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'status', 'value' => function ($model, $key, $index, $widget) { return $model->getStatus(); }, 'editableOptions' => ['header' => 'Статус', 'format' => Editable::FORMAT_BUTTON, 'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST, 'data' => \app\models\Product::selectStatus(), 'options' => ['class' => 'form-control']]], ['attribute' => 'category_id', 'content' => function ($data) { $category = \app\models\Category::findOne(['id' => $data->category_id]); return $category == NULL ? "<div style='color:red;'>(Не задано)</div>" : Html::a($category->name, ['category/view', 'id' => $category->id]); }], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Действия', 'headerOptions' => ['width' => '80'], 'template' => '{view} | {update} | {delete}{link}']]]); ?> <?php Pjax::end(); ?> </div>
echo Html::encode($this->title); ?> </h4> <div class="toolbar"> <p> <?php echo Html::a('Cập nhật', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Xóa', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Bạn có chắc muốn xóa danh mục này?', 'method' => 'post']]); ?> </p> </div> </header> <div class="body"> <?php if ($created_by = AdminUser::findOne($model->created_by)) { $created_by = $created_by->fullname != '' ? $created_by->fullname : $created_by->username; } if ($updated_by = AdminUser::findOne($model->updated_by)) { $updated_by = $updated_by->fullname != '' ? $updated_by->fullname : $updated_by->username; } $categoryName = Category::findOne($model->cat_id)->title; ?> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'title', 'alias', ['attribute' => 'cat_id', 'value' => $categoryName ? $categoryName : '<span style="color:red">Không tìm danh mục</span>', 'format' => 'raw'], 'description:ntext', 'created_at', ['attribute' => 'created_by', 'value' => isset($created_by) ? $created_by : '<span style="color:red">Không tìm thấy người tạo</span>', 'format' => 'raw'], 'updated_at', ['attribute' => 'updated_by', 'value' => isset($updated_by) ? $updated_by : '<span style="color:red">Không tìm thấy người sửa</span>', 'format' => 'raw'], ['attribute' => 'state', 'value' => $model->state == 1 ? '<span class="label-success label label-default">Hiển thị</span>' : '<span class="label-default label">Không hiển thị</span>', 'format' => 'raw'], ['attribute' => 'image', 'value' => Html::img($model->image), 'format' => ['raw']], 'hits', 'views', 'type', 'quizid_demo']]); ?> </div> </div> </div>
/** * @param array $arr * @return Category[] */ public function getParents($arr = []) { if (!is_null($parentCat = Category::findOne($this->parent))) { array_unshift($arr, $parentCat); $arr = $parentCat->getParents($arr); } return $arr; }
<?php use yii\helpers\Html; use app\models\Category; ?> <div class="list_form_road"> <div class="list_form_road_div"> <span class="list_form_road_lock">1</span> <p>选择类目 (<?php echo Category::findOne($view)->name; ?> > <?php echo Category::findOne($id)->name; ?> <?php echo HTML::a('重选', ['info/category_list']); ?> )</p> </div> <div class="list_form_road_gt"></div> <div class="list_form_road_div"> <span class="list_form_road_lock">2</span> <p>填写信息</p> </div> <div class="list_form_road_gt"></div> <div class="list_form_road_div"> <span>3</span> <p>完成发布</p> </div> <div class="clear"></div>
/** * Updates an existing Race model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $sports = Sport::findAll(['status' => 'ACTIVE']); $categories = Category::find()->all(); $c = []; foreach ($categories as $category) { $c[$category->id] = $category->name; } $picture = UploadedFile::getInstance($model, 'picture'); $sponsor = UploadedFile::getInstance($model, 'sponsor'); $attachment1 = UploadedFile::getInstance($model, 'attachment1'); $attachment2 = UploadedFile::getInstance($model, 'attachment2'); $last_picture = $model->picture; $last_attachment1 = $model->attachment1; $last_attachment2 = $model->attachment2; if ($model->load(Yii::$app->request->post())) { if ($_POST['pictureChanged'] == 'true') { // unlink('images/'.$last_picture); if ($picture != NULL) { $name = date('Y_m_d_H_i_s_') . $picture->baseName . '.' . $picture->extension; $model->picture = $name; } } else { $model->picture = $last_picture; } if ($_POST['sponsorChanged'] == 'true') { if ($sponsor != NULL) { if ($picture != NULL) { $model->sponsor = $name; } else { $model->sponsor = $last_picture; } } } else { $model->sponsor = $last_picture; } if ($_POST['attachment1Changed'] == 'true') { if ($attachment1 != NULL) { $name1 = date('Y_m_d_H_i_s_') . $attachment1->baseName . '.' . $attachment1->extension; $model->attachment1 = $name1; } } else { $model->attachment1 = $last_attachment1; } if ($_POST['attachment2Changed'] == 'true') { if ($attachment2 != NULL) { $name2 = date('Y_m_d_H_i_s_') . $attachment2->baseName . '.' . $attachment2->extension; $model->attachment2 = $name2; } } else { $model->attachment2 = $last_attachment2; } if ($_POST['Race']['categories'] != '') { foreach ($model->categories as $i => $category) { if (!array_search($category->id, $_POST['Race']['categories'])) { $nt = Category::findOne($category->id); $model->unlink('categories', $nt, true); } } foreach ($_POST['Race']['categories'] as $i => $category) { if (!Categories::findOne(['race_id' => $model->id, 'category_id' => $category])) { $nt = Category::findOne($category); $model->link('categories', $nt); } } } else { $model->unlinkAll('categories', true); } if ($model->save()) { if ($picture != NULL) { $picture->saveAs('img/carrera/' . $name); } if ($sponsor != NULL) { if ($picture != NULL) { $sponsor->saveAs('img/carrera/auspiciante/' . $name); } else { $sponsor->saveAs('img/carrera/auspiciante/' . $last_picture); } } if ($attachment1 != NULL) { $attachment1->saveAs('img/carrera/adjunto/' . $name1); } if ($attachment2 != NULL) { $attachment2->saveAs('img/carrera/adjunto/' . $name2); } return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('update', ['model' => $model, 'sports' => $sports, 'categories' => $c]); } }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $category_id * @param string $category_name * @param integer $parent_id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($category_id, $category_name, $parent_id) { if (($model = Category::findOne(['category_id' => $category_id, 'category_name' => $category_name, 'parent_id' => $parent_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getAllArticles($cid) { $category = Category::findOne($cid); return $category->articles; }