public function getCategory($id)
 {
     $result['categories'] = $this->category->getCategories();
     $result['title'] = 'Shop';
     $result['currentCategory'] = $id;
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     if ($result['isEditor']) {
         $result['products'] = $this->product->getProductsForCategoryWitnUnavailable($id);
     } else {
         $result['products'] = $this->product->getProductsForCategory($id);
     }
     $all_promotion = $this->promotion->getHighestActivePromotion();
     foreach ($result['products'] as $k => $p) {
         $productPromotion = max($all_promotion['discount'], $p['discount'], $p['category_discount']);
         if (is_numeric($productPromotion)) {
             $result['products'][$k]['promotion_price'] = $p['price'] - $p['price'] * ($productPromotion / 100);
         }
     }
     View::make('index', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->appendTemplateToLayout('catMenu', 'side_bar/category_menu')->render();
 }
 public function getAdd()
 {
     $result['title'] = 'Shop';
     $result['action'] = '/promotion/add';
     $result['submit'] = 'add';
     $categories = $this->category->getCategories();
     $result['categories'][] = array('text' => 'No category', 'options' => array('value' => 0));
     foreach ($categories as $c) {
         $currentCategory = array();
         $currentCategory['text'] = $c['name'];
         $currentCategory['options'] = array('value' => $c['id']);
         $result['categories'][] = $currentCategory;
     }
     $products = $this->product->getProducts();
     $result['products'][] = array('text' => 'No product', 'options' => array('value' => 0));
     foreach ($products as $c) {
         $currentProduct = array();
         $currentProduct['text'] = $c['name'];
         $currentProduct['options'] = array('value' => $c['id']);
         $result['products'][] = $currentProduct;
     }
     View::make('promotion.add', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function index()
 {
     $result['title'] = 'Categories';
     $result['categories'] = $this->category->getCategories();
     View::make('category.index', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function getEdit($id)
 {
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     if ($result['isEditor']) {
         $result = array('product' => $this->product->getProductWitnUnavailable($id));
     } else {
         $result = array('product' => $this->product->getProduct($id));
     }
     $result['title'] = 'Shop';
     $result['action'] = '/product/edit/' . $result['product']['id'];
     $result['submit'] = 'edit';
     $categories = $this->category->getCategories();
     foreach ($categories as $c) {
         $currentCategory = array();
         $currentCategory['text'] = $c['name'];
         $currentCategory['options'] = array('value' => $c['id']);
         if ($id == $c['id']) {
             $currentCategory['options']['selected'] = 'true';
         }
         $result['categories'][] = $currentCategory;
     }
     View::make('product.add', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function getEdit($id)
 {
     $result['title'] = 'Edit';
     /* @var $estate \Models\ViewModels\EstateViewModel */
     $estate = $this->estate->getEstate($id);
     if ($estate == null) {
         Session::setError('The estate id is incorrect');
         Redirect::to('');
     }
     $estate->images = $this->image->getImagesByEstate($id);
     foreach ($estate->images as $i) {
         $i->thumbnailName = $this->setImageThumb($i->name);
     }
     $result['estate'] = $estate;
     $result['action'] = '/admin/estate/' . $estate->id . '/edit';
     $result['submit'] = 'Edit';
     $result['categories'] = $this->setCategoryFormOptions($this->category->getCategories(), $estate);
     $result['cities'] = $this->setCityFormOptions($this->city->getCities(), $estate);
     View::make('estate.add', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }