示例#1
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get content images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
                 // Get content videos
                 $item->get_videos = static::lazy_load(function () use($item) {
                     return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'videos');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Casestudy::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get content accordions
                 $item->get_accordions = static::lazy_load(function () use($item) {
                     return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'accordions');
                 // Get content children
                 $item->get_seo = static::lazy_load(function () use($item) {
                     return Model_Seo::find_one_by_content_id($item->id);
                 }, $item->id, 'seo', 'object');
                 // Get related products
                 $item->get_related_products = static::lazy_load(function () use($item) {
                     $related = Model_Application_To_Related::find(function ($query) use($item) {
                         return $query->where('application_id', $item->id);
                     }, 'related_id');
                     if (!empty($related)) {
                         $related = '(' . implode(',', array_keys($related)) . ')';
                         return \Product\Model_Product::find(function ($query) use($related, $item) {
                             $query->where('id', 'IN', \DB::expr($related));
                             $query->where('id', '<>', $item->id);
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'related_products');
                 // Get hotspot images
                 $item->get_hotspot = static::lazy_load(function () use($item) {
                     $return = new \stdClass();
                     $return->images = Model_Application_Image::find_by_application_id($item->id);
                     return $return;
                 }, $item->id, 'hotspot', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
示例#2
0
 public function get_search_products($category_id = false)
 {
     // Override category_id if its a search
     $category_id = \Input::get('category_id', $category_id);
     $product_ids = array();
     // If we are viewing category products
     // We need to find all products from that and child categories
     if (\Input::get()) {
         if (\Input::get('status') != 'select') {
             if (is_numeric($category_id)) {
                 $category = \Product\Model_Category::find_one_by_id($category_id);
                 if ($category) {
                     \View::set_global('category', $category);
                     if ($category->all_products) {
                         $product_ids = array_keys($category->all_products);
                     }
                 }
             }
         }
     }
     // If we are filtering products by category and there is nothing found
     // We return empty array of products without even going to database
     if (empty($product_ids) && is_numeric($category_id)) {
         $items = array();
     } else {
         /************ Start generating query ***********/
         if (\Input::get()) {
             if (\Input::get('status') != 'select') {
                 $items = \Product\Model_Product::find(function ($query) use($product_ids) {
                     if (!empty($product_ids)) {
                         $query->where('id', 'in', $product_ids);
                     }
                     // Get search filters
                     foreach (\Input::get() as $key => $value) {
                         if (!empty($value) || $value == '0') {
                             switch ($key) {
                                 case 'title':
                                     $query->where($key, 'like', "%{$value}%")->or_where('code', 'like', "%{$value}%");
                                     break;
                                 case 'status':
                                     if (is_numeric($value)) {
                                         $query->where($key, $value);
                                     }
                                     break;
                                 case 'active_from':
                                     $date = strtotime($value);
                                     if ($date) {
                                         $query->where($key, '>=', $date);
                                     }
                                     break;
                                 case 'active_to':
                                     $date = strtotime($value);
                                     if ($date) {
                                         $query->where($key, '<=', $date);
                                     }
                                     break;
                             }
                         }
                     }
                     // Order query
                     $query->order_by('sort', 'asc');
                     $query->order_by('id', 'asc');
                 });
             }
         }
     }
     /************ End generating query ***********/
     // Reset to empty array if there are no result found by query
     if (empty($items)) {
         $items = array();
     }
     return array('items' => $items);
 }
示例#3
0
  <div class="blurb">
    <div class="container">
      <!-- Description -->
      <h2 class="blurb-title"><?php 
echo $item->description_full;
?>
</h2>
      <!-- EOF Description -->
    </div>
  </div>

  <?php 
// get active products
$products = \Product\Model_Product::find(function ($query) {
    $query->where('status', 1);
    $query->order_by('created_at', 'desc');
});
?>
  <div class="featured-products">
    <div class="container">
      <h2 class="featured-title">Products</h2>
      <div class="row">
        <?php 
$limit = 9;
$counter = 0;
foreach ($products as $product) {
    $counter++;
    if ($limit < $counter) {
        break;
    }
    ?>
示例#4
0
 public function get_search_items($item)
 {
     /************ Get non related infotabs ***********/
     $items = \Product\Model_Product::find(function ($query) use($item) {
         $related_ids = array();
         foreach ($item->related_products as $related) {
             array_push($related_ids, $related->id);
         }
         if (!empty($related_ids)) {
             $related_ids = '(' . implode(',', $related_ids) . ')';
             $query->where('id', 'NOT IN', \DB::expr($related_ids));
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     $item->not_related_products = $items ? $items : array();
     /************ End generating query ***********/
     foreach ($item->not_related_products as $item_key => $item_value) {
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         if (stripos($item_value->title, $value) === false) {
                             unset($item->not_related_products[$item_key]);
                         }
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             if ($item_value->status != $value) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             if ($item_value->active_from < $value) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             if ($item_value->active_to > $value) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                     case 'category_id':
                         if (is_numeric($value)) {
                             if (!array_key_exists($value, $item_value->categories)) {
                                 unset($item->not_related_products[$item_key]);
                             }
                         }
                         break;
                 }
             }
         }
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($item->not_related_products), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $item->not_related_products = array_slice($item->not_related_products, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('item' => $item, 'pagination' => $pagination, 'status' => $status);
 }