public function actionCategory() { for ($i = 1; $i <= 10; $i++) { $model = new Categories(); $model->attributes = ['name' => 'Danh Mục Số ' . $i, 'title' => 'Title cua danh muc so ' . $i, 'slug' => 'danh-muc-so-' . $i, 'images' => '3.png', 'created_at' => time(), 'updated_at' => time()]; $model->save(); } }
public function save_category(Request $request) { $category = new Categories(); $category->category_name = $request->category_name; $category->category_description = $request->category_description; $category->publication_status = $request->publication_status; $category->save(); Session::put('message', 'Save Category Information Successfully !'); return redirect('/add-category'); }
public function getForm($id = null) { $dataAdmin = new PrProviders(); $modelProviders = new PrTypes(); $modelCategories = new Categories(); $listProviders = $modelProviders->where('flagactive', PrTypes::STATE_ACTIVE)->lists('name_type', 'id')->toArray(); $listProviders = [null => 'Select un tipo'] + $listProviders; $listCategories = $modelCategories->where('flagactive', Categories::STATE_ACTIVE)->lists('name_category', 'id')->toArray(); $listCategories = [null => 'Select una categoria'] + $listCategories; if (!is_null($id)) { $dataAdmin = PrProviders::find($id); } return viewc('admin.' . self::NAMEC . '.form', compact('dataAdmin', 'listProviders'), ['listCategories' => $listCategories, 'listCategories' => $listCategories]); }
/** * Creates a new Resources model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id) { if ($id == 0) { throw new \yii\web\BadRequestHttpException("Неправильный запрос"); } $model = new Categories(); $model->parent_id = $id; $model->handler = $this->id; $model->attachBehavior('createStoreDir', ['class' => StoreDirBehavior::className(), 'handlerName' => $this->id]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['list', 'id' => $model->parent_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $dataCategory = Categories::whereFlagactive(1)->lists('id')->toArray(); $listCategory = implode(",", $dataCategory); $rules = ['description' => 'required', 'pu_category_id' => "required|in:{$listCategory}", 'name_provider' => 'required', 'email' => 'required:unique:pr_providers,email', 'phone' => 'required']; return $rules; }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $categories = Categories::where('parent_id', '>=', 0)->get(); $baseUrl = 'http://7xkn9n.com1.z0.glb.clouddn.com/img/'; $string = file_get_contents(__DIR__ . "/../data/products.json"); $products = json_decode($string, true); $cate_ids = []; foreach ($categories as $category) { $cate_ids[] = $category->id; } foreach ($products as $productData) { try { $name = $productData['meta']['title']; $content = ''; if (isset($productData['content'])) { $content = str_replace('<h2 class="title">百科词条</h2>', '', $productData['content']); } $klass = $productData['meta']['class']['text']; $category = Categories::where('name', $klass)->get(); $description = substr($content, 0, 100); $cid = $faker->randomElement($cate_ids); if ($category->count() == 1) { $cid = $category[0]->id; } $pieces = preg_split("/\\//i", $productData['meta']['image']); $product = Product::create(['name' => $name, 'slug' => $name, 'description' => $description, 'keywords' => $klass, 'cover' => $baseUrl . $pieces[count($pieces) - 1], 'category_id' => $cid, 'user_id' => 1]); $detailTopic = Topic::create(['title' => $name, 'slug' => $name, 'product_id' => $product->id, 'user_id' => 1, 'keywords' => $name, 'description' => $description, 'content' => $content, 'is_product_detail_topic' => true]); $product->detail_topic_id = $detailTopic->id; $product->save(); } catch (Exception $e) { throw $e; } } }
public function compose(View $view) { $categories = \App\Models\Categories::i()->withPostsCount(); $posts_count = \App\Models\Posts::active()->count(); $view->with('categories', $categories); $view->with('posts_count', $posts_count); }
public function upload() { if ($this->validate()) { $cat = Categories::findOne($this->id); $contr = Yii::$app->controllerNamespace . '\\' . ucfirst($cat->handler) . 'Controller'; $base = $contr::baseStorePath(); $store_to = $base['real'] . $cat->route; foreach ($this->files as $f) { $new_fn = $this->newFileName($f->baseName, $f->extension); if ($f->saveAs($store_to . $new_fn)) { $res = new Resources(); $res->attachBehavior('ImageBehavior', ['class' => ImageBehavior::className()]); $res->category_id = $this->id; $res->title = $res->description = $f->baseName; $res->keywords = $new_fn; //реальное имя файла с расширением $res->alias = str_replace('.' . $f->extension, '', $new_fn); //псевдоним изначально равен имени файла $res->path = $store_to; $res->webroute = $base['web'] . $cat->route; $res->filename = $new_fn; $res->save(); } //TODO обработка ошибки сохранения файла } return true; } return false; }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $dataCategory = Categories::whereFlagactive(1)->lists('id')->toArray(); $listCategory = implode(",", $dataCategory); $rules = ['description' => 'required', 'pu_category_id' => "required|in:{$listCategory}"]; return $rules; }
public function index($slug = '') { if ($slug != '') { $category = Categories::i()->getBySlug($slug); if (empty($category)) { abort(404); } $category_id = $category->id; view()->share('active_category', $category_id); view()->share('seo_title', 'Категория: ' . $category->seo_title); view()->share('seo_description', $category->seo_description); view()->share('seo_keywords', $category->seo_keywords); Title::prepend('Категория'); Title::prepend($category->seo_title); } else { Title::append(Conf::get('seo.default.seo_title')); $category = null; $category_id = null; } $q = request('q', null); if (!empty($q)) { } $posts = Posts::i()->getPostsByCategoryId($category_id, $q); $data = ['posts' => $posts, 'category' => $category, 'q' => $q, 'title' => Title::renderr(' : ', true)]; return view('site.posts.index', $data); }
/** * @param $id */ public static function edit($id) { $post = Posts::findByPK($id); if (!Request::is_authenticated()) { Session::push('flash-message', 'You must login before!'); Response::redirect('login?next=post/edit/' . $id); } else { if (Request::user()->id !== $post['id_account']) { Session::push('flash-message', 'You does not have permission to edit the other Member\'s post!'); Response::redirect(''); } } if ("POST" == Request::method()) { $id_member = Request::user()->id; $data = Request::POST()->post; $title = Request::POST()->title; $cat = Request::POST()->category; Posts::edit($id, $id_member, $title, $data, $cat); # set flash messages Session::push('flash-message', 'Your post has changed successfully!'); Response::redirect('post/read/' . $id); } else { $users = Accounts::find(['type' => 2]); $categories = Categories::all(); View::render('member/edit-post', ['post' => $post, 'users' => $users, 'categories' => $categories]); } }
public function showCategoriesProducts($id) { $category = Categories::findOrFail($id); $active_menu = ''; $products = Product::getProductInCategory($id); return view('category', compact(['category', 'active_menu', 'products'])); }
private function buildItems() { $tpl = $this->_config['itemTemplate']; $hasParams = preg_match('/@\\d+@/', $tpl) != false; Yii::trace('hasParams=' . $hasParams); $cats = Categories::findAll(array_keys($this->_config['filterCategories'])); foreach ($cats as $c) { if (!$c->isEmpty) { foreach ($c->resources as $r) { $t = $tpl; if ($hasParams) { $params = $r->getParams(); if ($params !== null) { $search = $replace = []; foreach ($params as $p) { $search[] = '@' . $p->type_id . '@'; $replace[] = $p->value; } $t = str_replace($search, $replace, $t); $t = preg_replace('/@\\d+@/', '', $t); //удаление лишних/не найденных } } $this->_items[] = str_replace($this->_ph, [$r->id, $r->created, $r->alias, $r->title, $r->description, '/' . $r->route], $t); } } } return implode('', $this->_items); }
public function getForm($id = null, $modulo = null) { $modelCategories = new Categories(); $listTypes = PuTypes::whereFlagactive(PuTypes::STATE_ACTIVE)->lists('name_type', 'id')->toArray(); $listTypes = [null => 'Select un tipo'] + $listTypes; $listCategories = $modelCategories->where('flagactive', Categories::STATE_ACTIVE)->lists('name_category', 'id')->toArray(); $listCategories = [null => 'Select una categoria'] + $listCategories; $dataPost = PuAds::find($id); if (!is_null($id)) { $dataPost = PuAds::find($id); $dataPicture = PuPicture::wherePuAdId($id)->first(); $dataPost->picture = !empty($dataPicture->url) ? "{$dataPost->picture}" : null; $dataPost->pr_provider_id = !empty($dataPost->pr_provider_id) ? "{$dataPost->pr_provider_id}" : 0; } return viewc('admin.' . self::NAMEC . '.form', compact('dataPost', 'modulo'), ['listCategories' => $listCategories, 'listTypes' => $listTypes]); }
/** * Reads file content and convert into array or object * * @params string $filePath * @return object * */ private function parseData($filePath) { $catID = \app\models\Categories::getCategoryID('Construction'); $content = file_get_contents($filePath); $data = array_map('str_getcsv', file($filePath)); array_walk($data, function (&$a) use($data) { $a = array_combine($data[0], $a); }); array_shift($data); $parsedData = array(); foreach ($data as $key => $item) { $parsedData[$key] = (object) array(); $parsedData[$key]->date = date("Y-m-d", strtotime($item['date'])); $parsedData[$key]->lot_title = $item['lot title']; $parsedData[$key]->lot_location = $item['lot location']; $parsedData[$key]->pre_tax_amount = $item['pre-tax amount']; $parsedData[$key]->tax_amount = $item['tax amount']; $parsedData[$key]->category = \app\models\Categories::getCategoryID($item['category']); $parsedData[$key]->lot_condition = \app\models\LotCondition::getLotConditionID($item['lot condition']); $parsedData[$key]->tax_name = \app\models\TaxName::getTaxNameID($item['tax name']); if (is_null($parsedData[$key]->category)) { // category does not exist, so add it $parsedData[$key]->category = \app\models\Categories::addCategory($item['category']); } if (is_null($parsedData[$key]->lot_condition)) { // lot condition does not exist, so add it $parsedData[$key]->lot_condition = \app\models\LotCondition::addLotCondition($item['lot condition']); } if (is_null($parsedData[$key]->tax_name)) { // tax name does not exist, so add it $parsedData[$key]->tax_name = \app\models\TaxName::addTaxName($item['tax name']); } } return $parsedData; }
/** * Display a listing of the resource. * * @return Response */ public function post(Request $request, $post) { $qGetTags = Tags::all(); $qGetCategories = Categories::where('cID', '!=', 1)->get(); $qArticle = $post; return view('user.show-post', compact('qGetTags', 'qGetCategories', 'qArticle')); }
/** * Показывает контент * @return string * @TODO Нужно предусмотреть возможность вывода разного контента, привязаного к одной категории * */ public function actionShow() { $this->cat_id = Yii::$app->getRequest()->getQueryParam('id') ? Yii::$app->getRequest()->getQueryParam('id') : null; $cat_obg = Categories::find()->where('id = ' . $this->cat_id)->one(); $allContent = Articles::find()->where('cat_id = ' . $this->cat_id)->all(); $allArticlesForPager = Articles::find()->where(['cat_id' => $this->cat_id]); $countQueryCont = clone $allArticlesForPager; $pagesGlobal = new Pagination(['totalCount' => $countQueryCont->count(), 'pageSize' => 1, 'forcePageParam' => false, 'pageSizeParam' => false]); $artPages = $allArticlesForPager->offset($pagesGlobal->offset)->limit($pagesGlobal->limit)->all(); foreach ($allContent as $article) { //var_dump($this->cat_id); $this->article_id = $article->id; $article = Articles::findOne($this->article_id); $allArticles = ArticlesContent::find()->where(['articles_id' => $this->article_id])->orderBy(['id' => SORT_DESC]); //var_dump($allArticles); exit; $countQuery = clone $allArticles; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]); $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all(); $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title; $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name; $this->articles[] = ['article' => $article, 'contents' => $models, 'pages' => $pages, 'source' => $this->source, 'author' => $this->author]; } //var_dump($this->articles); exit; return $this->renderPartial($cat_obg->action, ['articles' => $this->articles, 'cat' => $this->cat_id, 'pagesGlobal' => $pagesGlobal, 'artPages' => $artPages, 'cat_obg' => $cat_obg]); }
protected function findModel($id) { if (($model = Categories::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getCategoryID($category) { if (is_null(\app\models\Categories::findOne(['category' => $category]))) { return null; } else { return \app\models\Categories::findOne(['category' => $category])->id; } }
/** * Загружает запись модели текущего контроллера по айдишнику * @param $id * @return null|static * @throws \yii\web\HttpException */ public function loadModel($id) { $model = Categories::findOne($id); if ($model === null) { throw new \yii\web\HttpException(404, 'The requested page does not exist.'); } return $model; }
public function getRoute() { $rt = ''; $parents = Categories::getHierarchy($this->id); foreach ($parents as $p) { $rt = ($p->alias !== '0' ? $p->alias . '/' : '') . $rt; } return $rt; }
public function actionViewall($cid = 2) { $query = Article::find()->where(['cid' => $cid, 'published' => 1]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('ordering')->all(); $cat = \app\models\Categories::findOne($cid); return $this->render('viewall', ['model' => $models, 'cat' => $cat, 'pages' => $pages]); }
public function actionKlavarosCats() { $res = []; $m = Categories::find()->where(['site_id' => 13])->all(); foreach ($m as $h) { $res[] = $h->name; } return json_encode($res); }
public function actionCategory($id) { $model = Categories::findOne($id); $category = $model->find()->where(['id' => $id])->one(); $news = new News(); $data = $news->fromCategory($id, 20, $this->paging(20)); $datat1 = $news->fromCategory($id, 5, 0); $datat2 = $news->fromCategory($id, 4, 5); return $this->render('itemcategory', ['data' => $data, 'datat1' => $datat1, 'datat2' => $datat2, 'category' => $category, 'model' => $model]); }
/** * Run the database seeds. * * @return void */ public function run() { $categories = ['shoujitongxun' => ['display_name' => '手机通讯', 'sub' => [['zhinengshouji', '智能手机'], ['feizhinengshouji', '非智能手机'], ['duijiangji', '对讲机'], ['lanyaerji', '蓝牙耳机']]], 'sheyingshexiang' => ['display_name' => '摄影摄像', 'sub' => [['danfangjisheng', '单反机身'], ['weidanxiangji', '微单相机'], ['shumaxiangji', '数码相机'], ['jiayongshexiangji', '家用摄像机'], ['zhuanyeshexiangji', '专业摄像机']]], 'xiangjipeijian' => ['display_name' => '相机配件', 'sub' => [['shumapeijian', '数码配件'], ['chongdianqi', '充电器'], ['dianchi', '电池'], ['diannaozhijia', '电脑支架'], ['yidongdianyuan', '移动电源'], ['chukongbi', '触控笔'], ['qitashumapeijian', '其它数码配件']]]]; foreach ($categories as $name => $category) { $parent = Categories::create(['slug' => $name, 'name' => $category['display_name'], 'parent_id' => -1]); $subs = $category['sub']; foreach ($subs as $sub_category) { Categories::create(['slug' => $sub_category[0], 'name' => $sub_category[1], 'parent_id' => $parent->id]); } } }
/** ** Вывод списка страниц. Если задан $id категории - списка страниц категории */ public function actionList($id = 0) { $q = Resources::find(); if ($id > 0) { $q->where(['category_id' => $id]); } else { $q->joinWith('category')->where(['categories.handler' => $this->id]); } $dataProvider = new ActiveDataProvider(['query' => $q, 'pagination' => false]); return $this->render('list', ['category' => Categories::findOne($id), 'dataProvider' => $dataProvider, 'category_id' => $id]); }
/** * Updates an existing Product model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $itemId * @return mixed */ public function actionUpdate($itemId) { $categories = Categories::find()->all(); // need this for dropDownList in views/product/_form.php $model = $this->findModel($itemId); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'itemId' => $model->item_id]); } else { return $this->render('update', ['model' => $model, 'categories' => $categories]); } }
/** * Render the profile page * @param $username */ public static function profile($username) { # fetch account data by username $account = Accounts::findByUsername($username); # fecth all categories $categories = Categories::all(); # fetch all of this member's post $posts = Posts::find(['id_account' => $account['id']]); # fetch all accounts $users = Accounts::find(['type' => 2]); View::render('member/profile', ['account' => $account, 'posts' => $posts, 'users' => $users, 'categories' => $categories]); }
public static function delete($id) { if (!Request::is_admin()) { Response::redirect(''); } # perform the categories deletion Categories::delete($id); # push flash-message Session::push('flash-message', 'That category has deleted successfuly!'); # redirect to main page Response::redirect('categories'); }
public function create(Request $request) { $qCategories = Categories::all(); $qTags = Tags::all(); $articleID = $request->aID ? $request->aID : 0; if ($articleID) { $qArticles = Articles::where("aID", $articleID)->first(); } else { $qArticles = new Articles(); } return view('admin.article.create', compact('qArticles', 'articleID', 'qCategories', 'qTags')); }