* @since 1.0
*/
class AppadminbaseBlock extends Object{
/**
* parameter storage front passed.
*/
public $_param = [];
/**
* fecshop service
*/
public $_service;
/**
* default pages number
*/
public $_pageNum = 1;
/**
* collection default number displayed.
*/
public $_numPerPage = 50;
/**
* collection primary key.
*/
public $_primaryKey ;
/**
* collection sort direction , the default value is 'desc'.
*/
public $_sortDirection = 'desc';
/**
* collection sort field , the default value is primary key.
*/
public $_orderField ;
public $_asArray = true;
/**
* current url with param,like http://xxx.com?p=3&sort=desc
*/
public $_currentParamUrl;
/**
* current url with no param,like http://xxx.com
*/
public $_currentUrlKey;
/**
* data edit url, if you not set value ,it will be equal to current url.
*/
public $_editUrl;
/**
* data delete url, if you not set value ,it will be equal to current url.
*/
public $_deleteUrl;
public $_currentUrl;
/**
* it will be execute during initialization ,the following object variables will be initialize.
* $_primaryKey , $_param , $_currentUrl ,
* $_currentParamUrl , $_addUrl , $_editUrl,
* $_deleteUrl.
*/
public function init(){
if(!($this instanceof AppadminbaseBlockInterface)){
echo 'Managere must implements fecshop\app\appadmin\interfaces\base\AppadminbaseBlockInterface';
exit;
}
$param = \fec\helpers\CRequest::param();
$this->_primaryKey = $this->_service->getPrimaryKey();
if(empty($param['pageNum'])) $param['pageNum'] = $this->_pageNum ;
if(empty($param['numPerPage'])) $param['numPerPage'] = $this->_numPerPage ;
if(empty($param['orderField'])) $param['orderField'] = $this->_primaryKey ;
if(empty($param['orderDirection'])) $param['orderDirection'] = $this->_sortDirection ;
if(is_array($param) && !empty($param)){
$this->_param = array_merge($this->_param, $param) ;
}
$currentUrl = CUrl::getCurrentUrlNoParam();
$this->_currentParamUrl = CUrl::getCurrentUrl();
$this->_editUrl = $this->_editUrl ? $this->_editUrl : $currentUrl;
$this->_deleteUrl = $this->_deleteUrl ? $this->_deleteUrl : $currentUrl;
}
/**
* generate pager form html, it is important to j-ui js framework, which will storage current request param as hidden way.
* @return $str|String , html format string.
*/
public function getPagerForm(){
$str = "";
if(is_array($this->_param) && !empty($this->_param)){
foreach($this->_param as $k=>$v){
if($k != "_csrf"){
$str .='';
}
}
}
return $str;
}
/**
* @property $data|Array, it was return by defined function getSearchArr();
* generate search section html,
*/
public function getSearchBarHtml($data){
if(is_array($data) && !empty($data)){
$r_data = [];
$i = 0;
foreach($data as $k=>$d){
$type11 = $d['type'];
if($type11 == 'select'){
$value = $d['value'];
$name = $d['name'];
$title = $d['title'];
$d['value'] = $this->getSearchBarSelectHtml($name,$value,$title);
}else if($type11 == 'chosen_select'){
$i++;
$value = $d['value'];
$name = $d['name'];
$title = $d['title'];
$d['value'] = $this->getSearchBarChosenSelectHtml($name,$value,$title,$i);
}
$r_data[$k] = $d;
}
}
$searchBar = $this->getDbSearchBarHtml($r_data);
return $searchBar;
}
/**
* @property $name|String , html code select name.
* @property $data|Array, select options key and value.
* @property $title|String , select title , as select default display.
* generate html select code .
* @return String, select html code.
*/
public function getSearchBarSelectHtml($name,$data,$title){
if(is_array($data) && !empty($data)){
$html_chosen_select = '';
return $html_chosen_select;
}else{
return '';
}
}
/**
* @property $name|String , html code select name.
* @property $data|Array, select options key and value.
* @property $title|String , select title , as select default display.
* @property $id|Int , use for chosen select config, if you use this function muilt times , $id must be unique in each time
* for example ,first time use this function set $id = 1, next time ,you can set $id=2,because is must be unique in front html.
* generate html select code .
* @return String, chosen select html code.
*/
public function getSearchBarChosenSelectHtml($name,$data,$title,$id=1){
if(is_array($data) && !empty($data)){
$html_chosen_select .= '
';
$html_chosen_select .= '';
return $html_chosen_select;
}else{
return '';
}
}
/**
* custom html code at the end of Search Bar.
* your can rewrite this function in your block class.
*/
public function customSearchBarHtml(){
return '';
}
/**
* @property $data|Array
*/
public function getDbSearchBarHtml($data){
$searchBar = '';
if(!empty($data)){
$searchBar .= '';
$searchBar .='