/** * Adds a level into the breadcrumbs, converting service parameters in the link and extracting a label in help with SQL-query that is preliminary defined by $this->query. * @param int $level Zero or negative value as step downwards. * @param string $action Controller's action to link to. * @param string $label Label for breadcrumb. * @param bool $labelNonStatic Forces to make a query and use $label as postfix for the found label. * @return string A final breadcrumb label. * @throws AAException */ public function addLevel($level, $action, $label=null, $labelNonStatic=false) { if($level > 0) return; if($labelNonStatic || is_null($label)) { if(!isset($this->query->command->from) || !isset($this->query->command->select)) throw new AAException(Yii::t('AutoAdmin.errors', 'Breadcrumbs can be generated only after AABreadcrumbs->query->select()->from() initializing. Or use call with static label.')); if(!$this->query->command->where) //otherwise means a user set where by himself. { if($level == 0) { $bk = Yii::app()->request->getParam('bk'); } else { $bkp = Yii::app()->request->getParam('bkp'); if(!isset($bkp[abs($level)-1])) throw new AAException(Yii::t('AutoAdmin.errors', 'Incorrect breadcrumbs level.')); $bk = $bkp[abs($level)-1]; } if(is_null($bk) || !is_array($bk)) throw new AAException(Yii::t('AutoAdmin.errors', 'Auto-generation of the breadcrumbs can be done only with the default inside-controller navigation.')); $where = array('AND'); $params = array(); foreach($bk as $pk=>$pkValue) { $where[] = "{$pk}=:{$pk}"; $params[":{$pk}"] = $pkValue; } $this->query->where($where, $params); $this->query->command->limit(1); } $newLabel = $this->query->command->queryScalar(); $label = ($label && $labelNonStatic) ? "{$newLabel}. {$label}" : $newLabel; } if($level == 0) { $this->controller->breadcrumbs[] = $this->controller->pageTitle = AAHelperText::ucfirst($label).'. '.$this->controller->pageTitle; } else { $params = AAHelperUrl::uriToParamsArray(Yii::app()->request->getRequestUri()); if($params) { //Removing GET-params which relate to the current page $paramsToExclude = array('page', 'sortBy', 'searchBy', 'searchQ', 'msg', 'action', 'bk', 'bkp', 'id', 'foreign'); foreach($paramsToExclude as $param) { if(array_key_exists($param, $params)) unset($params[$param]); if(!$params) break; else { foreach($params as $key=>$value) { if(preg_match("/^{$param}\[/i", $key)) { unset($params[$key]); continue 2; } } } } } $link = "../{$action}/"; $bkp = Yii::app()->request->getParam('bkp', array()); if(isset($bkp[0])) { foreach($bkp as $pkLevel=>$pk) { if($pkLevel < abs($level)-1) continue; if($pkLevel==0) $paramBase = 'bk'; else $paramBase = 'bkp['.($pkLevel-1).']'; foreach($pk as $keyField=>$keyValue) { $params[$paramBase.'['.$keyField.']'] = $keyValue; } } } if($params) { $paramStr = ''; foreach($params as $param=>$value) $paramStr .= ($paramStr ? '&' : '?').$param.'='.$value; $link .= $paramStr; } $this->insertToPosition((count($this->controller->breadcrumbs)+$level), $label, $link); } $this->query->command->reset(); return $label; }
<?php $actionURL = AAHelperUrl::update($baseURL, array('searchQ', 'searchBy')); $getParams = AAHelperUrl::uriToParamsArray($actionURL); if($getParams) $actionURL = AAHelperUrl::update($actionURL, array_keys($getParams)); echo CHtml::form($actionURL, 'get', array('id'=>'search-panel')); foreach($getParams as $param=>$value) echo CHtml::hiddenField($param, $value); echo CHtml::label(Yii::t('AutoAdmin.common', 'Search').':', 'searchQ'); echo CHtml::textField('searchQ', (isset($searchOptions['query']) && !is_array($searchOptions['query']) ? $searchOptions['query'] : ''), array('id'=>'searchQ')); $inSearch = array(); $selectedIndex = null; foreach($fields as $k=>$field) { if(!empty($field->options['inSearch'])) { $inSearch[$k] = $field->label; if(!empty($searchOptions['field']) && $searchOptions['field']->name == $field->name) $selectedIndex = $k; } } echo CHtml::dropDownList('searchBy', $selectedIndex, $inSearch); echo CHtml::submitButton('OK', array('name'=>null, 'title'=>Yii::t('AutoAdmin.common', 'Search'))); echo CHtml::resetButton(Yii::t('AutoAdmin.common', 'Reset'), array('name'=>null, 'title'=>Yii::t('AutoAdmin.common', 'Reset'))); echo CHtml::closeTag('form'); ?>