| 365 | | /** |
|---|
| 366 | | * Get the input for the filter |
|---|
| 367 | | * |
|---|
| 368 | | * @param string $type The type of the filter |
|---|
| 369 | | * @param string $column The column name |
|---|
| 370 | | * @param string $value The value of the input |
|---|
| 371 | | * @param sfDatagrid $object The datagrid object |
|---|
| 372 | | * @param string $suffix The url suffix |
|---|
| 373 | | * @return string The html output |
|---|
| 374 | | */ |
|---|
| 375 | | protected function getInputFilter($type, $column, $value, $object, $suffix) |
|---|
| 376 | | { |
|---|
| 377 | | |
|---|
| 378 | | $output = ''; |
|---|
| 379 | | try |
|---|
| 380 | | { |
|---|
| 381 | | /* |
|---|
| 382 | | * @todo il faudra penser a déplacer ce morceau de code afin de prendre en entrer $mapBuilder pour le |
|---|
| 383 | | * calculer qu'une fois |
|---|
| 384 | | */ |
|---|
| 385 | | $tablePeer=$object->_get('peerTable').'Peer'; |
|---|
| 386 | | $builder=$object->_get('peerTable').'MapBuilder'; |
|---|
| 387 | | $mapBuilder=new $builder; |
|---|
| 388 | | $mapBuilder->doBuild(); |
|---|
| 389 | | $adminrelated = $mapBuilder->getDatabaseMap()->getTable(sfInflector::underscore($object->_get('peerTable')))->getColumn(strtoupper($column)); |
|---|
| 390 | | |
|---|
| 391 | | |
|---|
| 392 | | }catch(Exception $e) |
|---|
| 393 | | { |
|---|
| 394 | | $adminrelated = ''; |
|---|
| 395 | | } |
|---|
| 396 | | |
|---|
| 397 | | switch($type) |
|---|
| 398 | | { |
|---|
| 399 | | |
|---|
| 400 | | |
|---|
| 401 | | case 'FOREIGN': |
|---|
| 402 | | |
|---|
| 403 | | if(($adminrelated instanceof ColumnMap)&&($adminrelated->isForeignKey())) |
|---|
| 404 | | { |
|---|
| 405 | | $c=sfDatagrid::getConfig('class_for_foreign'); |
|---|
| 406 | | if(class_exists(sfInflector::camelize($adminrelated->getRelatedTableName()))){ |
|---|
| 407 | | $class=sfInflector::camelize($adminrelated->getRelatedTableName()); |
|---|
| 408 | | }else{ |
|---|
| 409 | | $class=sfInflector::camelize($adminrelated->getRelatedTableName()); |
|---|
| 410 | | $class=strtolower($class[0]).substr($class,1); |
|---|
| 411 | | |
|---|
| 412 | | } |
|---|
| 413 | | |
|---|
| 414 | | if(class_exists($class)){ |
|---|
| 415 | | $wSelect= new $c( |
|---|
| 416 | | array('model' => $class, 'add_empty' =>true)); |
|---|
| 417 | | if($object->getOrderByForFilter($column)){ |
|---|
| 418 | | $wSelect->setOption( 'order_by',$object->getOrderByForFilter($column)); |
|---|
| 419 | | } |
|---|
| 420 | | $output = $wSelect->render('search[' . $column . ']', $value, array('style' => 'width: 100%;')); |
|---|
| 421 | | } |
|---|
| 422 | | } |
|---|
| 423 | | break; |
|---|
| 424 | | case is_array($type): |
|---|
| 425 | | $choices[''] = ''; |
|---|
| 426 | | |
|---|
| 427 | | foreach($type as $key => $values) |
|---|
| 428 | | { |
|---|
| 429 | | $choices[$key] = $values; |
|---|
| 430 | | } |
|---|
| 431 | | |
|---|
| 432 | | $wSelect = new sfWidgetFormSelect(array('choices' => $choices)); |
|---|
| 433 | | $output = $wSelect->render('search[' . $column . ']', $value, array('style' => 'width: 100%;')); |
|---|
| 434 | | break; |
|---|
| 435 | | |
|---|
| 436 | | case 'NOTYPE': |
|---|
| 437 | | $output = ''; |
|---|
| 438 | | break; |
|---|
| 439 | | |
|---|
| 440 | | case 'BOOLEAN': |
|---|
| 441 | | $wSelect = new sfWidgetFormSelect(array('choices' => array('' => '', 1 => 'Oui', 0 => 'Non'))); |
|---|
| 442 | | $output = $wSelect->render('search[' . $column . ']', $value, array('style' => 'width: 100%;')); |
|---|
| 443 | | break; |
|---|
| 444 | | |
|---|
| 445 | | case (strtoupper($type) == 'DATE' || strtoupper($type) == 'TIMESTAMP'): |
|---|
| 446 | | if(@array_key_exists('start_' . $object->_get('datagridName'), $value) && $value['start_' . $object->_get('datagridName')] != '') |
|---|
| 447 | | { |
|---|
| 448 | | $value1 = format_date(strtotime($value['start_' . $object->_get('datagridName')]), 'dd.MM.yyyy'); |
|---|
| 449 | | } |
|---|
| 450 | | else |
|---|
| 451 | | { |
|---|
| 452 | | $value1 = ''; |
|---|
| 453 | | } |
|---|
| 454 | | |
|---|
| 455 | | if(@array_key_exists('start_' . $object->_get('datagridName'), $value) && $value['stop_' . $object->_get('datagridName')] != '') |
|---|
| 456 | | { |
|---|
| 457 | | $value2 = format_date(strtotime($value['stop_' . $object->_get('datagridName')]), 'dd.MM.yyyy'); |
|---|
| 458 | | } |
|---|
| 459 | | else |
|---|
| 460 | | { |
|---|
| 461 | | $value2 = ''; |
|---|
| 462 | | } |
|---|
| 463 | | if(@array_key_exists('null_' . $object->_get('datagridName'), $value) && $value['null_' . $object->_get('datagridName')] != '') |
|---|
| 464 | | { |
|---|
| 465 | | |
|---|
| 466 | | $value3 = array('null'=>$value['null_' . $object->_get('datagridName')][0]); |
|---|
| 467 | | } |
|---|
| 468 | | else |
|---|
| 469 | | { |
|---|
| 470 | | $value3 = null; |
|---|
| 471 | | } |
|---|
| 472 | | $wDateStart = new sfWidgetFormInput(); |
|---|
| 473 | | $wDateStop = new sfWidgetFormInput(); |
|---|
| 474 | | |
|---|
| 475 | | $output = '<span style="padding-bottom: 5px; display: block;">'; |
|---|
| 476 | | $output.= $this->traduct(sfDatagrid::getConfig('text_from')) . ' '; |
|---|
| 477 | | $output.= $wDateStart->render('search[' . $column . '][start_' . $object->_get('datagridName') . ']', $value1, array('onclick' => 'displayDatePicker(this.name)', 'style' => 'width: 75px;')); |
|---|
| 478 | | $output.= '</span>'; |
|---|
| 479 | | $output.= ' ' .$this->traduct(sfDatagrid::getConfig('text_to')) . ' '; |
|---|
| 480 | | $output.= $wDateStop->render('search[' . $column . '][stop_' . $object->_get('datagridName') . ']', $value2, array('type' => 'text', 'onclick' => 'displayDatePicker(this.name)', 'style' => 'width: 75px;')); |
|---|
| 481 | | |
|---|
| 482 | | if((($adminrelated instanceof ColumnMap)&&(!$adminrelated->isNotNull()))){ |
|---|
| 483 | | $chk = new sfWidgetFormSelectCheckbox(array('choices'=>array('null'=>$this->traduct(sfDatagrid::getConfig('label_null'))))); |
|---|
| 484 | | $output .= $chk->render('search[' . $column . '][null_'. $object->_get('datagridName') . ']',$value3,array()); |
|---|
| 485 | | } |
|---|
| 486 | | break; |
|---|
| 487 | | |
|---|
| 488 | | default: |
|---|
| 489 | | $wInput = new sfWidgetFormInput(); |
|---|
| 490 | | $url = $object->_get('moduleAction') . '?' . $this->P_PAGE . '=1' . $suffix . '&' . $this->P_SORT . '=' . $object->_get('sortBy') . '&' . $this->P_ORDER . '=' . $object->_get('sortOrder'); |
|---|
| 491 | | $output = $wInput->render('search[' . $column . ']', $value, array('style' => 'width: 100%;', 'onkeydown' => 'dg_keydown(\'' . $object->_get('datagridName') . '-form\', \'' . $object->_get('datagridName') . '\', \'search\', \'' . url_for($url) . '\', event)')); |
|---|
| 492 | | break; |
|---|
| 493 | | } |
|---|
| 494 | | |
|---|
| 495 | | return content_tag('div', $output); |
|---|
| 496 | | } |
|---|