Dotclear

Changeset 1156:92f840a91f98


Ignore:
Timestamp:
04/26/13 16:23:16 (12 years ago)
Author:
Dsls <dsls@…>
Branch:
twig
Message:

Commented code, small tuning

Location:
inc/admin
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/class.dc.admincontext.php

    r1153 r1156  
    208208               'debug_info' => new Twig_Function_Method($this, 'getDebugInfo', array('is_safe' => array('html'))), 
    209209               'memorize' => new Twig_Function_Method($this, 'setMemory', array('is_safe' => array('html'))), 
    210                'memorized' => new Twig_Function_Method($this, 'getMemory', array('is_safe' => array('html'))) 
    211           ); 
    212      } 
    213       
     210               'memorized' => new Twig_Function_Method($this, 'getMemory', array('is_safe' => array('html'))), 
     211               'build_url' => new Twig_Function_Method($this,'buildUrl', array('is_safe' => array('html'))) 
     212          ); 
     213     } 
     214      
     215 
     216    /** 
     217     * Builds an url given a base, and parameters 
     218     *  
     219     * @param mixed $url    the base url as string 
     220     * @param mixed $params the parameters. 
     221     * 
     222     * @access public 
     223     * 
     224     * @return string the resulting url. 
     225     */ 
     226     public function buildUrl($url,$params=array()) { 
     227          if (is_array($url) && isset($url[0])) { 
     228               $base = $url[0]; 
     229               if (isset($url[1]) && is_array($url[1])) { 
     230                    $p = array_merge($params,$url[1]); 
     231               } 
     232          } else { 
     233               $base = $url; 
     234               $p=$params; 
     235          } 
     236          if (empty($p)) { 
     237               return $base; 
     238          } else { 
     239               return $base.'?'.http_build_query($p); 
     240          } 
     241     } 
     242 
    214243     /** 
    215244     Returns a list of global variables to add to the existing list. 
  • inc/admin/class.dc.filter.php

    r1154 r1156  
    1414 
    1515 
     16/** 
     17* dcFilterSet -- filter handling object 
     18* 
     19* @uses     dcForm 
     20* 
     21*/ 
    1622class dcFilterSet extends dcForm { 
    17      protected $filters;      /// <b>array</b> lists of currently applied filters 
     23     /** @var array list of variable filters */ 
     24     protected $filters; 
     25     /** @var array list of static filters */ 
    1826     protected $static_filters; 
     27     /** @var array list of all filters (union of the 2 previous props) */ 
    1928     protected $all_filters; 
    20      protected $form_prefix;       /// <b>string</b> displayed form prefix 
    21      protected $action;            /// <b>string</b> form action page 
    22      protected $hide_filterset;         /// <b>boolean</b> start form display hidden by default or not 
    23      protected $name;              /// <b>string</b> filterset name 
     29     /** @var string prefix to be used for all fields */ 
     30     protected $form_prefix; 
     31     /** @var string action to perform upon form submission */ 
     32     protected $action; 
     33     /** @var boolean start form display hidden by default or not */ 
     34     protected $hide_filterset; 
     35     /** @var string filterset name */ 
     36     protected $name; 
     37     /** @var dcCore dotclear core object */ 
    2438     protected $core; 
    2539 
     40    /** 
     41     * __init__ - class static initialiser (called at the very bottom of this 
     42     *                   page) 
     43     * 
     44     * @param mixed $env the twig environment. 
     45     * 
     46     * @access public 
     47     * @static 
     48     * 
     49     */ 
    2650     public static function __init__($env) { 
    27           $env->getExtension('dc_form')->addTemplate('@forms/formfilter_layout.html.twig'); 
     51          // filterset widgets are defined in a separate file 
     52          $env->getExtension('dc_form')->addTemplate( 
     53               '@forms/formfilter_layout.html.twig' 
     54          ); 
     55 
    2856          $env->addFunction( 
    2957               new Twig_SimpleFunction( 
     
    3664          ))); 
    3765     } 
    38       
    39      public static function renderFilterSet($env,$context,$name,$attributes=array()) 
    40      { 
    41           $context['filtersetname']=$name; 
    42           echo $env->getExtension('dc_form')->renderWidget( 
    43                'filterset', 
    44                $context 
    45           ); 
    46      } 
    47      /** 
    48      Inits dcFilterSet object 
    49       
    50      @param    core      <b>dcCore</b>       Dotclear core reference 
    51      @param    form_prefix    <b>string</b>       form prefix to use for parameters 
    52      */ 
    53      public function __construct($core,$name,$action,$form_prefix="f_") { 
     66 
     67    /** 
     68     * __construct -- constructor 
     69     * 
     70     * @param dcCore  $core       dotclear core instance. 
     71     * @param string  $name       filterset name. 
     72     * @param string  $action     form action. 
     73     * @param string $form_prefix form prefix. 
     74     * 
     75     * @access public 
     76     * 
     77     * @return mixed Value. 
     78     */ 
     79     public function __construct($core,$name,$action,$form_prefix="f_"){ 
    5480          $this->form_prefix=$form_prefix; 
    5581          $this->filters = new ArrayObject(); 
     
    6288     } 
    6389 
     90 
     91    /** 
     92     * renderFilterSet -- binding to twig function "filterset" 
     93     *                             renders a filterset given its name & context 
     94     * @param mixed $env        Twig environment (passed by Twig template). 
     95     * @param mixed $context    Context (passed by Twig template). 
     96     * @param mixed $name       filterset name. 
     97     * @param array $attributes filterset attributes. 
     98     * 
     99     * @access public 
     100     * @static 
     101     * 
     102     * @return mixed Value. 
     103     */ 
     104     public static function renderFilterSet($env,$context,$name, 
     105                                                     $attributes=array())  { 
     106          $context['filtersetname']=$name; 
     107          echo $env->getExtension('dc_form')->renderWidget( 
     108               'filterset', 
     109               $context 
     110          ); 
     111     } 
     112 
     113 
     114    /** 
     115     * setup - sets up the form filter from http context 
     116     * 
     117     * @access public 
     118     * 
     119     * @return mixed Value. 
     120     */ 
    64121     public function setup() { 
    65122          $form_combo = array(); 
     
    74131          $this 
    75132               ->addField ( 
    76                     new dcFieldCombo ($p.'add_filter','',$form_combo,array( 
    77                     ))) 
     133                    new dcFieldCombo ($p.'add_filter','',$form_combo, 
     134                         array())) 
    78135               ->addField ( 
    79                     new  dcFieldSubmit($p.'add',__('Add this filter'),array( 
    80                     ))) 
     136                    new  dcFieldSubmit($p.'add',__('Add this filter'), 
     137                         array())) 
    81138               ->addField ( 
    82                     new dcFieldSubmit($p.'clear_filters',__('Delete all filters'),array( 
    83                     ))) 
     139                    new dcFieldSubmit($p.'clear_filters',__('Delete all filters'), 
     140                         array())) 
    84141               ->addField ( 
    85                     new dcFieldSubmit($p.'apply',__('Apply filters and display options'),array( 
    86                     ))) 
     142                    new dcFieldSubmit($p.'apply', 
     143                         __('Apply filters and display options'), 
     144                         array())) 
    87145               ->addField ( 
    88                     new dcFieldSubmit($p.'reset',__('Reset'),array( 
    89                     ))) 
     146                    new dcFieldSubmit($p.'reset',__('Reset'), 
     147                         array())) 
    90148          ; 
    91149          $this->setupFields(); 
    92           /* Use cases : 
     150          /*  Since we have specific handling for actions 
     151              (for instance "del_*" fields), we do not take advantage of 
     152              submitfields features, actions are performed manually here. 
     153 
     154               Use cases : 
    93155               (1) $_POST not empty for formfilter fields : 
    94                     * efilters are set from $_POST 
    95                     * lfilters are set from $_GET 
     156                    * filters are set from $_POST 
     157                    * applied filters values are set from $_GET 
    96158                    * keep filters div shown 
    97159               (2) $_POST empty : 
    98                     * both efilters and lfilters are set from $_GET 
     160                    * both filters fields & applied values are set from $_GET 
    99161                    * hide filter div 
    100162          */ 
     
    102164          //$allowed_actions = array('clear_filters','add','del_.*','apply','reset'); 
    103165          $allowed_actions = '#^(clear_filters|add|del_.*|apply|reset)$#'; 
     166 
    104167          // Fetch each $_POST parameter to see whether filters are concerned. 
    105168          // Only 1 action at a time is allowed. 
    106  
    107169          foreach ($_POST as $k => $v) { 
    108170               if (strpos($k,$this->form_prefix)===0) { 
     
    119181               // Use case (1) 
    120182               if ($action != 'clear_filters' && $action != 'reset')  { 
     183                    // initialize fields from $_POST 
    121184                    $this->setupEditFilters($this->all_filters,$_POST); 
    122185                    if ($action == 'add'){ 
     186                         // Add a new filter 
    123187                         $fname = $p.'add_filter'; 
    124188                         if (isset($_POST[$fname]) 
    125189                              && isset($this->filters[$_POST[$fname]])) { 
    126                          $this->filters[$_POST[$fname]]->add(); 
     190                              $this->filters[$_POST[$fname]]->add(); 
    127191                         } 
    128192                         $this->hide_filterset = false; 
    129193                    } elseif (strpos($action,'del_') === 0) { 
     194                         // Remove a filter 
    130195                         $count = preg_match('#del_(.+)_([0-9]+)#',$action,$match); 
    131196                         if (($count == 1) && isset($this->filters[$match[1]])) { 
     
    134199                         $this->hide_filterset = false; 
    135200                    } elseif ($action=="apply") { 
     201                         // Apply all filters 
     202                         // ==> store filter to preferences and redirect to 
     203                         //     page with filter as $_GET attributes 
    136204                         $data = $this->saveFilters(); 
    137205                         $query = http_build_query($data,'','&'); 
     
    143211                    } 
    144212               } 
     213               // Form as been submitted with POST method, retrieve 
     214               // applied filter values from "query" field 
    145215               if (isset($_POST[$p."query"])) { 
    146216                    parse_str($_POST[$p."query"],$out); 
    147                     $this->setupAppliedFilters($this->all_filters,$out); 
     217                    $this->setupAppliedValues($this->all_filters,$out); 
    148218                    if ($action == 'reset') { 
     219                         // RESET action => set fields from query field 
    149220                         $this->setupEditFilters($this->all_filters,$out); 
    150221                    } elseif ($action == 'clear_filters') { 
     
    155226                    } 
    156227               } 
    157                 
    158228          } else { 
    159                // Use case (2) 
     229               // Use case (2) : GET method; set both filters and applied values 
     230               // from GET args or from settings if no GET args. 
    160231               $load_from_settings = true; 
    161232               foreach($_GET as $k=>$v) { 
     
    167238               $get = $_GET; 
    168239               if ($load_from_settings) { 
    169                     $get = new ArrayObject(array_merge($this->loadFilters(),$get)); 
     240                    $get = array_merge($this->loadFilters(),$get); 
    170241               } 
    171242               $this->setupEditFilters($this->all_filters,$get); 
    172243 
    173                $this->setupAppliedFilters($this->all_filters,$get); 
     244               $this->setupAppliedValues($this->all_filters,$get); 
    174245          } 
    175246          foreach ($this->static_filters as $f) { 
     
    178249               } 
    179250          } 
    180           $queryParams = $this->getAppliedFilters(); 
     251          $queryParams = $this->getAppliedFilterValues(); 
    181252          $this->addField( 
    182253               new dcFieldHidden($this->form_prefix.'query', 
    183254                    http_build_query($queryParams))); 
    184           $this->core->tpl->addGlobal('filterset_'.$this->name,$this->getContext()); 
     255          // form context is set through a global twig variable 
     256          $this->core->tpl->addGlobal( 
     257               'filterset_'.$this->name, 
     258               $this->getContext()); 
    185259     } 
    186260 
    187261     public function getURLParams() { 
    188           return $this->getAppliedFilters(); 
    189      } 
    190  
    191      /** 
    192      Saves user filters to preferences 
    193      */ 
     262          return $this->getAppliedFilterValues()->getArrayCopy(); 
     263     } 
     264 
     265    /** 
     266     * saveFilters - save user defined filters into preferences 
     267     * 
     268     * @access protected 
     269     */ 
    194270     protected function saveFilters() { 
    195271          $ser = array(); 
    196272          $ws = $GLOBALS['core']->auth->user_prefs->addWorkspace('filters'); 
    197           $data = new ArrayObject(); 
    198273          $data= $this->serialize(); 
    199274          $ws->put($this->name,serialize($data->getArrayCopy()),'string'); 
     
    201276     } 
    202277 
    203      /** 
    204      Loads user filters from preferences 
    205      */ 
     278    /** 
     279     * loadFilters - load user filters from preferences 
     280     * 
     281     * @access protected 
     282     * 
     283     * @return mixed Value. 
     284     */ 
    206285     protected function loadFilters() { 
    207286          $ws = $GLOBALS['core']->auth->user_prefs->addWorkspace('filters'); 
    208           $data = (!is_null($ws->{$this->name})) ? unserialize($ws->{$this->name}) : array(); 
     287          $data = (!is_null($ws->{$this->name})) 
     288               ? unserialize($ws->{$this->name}) 
     289               : array(); 
    209290          if (is_array($data)) 
    210291               return $data; 
     
    213294     } 
    214295 
    215      /** 
    216      Updates filters values according to form_data 
    217      To be called before any call to display() or getForm() 
    218       
    219      @param    form_data <b>array</b>   form values (usually $_GET or $_POST) 
    220      */ 
     296    /** 
     297     * setupEditFilters - Updates filters fields according to form_data 
     298     *                        To be called before any call to display() or getForm() 
     299     * 
     300     * @param array $filters   list of filters to update 
     301     * @param array $form_data form values (usually $_GET or $_POST) 
     302     * 
     303     * @access protected 
     304     * 
     305     * @return mixed Value. 
     306     */ 
    221307     protected function setupEditFilters ($filters,$form_data) { 
    222308          foreach ($filters as $filter) { 
     
    224310          } 
    225311     } 
    226      protected function setupAppliedFilters ($filters,$form_data) { 
     312 
     313    /** 
     314     * setupAppliedValues - Updates filters applied values according to 
     315     *                             form_data 
     316     * 
     317     * @param array $filters   list of filters to update 
     318     * @param array $form_data form values (usually $_GET or $_POST) 
     319     * 
     320     * @access protected 
     321     * 
     322     * @return mixed Value. 
     323     */ 
     324     protected function setupAppliedValues ($filters,$form_data) { 
    227325          foreach ($filters as $filter) { 
    228                $filter->setupAppliedFilter ($form_data); 
    229           } 
    230      } 
    231      /** 
    232      Retrieves the filters values as parameters 
    233       
    234      @param    filters   <b>array</b>   list of concerned filters 
    235       
    236      @return   <b>array</b>   the array of parameters 
    237  
    238      */ 
    239  
     326               $filter->setupAppliedValue ($form_data); 
     327          } 
     328     } 
     329 
     330    /** 
     331     * serialize - retrieves filter applied values in a serialized form 
     332     * 
     333     * @access protected 
     334     * 
     335     * @return ArrayObject serialized data. 
     336     */ 
    240337     protected function serialize() { 
    241338          $arr = new ArrayObject(); 
     
    250347          return $arr; 
    251348     } 
    252      /** 
    253      Adds a new filter to list 
    254       
    255      @param    filter         <b>dcFilter</b>          the filter to add 
    256      */ 
     349 
     350    /** 
     351     * addFilter - registers a new filter in filterset 
     352     * 
     353     * @param mixed \dcFilter the filter. 
     354     * 
     355     * @access public 
     356     * 
     357     * @return dcFilterSet the filterset (enabling to chain addFilter). 
     358     */ 
    257359     public function addFilter (dcFilter $filter) { 
    258360          $filter->setFormPrefix($this->form_prefix); 
     
    267369     } 
    268370 
     371    /** 
     372     * getContext - retrieves current filterset context 
     373     *                   (to be given to twig template) 
     374     * 
     375     * @access public 
     376     * 
     377     * @return array the context 
     378     */ 
    269379     public function getContext() { 
    270380          $fcontext = new ArrayObject(); 
     
    272382          foreach ($this->filters as $f) { 
    273383               if($f->isEnabled()) { 
    274                     $f->appendEditLines($fcontext); 
     384                    $f->appendFilterContext($fcontext); 
    275385               } 
    276386          } 
    277387          foreach ($this->static_filters as $f) { 
    278                $f->appendEditLines ($sfcontext); 
     388               $f->appendFilterContext($sfcontext); 
    279389          } 
    280390          return array( 
    281                'active_filters' => $fcontext,  
     391               'active_filters' => $fcontext, 
    282392               'static_filters' => $sfcontext, 
    283393               'hide_filters'  => $this->hide_filterset, 
     
    285395     } 
    286396 
    287      protected function getAppliedFilters() { 
     397    /** 
     398     * getAppliedFilterValues - retrieves the list of applied filter values 
     399     * 
     400     * @access protected 
     401     * 
     402     * @return ArrayObject the list of applied values 
     403     */ 
     404     protected function getAppliedFilterValues() { 
    288405          $arr = new ArrayObject(); 
    289406          foreach ($this->all_filters as $f) { 
     
    293410          return $arr; 
    294411     } 
    295      /** 
    296      Applies fieldset and return resulting parameters for request 
    297       
    298      @param    method    <b>string</b>       form method to use (default: "get") 
    299      @param    method    <b>string</b>       form method to use (default: "get") 
    300       
    301      */ 
     412 
     413    /** 
     414     * applyFilters -- applies filterset 
     415     * 
     416     * @param mixed $params the parameters to update. 
     417     * 
     418     * @access public 
     419     * 
     420     * @return mixed true if at least 1 filter has been applied, false otherwise 
     421     */ 
    302422     public function applyFilters($params) { 
    303423          foreach ($this->all_filters as $filter) { 
     
    310430     } 
    311431 
    312      public function getDelName($field_id,$pos) { 
    313           return $this->form_prefix.'del_'.$field_id.'_'.$pos; 
     432    /** 
     433     * buildFieldName -- builds a field name given a verb, an id and a position 
     434     *                        takes the form prefix into consideration 
     435     * @param mixed $verb     the verb to use (ex  : "del") 
     436     * @param mixed $field_id the field id 
     437     * @param mixed $pos      the field position 
     438     * 
     439     * @access public 
     440     * 
     441     * @return mixed the field name 
     442     */ 
     443     public function buildFieldName($verb,$field_id,$pos) { 
     444          return $this->form_prefix.$verb.'_'.$field_id.'_'.$pos; 
    314445     } 
    315446 
     
    317448 
    318449 
    319  
    320450/** 
    321 * dcFilter - describes an abstract filter 
     451* dcFilter -- base filter class 
     452* 
     453*  A filter can be edited while being applied with other values 
     454*  that enables to keep the list of applied filters (to display a list of items) 
     455*  while modifing the filter itself. 
     456*  Therefore it contains : 
     457*   * a Field that tracks the currently edited filter 
     458*   * an applied values that tracks the currently applied filter 
    322459* 
    323460*/ 
    324461abstract class dcFilter  { 
    325      public $filterset;            ///<b>string</b> filterset parent 
    326      public $id;                        ///<b>string</b> field id (local to fieldset) 
    327      public $name;                 ///<b>string</b> filter name 
    328      public $desc;                 ///<b>string</b> field description 
    329      public $filter_id;            ///<b>string</b> field id (global to the page) 
    330      protected $request_param;     ///<b>string</b> resulting parameter array key 
    331      protected $field;             ///<b>array</b> currently edited values 
    332      protected $avalues;           ///<b>array</b> currently applied values 
     462     /** @var dcFilterSet filterset parent */ 
     463     public $filterset; 
     464     /** @var string filter id */ 
     465     public $id; 
     466     /** @var string filter name */ 
     467     public $name; 
     468     /** @var string filter description */ 
     469     public $desc; 
     470     /** @var string filter id (including form prefix) */ 
     471     public $filter_id; 
     472     /** @var string resulting parameter array key */ 
     473     protected $request_param; 
     474     /** @var dcField edited field */ 
     475     protected $field; 
     476     /** @var array currently applied values */ 
     477     protected $avalues; 
     478     /** @var boolean true if field is static */ 
    333479     protected $static; 
     480     /** @var array generic field options */ 
    334481     protected $options; 
     482     /** @var boolean true if field can have multiple values */ 
    335483     protected $multiple; 
    336484 
     485    /** 
     486     * __construct -- filter constructor 
     487     * 
     488     * @param mixed $id            filter id. 
     489     * @param mixed $name          filter name. 
     490     * @param mixed $desc          filter description. 
     491     * @param mixed $request_param request parameter (see dcBlog::getPosts for 
     492     *                             instance). 
     493     * @param array $options       filter options. 
     494     * 
     495     * @access public 
     496     * 
     497     * @return mixed Value. 
     498     */ 
    337499     public function __construct ($id,$name,$desc,$request_param,$options=array()) { 
    338500          $this->id                     = $id; 
     
    353515     } 
    354516 
    355      /** 
    356      Extract values from data (data being an array, such as $_GET or $_POST) 
    357       
    358      @param    $data     <b>array</b>   data to parse 
    359      @return   <b>array</b>   field values 
    360       
    361      */ 
     517 
     518    /** 
     519     * parseData - Extract values from data (data being an array, such as $_GET  
     520     *                   or $_POST) ; does not update any field, only return parsed 
     521     *                   data 
     522     * 
     523     * @param mixed $data input data. 
     524     * 
     525     * @access protected 
     526     * 
     527     * @return array an array containing parsed data. 
     528     */ 
    362529     protected function parseData($data) { 
    363530          $arr = $this->field->parseValues($data); 
     
    365532     } 
    366533 
     534    /** 
     535     * isStatic -- returns whether the filter is static or not 
     536     * 
     537     * @access public 
     538     * 
     539     * @return boolean true if the filter is static. 
     540     */ 
    367541     public function isStatic() { 
    368542          return $this->static; 
    369543     } 
    370544 
     545    /** 
     546     * setupFields -- sets up filter fielt from $_GET or $_POST 
     547     * 
     548     * @param mixed $data input data (either $_GET or $_POST). 
     549     * 
     550     * @access public 
     551     * 
     552     * @return mixed Value. 
     553     */ 
    371554     public function setupFields($data) { 
    372555          $this->field->setup($data); 
     
    374557 
    375558 
     559    /** 
     560     * init -- initializes filter (called after setup) 
     561     * 
     562     * @access public 
     563     * 
     564     * @return mixed Value. 
     565     */ 
    376566     public function init() { 
    377567     } 
    378568 
     569    /** 
     570     * cleanup - resets filter field to its default value 
     571     * 
     572     * @access public 
     573     * 
     574     * @return mixed Value. 
     575     */ 
    379576     public function cleanup() { 
    380577          $this->field->setValues(array()); 
    381578     } 
    382579 
    383      public function setupAppliedFilter($data) { 
     580    /** 
     581     * setupAppliedValue -- defines field applied values from data 
     582     * 
     583     * @param mixed $data data to retrieve values from ($_GET or $_POST). 
     584     * 
     585     * @access public 
     586     * 
     587     * @return mixed Value. 
     588     */ 
     589     public function setupAppliedValue($data) { 
    384590          $this->avalues = $this->parseData($data); 
    385591     } 
     
    389595     } 
    390596 
    391      /** 
    392      Defines the filterset containing this filter 
    393       
    394      @param    prefix         <b>dcFilterset</b>  the filterset 
    395      */ 
    396      public function setFilterSet($fs) { 
     597    /** 
     598     * setFilterSet -- sets filterSet for filter 
     599     * 
     600     * @param mixed \dcFilterset Description. 
     601     * 
     602     * @access public 
     603     * 
     604     */ 
     605     public function setFilterSet(dcFilterset $fs) { 
    397606          $this->filterset = $fs; 
    398607     } 
    399       
    400      /** 
    401       
    402      Defines form prefix for filter 
    403       
    404      @param    prefix         <b>string</b>  the form prefix 
    405      */ 
     608 
     609    /** 
     610     * setFormPrefix -- sets filter form prefix 
     611     *  
     612     * @param string $prefix the form prefix. 
     613     * 
     614     * @access public 
     615     * 
     616     * @return mixed Value. 
     617     */ 
    406618     public function setFormPrefix($prefix) { 
    407619          $this->filter_id = $prefix.$this->id; 
    408620     } 
    409621 
    410      /** 
    411      Tells whether the filter is enabled or not 
    412       
    413      @return   <b>boolean</b> true if enabled, false otherwise 
    414      */ 
     622    /** 
     623     * isEnabled -- Tells whether the filter is enabled or not (ie field has 
     624     *                   at least 1 value defined) 
     625     * 
     626     * @access public 
     627     * 
     628     * @return mixed true if the filter is enabled. 
     629     */ 
    415630     public function isEnabled() { 
    416631          return count($this->field) != 0; 
    417632     } 
    418       
     633 
    419634     protected abstract function addValue($value=NULL); 
    420635 
    421      /** 
    422      Adds the current filter to the list 
    423      */ 
     636    /** 
     637     * add -- adds a value for the filter 
     638     * 
     639     * @access public 
     640     * 
     641     * @return mixed Value. 
     642     */ 
    424643     public function add() { 
    425644          if (count($this->field) > 1 && !$this->multiple) 
     
    427646          $this->addValue(); 
    428647     } 
    429       
    430      /** 
    431      Removes a value from filter 
    432      */ 
     648 
     649    /** 
     650     * remove -- Removes a value from filter 
     651     * 
     652     * @param mixed $pos value position. 
     653     * 
     654     * @access public 
     655     * 
     656     * @return mixed Value. 
     657     */ 
    433658     public function remove($pos) { 
    434659          $values = $this->field->getValues(); 
     
    439664     } 
    440665 
    441      abstract protected function appendSingleLine($ctx,$pos); 
    442  
    443      public function appendEditLines($ctx) { 
     666     abstract protected function appendContextLine($ctx,$pos); 
     667 
     668    /** 
     669     * appendFilterContext -- appends current filter context to the given  
     670     *                        context. 
     671     *    A filter context consists in a list of array elements, one for 
     672     *    each field line displayed. 
     673     *    If a field has multiple values, there will be as many lines as values 
     674      * 
     675     *  The twig template then iterates through the array to display 
     676     *  each and every line 
     677     * @param mixed $ctx the context to enrich 
     678     * 
     679     * @access public 
     680     * 
     681     * @return mixed Value. 
     682     */ 
     683     public function appendFilterContext($ctx) { 
    444684          foreach ($this->field->getValues() as $cur => $f) { 
     685               /* 
     686               * each line of context has the following properties : 
     687               *  * lineclass : <tr> class to use 
     688               *  * 'del_id' : delete input field name to delete current value 
     689               *  * other field-type specific values that are set from  
     690               *         appendContextLine method 
     691                */ 
    445692               $line = new ArrayObject(); 
    446693               $line['lineclass'] = $this->id; 
    447                $line['del_id'] = $this->filterset->getDelName($this->id,$cur); 
     694               $line['del_id'] = $this->filterset->buildFieldName('del',$this->id,$cur); 
     695               // Create the delete field for this line 
    448696               $del = new dcFieldSubmit( 
    449                     $this->filterset->getDelName($this->id,$cur), 
     697                    $this->filterset->buildFieldName('del',$this->id,$cur), 
    450698                    '-', 
    451699                    array( 
     
    454702               ); 
    455703               $this->filterset->addField($del); 
    456                $this->appendSingleLine($line,$cur); 
     704               $this->appendContextLine($line,$cur); 
    457705               $ctx[]=$line; 
    458706          } 
    459707     } 
    460708 
     709    /** 
     710     * serialize - serializes field value into given array 
     711     *  
     712     * @param mixed $arr the context to update. 
     713     * 
     714     * @access public 
     715     * 
     716     * @return mixed Value. 
     717     */ 
    461718     public function serialize($arr) { 
    462719          if (count($this->fields) == 1) { 
     
    466723          } 
    467724     } 
    468       
     725 
     726    /** 
     727     * isApplied -- returns true when the filter is applied 
     728     *    (ie. has at least 1 applied value) 
     729     * @access public 
     730     * 
     731     * @return mixed Value. 
     732     */ 
    469733     public function isApplied(){ 
    470734          return (count($this->avalues['values']) != 0); 
    471735     } 
    472736 
    473      /** 
    474      Convert filter values into a $param filter, used for the upcoming SQL request 
    475       
    476      @param <b>ArrayObject</b> the parameters array to enrich 
    477  
    478     @return boolean true if a filter has been applied, false otherwise  
    479     */ 
     737    /** 
     738     * applyFilter -- Converts filter values into a $param filter, used for the 
     739     *                    upcoming SQL request 
     740     * 
     741     * @param mixed $params Description. 
     742     * 
     743     * @access public 
     744     * 
     745     * @return mixed Value. 
     746     */ 
    480747     public function applyFilter($params) { 
    481748          return false; 
    482749     } 
    483750 
     751    /** 
     752     * header -- tbd 
     753     *  
     754     * @access public 
     755     * 
     756     * @return mixed Value. 
     757     */ 
    484758     public function header() { 
    485759          return ''; 
    486760     } 
    487761 
     762    /** 
     763     * getFields -- returns filter field(s) 
     764     *  
     765     * @access public 
     766     * 
     767     * @return dcField the filter field. 
     768     */ 
    488769     public function getFields() { 
    489770          return $this->field; 
     
    492773} 
    493774 
    494  
    495  
     775/** 
     776* dcFilterText - basic single field text filter 
     777* 
     778* @uses     dcFilter 
     779* 
     780*/ 
    496781class dcFilterText extends dcFilter { 
    497782 
     783    /** 
     784     * @see dcFilter::init() 
     785     */ 
    498786     public function init() { 
    499787          $this->field = new dcFieldText( 
     
    505793 
    506794 
    507      public function appendSingleLine($line,$pos) { 
     795    /** 
     796     * @see dcFilter::appendContextLine() 
     797     */ 
     798     public function appendContextLine($line,$pos) { 
     799          /* 
     800          Extra data provided by this filter : 
     801          * ffield : field name 
     802          * display_inline : true if the field is static 
     803          * fwidget : name of the widget (filter_text) 
     804          * desc : filter description 
     805           */ 
    508806          $line['ffield'] = $this->field->getName(); 
    509807          if ($this->static) { 
     
    517815     } 
    518816 
    519      protected function addValue($value=NULL) { 
     817    /** 
     818     * @see dcFilter::addValue() 
     819     */ 
     820    protected function addValue($value=NULL) { 
    520821          if ($value === NULL) { 
    521822               $value = ''; 
     
    524825     } 
    525826 
     827    /** 
     828     * @see dcFilter::applyFilter() 
     829     */ 
    526830     public function applyFilter($params) { 
    527831          $params[$this->request_param]=$this->avalues['values'][0]; 
    528832     } 
    529       
    530833} 
     834 
    531835/** 
    532 @ingroup DC_CORE 
    533 @nosubgrouping 
    534 @brief abstract filter class. 
    535  
    536 Handle combo filter on admin side. Can be single or multi-valued 
     836* dcFilterCombo -- combo filter 
     837* 
     838* Enables to filter through a list of values, can be used to check 
     839* if a value is in a list of items 
     840* 
     841* @uses     dcFilter 
     842* 
    537843*/ 
    538844class dcFilterCombo extends dcFilter { 
     845     /** @var combo the list of possible values in combo */ 
    539846     protected $combo; 
    540847      
    541      public function __construct($id,$name,$desc,$request_param,$combo,$options=array()) { 
     848    /** 
     849     * @see dcFilter::__construct() 
     850     */ 
     851     public function __construct($id,$name,$desc,$request_param,$combo, 
     852                                        $options=array()) { 
    542853          parent::__construct($id,$name,$desc,$request_param,$options); 
    543854          $this->combo = $combo; 
    544855     } 
     856 
     857    /** 
     858     * @see dcFilter::init() 
     859     */ 
    545860     public function init() { 
    546861          $this->field = new dcFieldCombo( 
     
    551866     } 
    552867 
     868    /** 
     869     * @see dcFilter::addValue() 
     870     */ 
    553871     protected function addValue($value=NULL) { 
    554872          if ($value === NULL) { 
     
    558876     } 
    559877 
    560      public function appendSingleLine($line,$pos) { 
     878    /** 
     879     * @see dcFilter::init() 
     880     */ 
     881     public function appendContextLine($line,$pos) { 
     882          /* 
     883          Extra data provided by this filter : 
     884          * ffield : field name 
     885          * display_inline : true if the field is static 
     886          * fwidget : name of the widget (filter_combo or filter_combo_cont) 
     887          * foffset : field value offset 
     888          * desc : filter description 
     889          Only the 1st item contains description. 
     890           */ 
    561891          if ($this->static) { 
    562892               $line['display_inline'] = true; 
     
    571901          }; 
    572902     } 
    573       
     903 
     904    /** 
     905     * @see dcFilter::applyFilter() 
     906     */ 
    574907     public function applyFilter($params) { 
    575908          $attr = $this->request_param; 
     
    583916 
    584917/** 
    585 @ingroup DC_CORE 
    586 @nosubgrouping 
    587 @brief abstract filter class. 
    588  
    589 Handle combo filter on admin side. Can be single or multi-valued 
     918* dcFilterRichCombo -- rich combo filter 
     919* 
     920* Same as dcFilterCombo, with the possibility to exclude a list of values 
     921* 
     922* @uses     dcFilter 
     923* 
    590924*/ 
    591925class dcFilterRichCombo extends dcFilterCombo { 
     926     /** @var verb verb field ('is' or 'is not') */ 
    592927     protected $verb; 
    593928 
     929    /** 
     930     * @see dcFilter::init() 
     931     */ 
    594932     public function init() { 
    595933          parent::init(); 
     
    604942     } 
    605943 
     944    /** 
     945     * @see dcFilter::parseData() 
     946     */ 
    606947     protected function parseData($data) { 
    607948          $val = parent::parseData($data); 
     
    614955     } 
    615956 
     957    /** 
     958     * @see dcFilter::setupFields() 
     959     */ 
    616960     public function setupFields($data) { 
    617961          parent::setupFields($data); 
     
    619963     } 
    620964 
     965    /** 
     966     * @see dcFilter::updateAppliedValues() 
     967     */ 
    621968     public function updateAppliedValues($arr) { 
    622969          parent::updateAppliedValues($arr); 
    623           $arr['verb'] = $this->verb->getValue(); 
    624      } 
    625  
    626      public function appendSingleLine($line,$pos) { 
    627           parent::appendSingleLine($line,$pos); 
     970          $arr[$this->verb->getName()] = $this->verb->getValue(); 
     971     } 
     972 
     973    /** 
     974     * @see dcFilter::appendContextLine() 
     975     */ 
     976     public function appendContextLine($line,$pos) { 
     977          parent::appendContextLine($line,$pos); 
    628978          if ($pos == 0) { 
    629979               $line['fverb'] = $this->verb->getName(); 
    630980               $line['fwidget']='filter_richcombo'; 
    631           }  
    632      } 
    633       
     981          } 
     982     } 
     983 
     984    /** 
     985     * @see dcFilter::serialize() 
     986     */ 
    634987     public function serialize($arr) { 
    635988          parent::serialize($arr); 
    636989          $arr[$this->filter_id.'_v']=$this->verb->getValue(); 
    637990     } 
    638       
     991 
     992    /** 
     993     * @see dcFilter::applyFilter() 
     994     */ 
    639995     public function applyFilter($params) { 
    640996          parent::applyFilter($params); 
     
    6471003} 
    6481004 
    649  
    650  
     1005// Static initializer 
    6511006dcFilterSet::__init__($GLOBALS['core']->tpl); 
    6521007?> 
  • inc/admin/class.dc.form.php

    r1154 r1156  
    1313 
    1414/** 
    15 * dcFormNode 
     15* dcFormNode Twig Node for Form handling 
    1616* 
    1717* @uses     Twig_Node 
     
    5757class dcFormTokenParser extends Twig_TokenParser 
    5858{ 
     59    /** 
     60     * parse - parses form tag 
     61     * General syntax is : 
     62     *  {% form 'formname' %} 
     63     *  ... {{ form_field (...)}} 
     64     *  {% endform %} 
     65     * Specific attributes can be passed to the form, enabling to set 
     66     * attributes to the form template : 
     67     * {% form 'formname' with {'id':'myform'} %} 
     68     * @param mixed \Twig_Token Description. 
     69     * 
     70     * @access public 
     71     * 
     72     * @return mixed Value. 
     73     */ 
    5974     public function parse(Twig_Token $token) 
    6075     { 
     
    6378          $name = $this->parser->getExpressionParser()->parseExpression(); 
    6479          $attr = null; 
     80          /* parse optional context */ 
    6581          if ($stream->test(Twig_Token::NAME_TYPE, 'with')) { 
    6682               $stream->next(); 
     
    7086          $body = $this->parser->subparse(array($this,'decideBlockEnd'),true); 
    7187          $stream->expect(Twig_Token::BLOCK_END_TYPE); 
    72            
     88 
    7389          return new dcFormNode($name,$body,$attr,$token->getLine(),$this->getTag()); 
    7490     } 
    75       
     91 
    7692     public function decideBlockEnd(Twig_Token $token) 
    7793     { 
    7894          return $token->test('endform'); 
    7995     } 
    80       
     96 
    8197     public function getTag() 
    8298     { 
     
    97113     protected $currentForm; 
    98114     protected $blocks; 
    99       
     115 
    100116     public function __construct($core) 
    101117     { 
     
    106122          $this->currentForm = null; 
    107123     } 
    108       
     124 
    109125     public function initRuntime(Twig_Environment $environment) 
    110126     { 
     
    116132          } 
    117133     } 
    118       
     134 
    119135     public function addTemplate($tpl) { 
    120136          $this->tpl[]=$tpl; 
     
    129145          return array('dc_form' => $this); 
    130146     } 
    131       
     147 
    132148     public function getFunctions() 
    133149     { 
     
    160176          ); 
    161177     } 
    162       
     178 
     179    /** 
     180     * isChoiceGroup - binding for twig function "_form_is_choice_group" 
     181     *                        returns whether a choice is a group or not 
     182     * @param mixed $choice the choice. 
     183     * 
     184     * @access public 
     185     * 
     186     * @return boolean true is choice is a group (optgroup). 
     187     */ 
    163188     public function isChoiceGroup($choice) 
    164189     { 
    165190          return is_array($choice); 
    166191     } 
    167       
     192 
     193    /** 
     194     * isChoiceSelected - binding for twig function "_form_is_choice_selected" 
     195     *                        returns whether current choice matches a value or not 
     196     * @param mixed $choice the choixe. 
     197     * @param mixed $value  the value to check matching. 
     198     * 
     199     * @access public 
     200     * 
     201     * @return boolean if choice is matching the value. 
     202     */ 
    168203     public function isChoiceSelected($choice,$value) 
    169204     { 
    170205          return $choice == $value; 
    171206     } 
    172       
     207 
     208    /** 
     209     * getTokenParsers returns token parsers 
     210     * 
     211     * @access public 
     212     * 
     213     * @return mixed Value. 
     214     */ 
    173215     public function getTokenParsers() 
    174216     { 
    175217          return array(new dcFormTokenParser()); 
    176218     } 
    177       
     219 
     220    /** 
     221     * hasWidget - binding for twig "haswidget" function 
     222     *    returns whether a widget is defined or not 
     223     *  
     224     * @param mixed $name the widget name. 
     225     * 
     226     * @access public 
     227     * 
     228     * @return boolean true if the widget exists. 
     229     */ 
    178230     public function hasWidget($name) { 
    179231          return isset($this->blocks[$name]); 
    180232     } 
     233 
     234    /** 
     235     * renderWidget - binding for 'widget' twig function 
     236     * behaves exactly like "block" function, except that a context 
     237     * can be passed to the function 
     238     *  
     239     * @param mixed $name the widget (block) name to render. 
     240     * @param mixed $attr Description the context for this block. 
     241     * 
     242     * 
     243     * @return mixed Value. 
     244     */ 
    181245     public function renderWidget($name,$attr) { 
    182246          if (!isset($this->blocks[$name])) 
     
    189253     } 
    190254 
     255    /** 
     256     * getCurrentForm - returns current form if called within a {% form %} tag 
     257     * 
     258     * @access public 
     259     * 
     260     * @return string the current form. 
     261     */ 
    191262     public function getCurrentForm() { 
    192263          return $this->currentForm; 
    193264     } 
    194265 
     266    /** 
     267     * renderField - binding for 'form_field' twig function; renders a field 
     268     * 
     269     * @param mixed $name       field name as defined on php side. 
     270     * @param array $attributes html attributes for field (ex : class, ...). 
     271     * @param array $extra      extra attributes that may be template specific. 
     272     * 
     273     * @access public 
     274     * 
     275     * @return mixed Value. 
     276     */ 
    195277     public function renderField($name,$attributes=array(),$extra=array()) 
    196278     { 
     
    213295     } 
    214296 
     297    /** 
     298     * renderHiddenWidgets -- renders all form hidden fields 
     299     * 
     300     * @access public 
     301     * 
     302     * @return mixed Value. 
     303     */ 
    215304     public function renderHiddenWidgets() 
    216305     { 
     
    225314     } 
    226315 
     316    /** 
     317     * addForm -- registers a new form 
     318     * 
     319     * @param mixed \dcForm Description. 
     320     * 
     321     * @access public 
     322     * 
     323     * @return mixed Value. 
     324     */ 
    227325     public function addForm(dcForm $form) 
    228326     { 
     
    230328     } 
    231329 
     330    /** 
     331     * beginForm -- displays form beginning 
     332     *  
     333     * @param mixed $name form name. 
     334     * @param array $attr extra attributes. 
     335     * 
     336     * @access public 
     337     * 
     338     * @return mixed Value. 
     339     */ 
    232340     public function beginForm($name,$attr=array()) 
    233341     { 
     
    243351          } 
    244352     } 
    245       
     353 
     354    /** 
     355     * endForm -- displays form ending 
     356     *  
     357     * @access public 
     358     * 
     359     * @return mixed Value. 
     360     */ 
    246361     public function endForm() 
    247362     { 
     
    263378class dcForm 
    264379{ 
     380     /** @var string form id */ 
    265381     protected $id; 
     382     /** @var string form name */ 
    266383     protected $name; 
     384     /** @var dcCore dcCore instance */ 
    267385     protected $core; 
     386     /** @var string form action */ 
    268387     protected $action; 
     388     /** @var array(dcField) list of form fields */ 
    269389     protected $fields; 
     390     /** @var string form method (GET/POST) */ 
    270391     protected $method; 
     392     /** @var array(dcField) list of submit fields */ 
    271393     protected $submitfields; 
     394     /** @var array(dcField) list of hidden fields */ 
    272395     protected $hiddenfields; 
     396     /** @var array(dcField) list of form errors */ 
    273397     protected $errors; 
    274       
    275      public function addTemplate($t) { 
    276           $this->core->tpl->getExtension('dc_form')->addTemplate($t); 
    277      } 
    278  
    279     /** 
    280      * addNonce -- adds dc nonce to form fields 
    281      *  
    282      * @access protected 
    283      * 
    284      * @return nothing 
    285      */ 
    286      protected function addNonce() 
    287      { 
    288           $this->addField( 
    289                new dcFieldHidden(array('xd_check'), 
    290                $this->core->getNonce()) 
    291           ); 
    292      } 
    293       
    294  
    295     /** 
    296      * Defines Name & ID from field 
    297      *  
    298      * @param mixed $nid either an array (name, id) or a string (name only, id will be set to null). 
    299      * 
    300      * @access protected 
    301      * 
    302      * @return nothing. 
    303      */ 
    304      protected function setNID($nid) 
    305      { 
    306           if (is_array($nid)) { 
    307                $this->name = $nid[0]; 
    308                $this->id = !empty($nid[1]) ? $nid[1] : null; 
    309           } 
    310           else { 
    311                $this->id = null; 
    312                $this->name = $nid; 
    313           } 
    314      } 
    315       
    316      public function getContext() { 
    317           return array(); 
    318      } 
    319398 
    320399    /** 
     
    322401     *  
    323402     * @param mixed  $core   dotclear core 
    324      * @param mixed  $name   form name 
     403     * @param mixed  $name   form name - can be an array (name,id) 
    325404     * @param mixed  $action form action 
    326405     * @param string $method form method ('GET' or 'POST') 
     
    345424          } 
    346425     } 
    347       
     426 
     427    /** 
     428     * addTemplate - Adds a template file to enrich form fields 
     429     *  
     430     * @param string $t the template file. 
     431     * 
     432     * @access public 
     433     */ 
     434     public function addTemplate($t) { 
     435          $this->core->tpl->getExtension('dc_form')->addTemplate($t); 
     436     } 
     437 
     438    /** 
     439     * addNonce -- adds dc nonce to form fields 
     440     * 
     441     * @access protected 
     442     * 
     443     * @return nothing 
     444     */ 
     445     protected function addNonce() 
     446     { 
     447          $this->addField( 
     448               new dcFieldHidden(array('xd_check'), 
     449               $this->core->getNonce()) 
     450          ); 
     451     } 
     452 
     453    /** 
     454     * Defines Name & ID from field 
     455     * 
     456     * @param mixed $nid either an array (name, id) or a string 
     457     *                   (name only, id will be set to null). 
     458     * 
     459     * @access protected 
     460     * 
     461     * @return nothing. 
     462     */ 
     463     protected function setNID($nid) 
     464     { 
     465          if (is_array($nid)) { 
     466               $this->name = $nid[0]; 
     467               $this->id = !empty($nid[1]) ? $nid[1] : null; 
     468          } 
     469          else { 
     470               $this->id = null; 
     471               $this->name = $nid; 
     472          } 
     473     } 
     474 
     475    /** 
     476     * getContext - returns form context (to fill-in twig context for instance), 
     477     *                   if any 
     478     * 
     479     * @access public 
     480     * 
     481     * @return array the form context. 
     482     */ 
     483     public function getContext() { 
     484          return array(); 
     485     } 
     486 
    348487 
    349488    /** 
    350489     * Returns form name 
    351      *  
     490     * 
    352491     * @access public 
    353492     * 
     
    358497          return $this->name; 
    359498     } 
    360       
     499 
     500    /** 
     501     * getErrors - returns form errors 
     502     * 
     503     * @access public 
     504     * 
     505     * @return array the list of errors. 
     506     */ 
    361507     public function getErrors() 
    362508     { 
    363509          return $this->errors; 
    364510     } 
    365       
     511 
     512    /** 
     513     * addField - adds a new field to form 
     514     * 
     515     * @param mixed \dcField the field to add. 
     516     * 
     517     * @access public 
     518     * 
     519     * @return dcForm the form instance (therefore addField can be chained) 
     520     */ 
    366521     public function addField(dcField $f) 
    367522     { 
     
    373528          } 
    374529          $this->fields[$f->getName()] = $f; 
    375            
     530 
    376531          return $this; 
    377532     } 
    378       
     533 
     534    /** 
     535     * removeField - removes a field 
     536     * 
     537     * @param mixed \dcField the field to remove. 
     538     * 
     539     * @access public 
     540     * 
     541     * @return dcForm the form instance (therefore addField can be chained) 
     542     */ 
    379543     public function removeField(dcField $f) { 
    380544          $n = $f->getName(); 
     
    382546               unset($this->fields[$n]); 
    383547          } 
    384  
    385      } 
     548          return $this; 
     549     } 
     550 
     551 
     552    /** 
     553     * renameField - renames a field 
     554     * 
     555     * @param mixed $field   the field to rename. 
     556     * @param mixed $newname new field name 
     557     * 
     558     * @access public 
     559     * 
     560     * 
     561     * @return dcForm the form instance (therefore addField can be chained) 
     562     */ 
    386563     public function renameField($field,$newname) { 
    387564          $oldname = $field->getName(); 
     
    391568               $this->fields[$newname] = $field; 
    392569          } 
    393      } 
     570          return $this; 
     571     } 
     572 
     573    /** 
     574     * begin - begins a form. Should be not be called directly, it is handled 
     575     *              by the Twig Form extension. 
     576     * 
     577     * @param array $attr form extra attributes, if any. 
     578     * 
     579     * @access public 
     580     * 
     581     * @return mixed Value. 
     582     */ 
    394583     public function begin($attr=array()) 
    395584     { 
     
    403592               $attr); 
    404593     } 
    405       
     594 
     595    /** 
     596     * end - ends a form. Should be not be called directly, it is handled 
     597     *              by the Twig Form extension. 
     598     * 
     599     * @access public 
     600     * 
     601     * @return mixed Value. 
     602     */ 
    406603     public function end() 
    407604     { 
    408           echo '</form>'; 
    409      } 
    410       
     605          $this->core->tpl->getExtension('dc_form')->renderWidget( 
     606               'endform'); 
     607     } 
     608 
     609    /** 
     610     * __isset - magic method isset, checks whether a field exists 
     611     *                   example : if (isset($form->field1)) 
     612     * 
     613     * @param mixed $name field name to check. 
     614     * 
     615     * @access public 
     616     * 
     617     * @return boolean true if the field exists. 
     618     */ 
    411619     public function __isset($name) 
    412620     { 
    413621          return isset($this->fields[$name]); 
    414622     } 
    415       
     623 
     624    /** 
     625     * __get -- magic method, retrieves a field from a form 
     626     *              example : $f = $form->field1 
     627     * 
     628     * @param mixed $name Description. 
     629     * 
     630     * @access public 
     631     * 
     632     * @return mixed Value. 
     633     */ 
    416634     public function __get($name) 
    417635     { 
     
    420638     } 
    421639 
     640    /** 
     641     * __set -- magic method, sets a value for a given form field 
     642     *              example : $form->field1 = 'my value'; 
     643     * 
     644     * @param mixed $name  the field name. 
     645     * @param mixed $value the field value. 
     646     * 
     647     * @access public 
     648     */ 
    422649     public function __set($name,$value) 
    423650     { 
     
    427654     } 
    428655 
    429      public function isSubmitted() 
     656/*   public function isSubmitted() 
    430657     { 
    431658          $from = $this->method == 'POST' ? $_POST : $_GET; 
    432659     } 
    433  
     660*/ 
     661 
     662    /** 
     663     * setupFields - initializes form & fields from $_GET or $_POST 
     664     *  
     665     * @access protected 
     666     */ 
    434667     protected function setupFields() { 
    435668          $from = $this->method == 'POST' ? $_POST : $_GET; 
     
    439672     } 
    440673 
     674    /** 
     675     * handleActions - handle appropriate actions, according to submitted fields 
     676     *  
     677     * @param mixed $submitted the fields that have been submitted. 
     678     * 
     679     * @access protected 
     680     */ 
    441681     protected function handleActions($submitted) { 
    442682          foreach ($submitted as $f) { 
     
    448688     } 
    449689 
     690    /** 
     691     * getSubmittedFields - retrieves fields that have been submitted, if any 
     692     * 
     693     * @access protected 
     694     * 
     695     * @return array the list of submitted fields. 
     696     */ 
    450697     protected function getSubmittedFields() { 
    451698          $s = array(); 
     
    458705     } 
    459706 
     707    /** 
     708     * setup - sets up the form, given the parameters given to the page 
     709     *              should be called after fields have been defined. 
     710     * 
     711     * @access public 
     712     * 
     713     * @return mixed Value. 
     714     */ 
    460715     public function setup() 
    461716     { 
     
    465720     } 
    466721 
     722    /** 
     723     * check - checks if the form is valid, errors are filled in, in case of 
     724     *              incorrect fields 
     725     * 
     726     * @access public 
     727     */ 
    467728     public function check() 
    468729     { 
     
    476737          } 
    477738     } 
    478       
     739 
     740    /** 
     741     * getHiddenFields - returns the list of hidden fields 
     742     * 
     743     * @access public 
     744     * 
     745     * @return array the list of hidden fields. 
     746     */ 
    479747     public function getHiddenFields() 
    480748     { 
     
    488756abstract class dcField implements Countable 
    489757{ 
     758     /** @var string field options */ 
    490759     protected $options; 
     760     /** @var string field name */ 
    491761     protected $name; 
     762     /** @var string field values */ 
    492763     protected $values; 
     764     /** @var string field id */ 
    493765     protected $id; 
     766     /** @var boolean true if field can contain multiple values */ 
    494767     protected $multiple; 
     768     /** @var boolean true if the field has been defined */ 
    495769     protected $defined; 
    496       
    497      protected function setNID($nid) 
    498      { 
    499           if (is_array($nid)) { 
    500                $this->name = $nid[0]; 
    501                $this->id = !empty($nid[1]) ? $nid[1] : null; 
    502           } 
    503           else { 
    504                $this->id = $this->name = $nid; 
    505           } 
    506      } 
    507       
     770 
     771    /** 
     772     * __construct - constructor 
     773     * 
     774     * @param string $name   Name or array(name,id) for field. 
     775     * @param array $values  field values. 
     776     * @param array $options options 
     777     * 
     778     * Currently globally available options are : 
     779     *  * multiple : true/false. Enable multiple values for field 
     780     * @access public 
     781     * 
     782     * @return mixed Value. 
     783     */ 
    508784     public function __construct($name,$values,$options=array()) 
    509785     { 
     
    518794 
    519795     } 
    520       
     796 
     797    /** 
     798     * setNID - defines fiels name & id 
     799     * 
     800     * @param mixed $nid field name (string) or an array containing  name (1st) 
     801     *                   and id (2nd field). 
     802     * 
     803     * @access protected 
     804     */ 
     805     protected function setNID($nid) 
     806     { 
     807          if (is_array($nid)) { 
     808               $this->name = $nid[0]; 
     809               $this->id = !empty($nid[1]) ? $nid[1] : null; 
     810          } 
     811          else { 
     812               $this->id = $this->name = $nid; 
     813          } 
     814     } 
     815 
     816    /** 
     817     * setValue - sets field value 
     818     * 
     819     * @param mixed $value  field value. 
     820     * @param int   $offset value offset to define (default 0). 
     821     * 
     822     * @access public 
     823     */ 
    521824     public function setValue($value,$offset=0) { 
    522825          $this->values[$offset] = $value; 
    523826     } 
    524827 
     828    /** 
     829     * setValues - set field values 
     830     * 
     831     * @param mixed $values the array of values. If not an array, the parameter 
     832     *                      will be converted to an array containing the value 
     833     * 
     834     * @access public 
     835     */ 
    525836     public function setValues($values) { 
    526837          if (is_array($values)) { 
     
    532843     } 
    533844 
     845    /** 
     846     * getValues - return field values 
     847     * 
     848     * @access public 
     849     * 
     850     * @return mixed the array of values. 
     851     */ 
    534852     public function getValues() { 
    535853          return $this->values; 
    536854     } 
    537855 
     856    /** 
     857     * getValue - retrieves a field value 
     858     * 
     859     * @param int $offset value offset (by default 1st value is returned). 
     860     * 
     861     * @access public 
     862     * 
     863     * @return mixed the field value. 
     864     */ 
    538865     public function getValue($offset=0) { 
    539866          if (isset($this->values[$offset])) { 
     
    542869     } 
    543870 
     871    /** 
     872     * addValue -- Adds a value to the field values. 
     873     *  
     874     * @param mixed $value Description. 
     875     * 
     876     * @access public 
     877     * 
     878     * @return mixed Value. 
     879     */ 
    544880     public function addValue($value) { 
    545881          $this->values[] = $value; 
     
    551887     } 
    552888 
     889    /** 
     890     * count -- returns the number of field values 
     891     *  
     892     * @access public 
     893     * 
     894     * @return integer the number of values. 
     895     */ 
    553896     public function count() { 
    554897          return count($this->values); 
     
    562905     abstract public function getWidgetBlock(); 
    563906      
     907 
     908    /** 
     909     * getAttributes - retrieve field attributes that will be given to the 
     910     *                   twig widget 
     911     * 
     912     * @param array $options extra options given to the widget 
     913     * 
     914     * @access public 
     915     * 
     916     * @return array the attributes. 
     917     */ 
    564918     public function getAttributes($options) 
    565919     { 
     
    581935          return $attr; 
    582936     } 
    583       
     937 
     938    /** 
     939     * getDefaultValue - returns field default value 
     940     *  
     941     * @access public 
     942     * 
     943     * @return mixed the field default value. 
     944     */ 
    584945     public function getDefaultValue() { 
    585946          return ''; 
    586947     } 
    587948 
     949    /** 
     950     * getName - returns field name 
     951     *  
     952     * @access public 
     953     * 
     954     * @return string the field name. 
     955     */ 
    588956     public function getName() 
    589957     { 
     
    591959     } 
    592960 
     961    /** 
     962     * setName - defines field name and/or field id 
     963     *  
     964     * @param mixed $name the field name or an array containing name and id. 
     965     * 
     966     * @access public 
     967     */ 
    593968     public function setName($name) { 
    594969          $this->setNID($name); 
    595970     } 
    596971 
     972    /** 
     973     * check - checks whether the field is valid or not - raises an exception  
     974     *              if not valid 
     975     * @access public 
     976     */ 
    597977     public function check() 
    598978     { 
     
    604984          } 
    605985     } 
    606       
     986 
     987    /** 
     988     * parseValues - parses field value from context (GET or POST) 
     989     *                   and returns parsed value(s) 
     990     *                   NOTE : the field is not updated with this method 
     991     *                   use setup() to also update the field. 
     992     * @param mixed $from the context (usually $_GET or $_POST). 
     993     * 
     994     * @access public 
     995     * 
     996     * @return array the list of values (empty array if no value). 
     997     */ 
    607998     public function parseValues($from) { 
    608999          if (isset($from[$this->name])) { 
     
    6161007     } 
    6171008 
     1009    /** 
     1010     * setup - sets up the field from conetxt (GET or $POST) 
     1011     * 
     1012     * @param mixed $from the context (usually $_GET or $_POST). 
     1013     * 
     1014     * @access public 
     1015     * 
     1016     * @return mixed Value. 
     1017     */ 
    6181018     public function setup($from) 
    6191019     { 
     
    6241024          } 
    6251025     } 
    626       
     1026 
     1027    /** 
     1028     * isDefined - returns whether the field is defined or not 
     1029     *                   (a field is defined if some values are set after setup()) 
     1030     * @access public 
     1031     * 
     1032     * @return mixed Value. 
     1033     */ 
    6271034     public function isDefined() 
    6281035     { 
     
    7321139{ 
    7331140     protected $combo; 
    734       
     1141 
    7351142     public function __construct($name,$value,$combo,$options=array()) 
    7361143     { 
     
    7381145          parent::__construct($name,$value,$options); 
    7391146     } 
    740       
     1147 
    7411148     public function getWidgetBlock() 
    7421149     { 
  • inc/admin/class.dc.list.php

    r1154 r1156  
    2121     protected $nb_items; 
    2222     protected $nb_items_per_page; 
     23     protected $nb_pages; 
     24     protected $page; 
    2325 
    2426 
     
    6264     public function setup() { 
    6365          $this 
    64                ->addField(new dcFieldCombo('action',$this->actions_combo, '', array( 
     66               ->addField(new dcFieldCombo('action','',array(), array( 
    6567                    'label' => __('Selected entries action:')))) 
    66                ->addField(new dcFieldSubmit('ok',__('ok'), array())) 
    67                ->addField(new dcFieldHidden('page','1')); 
     68               ->addField(new dcFieldSubmit('ok',__('ok'), array())); 
    6869          $columns_combo = array(); 
    6970          foreach ($this->columns as $c) { 
     
    8687          parent::setup(); 
    8788          $this->nb_items_per_page = $limit->getFields()->getValue(); 
     89          if ($this->nb_items_per_page == 0) 
     90               $this->nb_items_per_page = 10; 
    8891          $this->fetchEntries(); 
    8992 
     
    9295     protected function fetchEntries() { 
    9396          $params = new ArrayObject(); 
    94           $offset = $this->nb_items_per_page*($this->page->getValue()-1); 
    9597          $this->filterset->applyFilters($params); 
    9698          $this->nb_items = $this->fetcher->getEntriesCount($params); 
     99          $this->nb_pages = round($this->nb_items / $this->nb_items_per_page) + 1; 
     100          if (isset($_GET['page'])) { 
     101               $this->page = (int)$_GET['page']; 
     102          } else { 
     103               $this->page = 1; 
     104          } 
     105          if ($this->page > $this->nb_pages) { 
     106               $this->page = $this->nb_pages; 
     107          } 
     108          $offset = $this->nb_items_per_page*($this->page-1); 
    97109          $entries = $this->fetcher->getEntries($params,$offset,$this->nb_items_per_page); 
    98110          $this->setEntries($entries); 
    99           /*echo "LIMIT:".$this->nb_items_per_page; 
    100           echo 'count :'.print_r($this->nb_items,true); 
    101           echo 'page'.$this->page;*/ 
     111 
    102112     } 
    103113 
     
    115125               $c->appendEditLines($ccontext); 
    116126          } 
     127          $page = $this->page; 
     128          $nb_pages = $this->nb_pages; 
     129          $nb_pages_around = 2; 
     130          $pages = array(1); 
     131          if ($page>$nb_pages_around+2) { 
     132               $pages[]='...'; 
     133          } 
     134          for ($p=max(2,$page-$nb_pages_around);  
     135               $p<=min($page+$nb_pages_around,$nb_pages-1); $p++) { 
     136               $pages[]=$p; 
     137          } 
     138          if ($page<$nb_pages-$nb_pages_around-1) { 
     139               $pages[]='...'; 
     140          } 
     141          $pages[] = $nb_pages; 
     142 
     143 
    117144          return array( 
     145               'url' => array('',$this->filterset->getURLParams()), 
    118146               'cols' => $ccontext, 
    119                'entries' => $this->entries); 
     147               'entries' => $this->entries, 
     148               'nb_entries' => $this->nb_items, 
     149               'page' => $page, 
     150               'pages_links' => $pages); 
    120151     } 
    121152 
  • inc/admin/default-templates/forms/lists_layout.html.twig

    r1154 r1156  
    22{% set lenv = _context['list_' ~ listname] %} 
    33{% if lenv.entries %} 
    4 <p>Pages:</p> 
     4{% block list_pagination %} 
     5<p>Page : {% for p in lenv.pages_links %} 
     6{% if p == lenv.page or p == '...' %} 
     7<b>{{p}}</b> 
     8{% else %} 
     9<a href="{{build_url(lenv.url,{'page':p})}}">{{p}}</a> 
     10{% endif %} 
     11{% endfor %}</p> 
     12{% endblock %} 
    513{% form listname -%} 
    614{% spaceless %} 
    715<table class="maximal clear"> 
    8      <caption> {{ caption }} - {{__('Page %s')|format(page)}}</caption> 
     16     <caption> {{ caption }} - {{__('%s entries')|format(lenv.nb_entries)}}</caption> 
    917          <tr> 
    1018          {% for h in lenv.cols -%} 
     
    2937     <p>{{ __('No entries') }}</p> 
    3038{% endif %} 
     39{{ block('list_pagination')}} 
    3140{%- endblock %} 
    3241 
  • inc/admin/default-templates/js_helpers.html.twig

    r1100 r1156  
    1414     {{ _self.load('js/jquery/jquery.biscuit.js') }} 
    1515     {{ _self.load('js/jquery/jquery.bgFade.js') }} 
    16      {{ _self.load('js/jquery/jquery.constantfooter.js') }} 
    1716     {{ _self.load('js/common.js') }} 
    1817     {{ _self.load('js/prelude.js') }} 
  • inc/admin/default-templates/posts_cols.html.twig

    r1152 r1156  
    66{% block col_title %} 
    77     {{block('col_ref')}} 
    8      {{e.post_title}} 
     8     <a href="post.php?id={{e.post_id}}">{{e.post_title}}</a> 
    99{% endblock %} 
    1010 
Note: See TracChangeset for help on using the changeset viewer.

Sites map