public function convertSingleToArray($data) { // echo '<pre>'; // print_r($data); // echo '</pre>'; $catInfo = Utility::getCatInfo($data->getCatId()); $array = array(); $array['id'] = $data->getId(); $array['name'] = $data->getName(); $array['function'] = Utility::getMenuStoreInMenu($data->getId()); $array['desc'] = $data->getDescription(); $array['image'] = $data->getImage(); $array['catId'] = $catInfo->getName(); $array['cost'] = $data->getCost(); $array['taCost'] = $data->getTakeAwayCost(); $array['isCombo'] = Utility::getCombo(number_format($data->getIsCombo())); return $array; }
public function ajaxListAction() { $fields = array('id', 'name', 'cost', 'takeAwayCost', 'description', 'catId', 'isdelete'); $offset = $this->getDataTableQueryOffset(); $limit = $this->getDataTableQueryLimit(); $sortCol = $this->getDataTableQuerySortingColumn(); $sortDirection = $this->getDataTableQuerySortingDirection(); $search = $this->getDataTableQuerySearch(); $customWhere = ' c.isdelete = 0'; // WHERE conditions $customQuery = $this->customWhereSql($customWhere); $dqlWhere = $this->getDataTableWhereDql('c', $fields, $search, $customWhere); if (!empty($dqlWhere)) { $customQuery = ''; } // ORDERING $dqlOrder = $this->getDataTableOrderDql('c', $fields, $sortCol, $sortDirection); // DQL $dql = "SELECT c FROM Admin\\Entity\\Menu c "; // RESULTS $query = $this->getEntityManager()->createQuery($dql . $customQuery . $dqlWhere . $dqlOrder); //$parameter = array('isdelete'=>0); if (!empty($dqlWhere)) { $query->setParameter(':search', '%' . $search . '%'); } $results = $query->setMaxResults($limit)->setFirstResult($offset)->getResult(); // echo $query->getSQL(); // TOTAL RESULTS COUNT $countDql = "SELECT COUNT(c.id) FROM Admin\\Entity\\Menu c"; $count = $this->getEntityManager()->createQuery($countDql)->getSingleScalarResult(); $ret = array_map(function ($item) { $categoryInfo = Utility::getCatInfo($item->getCatId()); $formular = Utility::getMenuStoreInMenu($item->getId()); $linkEdit = '/admin/index/add/' . $item->getId(); $linkDelete = '/admin/index/delete/' . $item->getId(); $linkDetail = '/admin/index/detail/' . $item->getId(); return array('id' => $item->getId(), 'name' => $item->getName(), 'cost' => $item->getCost(), 'takeAwayCost' => $item->getTakeAWayCost(), 'description' => $item->getDescription(), 'catId' => $categoryInfo->getName(), 'formula' => $formular, 'action' => ' <a href="' . $linkDetail . '" class="btn btn-info"><i class="icon-edit-sign"></i></a> <a class="btn btn-primary" href="' . $linkEdit . '"><i class="icon-edit-sign"></i></a> <a id="' . $item->getId() . '" data-link="' . $linkDelete . '" data-id="' . $item->getId() . '" href="#" class="btn btn-danger btn-delete"><i class="icon-trash"></i></a>'); }, $results); return $this->getDataTableJsonResponse($ret, $count, $dqlWhere); }