Exemplo n.º 1
0
 public function listType()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $start = Input::has('start') ? (int) Input::get('start') : 0;
     $length = Input::has('length') ? Input::get('length') : 10;
     $search = Input::has('search') ? Input::get('search') : [];
     $types = Type::select('types.id', 'types.image', 'types.name', 'types.description', 'types.order_no', 'parent.name as parent_name', 'types.active');
     if (!empty($search)) {
         foreach ($search as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             if ($key == 'active') {
                 if ($value == 'yes') {
                     $value = 1;
                 } else {
                     $value = 0;
                 }
                 $types->where('types.' . $key, $value);
             } else {
                 if ($key == 'parent_id') {
                     $types->where('types.' . $key, (int) $value);
                 } else {
                     $value = ltrim(rtrim($value));
                     $types->where('types.' . $key, 'like', '%' . $value . '%');
                 }
             }
         }
     }
     $count = $types->count();
     $order = Input::has('order') ? Input::get('order') : [];
     if (!empty($order)) {
         $columns = Input::has('columns') ? Input::get('columns') : [];
         foreach ($order as $value) {
             $column = $value['column'];
             if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) {
                 continue;
             }
             $types->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc');
         }
     }
     if ($length > 0) {
         $types = $types->skip($start)->take($length);
     }
     $arrtypes = $types->leftJoin('types as parent', 'types.parent_id', '=', 'parent.id')->get()->toArray();
     $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => Type::count(), 'recordsFiltered' => $count, 'data' => []];
     if (!empty($arrtypes)) {
         foreach ($arrtypes as $type) {
             $type['parent_name'] = is_null($type['parent_name']) ? 'No Parent' : $type['parent_name'];
             $arrReturn['data'][] = [++$start, $type['id'], $type['name'], $type['description'], $type['image'], $type['order_no'], $type['parent_name'], $type['active']];
         }
     }
     return $arrReturn;
 }
Exemplo n.º 2
0
 public function actionList()
 {
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     $list = array();
     $criteria = new CDbCriteria(array('order' => 'id ASC'));
     $types = new Type();
     $count = $types->count($criteria);
     $pager = new CPagination($count);
     $pager->pageSize = Yii::app()->params['postsPerPage'];
     $pager->setCurrentPage($page - 1);
     $pager->applyLimit($criteria);
     $list = $types->findAll($criteria);
     $this->render('list', array('r' => Yii::app()->request->baseUrl . '/', 'pages' => $pager, 'list' => $list));
 }
Exemplo n.º 3
0
 public function getType()
 {
     return View::make('branch.type')->with('type', Type::paginate())->with('count', Type::count());
 }