Inheritance: extends Illuminate\Database\Eloquent\Model
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateCategoryRequest $request)
 {
     $category = new Category();
     $data = $request->input();
     $category->create($data);
     return Redirect()->route('categories');
 }
Example #2
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $pro = new Product();
     $adSlotObj = new Adslot();
     $catObj = new Category();
     $brandObj = new Brand();
     /*getting all products for all slots(currently we have 7 slots)*/
     $adSlot_data = $adSlotObj->with(['products'])->get();
     /*t1-t7*/
     // dd($adSlot_data[4]['products'][0]);
     $category_temp_data = $catObj->orderBy('created_at')->take(10)->get();
     /*f1-f10*/
     $brand_data = $brandObj->with(['products'])->get();
     $category_data = [];
     foreach ($category_temp_data as $cat_id) {
         $cat_latest_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('photo_1');
         $cat_latest_product_id = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('id');
         $cat_random_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy(DB::raw('RAND()'))->take(6)->get();
         $cat_brands = $pro->with(['brand'])->where('category_id', '=', $cat_id['id'])->take(5)->get();
         $cat_products_random_photos = [];
         foreach ($cat_random_product as $photo) {
             $cat_products_random_photos[] = $photo;
         }
         $category_data[] = ['color' => $cat_id['color'], 'floor' => $cat_id['floor'], 'name' => $cat_id['name'], 'desc' => $cat_id['description'], 'logo' => $cat_id['logo'], 'latest_photo_id' => $cat_latest_product_id, 'latest_photo' => $cat_latest_product, 'random_photos' => $cat_products_random_photos, 'brands' => $cat_brands];
     }
     return view('landing_page', compact(['adSlot_data', 'category_data']));
 }
Example #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /*Default Category*/
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Food & Drink";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Bills";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Transportation";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Cellular";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Tax";
     $category->save();
     $admin = new Admin();
     $admin->username = "******";
     $admin->password = "******";
     $admin->secret = "123456";
     $admin->save();
 }
Example #4
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->category->name = $this->request->input('name');
     $this->category->options = ['manager' => $this->request->has('manager')];
     $this->category->parent_id = $this->request->parent;
     return $this->category->save();
 }
 /**
  * Delete a category.
  *
  * @param Category $category
  * @return mixed
  */
 public function deleteCategory(Category $category)
 {
     $result = \DB::transaction(function () use($category) {
         return $category->delete();
     });
     return $result;
 }
Example #6
0
 public static function addCategory($title, $mid)
 {
     $category = new Category();
     $category->title = $title;
     $category->mid = $mid;
     $category->sort_id = 1;
     $category->save();
 }
 /**
  * Get by category id.
  *
  * @param $id
  */
 public function getById($id)
 {
     $category = $this->model->find($id);
     if (!is_null($category)) {
         $category->hot++;
         $category->update();
     }
     return $category;
 }
Example #8
0
 public function index(Advertisement $advertModel)
 {
     $b1_baner = Baner::where('type', 'b1')->get();
     $b2_baner = Baner::where('type', 'b2')->get();
     $latest_advert = $advertModel->get_last_advert();
     $popular_advert = $advertModel->get_popular_advert();
     $categoryModel = new Category();
     $categories = $categoryModel->get_order_count();
     return view('site.front')->with('b1_baner', $b1_baner)->with('b2_baner', $b2_baner)->with('latest_advert', $latest_advert)->with('popular_advert', $popular_advert)->with('categories', $categories);
 }
Example #9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Category::truncate();
     $categoryNames = ['coding', 'social', 'faith', 'health', 'minimalism'];
     foreach ($categoryNames as $name) {
         $category = new Category(['name' => $name]);
         $category->user()->associate(User::first());
         $category->save();
     }
 }
Example #10
0
 /**
  * 具体文章显示
  * @return string
  */
 public function actionArticle()
 {
     $categoryName = Yii::$app->request->get('dir');
     $articleName = Yii::$app->request->get('name');
     $categoryModel = new Category();
     $articleInfo = $categoryModel->getArticleBody($categoryName, $articleName);
     $parser = new GithubMarkdown();
     $articleInfo['content'] = $parser->parse($articleInfo['content']);
     $articleInfo['category'] = $categoryName;
     return $this->render('article', ['article' => $articleInfo]);
 }
 public function get_add_test(Category $category)
 {
     if (!$this->bool_has_role) {
         return $this->roleHelper->call_redirect();
     } else {
         $arr_categories_raw = $category->all()->toArray();
         $arr_categories_processed = $category->process_categories($arr_categories_raw);
         $data = array('arr_logged_in_user' => $this->arr_logged_in_user, 'arr_categories_processed' => $arr_categories_processed);
         return view('tests/add_test')->with('data', $data);
     }
 }
