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 getLogin()
 {
     $result['title'] = 'Shop';
     View::make('user.login', $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 getEdit($id)
 {
     $result = array('city' => $this->city->getCity($id));
     $result['title'] = 'Edit city';
     $result['action'] = '/admin/city/' . $result['city']->id . '/edit';
     $result['submit'] = 'Edit';
     View::make('city.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 getAdd($id)
 {
     $result['title'] = 'Send Messages';
     /* @var $estate \Models\ViewModels\EstateViewModel */
     $estate = $this->estate->getEstate($id);
     $result['estateInfo'] = 'ID: ' . $estate->id . '; Category: ' . $estate->category . '; Type: ' . ($estate->ad_type == 1 ? 'For Sale' : 'For Rent') . '; City: ' . $estate->city . '; Location: ' . $estate->location . '; Price: ' . $estate->price . ' EUR';
     View::make('message.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 getAll()
 {
     $cart = array();
     if (Session::containKey('cart')) {
         $cart = Session::get('cart');
     }
     $result['title'] = 'Shop';
     $result['products'] = $this->getProductsFromCart($cart);
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     $result['user_cash'] = $this->user->getUserMoney(Auth::getUserId());
     View::make('cart', $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();
 }
예제 #6
0
                                <a href="<?php 
        echo Common::getBaseURL();
        ?>
/comment/delete/<?php 
        echo $c['id'];
        ?>
" class="btn btn-danger">Delete</a>
                            <?php 
    }
    ?>
                        </div>
                    <?php 
}
?>
                    <?php 
if (Auth::isAuth()) {
    ?>
                        <div class="thumbnail">
                            <div class="caption">
                                <?php 
    echo Form::open(array('action' => Common::getBaseURL() . '/product/' . $product['id'] . '/add/comment'));
    ?>
                                <?php 
    echo Form::textarea('', array('name' => 'content', 'placeholder' => 'Write here', 'rows' => '4', 'cols' => '100'));
    ?>
                                <?php 
    echo Form::submit(array('name' => 'submit', 'value' => 'Send', 'class' => 'btn btn-success'));
    ?>
                                <?php 
    echo Form::close();
    ?>
 public function dispatch()
 {
     $uri = $this->request->getURI();
     $uriParams = array_filter(explode('/', $uri), 'strlen');
     $controllerName = '';
     $controllerMethod = '';
     $paramsFromGET = array();
     foreach (Route::getRouters() as $route) {
         $paramsFromGET = array();
         if ($route['method'] != $_SERVER['REQUEST_METHOD']) {
             continue;
         }
         if (in_array('auth', explode('|', $route['details']['before']))) {
             if (!Auth::isAuth()) {
                 continue;
             }
         }
         if (!Auth::isUserInRole(array_filter(explode('|', $route['details']['roles']), 'strlen'))) {
             continue;
         }
         $routeParams = array_filter(explode('/', $route['url']), 'strlen');
         $nonRequiredFieldsForRoute = $this->getNonRequiredFieldsCount($routeParams);
         if (count($uriParams) < count($routeParams) - $nonRequiredFieldsForRoute || count($uriParams) > count($routeParams)) {
             continue;
         }
         for ($i = 0; $i < count($uriParams); $i++) {
             if (!Common::startsWith($routeParams[$i], '{') && !Common::endsWith($routeParams[$i], '}')) {
                 if ($uriParams[$i] != $routeParams[$i]) {
                     continue 2;
                 }
             } else {
                 if (!$this->isParameterValid($uriParams[$i], $routeParams[$i])) {
                     continue 2;
                 }
                 $paramName = $this->getParameterName($routeParams[$i]);
                 $paramsFromGET[$paramName] = $uriParams[$i];
             }
             if (count($uriParams) - 1 == $i) {
                 $controllerData = explode('@', $route['details']['use']);
                 $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $controllerData[0];
                 $controllerMethod = $controllerData[1];
                 break 2;
             }
         }
         $paramsFromGET = array();
         if (in_array('csrf', explode('|', $route['details']['before']))) {
             if (!CSRF::validateToken()) {
                 continue;
             }
         }
     }
     if ($controllerMethod === '') {
         if (App::getInstance()->getConfig()->app['enable_default_routing']) {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $uriParams[0] . 'Controller';
             $controllerMethod = $uriParams[1];
             $r = new \ReflectionMethod($controllerName, $controllerMethod);
             $params = $r->getParameters();
             $index = 2;
             foreach ($params as $param) {
                 $paramsFromGET[$param->name] = $uriParams[$index];
                 $index++;
             }
             for ($i = $index; $i < count($uriParams); $i++) {
                 $paramsFromGET[$i] = $uriParams[$i];
             }
         } else {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . App::getInstance()->getConfig()->app['default_controller'];
             $controllerMethod = App::getInstance()->getConfig()->app['default_method'];
         }
     }
     $requestInput = $this->bindDataToControllerMethod($paramsFromGET, $controllerName, $controllerMethod);
     $controller = new $controllerName();
     $controller = DependencyProvider::injectDependenciesToController($controller);
     call_user_func_array(array($controller, $controllerMethod), $requestInput);
     Session::setOldInput(InputData::getInstance()->getPost());
 }
 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();
 }
 /**
  * @return array
  */
 public function setUserFavorites()
 {
     $userFavorites = array();
     if (Auth::isAuth()) {
         $favorites = $this->user->getFavourites(Auth::getUserId());
         foreach ($favorites as $f) {
             $userFavorites[] = $f['estate_id'];
         }
     } else {
         $userFavorites = Session::get('favourites');
     }
     return is_array($userFavorites) ? $userFavorites : array();
 }
 public function getFavourites()
 {
     $result['title'] = 'User Favorites';
     $userFavourite = array();
     if (Auth::isAuth()) {
         $favorites = $this->user->getFavourites(Auth::getUserId());
         foreach ($favorites as $f) {
             $userFavourite[] = $f['estate_id'];
         }
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         $userFavourite = Session::get('favourites');
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     /* @var $estates \Models\ViewModels\EstateBasicViewModel[] */
     if (!empty($userFavourite)) {
         $estates = $this->estate->getFavoritesEstates($userFavourite);
         foreach ($estates as $estate) {
             $estate->image = EstateController::setEstateMainImage($estate);
             $estate->thumbnailName = EstateController::setImageThumb($estate->image);
         }
         $result['estates'] = $estates;
     } else {
         $result['estates'] = array();
     }
     View::make('user.favorites', $result);
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function getEdit($id)
 {
     $result = array('category' => $this->category->getCategory($id));
     $result['title'] = 'Shop';
     $result['action'] = '/category/edit/' . $result['category']['id'];
     $result['submit'] = 'edit';
     View::make('category.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();
 }