PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/core/include/core/action.finder_lister.php

http://phpfor.googlecode.com/
PHP | 144 lines | 125 code | 19 blank | 0 comment | 29 complexity | 54a7b2e9aa264c999139eb218e7f549a MD5 | raw file
  1. <?php
  2. if(!function_exists('type_modifier_date')){
  3. require(CORE_INCLUDE_DIR.'/modifiers.php');
  4. }
  5. function action_finder_lister(&$controller){
  6. $finder = &$controller->_vars['_finder'];
  7. $object = &$controller->model;
  8. if($_GET['act']!='recycleIndex' && ($views=$controller->_views())){
  9. $finder['views'] = array_keys($views);
  10. if(!$_GET['view']){
  11. $_GET['view'] = 0;
  12. }
  13. $finder['params'] = array_merge((array)$finder['params'],(array)$views[$finder['views'][$_GET['view']+0]]);
  14. }
  15. if($_GET['p']&&get_class($controller)==='ctl_articles'){
  16. $finder['params'] = array('node_id'=>$_GET['p'][0]);
  17. }
  18. if($finder['current_view'] = $_POST['lister']){
  19. $controller->system->set_op_conf('lister.'.$controller->object,$finder['current_view']);
  20. }else{
  21. $finder['current_view'] = $controller->system->get_op_conf('lister.'.$controller->object);
  22. }
  23. if(!$finder['current_view']){
  24. $finder['current_view'] = $controller->default_lister;
  25. }
  26. $cols = $finder['listViews'][$finder['current_view']]['cols'];
  27. if(!$cols){
  28. $cols = $controller->system->get_op_conf('view.'.$controller->object);
  29. }
  30. if(!$cols) $cols = $controller->finder_default_cols?$controller->finder_default_cols:$object->defaultCols;
  31. if(isset($_POST['_finder']['orderBy'])){
  32. $finder['order'] = array($_POST['_finder']['orderBy'],$_POST['_finder']['orderType']);
  33. }else{
  34. $finder['order'] = $object->defaultOrder;
  35. }
  36. if(isset($_POST['plimit']) && $_POST['plimit']){
  37. $controller->system->set_op_conf('lister.pagelimit',$_POST['plimit']);
  38. $finder['plimit'] = $_POST['plimit'];
  39. }else{
  40. $finder['plimit'] = $controller->system->get_op_conf('lister.pagelimit');
  41. if(!$finder['plimit'])$finder['plimit'] = 20;
  42. }
  43. $finder['plimit_in_sel'] = array(100,50,20,10);
  44. $finder['count'] = $object->count($finder['params']);
  45. $totalPages = ceil($finder['count']/$finder['plimit']);
  46. $page=$_GET['page']?$_GET['page']:1;
  47. if($page <0 || ($page >1 && $page > $totalPages)){
  48. $page = 1;
  49. }
  50. $allCols = &$object->getColumns($finder['params']);
  51. if($object->hasTag){
  52. $allCols = array_merge(array('_tag_'=>array('label'=>__('? &#x2021;筞'),'width'=>150,'noOrder'=>true)),$allCols);
  53. }
  54. $modifiers = array();
  55. $col_width_set = $object->system->get_op_conf('colwith.'.$_GET['ctl']);
  56. $type_modifier = array();
  57. $key_modifier = array();
  58. $object_modifier = array();
  59. foreach(explode(',',$cols) as $col){
  60. if($col=='_cmd' && $_GET['act']=='recycleIndex'){
  61. continue;
  62. }
  63. if(isset($allCols[$col])){
  64. $colArray[$col] = &$allCols[$col];
  65. if($allCols[$col]['escape_html']){
  66. $escape_html[$col] = array();
  67. }
  68. if(method_exists($object,'modifier_'.$col)){
  69. $key_modifier[$col] = array();
  70. }elseif(substr($colArray[$col]['type'],0,7)=='object:'){
  71. $object_modifier[$colArray[$col]['type']] = array();
  72. }elseif(function_exists('type_modifier_'.$colArray[$col]['type'])){
  73. $type_modifier[$colArray[$col]['type']] = array();
  74. }
  75. if(isset($col_width_set[$col]))$colArray[$col]['width'] = $col_width_set[$col];
  76. if($allCols[$col]['html']){
  77. $sql[] = '1 as '.$col;
  78. $allCols[$col]['readonly'] = 1;
  79. }elseif(isset($allCols[$col]['sql'])){
  80. $sql[] = $allCols[$col]['sql'].' as '.$col;
  81. }elseif($col=='_tag_'){
  82. $sql[] = $object->idColumn.' as _tag_';
  83. }else{
  84. $sql[] = $col;
  85. }
  86. }
  87. }
  88. if(!isset($colArray[$object->idColumn])) array_unshift($sql,$object->idColumn);
  89. if($finder['params']===-1){
  90. $list = array();
  91. }else{
  92. set_error_handler('object_finder_errhandler',E_USER_WARNING);
  93. $GLOBALS['last_error'] = null;
  94. $list = $object->getList(implode(',',$sql),$finder['params'],($page-1)*$finder['plimit'],$finder['plimit'],$finder['order']);
  95. restore_error_handler();
  96. if($GLOBALS['last_error']){
  97. $controller->_vars['sql_error'] = $GLOBALS['last_error'];
  98. $controller->_vars['items'] = false;
  99. }elseif($list===false){
  100. $controller->_vars['items'] = false;
  101. }elseif($list){
  102. if(!function_exists('object_cols_type')) require(CORE_INCLUDE_DIR.'/core/object.cols.type.php');
  103. object_cols_type($list, $colArray, $key_modifier, $object_modifier, $type_modifier, $object,'col',$escape_html);
  104. }
  105. $controller->_vars['items'] = array(
  106. 'list'=>&$list,
  107. 'cols'=>&$colArray,
  108. );
  109. $finder['detail_url'] = method_exists($controller,'_detail');
  110. $finder['pager'] = array(
  111. 'current'=> $page,
  112. 'total'=> ceil($finder['count']/$finder['plimit']),
  113. 'link'=> 'javascript:'.$finder['var'].'.page(_PPP_)',
  114. 'token'=> '_PPP_'
  115. );
  116. }
  117. }
  118. function object_finder_errhandler($errno, $errstr, $errfile, $errline){
  119. restore_error_handler();
  120. if(strpos($errfile,'AloneDB.php')){
  121. $GLOBALS['last_error'] = $errstr;
  122. }else{
  123. return false;
  124. }
  125. }