Example #12
0
 /**
  *
  * @param Category $category
  * @return Response
  */
 public function destroy(Category $category)
 {
     try {
         $category->delete();
         return response([], Response::HTTP_NO_CONTENT);
     } catch (\Exception $e) {
         //Integrity constraint violation
         if ($e->getCode() === '23000') {
             $message = 'Category could not be deleted. It is in use.';
         } else {
             $message = 'There was an error';
         }
         return response(['error' => $message, 'status' => Response::HTTP_BAD_REQUEST], Response::HTTP_BAD_REQUEST);
     }
 }
 public function confirmUnpublished(Product $product)
 {
     $authors_list = $product->is->authors->lists('lastname');
     $category = Category::where('id', $product->organizations->first()->pivot->cat_id)->first(['name']);
     $editor = $product->is->editor->e_name;
     return view('admin.products.unpublished.confirm', compact('product', 'authors_list', 'category', 'editor'));
 }
Example #14
0
 public function actionTopic()
 {
     static $topics = ['today', 'hot'];
     $topic = \Yii::$app->request->get('topic');
     $p = \Yii::$app->request->get('p', 1);
     if (in_array($topic, $topics)) {
         switch ($topic) {
             case 'hot':
                 $title = '热门推荐';
                 $list = Blog::hotList();
                 break;
             default:
                 break;
         }
     } else {
         if (is_numeric($topic)) {
             $cid = intval($topic);
             $list = Blog::getListByCid($cid);
             $title = Category::getName($cid);
         }
     }
     $this->getView()->params['title'] = $title;
     $this->getView()->params['description'] = $title;
     return $this->render('/site/list', ['data' => $list]);
 }
 public function actionDelete($id)
 {
     $model = Category::find()->where(['id' => $id])->one();
     $model->unlinkAll('posts', true);
     Category::deleteAll(['id' => $id]);
     return $this->actionNew();
 }
Example #16
0
 public static function add(BlogForm $blogform)
 {
     $blog = new Blog();
     $blog->uid = \Yii::$app->user->getId();
     $blog->title = htmlspecialchars($blogform->title);
     $blog->content = htmlspecialchars($blogform->content);
     $blog->tags = $blogform->tags;
     $blog->cid = $blogform->cid ? $blogform->cid : 0;
     $blog->status = $blogform->status ? $blogform->status : self::STATUS_PUBLISH;
     $blog->is_private = $blogform->is_private ? $blogform->is_private : 0;
     $blog->allow_review = $blogform->allow_review ? $blogform->allow_review : 1;
     $blog->addtime = $blog->uptime = time();
     $analyse = self::analyse($blogform->content);
     if (!$blogform->description) {
         $blog->description = $analyse['description'];
     } else {
         $blog->description = $blogform->description;
     }
     //$blog->image = $blogform->image ? $blogform->image : $analyse['image'];
     $blog->image = $analyse['image'];
     $blog->thumb = $analyse['thumb'];
     $result = $blog->insert();
     if ($result) {
         Tags::add($blog->tags, $blog->id);
         if ($blog->status == self::STATUS_PUBLISH) {
             Category::countInc($blog->cid);
         }
         return true;
     } else {
         return false;
     }
 }
Example #17
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Requests\Backend\StoreCategoryRequest $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\Backend\StoreCategoryRequest $request, $id)
 {
     $category = Category::findOrFail($id);
     $this->authorize($category);
     $category->update($request->all());
     return redirect()->action('Backend\\CategoryController@show', [$category]);
 }
