'Common', 'header' => true), array('name' => 'Site Map', 'url' => array('controller' => 'maps', 'action' => 'view', 1)), array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')), array('name' => 'Leases', 'url' => array('controller' => 'leases', 'action' => 'index')), array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')), array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')), array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')), array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')), ); } function beforeRender() { $this->set('sidemenu', $this->sideMenuLinks()); } /************************************************************************** ************************************************************************** ************************************************************************** * action: jqGridData * - Fetches the actual data requested by jqGrid as XML */ function jqGridData() { // Grab a copy of the parameters that control this request $params = array(); if (isset($this->params['url']) && is_array($this->params['url'])) $params = $this->params['url']; // Do any preliminary setup necessary $this->jqGridDataSetup($params); // Get the top level model for this grid $model = $this->jqGridDataModel($params); // Establish the basic query and conditions $query = array_intersect_key($this->jqGridDataTables($params), array('link'=>1, 'contain'=>1)); $query['conditions'] = $this->jqGridDataConditions($params); // Get the number of records prior to pagination $count = $this->jqGridDataRecordCount($params, $model, $query); // Verify a few parameters and determine our starting row $limit = $params['rows']; $total = ($count < 0) ? 0 : ceil($count/$limit); $page = ($params['page'] <= 1) ? 1 : (($params['page'] > $total) ? $total : $params['page']); $start = $limit*$page - $limit; $sidx = isset($params['sidx']) ? $params['sidx'] : ''; $sord = isset($params['sord']) ? ' ' . $params['sord'] : ''; // Grab the actual records taking pagination into account $query['group'] = $model->alias . '.id'; $query['order'] = $sidx ? $sidx . $sord : null; $query['limit'] = $start . ', ' . $limit; $query['fields'] = $this->jqGridDataFields($params); $results = $this->jqGridDataRecords($params, $model, $query); // DEBUG PURPOSES ONLY $params['query'] = $query; // Finally, dump out the data $this->jqGridDataOutputHeader($params); echo "\n"; echo "\n"; $this->jqGridDataOutputSummary($params, $page, $total, $count); $this->jqGridDataOutputRecords($params, $model, $results); echo "\n"; // Call out to finalize everything $this->jqGridDataFinalize($params); } /************************************************************************** ************************************************************************** ************************************************************************** * virtual: jqGridData* functions * - These set up the context for the jqGrid data, and will * need to be overridden in the derived class for anything * other than the most basic of grids. */ function jqGridDataSetup(&$params) { // Assume we're debugging. // The actual jqGrid request will set this to false $debug = true; if (isset($this->passedArgs['debug'])) $debug = $this->passedArgs['debug']; $params['debug'] = $debug; if (!$debug) { $this->layout = null; $this->autoLayout = false; $this->autoRender = false; Configure::write('debug', '0'); } // Unserialize our complex structure of fields // This SHOULD be always set, except when debugging if (isset($params['fields'])) $fields = unserialize($params['fields']); else $fields = array($this->modelClass . '.id'); $params['fields_str'] = $params['fields']; $params['fields'] = $fields; // Establish some defaults before extracting params $params = array_merge(array('page' => 1, 'rows' => 20), $params); } function jqGridDataModel(&$params) { return $this->{$this->modelClass}; } function jqGridDataTables(&$params) { return array('contain' => false); } function jqGridDataConditions(&$params) { if (isset($params['_search']) && $params['_search'] === 'true') { $op = $params['searchOper']; $field = $params['searchField']; $string = $params['searchString']; } elseif (isset($params['filt']) && $params['filt']) { $op = 'bw'; $field = $params['filtField']; $string = $params['filtString']; } else { return array(); } $ops = array('eq' => array('op' => null, 'pre' => '', 'post' => ''), 'ne' => array('op' => '<>', 'pre' => '', 'post' => ''), 'lt' => array('op' => '<', 'pre' => '', 'post' => ''), 'le' => array('op' => '<=', 'pre' => '', 'post' => ''), 'gt' => array('op' => '>', 'pre' => '', 'post' => ''), 'ge' => array('op' => '>=', 'pre' => '', 'post' => ''), 'bw' => array('op' => 'LIKE', 'pre' => '', 'post' => '%'), 'ew' => array('op' => 'LIKE', 'pre' => '%', 'post' => ''), 'cn' => array('op' => 'LIKE', 'pre' => '%', 'post' => '%'), ); $op = $ops[$op]; $field .= $op['op'] ? ' '.$op['op'] : ''; $string = $op['pre'] . $string . $op['post']; return array($field => $string); } function jqGridDataFields(&$params) { return null; } function jqGridDataRecordCount(&$params, $model, $query) { return $model->find('count', $query); } function jqGridDataRecords(&$params, $model, $query) { return $model->find('all', $query); } function jqGridDataOutputHeader(&$params) { if ($params['debug']) { ob_start(); } else { header("Content-type: text/xml;charset=utf-8"); } } function jqGridDataOutputSummary(&$params, $page, $total, $records) { echo " \n"; echo " $page\n"; echo " $total\n"; echo " $records\n"; } function jqGridDataOutputRecords(&$params, $model, $records) { $model_alias = $model->alias; foreach ($records AS $record) { // Add the calculated fields (if any), to the model fields if (isset($record[0])) $record[$model_alias] += $record[0]; echo " \n"; foreach ($params['fields'] AS $field) { if (preg_match("/\./", $field)) { list($tbl, $col) = explode(".", $field); $data = $record[$tbl][$col]; } else { $data = $record[$model_alias][$field]; } // be sure to put text data in CDATA if (preg_match("/^\d*$/", $data)) echo " $data\n"; else echo " \n"; } echo " \n"; } } function jqGridDataFinalize(&$params) { if ($params['debug']) { $xml = ob_get_contents(); ob_end_clean(); $xml = preg_replace("/&/", "&", $xml); $xml = preg_replace("//", ">", $xml); echo ("\n
\n$xml\n
\n"); } } } ?>