/** * Add infotabs to product * * @param $product_id = Product ID * */ public function action_infotab_list($produt_id = false) { if (!is_numeric($produt_id)) { \Response::redirect('admin/product/list'); } // Get news item to edit if (!($item = Model_Product::find_one_by_id($produt_id))) { \Response::redirect('admin/product/list'); } if (\Input::post()) { $add = \Input::post('infotabs.add', array()); $remove = \Input::post('infotabs.remove', array()); if (\Input::post('add', false)) { foreach ($add as $value) { $infotab = Model_Product_To_Infotabs::forge(array('infotab_id' => $value, 'product_id' => $item->id)); $infotab->save(); } \Messages::success('Info Tabs successfully added.'); } else { if (\Input::post('remove', false)) { foreach ($remove as $value) { $this->action_infotab_delete($value); } \Messages::success('Info Tabs successfully removed.'); } } if (\Input::is_ajax()) { echo \Messages::display('left', false); exit; } else { \Response::redirect(\Input::referrer(\Uri::create('admin/product/list'))); } } \View::set_global('title', 'Product Infotabs'); /************ Get non related infotabs ***********/ $items = Model_Infotab::find(function ($query) use($item) { $related_ids = array(); foreach ($item->infotabs as $infotab) { array_push($related_ids, $infotab->infotab_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_infotabs = $items ? $items : array(); \Theme::instance()->set_partial('content', $this->view_dir . 'infotabs_list')->set('product', $item); }
public function action_list() { \View::set_global('title', 'List Infotabs'); /************ Start generating query ***********/ $items = Model_Infotab::find(function ($query) { // Get search filters foreach (\Input::get() as $key => $value) { if (!empty($value) || $value == '0') { switch ($key) { case 'title': $query->where($key, 'like', "%{$value}%"); break; case 'status': if (is_numeric($value)) { $query->where($key, $value); } 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 (is_null($items)) { $items = array(); } // Initiate pagination $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null)); // Remove unwanted items, and show only required ones $items = array_slice($items, $pagination->offset, $pagination->per_page); \Theme::instance()->set_partial('content', $this->view_dir . 'list')->set('items', $items)->set('pagination', $pagination, false); }