public function index()
 {
     $result['categories'] = $this->category->getCategories();
     $result['title'] = 'Shop';
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     if ($result['isEditor']) {
         $result['products'] = $this->product->getProductsWitnUnavailable();
     } else {
         $result['products'] = $this->product->getProducts();
     }
     $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);
         }
     }
     //        $val=new Validation();
     //        $val->setRule('matches',3,4,'az');
     //        $val->setRule('different',6,6,'min');
     //        $val->setRule('afterDate','10/10/2010','10/10/2011','date');
     //        $val->setRule('required','',null,'username')->validate();
     //var_dump($val->getErrors());
     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();
 }