Example #18
0
 public function actionDrop()
 {
     $model = new SurveyResult();
     $catList = ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'name');
     $subcatList = ArrayHelper::map(Subcategory::find()->asArray()->all(), 'id', 'name');
     return $this->render('drop', ['model' => $model, 'catList' => $catList, 'subcatList' => $subcatList]);
 }
 /**
  * Lists all Service models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new ServiceSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $cat = Category::find()->orderBy('name_pt')->asArray()->all();
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'cat' => $cat]);
 }
Example #20
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $videos = glob(public_path() . '/b/*');
     usort($videos, function ($a, $b) {
         $a = (int) basename($a, '.webm');
         $b = (int) basename($b, '.webm');
         if ($a == $b) {
             return 0;
         }
         return $a < $b ? -1 : 1;
     });
     $category = \App\Models\Category::where('shortname', '=', 'misc')->first();
     $user = \App\Models\User::find(1);
     foreach ($videos as $video) {
         if (\App\Models\Video::whereFile(basename($video))->count() > 0) {
             continue;
         }
         $v = new \App\Models\Video();
         $v->user()->associate($user);
         $v->category()->associate($category);
         $v->hash = sha1_file($video);
         $v->file = basename($video);
         $v->save();
     }
 }
Example #21
0
 /**
  * @depends testStore
  */
 public function testUpdate($category)
 {
     $this->put(route('api.admin.category.item', $category), json_encode(['category_name' => 'test edited']));
     $category = Category::find($category->id);
     $this->assertEquals('test edited', $category->category_name);
     $this->assertResponseOk();
 }
 /**
  * Update the visibility of a category
  *
  * @param $id
  * @param $visible
  * @return mixed
  */
 public function updateVisibility($id, $visible)
 {
     $category = Category::find($id);
     $category->visible = $visible;
     $category->save();
     return $category;
 }
Example #23
0
 public static function getCategoryArr()
 {
     $category_id_root = Yii::$app->getRequest()->getQueryParam('category_id_root');
     $category_id = Yii::$app->getRequest()->getQueryParam('category_id');
     if (!$category_id) {
         return false;
     }
     $category = Category::find()->all();
     $categories = [];
     // categories
     $parents = [];
     foreach ($category as $cate) {
         $categories[$cate['category_name']] = $cate;
         $parents[$cate['category_id_root']][$cate['category_id']] = $cate['category_id'];
     }
     $cateQueryArr = array();
     $queue = array();
     array_push($queue, $category_id);
     while ($subCate = array_shift($queue)) {
         $cateQueryArr[$subCate] = $subCate;
         if (isset($parents[$subCate])) {
             foreach ($parents[$subCate] as $cid) {
                 array_push($queue, $cid);
             }
         }
     }
     //        echo'<pre>';
     //        var_dump($cateQueryArr);
     //        echo'</pre>';
     //        die();
     return $cateQueryArr;
 }
 public function save()
 {
     $category = Category::findOrNew(Input::get('id'));
     $category->category = Input::get('category');
     $category->is_home = Input::get('is_home');
     $category->is_nav = Input::get('is_nav');
     $category->sort_order = Input::get('sort_order');
     $category->url_key = Input::get('url_key');
     $category->short_desc = Input::get('short_desc');
     $category->long_desc = Input::get('long_desc');
     $category->meta_title = Input::get('meta_title');
     $category->meta_keys = Input::get('meta_keys');
     $category->meta_desc = Input::get('meta_desc');
     // $catImgs = [];
     $catImgs = json_decode(empty(Input::get('imgs')) ? "[]" : Input::get('imgs'), true);
     $destinationPath = public_path() . '/admin/uploads/catalog/category/';
     if (Input::hasFile('images')) {
         $i = 1;
         foreach (Input::file("images") as $file) {
             $fileName = date("YmdHis") . "-{$i}" . "." . $file->getClientOriginalExtension();
             $upload_success = $file->move($destinationPath, $fileName);
             if ($upload_success) {
                 array_push($catImgs, $fileName);
                 $i++;
             }
         }
     }
     $category->images = json_encode($catImgs);
     $category->save();
     if (!empty(Input::get("parent_id"))) {
         $category->makeChildOf(Input::get("parent_id"));
     }
     return redirect()->route('admin.category.view');
 }
 public function actionIndex($mid = '', $f = 0)
 {
     $user = User::findIdentity(Yii::$app->user->id);
     $regFrm = new RegisterForm();
     $rstFrm = new RestorePswForm();
     $spOffs = new SpecialOffer();
     $spOffs = $spOffs->getAllSpecialOffers();
     if ($f) {
         $logFrm = new LoginForm(['scenario' => LoginForm::SCENARIO_LOGIN_CAPTCHA]);
     } else {
         $logFrm = new LoginForm(['scenario' => LoginForm::SCENARIO_LOGIN]);
     }
     $city = City::find()->all();
     $address = new Address();
     $distr = $address->getDistrict();
     $category = Category::find()->all();
     $brand = Brand::find()->all();
     $msg = '';
     switch ($mid) {
         case 1:
             $msg = Common::M_EMAIL_SEND;
             break;
         case 2:
             $msg = Common::M_PSW_EMAIL_SEND;
             break;
         case 3:
             $msg = Common::M_PSW_RESTORE_SUCCESS;
             break;
     }
     return $this->render('index', ['msg' => $msg, 'user' => $user, 'spOffs' => $spOffs, 'regFrm' => $regFrm, 'logFrm' => $logFrm, 'rstFrm' => $rstFrm, 'city' => $city, 'distr' => $distr, 'category' => $category, 'brand' => $brand]);
 }
