/** * Returns pre-formated data for Extjs grid with mac information * * Request must be Ajax * * $request may contain the following keys: * - query: json array (field name => value) * - mac: string mac * @return array json array('total'=>num elems, 'data'=>array(mac)) */ public function executeJsonGridQueryAll(sfWebRequest $request) { $isAjax = $request->isXmlHttpRequest(); if (!$isAjax) { return $this->redirect('@homepage'); } $macs = array(); $query = $this->getRequestParameter('query') ? json_decode($this->getRequestParameter('query'), true) : array(); $criteria = new Criteria(); foreach ($query as $key => $val) { $column = EtvaMacPeer::translateFieldName(sfInflector::camelize($key), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); $criteria->add($column, $val); } // filter by mac if ($this->getRequestParameter('mac')) { $mac = $this->getRequestParameter('mac'); $newCriterion = $criteria->getNewCriterion(EtvaMacPeer::MAC, $mac . '%', Criteria::LIKE); $criteria->add($newCriterion); } $mac_list = EtvaMacPeer::doSelect($criteria); if (!$mac_list) { $msg_i18n = $this->getContext()->getI18N()->__(EtvaMacPeer::_ERR_NOMACS_); $info = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); $error = $this->setJsonError($info); return $this->renderText($error); } foreach ($mac_list as $etva_mac) { $macs[] = $etva_mac->toArray(); } $final = array('total' => count($macs), 'data' => $macs); $result = json_encode($final); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); }