Changeset 1156:92f840a91f98 for inc/admin/class.dc.filter.php
- Timestamp:
- 04/26/13 16:23:16 (12 years ago)
- Branch:
- twig
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/class.dc.filter.php
r1154 r1156 14 14 15 15 16 /** 17 * dcFilterSet -- filter handling object 18 * 19 * @uses dcForm 20 * 21 */ 16 22 class 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 */ 18 26 protected $static_filters; 27 /** @var array list of all filters (union of the 2 previous props) */ 19 28 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 */ 24 38 protected $core; 25 39 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 */ 26 50 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 28 56 $env->addFunction( 29 57 new Twig_SimpleFunction( … … 36 64 ))); 37 65 } 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_"){ 54 80 $this->form_prefix=$form_prefix; 55 81 $this->filters = new ArrayObject(); … … 62 88 } 63 89 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 */ 64 121 public function setup() { 65 122 $form_combo = array(); … … 74 131 $this 75 132 ->addField ( 76 new dcFieldCombo ($p.'add_filter','',$form_combo, array(77 )))133 new dcFieldCombo ($p.'add_filter','',$form_combo, 134 array())) 78 135 ->addField ( 79 new dcFieldSubmit($p.'add',__('Add this filter'), array(80 )))136 new dcFieldSubmit($p.'add',__('Add this filter'), 137 array())) 81 138 ->addField ( 82 new dcFieldSubmit($p.'clear_filters',__('Delete all filters'), array(83 )))139 new dcFieldSubmit($p.'clear_filters',__('Delete all filters'), 140 array())) 84 141 ->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())) 87 145 ->addField ( 88 new dcFieldSubmit($p.'reset',__('Reset'), array(89 )))146 new dcFieldSubmit($p.'reset',__('Reset'), 147 array())) 90 148 ; 91 149 $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 : 93 155 (1) $_POST not empty for formfilter fields : 94 * efilters are set from $_POST95 * lfilters are set from $_GET156 * filters are set from $_POST 157 * applied filters values are set from $_GET 96 158 * keep filters div shown 97 159 (2) $_POST empty : 98 * both efilters and lfilters are set from $_GET160 * both filters fields & applied values are set from $_GET 99 161 * hide filter div 100 162 */ … … 102 164 //$allowed_actions = array('clear_filters','add','del_.*','apply','reset'); 103 165 $allowed_actions = '#^(clear_filters|add|del_.*|apply|reset)$#'; 166 104 167 // Fetch each $_POST parameter to see whether filters are concerned. 105 168 // Only 1 action at a time is allowed. 106 107 169 foreach ($_POST as $k => $v) { 108 170 if (strpos($k,$this->form_prefix)===0) { … … 119 181 // Use case (1) 120 182 if ($action != 'clear_filters' && $action != 'reset') { 183 // initialize fields from $_POST 121 184 $this->setupEditFilters($this->all_filters,$_POST); 122 185 if ($action == 'add'){ 186 // Add a new filter 123 187 $fname = $p.'add_filter'; 124 188 if (isset($_POST[$fname]) 125 189 && isset($this->filters[$_POST[$fname]])) { 126 $this->filters[$_POST[$fname]]->add();190 $this->filters[$_POST[$fname]]->add(); 127 191 } 128 192 $this->hide_filterset = false; 129 193 } elseif (strpos($action,'del_') === 0) { 194 // Remove a filter 130 195 $count = preg_match('#del_(.+)_([0-9]+)#',$action,$match); 131 196 if (($count == 1) && isset($this->filters[$match[1]])) { … … 134 199 $this->hide_filterset = false; 135 200 } elseif ($action=="apply") { 201 // Apply all filters 202 // ==> store filter to preferences and redirect to 203 // page with filter as $_GET attributes 136 204 $data = $this->saveFilters(); 137 205 $query = http_build_query($data,'','&'); … … 143 211 } 144 212 } 213 // Form as been submitted with POST method, retrieve 214 // applied filter values from "query" field 145 215 if (isset($_POST[$p."query"])) { 146 216 parse_str($_POST[$p."query"],$out); 147 $this->setupApplied Filters($this->all_filters,$out);217 $this->setupAppliedValues($this->all_filters,$out); 148 218 if ($action == 'reset') { 219 // RESET action => set fields from query field 149 220 $this->setupEditFilters($this->all_filters,$out); 150 221 } elseif ($action == 'clear_filters') { … … 155 226 } 156 227 } 157 158 228 } 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. 160 231 $load_from_settings = true; 161 232 foreach($_GET as $k=>$v) { … … 167 238 $get = $_GET; 168 239 if ($load_from_settings) { 169 $get = new ArrayObject(array_merge($this->loadFilters(),$get));240 $get = array_merge($this->loadFilters(),$get); 170 241 } 171 242 $this->setupEditFilters($this->all_filters,$get); 172 243 173 $this->setupApplied Filters($this->all_filters,$get);244 $this->setupAppliedValues($this->all_filters,$get); 174 245 } 175 246 foreach ($this->static_filters as $f) { … … 178 249 } 179 250 } 180 $queryParams = $this->getAppliedFilter s();251 $queryParams = $this->getAppliedFilterValues(); 181 252 $this->addField( 182 253 new dcFieldHidden($this->form_prefix.'query', 183 254 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()); 185 259 } 186 260 187 261 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 */ 194 270 protected function saveFilters() { 195 271 $ser = array(); 196 272 $ws = $GLOBALS['core']->auth->user_prefs->addWorkspace('filters'); 197 $data = new ArrayObject();198 273 $data= $this->serialize(); 199 274 $ws->put($this->name,serialize($data->getArrayCopy()),'string'); … … 201 276 } 202 277 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 */ 206 285 protected function loadFilters() { 207 286 $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(); 209 290 if (is_array($data)) 210 291 return $data; … … 213 294 } 214 295 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 */ 221 307 protected function setupEditFilters ($filters,$form_data) { 222 308 foreach ($filters as $filter) { … … 224 310 } 225 311 } 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) { 227 325 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 */ 240 337 protected function serialize() { 241 338 $arr = new ArrayObject(); … … 250 347 return $arr; 251 348 } 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 */ 257 359 public function addFilter (dcFilter $filter) { 258 360 $filter->setFormPrefix($this->form_prefix); … … 267 369 } 268 370 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 */ 269 379 public function getContext() { 270 380 $fcontext = new ArrayObject(); … … 272 382 foreach ($this->filters as $f) { 273 383 if($f->isEnabled()) { 274 $f->append EditLines($fcontext);384 $f->appendFilterContext($fcontext); 275 385 } 276 386 } 277 387 foreach ($this->static_filters as $f) { 278 $f->append EditLines($sfcontext);388 $f->appendFilterContext($sfcontext); 279 389 } 280 390 return array( 281 'active_filters' => $fcontext, 391 'active_filters' => $fcontext, 282 392 'static_filters' => $sfcontext, 283 393 'hide_filters' => $this->hide_filterset, … … 285 395 } 286 396 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() { 288 405 $arr = new ArrayObject(); 289 406 foreach ($this->all_filters as $f) { … … 293 410 return $arr; 294 411 } 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 */ 302 422 public function applyFilters($params) { 303 423 foreach ($this->all_filters as $filter) { … … 310 430 } 311 431 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; 314 445 } 315 446 … … 317 448 318 449 319 320 450 /** 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 322 459 * 323 460 */ 324 461 abstract 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 */ 333 479 protected $static; 480 /** @var array generic field options */ 334 481 protected $options; 482 /** @var boolean true if field can have multiple values */ 335 483 protected $multiple; 336 484 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 */ 337 499 public function __construct ($id,$name,$desc,$request_param,$options=array()) { 338 500 $this->id = $id; … … 353 515 } 354 516 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 */ 362 529 protected function parseData($data) { 363 530 $arr = $this->field->parseValues($data); … … 365 532 } 366 533 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 */ 367 541 public function isStatic() { 368 542 return $this->static; 369 543 } 370 544 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 */ 371 554 public function setupFields($data) { 372 555 $this->field->setup($data); … … 374 557 375 558 559 /** 560 * init -- initializes filter (called after setup) 561 * 562 * @access public 563 * 564 * @return mixed Value. 565 */ 376 566 public function init() { 377 567 } 378 568 569 /** 570 * cleanup - resets filter field to its default value 571 * 572 * @access public 573 * 574 * @return mixed Value. 575 */ 379 576 public function cleanup() { 380 577 $this->field->setValues(array()); 381 578 } 382 579 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) { 384 590 $this->avalues = $this->parseData($data); 385 591 } … … 389 595 } 390 596 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) { 397 606 $this->filterset = $fs; 398 607 } 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 */ 406 618 public function setFormPrefix($prefix) { 407 619 $this->filter_id = $prefix.$this->id; 408 620 } 409 621 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 */ 415 630 public function isEnabled() { 416 631 return count($this->field) != 0; 417 632 } 418 633 419 634 protected abstract function addValue($value=NULL); 420 635 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 */ 424 643 public function add() { 425 644 if (count($this->field) > 1 && !$this->multiple) … … 427 646 $this->addValue(); 428 647 } 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 */ 433 658 public function remove($pos) { 434 659 $values = $this->field->getValues(); … … 439 664 } 440 665 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) { 444 684 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 */ 445 692 $line = new ArrayObject(); 446 693 $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 448 696 $del = new dcFieldSubmit( 449 $this->filterset-> getDelName($this->id,$cur),697 $this->filterset->buildFieldName('del',$this->id,$cur), 450 698 '-', 451 699 array( … … 454 702 ); 455 703 $this->filterset->addField($del); 456 $this->append SingleLine($line,$cur);704 $this->appendContextLine($line,$cur); 457 705 $ctx[]=$line; 458 706 } 459 707 } 460 708 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 */ 461 718 public function serialize($arr) { 462 719 if (count($this->fields) == 1) { … … 466 723 } 467 724 } 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 */ 469 733 public function isApplied(){ 470 734 return (count($this->avalues['values']) != 0); 471 735 } 472 736 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 */ 480 747 public function applyFilter($params) { 481 748 return false; 482 749 } 483 750 751 /** 752 * header -- tbd 753 * 754 * @access public 755 * 756 * @return mixed Value. 757 */ 484 758 public function header() { 485 759 return ''; 486 760 } 487 761 762 /** 763 * getFields -- returns filter field(s) 764 * 765 * @access public 766 * 767 * @return dcField the filter field. 768 */ 488 769 public function getFields() { 489 770 return $this->field; … … 492 773 } 493 774 494 495 775 /** 776 * dcFilterText - basic single field text filter 777 * 778 * @uses dcFilter 779 * 780 */ 496 781 class dcFilterText extends dcFilter { 497 782 783 /** 784 * @see dcFilter::init() 785 */ 498 786 public function init() { 499 787 $this->field = new dcFieldText( … … 505 793 506 794 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 */ 508 806 $line['ffield'] = $this->field->getName(); 509 807 if ($this->static) { … … 517 815 } 518 816 519 protected function addValue($value=NULL) { 817 /** 818 * @see dcFilter::addValue() 819 */ 820 protected function addValue($value=NULL) { 520 821 if ($value === NULL) { 521 822 $value = ''; … … 524 825 } 525 826 827 /** 828 * @see dcFilter::applyFilter() 829 */ 526 830 public function applyFilter($params) { 527 831 $params[$this->request_param]=$this->avalues['values'][0]; 528 832 } 529 530 833 } 834 531 835 /** 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 * 537 843 */ 538 844 class dcFilterCombo extends dcFilter { 845 /** @var combo the list of possible values in combo */ 539 846 protected $combo; 540 847 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()) { 542 853 parent::__construct($id,$name,$desc,$request_param,$options); 543 854 $this->combo = $combo; 544 855 } 856 857 /** 858 * @see dcFilter::init() 859 */ 545 860 public function init() { 546 861 $this->field = new dcFieldCombo( … … 551 866 } 552 867 868 /** 869 * @see dcFilter::addValue() 870 */ 553 871 protected function addValue($value=NULL) { 554 872 if ($value === NULL) { … … 558 876 } 559 877 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 */ 561 891 if ($this->static) { 562 892 $line['display_inline'] = true; … … 571 901 }; 572 902 } 573 903 904 /** 905 * @see dcFilter::applyFilter() 906 */ 574 907 public function applyFilter($params) { 575 908 $attr = $this->request_param; … … 583 916 584 917 /** 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 * 590 924 */ 591 925 class dcFilterRichCombo extends dcFilterCombo { 926 /** @var verb verb field ('is' or 'is not') */ 592 927 protected $verb; 593 928 929 /** 930 * @see dcFilter::init() 931 */ 594 932 public function init() { 595 933 parent::init(); … … 604 942 } 605 943 944 /** 945 * @see dcFilter::parseData() 946 */ 606 947 protected function parseData($data) { 607 948 $val = parent::parseData($data); … … 614 955 } 615 956 957 /** 958 * @see dcFilter::setupFields() 959 */ 616 960 public function setupFields($data) { 617 961 parent::setupFields($data); … … 619 963 } 620 964 965 /** 966 * @see dcFilter::updateAppliedValues() 967 */ 621 968 public function updateAppliedValues($arr) { 622 969 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); 628 978 if ($pos == 0) { 629 979 $line['fverb'] = $this->verb->getName(); 630 980 $line['fwidget']='filter_richcombo'; 631 } 632 } 633 981 } 982 } 983 984 /** 985 * @see dcFilter::serialize() 986 */ 634 987 public function serialize($arr) { 635 988 parent::serialize($arr); 636 989 $arr[$this->filter_id.'_v']=$this->verb->getValue(); 637 990 } 638 991 992 /** 993 * @see dcFilter::applyFilter() 994 */ 639 995 public function applyFilter($params) { 640 996 parent::applyFilter($params); … … 647 1003 } 648 1004 649 650 1005 // Static initializer 651 1006 dcFilterSet::__init__($GLOBALS['core']->tpl); 652 1007 ?>
Note: See TracChangeset
for help on using the changeset viewer.