Example #26
0
 public function save()
 {
     if (!$this->product_id) {
         return Category::find($this->category)->product()->create($this->fields());
     }
     return DB::table('products')->where('id', $this->product_id)->update(['category_id' => $this->category, 'name' => $this->name, 'type' => $this->type, 'length' => $this->length, 'thickness' => $this->thickness, 'width' => $this->width, 'description' => $this->description, 'hidden' => $this->hidden]);
 }
Example #27
0
 public function actionMap()
 {
     Yii::$app->response->format = Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     $headers->add('Content-Type', 'text/xml');
     $dom = new \DOMDocument("1.0", "utf-8");
     $root = $dom->createElement("urlset");
     $root->setAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
     $dom->appendChild($root);
     $categories = Category::findAll(['is_active' => 1]);
     $articles = Article::findAll(['is_active' => 1]);
     $items = array_merge($categories, $articles);
     foreach ($items as $item) {
         $url = $dom->createElement("url");
         $loc = $dom->createElement("loc");
         if ($item instanceof Article) {
             $loc->appendChild($dom->createTextNode(Url::to(['article/view', 'id' => $item->id], true)));
         } else {
             $loc->appendChild($dom->createTextNode(Url::to(['category/view', 'id' => $item->id], true)));
         }
         $lastmod = $dom->createElement("lastmod");
         $lastmod->appendChild($dom->createTextNode($item->timestamp));
         $changefreq = $dom->createElement("changefreq");
         $changefreq->appendChild($dom->createTextNode("monthly"));
         $priority = $dom->createElement("priority");
         $priority->appendChild($dom->createTextNode("0.5"));
         $url->appendChild($loc);
         $url->appendChild($lastmod);
         $url->appendChild($changefreq);
         $url->appendChild($priority);
         $root->appendChild($url);
     }
     return $dom->saveXML();
 }
Example #28
0
 public function test_delete_category()
 {
     $this->test_create_category();
     $category = Category::firstOrFail();
     $this->delete(route('inquiries.categories.destroy', [$category->id]));
     $this->dontSeeInDatabase('categories', ['id' => $category->id]);
 }
Example #29
0
 public function add()
 {
     if ($this->validate()) {
         return Category::add(['name' => $this->name, 'pid' => 0]);
     }
     return false;
 }
Example #30
0
 public function __construct(Route $route)
 {
     $this->middleware(function ($request, $next) {
         // if session is not set get it from .env SHOP_CODE
         if (!$request->session()->has('shop')) {
             $shop = Shop::where('code', config('app.shop_code'))->first();
             $request->session()->put('shop', $shop->id);
         }
         // if limit is not set default pagination limit
         if (!$request->session()->has('limit')) {
             $request->session()->put('limit', 100);
         }
         // if session is not set reset the session for the language
         if (!$request->session()->has('language')) {
             $request->session()->put('language', config('app.locale'));
         }
         // if session is not set reset the session for the basket
         if (!$request->session()->has('basket')) {
             $request->session()->put('basket', ['subtotal' => 0, 'count' => 0, 'items' => []]);
         }
         // global list of categories
         $categories = Category::where('shop_id', $request->session()->get('shop'))->orderBy('order', 'asc')->get();
         // share globals
         view()->share('language', $request->session()->get('language'));
         view()->share('categories', $categories);
         return $next($request);
     });
     // add controller & action to the body class
     $currentAction = $route->getActionName();
     list($controller, $method) = explode('@', $currentAction);
     $controller = preg_replace('/.*\\\\/', '', $controller);
     $action = preg_replace('/.*\\\\/', '', $method);
     view()->share('body_class', $controller . '-' . $action);
 }