コード例 #1
0
ファイル: Controller.php プロジェクト: xinix-technology/bono
 /**
  * Constructor
  *
  * @param [type] $app     [description]
  * @param [type] $baseUri [description]
  */
 public function __construct($app, $baseUri)
 {
     $this->app = $app;
     $this->request = $app->request;
     $this->response = $app->response;
     $this->baseUri = $baseUri;
     $exploded = explode('/', $baseUri);
     $clazz = $this->clazz = Inflector::classify(end($exploded));
     $controller = $this;
     $response = $this->response;
     $app->filter('controller', function () use($controller) {
         return $controller;
     });
     $app->filter('controller.name', function () use($clazz) {
         return $clazz;
     });
     $app->filter('controller.uri', function ($uri) use($controller, $app) {
         if (strpos($uri, ':id')) {
             $params = $app->router->getCurrentRoute()->getParams();
             $uri = str_replace(':id', $params['id'] ?: 'null', $uri);
         }
         return $controller->getBaseUri() . $uri;
     });
     $app->filter('controller.url', function ($uri) use($controller, $app) {
         return URL::site(f('controller.uri', $uri));
     });
     $app->filter('controller.urlWithQuery', function ($uri) use($controller, $app) {
         return f('controller.url', $uri) . ($app->environment['QUERY_STRING'] ? '?' . $app->environment['QUERY_STRING'] : '');
     });
     $app->filter('controller.redirectUrl', function ($uri) use($controller) {
         return $controller->getRedirectUri();
     });
     $app->hook('bono.controller.before', function ($options) use($app, $controller, $response) {
         $template = $controller->getTemplate($options['method']);
         $response->template($template);
     });
     $app->hook('bono.controller.after', function ($options) use($app, $controller, $response) {
         $response->data($controller->data());
     });
     $this->mapRoute();
 }
コード例 #2
0
ファイル: productsHelper.php プロジェクト: rolka/antVel
 /**
  * countingProductsByCategory
  * Products total by category collection
  * @param  [type] $all_products refine products
  * @param  [type] $categories   refine categories
  * @return [array] filter used in the product list view menu
  */
 public static function countingProductsByCategory($all_products, $categories)
 {
     $filters = ['category' => []];
     foreach ($categories as $value) {
         $category_id = $value['id'];
         $childs = \Cache::remember('progeny_of_' . $category_id, 15, function () use($category_id) {
             Category::progeny($category_id, $childs, ['id']);
             return $childs;
         });
         $all = $childs;
         $childs = [];
         foreach ((array) $all as $val) {
             $childs[] = $val['id'];
         }
         $qty = 0;
         if ($all_products) {
             $qty = $all_products->where('category_id', $category_id)->count();
             $qty += $all_products->filter(function ($item) use($childs) {
                 return in_array($item->category_id, $childs);
             })->count();
         }
         if ($qty) {
             $filters['category'][$category_id]['id'] = $category_id;
             $filters['category'][$category_id]['name'] = $value['name'];
             $filters['category'][$category_id]['qty'] = $qty;
         }
     }
     //Order by qty
     if (isset($filters['category'])) {
         $filters['category'] = collect($filters['category'])->sortByDesc('qty');
     }
     return $filters;
 }