/** * Clean array keys and values for later use in SQL * * @param array $arr * @return array */ protected function cleanArray(array $arr) { $clean = array(); foreach ($arr as $k => $v) { $key = jqGrid_Utils::checkAlphanum($k); if (is_object($v) and $v instanceof jqGrid_Data) { $val = strval($v); //no escaping on specififc field } else { $val = is_null($v) ? 'NULL' : $this->quote($v); } $clean[$key] = $val; } return $clean; }
/** * MAIN ACTION (3): Render grid * * $jq_loader->render('jq_example'); * * @param $extend name of javascript variable to extend PHP-rendered options * @param string $suffix suffix for grid_id. Use it if you need to set multiple grids on the same page * @return string final javascript */ public function render($extend = null, $suffix = null, $preloadParam = array()) { $data = array(); $data['extend'] = $extend; $data['suffix'] = $suffix ? jqGrid_Utils::checkAlphanum($suffix) : ''; $data['className'] = $this->className; $data['additional'] = isset($this->additional) ? $this->additional : array(); if (!empty($preloadParam) && is_array($preloadParam)) { foreach ($preloadParam as $k => $v) { $this->options['postData'][$k] = $v; } } //------------------ // Render ids //------------------ $this->grid_full_id = $this->grid_id . $data['suffix']; $data['id'] = $this->grid_full_id; $data['pager_id'] = $this->grid_id . $data['suffix'] . '_p'; //----------------- // Render colModel //----------------- foreach ($this->cols as $k => $c) { if (isset($c['unset']) and $c['unset']) { continue; } #Remove internal column properties $c = array_diff_key($c, array_flip($this->internals)); $colModel[] = $this->renderColumn($k, $c); } //----------------- // Render options //----------------- $opts = array('colModel' => $colModel, 'pager' => '#' . $data['pager_id']); #URL's $opts['url'] = $opts['editurl'] = $opts['cellurl'] = $this->renderGridUrl(); $data['options'] = $this->renderOptions(array_merge($this->default['options'], $opts, $this->options)); //----------------- // Render navigator //----------------- // Empty не ставить, если нужно скрыть панель - ставить null if (is_array($this->nav)) { if (is_array($this->nav)) { foreach ($this->nav as $k => $nav) { if (is_array($nav) && array_key_exists('group', $nav)) { $groups = is_array($nav["group"]) ? $nav["group"] : array($nav["group"]); if (!user_bo::grant($groups, false)) { unset($this->nav[$k]); } } else { continue; } } } $data['nav'] = $this->renderNav($this->nav); } //----------------- // Render context //----------------- if (!empty($this->context) && is_array($this->context)) { foreach ($this->context as $k => $con) { if (is_array($con) && array_key_exists('group', $con)) { if (!user_bo::grant(array($con["group"]), false)) { unset($this->context[$k]); } } else { continue; } } $data['context'] = $this->renderContext($this->context); } //----------------- // Compile the final string //----------------- return $this->renderComplete($data); }
/** * (Output) Perform searching based on input * Populates $this->where with SQL-expressions * * @return void */ protected function search() { foreach ($this->cols as $k => $c) { if (!isset($this->input[$k]) or $this->input[$k] === '') { continue; } #Preserve original input value $val = $this->input[$k]; if (is_array($val)) { foreach ($val as $kk => $vv) { jqGrid_Utils::checkAlphanum($kk); $val[$kk] = $this->searchCleanVal($vv); } } else { $val = $this->searchCleanVal($val); } //------------------ // Apply search operator //------------------ $callback = array($this, jqGrid_Utils::uscore2camel('searchOp', $c['search_op'])); if (!is_callable($callback)) { throw new jqGrid_Exception('Search operation ' . $c['search_op'] . ' is not defined'); } $wh = call_user_func($callback, $c, $val); if ($wh) { $this->where[] = $wh; } } }