AppadminbaseBlock.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecshop\app\appadmin\modules;
  10. use fec\helpers\CUrl;
  11. use fec\helpers\CRequest;
  12. use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockInterface;
  13. use Yii;
  14. use yii\base\BaseObject;
  15. /**
  16. * @author Terry Zhao <2358269014@qq.com>
  17. * @since 1.0
  18. */
  19. class AppadminbaseBlock extends BaseObject
  20. {
  21. /**
  22. * parameter storage front passed.
  23. */
  24. public $_param = [];
  25. /**
  26. * fecshop service.
  27. */
  28. public $_service;
  29. /**
  30. * default pages number.
  31. */
  32. public $_pageNum = 1;
  33. /**
  34. * collection default number displayed.
  35. */
  36. public $_numPerPage = 50;
  37. /**
  38. * collection primary key.
  39. */
  40. public $_primaryKey;
  41. /**
  42. * collection sort direction , the default value is 'desc'.
  43. */
  44. public $_sortDirection = 'desc';
  45. /**
  46. * collection sort field , the default value is primary key.
  47. */
  48. public $_orderField;
  49. public $_asArray = true;
  50. /**
  51. * current url with param,like http://xxx.com?p=3&sort=desc.
  52. */
  53. public $_currentParamUrl;
  54. /**
  55. * current url with no param,like http://xxx.com.
  56. */
  57. public $_currentUrlKey;
  58. /**
  59. * data edit url, if you not set value ,it will be equal to current url.
  60. */
  61. public $_editUrl;
  62. /**
  63. * data delete url, if you not set value ,it will be equal to current url.
  64. */
  65. public $_deleteUrl;
  66. public $_currentUrl;
  67. /**
  68. * it will be execute during initialization ,the following object variables will be initialize.
  69. * $_primaryKey , $_param , $_currentUrl ,
  70. * $_currentParamUrl , $_addUrl , $_editUrl,
  71. * $_deleteUrl.
  72. */
  73. public function init()
  74. {
  75. if (!($this instanceof AppadminbaseBlockInterface)) {
  76. echo 'Managere must implements fecshop\app\appadmin\interfaces\base\AppadminbaseBlockInterface';
  77. exit;
  78. }
  79. $param = CRequest::param();
  80. $this->_primaryKey = $this->_service->getPrimaryKey();
  81. if (empty($param['pageNum'])) {
  82. $param['pageNum'] = $this->_pageNum;
  83. }
  84. if (empty($param['numPerPage'])) {
  85. $param['numPerPage'] = $this->_numPerPage;
  86. }
  87. if (empty($param['orderField'])) {
  88. $param['orderField'] = $this->_primaryKey;
  89. }
  90. if (empty($param['orderDirection'])) {
  91. $param['orderDirection'] = $this->_sortDirection;
  92. }
  93. if (is_array($param) && !empty($param)) {
  94. $this->_param = array_merge($this->_param, $param);
  95. }
  96. $currentUrl = CUrl::getCurrentUrlNoParam();
  97. $this->_currentParamUrl = CUrl::getCurrentUrl();
  98. $this->_editUrl = $this->_editUrl ? $this->_editUrl : $currentUrl;
  99. $this->_deleteUrl = $this->_deleteUrl ? $this->_deleteUrl : $currentUrl;
  100. }
  101. /**
  102. * generate pager form html, it is important to j-ui js framework, which will storage current request param as hidden way.
  103. * @return $str|string , html format string.
  104. */
  105. public function getPagerForm()
  106. {
  107. $str = '';
  108. if (is_array($this->_param) && !empty($this->_param)) {
  109. foreach ($this->_param as $k=>$v) {
  110. if ($k != '_csrf') {
  111. $str .= '<input type="hidden" name="'.$k.'" value="'.$v.'">';
  112. }
  113. }
  114. }
  115. return $str;
  116. }
  117. /**
  118. * @param $data|Array, it was return by defined function getSearchArr();
  119. * generate search section html,
  120. */
  121. public function getSearchBarHtml($data)
  122. {
  123. if (is_array($data) && !empty($data)) {
  124. $r_data = [];
  125. $i = 0;
  126. foreach ($data as $k=>$d) {
  127. $type11 = $d['type'];
  128. if ($type11 == 'select') {
  129. $value = $d['value'];
  130. $name = $d['name'];
  131. $title = $d['title'];
  132. $d['value'] = $this->getSearchBarSelectHtml($name, $value, $title);
  133. } elseif ($type11 == 'chosen_select') {
  134. $i++;
  135. $value = $d['value'];
  136. $name = $d['name'];
  137. $title = $d['title'];
  138. $d['value'] = $this->getSearchBarChosenSelectHtml($name, $value, $title, $i);
  139. }
  140. $r_data[$k] = $d;
  141. }
  142. }
  143. $searchBar = $this->getDbSearchBarHtml($r_data);
  144. return $searchBar;
  145. }
  146. /**
  147. * @param $name|string , html code select name.
  148. * @param $data|Array, select options key and value.
  149. * @param $title|string , select title , as select default display.
  150. * generate html select code .
  151. * @return String, select html code.
  152. */
  153. public function getSearchBarSelectHtml($name, $data, $title)
  154. {
  155. if (is_array($data) && !empty($data)) {
  156. $html_chosen_select = '<select class="combox" name="'.$name.'">';
  157. $html_chosen_select .= '<option value="">'.$title.'</option>';
  158. $selected = $this->_param[$name];
  159. if (is_array($selected)) {
  160. $selected = $selected['$regex'];
  161. }
  162. foreach ($data as $k=>$v) {
  163. if ($selected == $k) {
  164. $html_chosen_select .= '<option selected="selected" value="'.$k.'">'.$v.'</option>';
  165. } else {
  166. $html_chosen_select .= '<option value="'.$k.'">'.$v.'</option>';
  167. }
  168. }
  169. $html_chosen_select .= '</select>';
  170. return $html_chosen_select;
  171. } else {
  172. return '';
  173. }
  174. }
  175. /**
  176. * @param $name|string , html code select name.
  177. * @param $data|Array, select options key and value.
  178. * @param $title|string , select title , as select default display.
  179. * @param $id|int , use for chosen select config, if you use this function muilt times , $id must be unique in each time
  180. * 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.
  181. * generate html select code .
  182. * @return String, chosen select html code.
  183. */
  184. public function getSearchBarChosenSelectHtml($name, $data, $title, $id = 1)
  185. {
  186. if (is_array($data) && !empty($data)) {
  187. $html_chosen_select .= '<script type="text/javascript">
  188. var config = {
  189. \'.chosen-select'.$id.'\' : {},
  190. \'.chosen-select'.$id.'-deselect\' : {allow_single_deselect:true},
  191. \'.chosen-select'.$id.'-no-single\' : {disable_search_threshold:10},
  192. \'.chosen-select'.$id.'-no-results\': {no_results_text:\'Oops, nothing found!\'},
  193. \'.chosen-select'.$id.'-width\' : {width:"95%"}
  194. }
  195. for (var selector in config) {
  196. $(selector).chosen(config[selector]);
  197. }
  198. </script>
  199. ';
  200. $html_chosen_select .= '<select data-placeholder="Your Favorite Type of Bear" class="chosen-select'.$id.'" tabindex="7" name="'.$name.'">';
  201. $html_chosen_select .= '<option value="">'.$title.'</option>';
  202. $selected = $this->_param[$name];
  203. if (is_array($selected)) {
  204. $selected = $selected['$regex'];
  205. }
  206. foreach ($data as $k=>$v) {
  207. if ($k) {
  208. if ($selected == $k) {
  209. $html_chosen_select .= '<option selected value="'.$k.'">'.$v.'</option>';
  210. } else {
  211. $html_chosen_select .= '<option value="'.$k.'">'.$v.'</option>';
  212. }
  213. }
  214. }
  215. $html_chosen_select .= '</select>';
  216. return $html_chosen_select;
  217. } else {
  218. return '';
  219. }
  220. }
  221. /**
  222. * custom html code at the end of Search Bar.
  223. * your can rewrite this function in your block class.
  224. */
  225. public function customSearchBarHtml()
  226. {
  227. return '';
  228. }
  229. /**
  230. * @param $data|array
  231. */
  232. public function getDbSearchBarHtml($data)
  233. {
  234. $searchBar = '';
  235. if (!empty($data)) {
  236. $searchBar .= '<input type="hidden" name="search_type" value="search" />';
  237. $searchBar .= '<table class="searchContent">
  238. <tr>';
  239. foreach ($data as $d) {
  240. $type = $d['type'];
  241. $name = $d['name'];
  242. $title = $d['title'];
  243. $value = $d['value'];
  244. if ($d['type'] == 'select') {
  245. $searchBar .= '<td>
  246. '.$value.'
  247. </td>';
  248. } elseif ($d['type'] == 'chosen_select') {
  249. $searchBar .= '<td>
  250. '.$value.'
  251. </td>';
  252. } elseif ($d['type'] == 'inputtext') {
  253. $searchBar .= '<td>
  254. '.$title.':<input type="text" value="'.(is_array($this->_param[$name]) ? $this->_param[$name]['$regex'] : $this->_param[$name]).'" name="'.$name.'" />
  255. </td>';
  256. } elseif ($d['type'] == 'inputdate') {
  257. $searchBar .= '<td>
  258. '.$title.'<input type="text" value="'.$this->_param[$name].'" name="'.$name.'" class="date" readonly="true" />
  259. </td>';
  260. } elseif ($d['type'] == 'inputdatefilter') {
  261. $value = $d['value'];
  262. if (is_array($value)) {
  263. foreach ($value as $t=>$title) {
  264. $searchBar .= '<td>
  265. '.$title.'<input type="text" value="'.$this->_param[$name.'_'.$t].'" name="'.$name.'_'.$t.'" class="date" readonly="true" />
  266. </td>';
  267. }
  268. }
  269. } elseif ($d['type'] == 'inputfilter') {
  270. $value = $d['value'];
  271. if (is_array($value)) {
  272. foreach ($value as $t=>$title) {
  273. $searchBar .= '<td>
  274. '.$title.'<input type="text" value="'.$this->_param[$name.'_'.$t].'" name="'.$name.'_'.$t.'" />
  275. </td>';
  276. }
  277. }
  278. }
  279. }
  280. $customSearchHtml = $this->customSearchBarHtml();
  281. $searchBar .= $customSearchHtml;
  282. $searchBar .= '</tr>
  283. </table>
  284. <div class="subBar">
  285. <ul>
  286. <li><div class="buttonActive"><div class="buttonContent"><button type="submit">
  287. '.Yii::$service->page->translate->__('Search').'
  288. </button></div></div></li>
  289. <!-- <li><a class="button" href="#" target="dialog" mask="true" title="查询框"><span>高级检索</span></a></li> -->
  290. </ul>
  291. </div>';
  292. }
  293. return $searchBar;
  294. }
  295. /**
  296. * get search bar html code.
  297. */
  298. public function getSearchBar()
  299. {
  300. $data = $this->getSearchArr();
  301. return $this->getSearchBarHtml($data);
  302. }
  303. /**
  304. * @param $searchArr|Array.
  305. * generate where Array by $this->_param and $searchArr.
  306. * foreach $searchArr , check each one if it is exist in this->_param.
  307. */
  308. public function initDataWhere($searchArr)
  309. {
  310. $where = [];
  311. foreach ($searchArr as $field) {
  312. $type = $field['type'];
  313. $name = $field['name'];
  314. $lang = $field['lang'];
  315. $columns_type = isset($field['columns_type']) ? $field['columns_type'] : '';
  316. if ($this->_param[$name] || $this->_param[$name.'_gte'] || $this->_param[$name.'_lt']) {
  317. if ($type == 'inputtext' || $type == 'select' || $type == 'chosen_select') {
  318. if ($columns_type == 'string') {
  319. if ($lang) {
  320. $langname = $name.'.'.\Yii::$service->fecshoplang->getDefaultLangAttrName($name);
  321. $where[] = ['like', $langname, $this->_param[$name]];
  322. } else {
  323. $val = $this->_param[$name];
  324. if($name == '_id'){
  325. $val = new \MongoDB\BSON\ObjectId($val);
  326. $where[] = [$name => $val];
  327. } else {
  328. $where[] = ['like', $name, $val];
  329. }
  330. }
  331. } elseif ($columns_type == 'int') {
  332. $where[] = [$name => (int) $this->_param[$name]];
  333. } elseif ($columns_type == 'float') {
  334. $where[] = [$name => (float) $this->_param[$name]];
  335. } elseif ($columns_type == 'date') {
  336. $where[] = [$name => $this->_param[$name]];
  337. } else {
  338. $where[] = [$name => $this->_param[$name]];
  339. }
  340. } elseif ($type == 'inputdatefilter') {
  341. $_gte = $this->_param[$name.'_gte'];
  342. $_lt = $this->_param[$name.'_lt'];
  343. if ($columns_type == 'int') {
  344. $_gte = strtotime($_gte);
  345. $_lt = strtotime($_lt);
  346. }
  347. if ($_gte) {
  348. $where[] = ['>=', $name, $_gte];
  349. }
  350. if ($_lt) {
  351. $where[] = ['<', $name, $_lt];
  352. }
  353. } elseif ($type == 'inputfilter') {
  354. $_gte = $this->_param[$name.'_gte'];
  355. $_lt = $this->_param[$name.'_lt'];
  356. if ($columns_type == 'int') {
  357. $_gte = (int) $_gte;
  358. $_lt = (int) $_lt;
  359. } elseif ($columns_type == 'float') {
  360. $_gte = (float) $_gte;
  361. $_lt = (float) $_lt;
  362. }
  363. if ($_gte) {
  364. $where[] = ['>=', $name, $_gte];
  365. }
  366. if ($_lt) {
  367. $where[] = ['<', $name, $_lt];
  368. }
  369. } else {
  370. $where[] = [$name => $this->_param[$name]];
  371. }
  372. }
  373. }
  374. //var_dump($where);
  375. return $where;
  376. }
  377. /**
  378. * get edit html bar, it contains add ,eidt ,delete button.
  379. */
  380. public function getEditBar()
  381. {
  382. /*
  383. if(!strstr($this->_currentParamUrl,"?")){
  384. $csvUrl = $this->_currentParamUrl."?type=export";
  385. }else{
  386. $csvUrl = $this->_currentParamUrl."&type=export";
  387. }
  388. <li class="line">line</li>
  389. <li><a class="icon csvdownload" href="'.$csvUrl.'" target="dwzExport" targetType="navTab" title="实要导出这些记录吗?"><span>导出EXCEL</span></a></li>
  390. */
  391. return '<ul class="toolBar">
  392. <li><a class="add" href="'.$this->_editUrl.'" target="dialog" height="680" width="1200" drawable="true" mask="true"><span>' . Yii::$service->page->translate->__('Add') . '</span></a></li>
  393. <li><a target="dialog" height="680" width="1200" drawable="true" mask="true" class="edit" href="'.$this->_editUrl.'?'.$this->_primaryKey.'={sid_user}" ><span>' . Yii::$service->page->translate->__('Update') . '</span></a></li>
  394. <li><a csrfName="' .CRequest::getCsrfName(). '" csrfVal="' .CRequest::getCsrfValue(). '" title="' . Yii::$service->page->translate->__('Are you sure you want to delete these records?') . '" target="selectedTodo" rel="'.$this->_primaryKey.'s" postType="string" href="'.$this->_deleteUrl.'" class="delete"><span>' . Yii::$service->page->translate->__('Batch Delete') . '</span></a></li>
  395. </ul>';
  396. }
  397. /**
  398. * list pager, it contains numPerPage , pageNum , totalNum.
  399. */
  400. public function getToolBar($numCount, $pageNum, $numPerPage)
  401. {
  402. return '<div class="pages">
  403. <span>' . Yii::$service->page->translate->__('Show') . '</span>
  404. <select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value})">
  405. <option '.($numPerPage == 2 ? 'selected' : '').' value="2">2</option>
  406. <option '.($numPerPage == 6 ? 'selected' : '').' value="6">6</option>
  407. <option '.($numPerPage == 20 ? 'selected' : '').' value="20">20</option>
  408. <option '.($numPerPage == 50 ? 'selected' : '').' value="50">50</option>
  409. <option '.($numPerPage == 100 ? 'selected' : '').' value="100">100</option>
  410. <option '.($numPerPage == 200 ? 'selected' : '').' value="200">200</option>
  411. </select>
  412. <span>' . Yii::$service->page->translate->__('Line, Total {numCount} Line', ['numCount' => $numCount]) . '</span>
  413. </div>
  414. <div class="pagination" targetType="navTab" totalCount="'.$numCount.'" numPerPage="'.$numPerPage.'" pageNumShown="10" currentPage="'.$pageNum.'"></div>
  415. ';
  416. }
  417. /**
  418. * list table thead.
  419. */
  420. public function getTableThead()
  421. {
  422. $table_th_bar = $this->getTableFieldArr();
  423. return $this->getTableTheadHtml($table_th_bar);
  424. }
  425. public function getTableTheadHtml($table_th_bar)
  426. {
  427. $table_th_bar = $this->getTableTheadArrInit($table_th_bar);
  428. $this->_param['orderField'] = $this->_param['orderField'] ? $this->_param['orderField'] : $this->_primaryKey;
  429. $this->_param['orderDirection'] = $this->_param['orderDirection'];
  430. foreach ($table_th_bar as $k => $field) {
  431. if ($field['orderField'] == $this->_param['orderField']) {
  432. $table_th_bar[$k]['class'] = $this->_param['orderDirection'];
  433. }
  434. }
  435. $str = '<thead><tr>';
  436. $str .= '<th width="22"><input type="checkbox" group="'.$this->_primaryKey.'s" class="checkboxCtrl"></th>';
  437. foreach ($table_th_bar as $b) {
  438. $width = $b['width'];
  439. $label = $b['label'];
  440. $orderField = $b['orderField'];
  441. $class = isset($b['class']) ? $b['class'] : '';
  442. $align = isset($b['align']) ? 'align="'.$b['align'].'"' : '';
  443. $str .= '<th width="'.$width.'" '.$align.' orderField="'.$orderField.'" class="'.$class.'">'.$label.'</th>';
  444. }
  445. $str .= '<th width="80" >' . Yii::$service->page->translate->__('Edit') . '</th>';
  446. $str .= '</tr></thead>';
  447. return $str;
  448. }
  449. public function getTableTheadArrInit($table_columns)
  450. {
  451. foreach ($table_columns as $field) {
  452. $d = [
  453. 'orderField' => $field['orderField'],
  454. // 'label' => $this->_obj->getAttributeLabel($field['orderField']) ,
  455. 'width' => $field['width'],
  456. 'align' => $field['align'],
  457. ];
  458. $d['label'] = $field['label'] ? $field['label'] : '';
  459. if (empty($d['label'])) {
  460. $d['label'] = $field['orderField'];
  461. }
  462. $table_th_bar[] = $d;
  463. }
  464. return $table_th_bar;
  465. }
  466. /**
  467. * list table body.
  468. */
  469. public function getTableTbody()
  470. {
  471. $searchArr = $this->getSearchArr();
  472. if (is_array($searchArr) && !empty($searchArr)) {
  473. $where = $this->initDataWhere($searchArr);
  474. }
  475. //var_dump($where);
  476. $filter = [
  477. 'numPerPage' => $this->_param['numPerPage'],
  478. 'pageNum' => $this->_param['pageNum'],
  479. 'orderBy' => [$this->_param['orderField'] => (($this->_param['orderDirection'] == 'asc') ? SORT_ASC : SORT_DESC)],
  480. 'where' => $where,
  481. 'asArray' => $this->_asArray,
  482. ];
  483. $coll = $this->_service->coll($filter);
  484. $data = $coll['coll'];
  485. $this->_param['numCount'] = $coll['count'];
  486. return $this->getTableTbodyHtml($data);
  487. }
  488. public function getTableTbodyHtml($data)
  489. {
  490. $fields = $this->getTableFieldArr();
  491. $str = '';
  492. $csrfString = CRequest::getCsrfString();
  493. foreach ($data as $one) {
  494. $str .= '<tr target="sid_user" rel="'.$one[$this->_primaryKey].'">';
  495. $str .= '<td><input name="'.$this->_primaryKey.'s" value="'.$one[$this->_primaryKey].'" type="checkbox"></td>';
  496. foreach ($fields as $field) {
  497. $orderField = $field['orderField'];
  498. $display = $field['display'];
  499. $translate = $field['translate'];
  500. $val = $one[$orderField];
  501. $display_title = '';
  502. if (isset($val)) {
  503. if (isset($field['display']) && !empty($field['display'])) {
  504. $display = $field['display'];
  505. $val = $display[$val] ? $display[$val] : $val;
  506. $display_title = $val;
  507. }
  508. if (isset($field['convert']) && !empty($field['convert'])) {
  509. $convert = $field['convert'];
  510. foreach ($convert as $origin =>$to) {
  511. if (strstr($origin, 'mongodate')) {
  512. if (isset($val->sec)) {
  513. $timestamp = $val->sec;
  514. if ($to == 'date') {
  515. $val = date('Y-m-d', $timestamp);
  516. } elseif ($to == 'datetime') {
  517. $val = date('Y-m-d H:i:s', $timestamp);
  518. } elseif ($to == 'int') {
  519. $val = $timestamp;
  520. }
  521. $display_title = $val;
  522. }
  523. } elseif (strstr($origin, 'date')) {
  524. if ($to == 'date') {
  525. $val = date('Y-m-d', strtotime($val));
  526. } elseif ($to == 'datetime') {
  527. $val = date('Y-m-d H:i:s', strtotime($val));
  528. } elseif ($to == 'int') {
  529. $val = strtotime($val);
  530. }
  531. $display_title = $val;
  532. } elseif ($origin == 'int') {
  533. if ($to == 'date') {
  534. $val = date('Y-m-d', $val);
  535. } elseif ($to == 'datetime') {
  536. $val = date('Y-m-d H:i:s', $val);
  537. } elseif ($to == 'int') {
  538. $val = $val;
  539. }
  540. $display_title = $val;
  541. } elseif ($origin == 'string') {
  542. if ($to == 'img') {
  543. $t_width = isset($field['img_width']) ? $field['img_width'] : '100';
  544. $t_height = isset($field['img_height']) ? $field['img_height'] : '100';
  545. $val = '<img style="width:'.$t_width.'px;height:'.$t_height.'px" src="'.$val.'" />';
  546. }
  547. }
  548. }
  549. }
  550. if (isset($field['lang']) && !empty($field['lang'])) {
  551. $val = Yii::$service->fecshoplang->getDefaultLangAttrVal($val, $orderField);
  552. }
  553. }
  554. if ($translate) {
  555. $val = Yii::$service->page->translate->__($val);
  556. }
  557. $str .= '<td><span title="'.$display_title.'">'.$val.'</span></td>';
  558. }
  559. $str .= '<td>
  560. <a title="' . Yii::$service->page->translate->__('Edit') . '" target="dialog" class="btnEdit" mask="true" drawable="true" width="1200" height="680" href="'.$this->_editUrl.'?'.$this->_primaryKey.'='.$one[$this->_primaryKey].'" ><i class="fa fa-pencil"></i></a>
  561. <a title="' . Yii::$service->page->translate->__('Delete') . '" target="ajaxTodo" href="'.$this->_deleteUrl.'?'.$this->_primaryKey.'='.$one[$this->_primaryKey].'" class="btnDel" csrfName="' .CRequest::getCsrfName(). '" csrfVal="' .CRequest::getCsrfValue(). '" ><i class="fa fa-trash-o"></i></a>
  562. </td>';
  563. $str .= '</tr>';
  564. }
  565. return $str;
  566. }
  567. /*
  568. example : getTableFieldArr
  569. detail refer function getTableTbodyHtml($data)。
  570. public function getTableFieldArr(){
  571. $table_th_bar = [
  572. [
  573. 'orderField' => '_id', # db columns
  574. 'label' => 'ID', # db columns display in table head
  575. 'width' => '40', # columns width in table list
  576. 'align' => 'center',# columns position in table list td
  577. ],
  578. [
  579. 'orderField' => 'keyword',
  580. 'label' => '关键字',
  581. 'width' => '110',
  582. 'align' => 'left',
  583. ],
  584. # select 选择类型 display 对应的是一个数组,通过key 对应值
  585. # 一般是状态,譬如 1 对应激活,2对应关闭等。
  586. [
  587. 'orderField' => 'unit',
  588. 'label' => '站点',
  589. 'width' => '110',
  590. 'align' => 'left',
  591. 'display' => CConfig::param("channel_type"), # Array
  592. ],
  593. # 图片类型:
  594. [
  595. 'orderField' => 'img',
  596. 'label' => '图片',
  597. 'width' => '110',
  598. 'align' => 'left',
  599. 'convert' => ['string' => 'img'],
  600. 'img_width' => '100', # 图片宽度
  601. 'img_height' => '100', # 图片高度
  602. ],
  603. [
  604. 'orderField' => 'created_at',
  605. 'label' => '创建时间',
  606. 'width' => '190',
  607. 'align' => 'center',
  608. //'convert' => ['datetime' =>'date'],
  609. # 把 datetime(Y-m-d H:i:s) 转化成datetime(Y-m-d)
  610. ],
  611. [
  612. 'orderField' => 'updated_at',
  613. 'label' => '更新时间',
  614. 'width' => '190',
  615. 'align' => 'center',
  616. 'convert' => ['datetime' =>'date'], # int date datetime 显示的转换
  617. ],
  618. [
  619. 'orderField' => 'updated_at',
  620. 'label' => '更新时间',
  621. 'width' => '190',
  622. 'align' => 'center',
  623. 'convert' => ['datetime' =>'int'], # datetime格式转换成时间戳
  624. ],
  625. ];
  626. return $table_th_bar ;
  627. }
  628. */
  629. }