Dotclear

Changeset 508:7dbb15fcd538 for inc/admin


Ignore:
Timestamp:
07/04/11 14:50:03 (14 years ago)
Author:
Tomtom33 <tbouron@…>
Branch:
formfilters
Message:

Added sort and order functionality in admin lists

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.pager.php

    r463 r508  
    100100     protected $core;         /// <b>object</b> dcCore object 
    101101     protected $id;           /// <b>string</b> ID of defined column 
     102     protected $alias;        /// <b>string</b> ID of defined column 
    102103     protected $title;        /// <b>string</b> Title of defined column 
    103104     protected $callback;     /// <b>array</b> Callback calls to display defined column 
    104      protected $html;         /// <b>string</b> Extra HTML for defined column 
    105      protected $visibility;   /// <b>boolean</b> Visibility of defined column 
     105     protected $html;         /// <b>array</b> Extra HTML for defined column 
    106106      
    107107     /** 
     
    109109      
    110110     @param    id        <b>string</b>       Column id 
     111     @param    alias     <b>string</b>       Column alias for SQL 
    111112     @param    title     <b>string</b>       Column title (for table headers) 
    112113     @param    callback  <b>array</b>        Column callback (used for display) 
    113      @param    html      <b>string</b>       Extra html (used for table headers) 
     114     @param    html      <b>array</b>        Extra html (used for table headers) 
     115     @param    sortable  <b>boolean</b>      Defines if the column can be sorted or not 
     116     @param    listable  <b>boolean</b>      Defines if the column can be listed or not 
    114117     @param    can_hide  <b>boolean</b>      Defines if the column can be hidden or not 
    115118     */ 
    116      public function __construct($id,$title,$callback,$html = null,$can_hide = true) 
     119     public function __construct($id,$alias,$title,$callback,$html = null,$sortable = true,$listable = true,$can_hide = true) 
    117120     { 
    118121          if (!is_string($id) || $id === '') { 
     
    124127          } 
    125128           
    126           if (is_null($html) || !is_string($html)) { 
    127                $html = ''; 
    128           } 
    129           if (!empty($html)) { 
    130                $html = ' '.$html; 
     129          if (is_null($html) || !is_array($html)) { 
     130               $html = array(); 
     131          } 
     132           
     133          if (!is_bool($sortable)) { 
     134               $sortable = true; 
     135          } 
     136           
     137          if (!is_bool($listable)) { 
     138               $listable = true; 
    131139          } 
    132140           
    133141          if (!is_bool($can_hide)) { 
    134142               $can_hide = true; 
     143          } 
     144           
     145          if (!is_string($alias) && $sortable) { 
     146               throw new Exception(__('Invalid column alias')); 
    135147          } 
    136148           
     
    162174           
    163175          $this->id = $id; 
     176          $this->alias = $alias; 
    164177          $this->title = $title; 
    165178          $this->callback = $callback; 
    166179          $this->html = $html; 
     180          $this->sortable = $sortable; 
     181          $this->listable = $listable; 
    167182          $this->can_hide = $can_hide; 
    168183          $this->visibility = true; 
     
    188203     public function setVisibility($visibility) 
    189204     { 
    190           if (is_bool($visibility)) { 
     205          if (is_bool($visibility) && $this->can_hide) { 
    191206               $this->visibility = $visibility; 
    192207          } 
     208          else { 
     209               $this->visibility = true; 
     210          } 
    193211     } 
    194212      
     
    201219     { 
    202220          return $this->visibility; 
     221     } 
     222      
     223     /** 
     224     Returns if the defined column can be sorted 
     225      
     226     @return   <b>boolean</b>      true if column is sortable, false otherwise 
     227     */ 
     228     public function isSortable() 
     229     { 
     230          return $this->sortable; 
     231     } 
     232      
     233     /** 
     234     Returns if the defined column can be listed 
     235      
     236     @return   <b>boolean</b>      true if column is listable, false otherwise 
     237     */ 
     238     public function isListable() 
     239     { 
     240          return $this->listable; 
    203241     } 
    204242      
     
    280318               $col_html = sprintf('<li class="line">%s</li>',$col_label.form::checkbox($col_id,1,$v->isVisible(),null,null,!$v->canHide())); 
    281319                
    282                array_push($list,$col_html); 
     320               if ($v->isListable()) { 
     321                    array_push($list,$col_html); 
     322               } 
    283323          } 
    284324           
     
    323363               foreach ($this->columns as $k => $v) { 
    324364                    if ($v->isVisible()) { 
    325                          $html_extra = $v->getInfo('html') != '' ? ' '.$v->getInfo('html') : ''; 
    326                          $html_block .= sprintf('<th scope="col"%s>%s</th>',$html_extra,$v->getInfo('title')); 
     365                         $title = $v->getInfo('title'); 
     366                         if ($v->isSortable()) { 
     367                              $title = sprintf('<a href="%2$s">%1$s</a>',$title,$this->getSortLink($v)); 
     368                         } 
     369                         $html_extra = ''; 
     370                         foreach ($v->getInfo('html') as $i => $j) { 
     371                              $html_extra = $i.'="'.implode(' ',$j).'"'; 
     372                         } 
     373                         $html_extra = !empty($html_extra) ? ' '.$html_extra : ''; 
     374                         $html_block .= sprintf('<th scope="col"%2$s>%1$s</th>',$title,$html_extra); 
    327375                    } 
    328376               } 
     
    358406      
    359407     @param    id        <b>string</b>       Column id 
     408     @param    alias     <b>string</b>       Column alias for SQL 
    360409     @param    title     <b>string</b>       Column title (for table headers) 
    361410     @param    callback  <b>array</b>        Column callback (used for display) 
    362411     @param    html      <b>string</b>       Extra html (used for table headers) 
     412     @param    sortable  <b>boolean</b>      Defines if the column can be sorted or not 
     413     @param    listable  <b>boolean</b>      Defines if the column can be listed or not 
    363414     @param    can_hide  <b>boolean</b>      Defines if the column can be hidden or not 
    364415     */ 
    365      protected function addColumn($id,$title,$callback,$html = null,$can_hide = true) 
     416     protected function addColumn($id,$alias,$title,$callback,$html = null,$sortable = true,$listable = true,$can_hide = true) 
    366417     { 
    367418          try { 
    368                $c = new adminGenericColumn($id,$title,$callback,$html,$can_hide); 
     419               if (is_null($html) || !is_array($html)) { 
     420                    $html = array(); 
     421               } 
     422               if (isset($_GET['sortby']) && $_GET['sortby'] === $alias && isset($_GET['order'])) { 
     423                    if (array_key_exists('class',$html)) { 
     424                         array_push($html['class'],$_GET['order']); 
     425                    } 
     426                    else { 
     427                         $html['class'] = array($_GET['order']); 
     428                    } 
     429               } 
     430               $c = new adminGenericColumn($id,$alias,$title,$callback,$html,$sortable,$listable,$can_hide); 
    369431               $this->columns[$id] = $c; 
    370432          } 
     
    411473                    $visibility = !array_key_exists($key,$_REQUEST) ? false : true; 
    412474               } 
    413                if (!$v->canHide()) { 
    414                     $visibility = true; 
    415                } 
    416475               $v->setVisibility($visibility); 
    417476               $user_pref[$k] = $visibility; 
     
    462521          return $caption; 
    463522     } 
     523      
     524     /** 
     525     Returns link to sort the defined column 
     526      
     527     @param    c         <b>adminGenericColumn</b>     Current column 
     528      
     529     @return   <b>string</b>       HTML link 
     530     */ 
     531     private function getSortLink($c) 
     532     { 
     533          $order = 'desc'; 
     534          if (isset($_GET['sortby']) && $_GET['sortby'] === $c->getInfo('alias')) { 
     535               if (isset($_GET['order']) && $_GET['order'] === 'desc') { 
     536                    $order = 'asc'; 
     537               } 
     538          } 
     539           
     540          $args = $_GET; 
     541          $args['sortby'] = $c->getInfo('alias'); 
     542          $args['order'] = $order; 
     543           
     544          array_walk($args,create_function('&$v,$k','$v=$k."=".$v;')); 
     545           
     546          $url = $_SERVER['PHP_SELF']; 
     547          $url .= '?'.implode('&amp;',$args); 
     548           
     549          return $url; 
     550     } 
    464551} 
    465552 
     
    475562     public function setColumns() 
    476563     { 
    477           $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); 
    478           $this->addColumn('date',__('Date'),array('adminPostList','getDate')); 
    479           $this->addColumn('datetime',__('Date and time'),array('adminPostList','getDateTime')); 
    480           $this->addColumn('category',__('Category'),array('adminPostList','getCategory')); 
    481           $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); 
    482           $this->addColumn('comment',__('Comments'),array('adminPostList','getComments')); 
    483           $this->addColumn('trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); 
    484           $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); 
     564          $this->addColumn('title','post_title',__('Title'),array('adminPostList','getTitle'),array('class' => array('maximal')),true,true,false); 
     565          $this->addColumn('date','post_dt',__('Date'),array('adminPostList','getDate')); 
     566          $this->addColumn('datetime','post_dt',__('Date and time'),array('adminPostList','getDateTime')); 
     567          $this->addColumn('category','cat_title',__('Category'),array('adminPostList','getCategory')); 
     568          $this->addColumn('author','user_id',__('Author'),array('adminPostList','getAuthor')); 
     569          $this->addColumn('comments','nb_comment',__('Comments'),array('adminPostList','getComments')); 
     570          $this->addColumn('trackbacks','nb_trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); 
     571          $this->addColumn('status','post_status',__('Status'),array('adminPostList','getStatus')); 
    485572     } 
    486573      
     
    599686     public function setColumns() 
    600687     { 
    601           $this->addColumn('title',__('Title'),array('adminPostMiniList','getTitle'),' class="maximal"',false); 
    602           $this->addColumn('date',__('Date'),array('adminPostList','getDate')); 
    603           $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); 
    604           $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); 
     688          $this->addColumn('title','post_title',__('Title'),array('adminPostMiniList','getTitle'),array('class' => array('maximal')),true,true,false); 
     689          $this->addColumn('date','post_dt',__('Date'),array('adminPostList','getDate')); 
     690          $this->addColumn('author','user_id',__('Author'),array('adminPostList','getAuthor')); 
     691          $this->addColumn('status','post_status',__('Status'),array('adminPostList','getStatus')); 
    605692     } 
    606693      
     
    627714     public function setColumns() 
    628715     { 
    629           $this->addColumn('title',__('Title'),array('adminCommentList','getTitle'),' class="maximal"',false); 
    630           $this->addColumn('date',__('Date'),array('adminCommentList','getDate')); 
    631           $this->addColumn('author',__('Author'),array('adminCommentList','getAuthor')); 
    632           $this->addColumn('type',__('Type'),array('adminCommentList','getType')); 
    633           $this->addColumn('status',__('Status'),array('adminCommentList','getStatus')); 
    634           $this->addColumn('edit','',array('adminCommentList','getEdit')); 
     716          $this->addColumn('title','post_title',__('Title'),array('adminCommentList','getTitle'),array('class' => array('maximal')),true,true,false); 
     717          $this->addColumn('date','comment_dt',__('Date'),array('adminCommentList','getDate')); 
     718          $this->addColumn('author','comment_author',__('Author'),array('adminCommentList','getAuthor')); 
     719          $this->addColumn('type','comment_trackback',__('Type'),array('adminCommentList','getType')); 
     720          $this->addColumn('status','comment_status',__('Status'),array('adminCommentList','getStatus')); 
     721          $this->addColumn('edit',null,'',array('adminCommentList','getEdit'),null,false,false,false); 
    635722     } 
    636723      
     
    730817     public function setColumns() 
    731818     { 
    732           $this->addColumn('username',__('Username'),array('adminUserList','getUserName'),'class="maximal"',false); 
    733           $this->addColumn('firstname',__('First name'),array('adminUserList','getFirstName'),'class="nowrap"'); 
    734           $this->addColumn('lastname',__('Last name'),array('adminUserList','getLastName'),'class="nowrap"'); 
    735           $this->addColumn('displayname',__('Display name'),array('adminUserList','getDisplayName'),'class="nowrap"'); 
    736           $this->addColumn('entries',__('Entries'),array('adminUserList','getEntries'),'class="nowrap"'); 
     819          $this->addColumn('username','U.user_id',__('Username'),array('adminUserList','getUserName'),array('class' => array('maximal')),true,true,false); 
     820          $this->addColumn('firstname','user_firstname',__('First name'),array('adminUserList','getFirstName'),array('class' => array('nowrap'))); 
     821          $this->addColumn('lastname','user_name',__('Last name'),array('adminUserList','getLastName'),array('class' => array('nowrap'))); 
     822          $this->addColumn('displayname','user_displayname',__('Display name'),array('adminUserList','getDisplayName'),array('class' => array('nowrap'))); 
     823          $this->addColumn('entries','nb_post',__('Entries'),array('adminUserList','getEntries'),array('class' => array('nowrap'))); 
    737824     } 
    738825      
     
    797884     public function setColumns() 
    798885     { 
    799           $this->addColumn('blogname',__('Blog name'),array('adminBlogList','getBlogName'),'class="maximal"',false); 
    800           $this->addColumn('lastupdate',__('Last update'),array('adminBlogList','getLastUpdate'),'class="nowrap"'); 
    801           $this->addColumn('entries',__('Entries'),array('adminBlogList','getEntries'),'class="nowrap"'); 
    802           $this->addColumn('blogid',__('Blog ID'),array('adminBlogList','getBlogId'),'class="nowrap"'); 
    803           $this->addColumn('action','',array('adminBlogList','getAction'),'class="nowrap"'); 
    804           $this->addColumn('status',__('status'),array('adminBlogList','getStatus'),'class="nowrap"'); 
     886          $this->addColumn('blogname','UPPER(blog_name)',__('Blog name'),array('adminBlogList','getBlogName'),array('class' => array('maximal')),true,true,false); 
     887          $this->addColumn('lastupdate','blog_upddt',__('Last update'),array('adminBlogList','getLastUpdate'),array('class' => array('nowrap'))); 
     888          $this->addColumn('entries',null,__('Entries'),array('adminBlogList','getEntries'),array('class' => array('nowrap')),false); 
     889          $this->addColumn('blogid','B.blog_id',__('Blog ID'),array('adminBlogList','getBlogId'),array('class' => array('nowrap'))); 
     890          $this->addColumn('action',null,'',array('adminBlogList','getAction'),array('class' => array('nowrap'))); 
     891          $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap'))); 
    805892     } 
    806893      
     
    872959     public function setColumns() 
    873960     { 
    874           $this->addColumn('blogid',__('Blog ID'),array('adminBlogPermissionsList','getBlogId'),'class="nowrap"',false); 
    875           $this->addColumn('blogname',__('Blog name'),array('adminBlogPermissionsList','getBlogName'),'class="maximal"'); 
    876           $this->addColumn('entries',__('Entries'),array('adminBlogList','getEntries'),'class="nowrap"'); 
    877           $this->addColumn('status',__('status'),array('adminBlogList','getStatus'),'class="nowrap"'); 
     961          $this->addColumn('blogid','B.blog_id',__('Blog ID'),array('adminBlogPermissionsList','getBlogId'),array('class' => array('nowrap')),false,true,false); 
     962          $this->addColumn('blogname','UPPER(blog_name)',__('Blog name'),array('adminBlogPermissionsList','getBlogName'),array('class' => array('maximal')),false); 
     963          $this->addColumn('entries',null,__('Entries'),array('adminBlogList','getEntries'),array('class' => array('nowrap')),false); 
     964          $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap')),false); 
    878965     } 
    879966      
Note: See TracChangeset for help on using the changeset viewer.

Sites map