private function getCategories()
 {
     $category_models = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get();
     $categories = $this->recursivePrint($category_models);
     natsort($categories);
     return $categories;
 }
 public function getEdit($sid)
 {
     // Find the module using the user id
     $module = Module::find($sid);
     // No such id
     if ($module == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The module cannot be found because it does not exist or may have been deleted.");
         return redirect('/admin/modules')->withErrors($errors);
     }
     $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get();
     $tagString = "";
     foreach ($module->tags as $tag) {
         if (!empty($tagString)) {
             $tagString .= ",";
         }
         $tagString .= $tag->name;
     }
     $translated = array();
     foreach ($module->translations as $translation) {
         $translated[$translation->lang] = json_decode($translation->content);
     }
     $pricelists = array();
     foreach (Membership::orderBy('rank')->get() as $membership) {
         $pricelist = Pricelist::where('module_id', $module->id)->where('membership_id', $membership->id)->first();
         if ($pricelist == null) {
             $pricelists[] = array('id' => $membership->id, 'name' => $membership->name, 'price' => '', 'active' => false);
         } else {
             $pricelists[] = array('id' => $membership->id, 'name' => $membership->name, 'price' => $pricelist->price, 'active' => $pricelist->active);
         }
     }
     return \View::make('redminportal::modules/edit')->with('module', $module)->with('translated', $translated)->with('categories', $categories)->with('tagString', $tagString)->with('pricelists', $pricelists)->with('imagine', new RImage());
 }
 public function getEdit($sid)
 {
     // Find the product using the user id
     $product = Product::find($sid);
     // No such id
     if ($product == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('errorNoSuchProduct', Lang::get('redminportal::messages.error_no_such_product'));
         return redirect($this->pageRoute)->withErrors($errors);
     }
     $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get();
     $tagString = "";
     foreach ($product->tags as $tag) {
         if (!empty($tagString)) {
             $tagString .= ",";
         }
         $tagString .= $tag->name;
     }
     $translated = array();
     foreach ($product->translations as $translation) {
         $translated[$translation->lang] = json_decode($translation->content);
     }
     $data = array('product' => $product, 'translated' => $translated, 'categories' => $categories, 'tagString' => $tagString, 'imagine' => new RImage(), 'weight_units' => $this->weight_units, 'volume_units' => $this->volume_units);
     return view('redminportal::products/edit', $data);
 }
 public function testCreateSubCategory()
 {
     $this->createNew();
     $model = Category::find(1);
     $new_model = new Category();
     $new_model->name = 'This is sub category';
     $new_model->short_description = 'This is the body 1';
     $new_model->active = true;
     $model->categories()->save($new_model);
     $new_model_2 = new Category();
     $new_model_2->name = 'This is another sub category';
     $new_model_2->short_description = 'This is the body 2';
     $new_model_2->active = true;
     $model->categories()->save($new_model_2);
     $this->assertTrue($model->categories->count() == 2);
     $this->assertTrue(Category::where('category_id', $model->id)->count() == 2);
     foreach ($model->categories as $cat) {
         if ($cat->name == 'This is sub category') {
             $this->assertTrue($cat->short_description == 'This is the body 1');
         } elseif ($cat->name == 'This is another sub category') {
             $this->assertTrue($cat->short_description == 'This is the body 2');
         } else {
             $this->assertTrue(false);
         }
     }
     // Delete main category will delete all sub categories
     $model->delete();
     $this->assertTrue(Category::where('category_id', $model->id)->count() == 0);
 }
 public function getEdit($sid)
 {
     // Find the post using the user id
     $post = Post::find($sid);
     if ($post == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The post cannot be found because it does not exist or may have been deleted.");
         return redirect('admin/posts')->withErrors($errors);
     }
     $translated = array();
     foreach ($post->translations as $translation) {
         $translated[$translation->lang] = json_decode($translation->content);
     }
     $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get();
     return view('redminportal::posts/edit')->with('post', $post)->with('translated', $translated)->with('imagine', new RImage())->with('categories', $categories);
 }
 public function getEdit($sid)
 {
     $bundle = Bundle::find($sid);
     if ($bundle == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The bundle cannot be found because it does not exist or may have been deleted.");
         return redirect('/admin/bundles')->withErrors($errors);
     }
     $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get();
     $products = Product::where('active', true)->lists('name', 'id');
     $membermodules = array();
     $pricelists = Pricelist::join('modules', 'modules.id', '=', 'pricelists.module_id')->join('memberships', 'memberships.id', '=', 'pricelists.membership_id')->where('pricelists.active', true)->orderBy('modules.name')->orderBy('memberships.rank', 'desc')->select('pricelists.*')->get();
     foreach ($pricelists as $pricelist) {
         $membermodules[$pricelist->id] = $pricelist->module->name . " (" . $pricelist->membership->name . ")";
     }
     $product_id = array();
     foreach ($bundle->products as $product) {
         $product_id[$product->id] = $product->id;
     }
     $pricelist_id = array();
     foreach ($bundle->pricelists as $pricelist) {
         $pricelist_id[$pricelist->id] = $pricelist->id;
     }
     $tagString = "";
     foreach ($bundle->tags as $tag) {
         if (!empty($tagString)) {
             $tagString .= ",";
         }
         $tagString .= $tag->name;
     }
     $translated = array();
     foreach ($bundle->translations as $translation) {
         $translated[$translation->lang] = json_decode($translation->content);
     }
     $data = array('categories' => $categories, 'products' => $products, 'membermodules' => $membermodules, 'bundle' => $bundle, 'product_id' => $product_id, 'pricelist_id' => $pricelist_id, 'translated' => $translated, 'categories' => $categories, 'tagString' => $tagString, 'imagine' => new RImage());
     return view('redminportal::bundles/edit', $data);
 }
 public function getEdit($sid)
 {
     // Find the product using the user id
     $product = Product::find($sid);
     // No such id
     if ($product == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The product cannot be found because it does not exist or may have been deleted.");
         return redirect('/admin/products')->withErrors($errors);
     }
     $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get();
     $tagString = "";
     foreach ($product->tags as $tag) {
         if (!empty($tagString)) {
             $tagString .= ",";
         }
         $tagString .= $tag->name;
     }
     $translated = array();
     foreach ($product->translations as $translation) {
         $translated[$translation->lang] = json_decode($translation->content);
     }
     return view('redminportal::products/edit')->with('product', $product)->with('translated', $translated)->with('categories', $categories)->with('tagString', $tagString)->with('imagine', new RImage());
 }
 public function getEdit($sid)
 {
     // Find the page using the user id
     $page = Page::find($sid);
     if ($page == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The page cannot be found because it does not exist or may have been deleted.");
         return redirect('admin/pages')->withErrors($errors);
     }
     $translated = array();
     foreach ($page->translations as $translation) {
         $translated[$translation->lang] = json_decode($translation->content);
     }
     $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get();
     $tagString = "";
     foreach ($page->tags as $tag) {
         if (!empty($tagString)) {
             $tagString .= ",";
         }
         $tagString .= $tag->name;
     }
     $data = ['page' => $page, 'translated' => $translated, 'imagine' => new RImage(), 'categories' => $categories, 'tagString' => $tagString];
     return view('redminportal::pages/edit', $data);
 }
 public function getDelete($sid)
 {
     // Find the category using the user id
     $category = Category::find($sid);
     if ($category == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "The category cannot be found because it does not exist or may have been deleted.");
         return redirect('/admin/categories')->withErrors($errors);
     }
     // Find if there's any child
     $children = Category::where('category_id', $sid)->count();
     if ($children > 0) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "The category '" . $category->name . "' cannot be deleted because it has " . $children . " children categories.");
         return redirect('/admin/categories')->withErrors($errors);
     }
     // Check in use by media
     $medias = Media::where('category_id', $sid)->get();
     if (count($medias) > 0) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "The category '" . $category->name . "' cannot be deleted because it is in used.");
         return redirect('/admin/categories')->withErrors($errors);
     }
     // Delete the category
     $category->delete();
     return redirect('admin/categories');
 }
Exemple #10
0
 public static function getAllActiveOrdered()
 {
     return Category::where('active', '=', '1')->orderBy('order', 'desc')->orderBy('name')->get();
 }
 public function getDelete($sid)
 {
     // Find the category using the user id
     $category = Category::find($sid);
     if ($category == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', Lang::get('redminportal::messages.category_error_category_not_found'));
         return redirect()->back()->withErrors($errors);
     }
     // Find if there's any child
     $children = Category::where('category_id', $sid)->count();
     if ($children > 0) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', Lang::get('redminportal::messages.category_error_cannot_delete_has_child', ['name' => $category->name, 'children' => $children]));
         return redirect()->back()->withErrors($errors);
     }
     // Delete the category
     $category->delete();
     return redirect()->back();
 }