~slincire/sahana-agasti/cuny-sps-trunk

« back to all changes in this revision

Viewing changes to plugins/sfDatagridPlugin/lib/sfDatagridFormatterPropel.class.php

  • Committer: Nils Stolpe
  • Date: 2011-01-21 04:31:58 UTC
  • mfrom: (62.1.79 trunk)
  • Revision ID: nils.stolpe@mail.cuny.edu-20110121043158-raqdgit068868lti
post merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
class sfDatagridFormatterPropel extends sfDatagridFormatterDefault{
4
 
        /**
5
 
         * Get the input for the filter
6
 
         *
7
 
         * @param string $type The type of the filter
8
 
         * @param string $column The column name
9
 
         * @param string $value The value of the input
10
 
         * @param sfDatagrid $object The datagrid object
11
 
         * @param string $suffix The url suffix
12
 
         * @return string The html output
13
 
         */
14
 
        protected function getInputFilter($type, $column, $value, $object, $suffix)
15
 
        {
16
 
                
17
 
                $output = '';
18
 
                try
19
 
                                {
20
 
                                /*
21
 
                                         * @todo il faudra penser a déplacer ce morceau de code afin de prendre en entrer $mapBuilder pour le
22
 
                                         * calculer qu'une fois
23
 
                                         */
24
 
                                $tablePeer=$object->_get('peerTable').'Peer';
25
 
                                $builder=$object->_get('peerTable').'MapBuilder';
26
 
                                if(sfAutoload::getInstance()->loadClass($builder)){
27
 
                                $mapBuilder=new $builder;
28
 
                                $mapBuilder->doBuild();
29
 
                                $adminrelated = $mapBuilder->getDatabaseMap()->getTable(sfInflector::underscore($object->_get('peerTable')))->getColumn(strtoupper($column));
30
 
                                
31
 
                                }else{
32
 
                                         $map=$object->_get('peerTable').'TableMap';
33
 
                                                 $map=new $map($object->_get('peerTable'),new DatabaseMap('propel'));
34
 
                                                 $map->initialize();
35
 
                                                 $adminrelated = $map->getColumn(strtoupper($column));
36
 
                                }
37
 
                                
38
 
                                
39
 
                                
40
 
                                }catch(Exception $e)
41
 
                                {
42
 
                                    $adminrelated = '';
43
 
                                }
44
 
                               
45
 
                switch($type)
46
 
                {
47
 
                        
48
 
                        
49
 
                        case 'FOREIGN':
50
 
                                 
51
 
                                 if(($adminrelated instanceof ColumnMap)&&($adminrelated->isForeignKey()))
52
 
                                 {
53
 
                                        $c=sfDatagrid::getConfig('class_for_foreign');
54
 
                                        if(sfAutoload::getInstance()->loadClass(sfInflector::camelize($adminrelated->getRelatedTableName()))){
55
 
                                                $class=sfInflector::camelize($adminrelated->getRelatedTableName());
56
 
                                        }else{
57
 
                                                $class=sfInflector::camelize($adminrelated->getRelatedTableName());
58
 
                                                $class=strtolower($class[0]).substr($class,1);
59
 
                                                
60
 
                                        }
61
 
                                        
62
 
                                        if(sfAutoload::getInstance()->loadClass($class)){
63
 
                                                        $wSelect= new $c(
64
 
                                                        array('model' => $class,  'add_empty' =>true)); 
65
 
                                                        if($object->getOrderByForFilter($column)){
66
 
                                                                $wSelect->setOption( 'order_by',$object->getOrderByForFilter($column));
67
 
                                                        }
68
 
                                                        $output = $wSelect->render('search[' . $column . ']', $value, array('style' => 'width: 100%;'));
69
 
                                        } 
70
 
                                }
71
 
                                        break;
72
 
                        case is_array($type):
73
 
                                $choices[''] = '';
74
 
                                
75
 
                                foreach($type as $key => $values)
76
 
                                {
77
 
                                        $choices[$key] = $values;
78
 
                                }
79
 
                                
80
 
                                $wSelect = new sfWidgetFormSelect(array('choices' => $choices));
81
 
                                $output = $wSelect->render('search[' . $column . ']', $value, array('style' => 'width: 100%;'));
82
 
                                break;
83
 
                                
84
 
                        case 'NOTYPE':
85
 
                                $output = '';
86
 
                                break;
87
 
                        
88
 
                        case 'BOOLEAN':
89
 
                                $wSelect = new sfWidgetFormSelect(array('choices' => array('' => '', 1 => 'Oui', 0 => 'Non')));
90
 
                                $output = $wSelect->render('search[' . $column . ']', $value, array('style' => 'width: 100%;'));
91
 
                                break;
92
 
                                
93
 
                        case (strtoupper($type) == 'DATE' || strtoupper($type) == 'TIMESTAMP'):
94
 
                                if(@array_key_exists('start_' . $object->_get('datagridName'), $value) && $value['start_' . $object->_get('datagridName')] != '')
95
 
                                {
96
 
                                        $value1 = format_date(strtotime($value['start_' . $object->_get('datagridName')]), 'dd.MM.yyyy');
97
 
                                }
98
 
                                else
99
 
                                {
100
 
                                        $value1 = '';
101
 
                                }
102
 
                                
103
 
                                if(@array_key_exists('start_' . $object->_get('datagridName'), $value) && $value['stop_' . $object->_get('datagridName')] != '')
104
 
                                {
105
 
                                        $value2 = format_date(strtotime($value['stop_' . $object->_get('datagridName')]), 'dd.MM.yyyy');
106
 
                                }
107
 
                                else
108
 
                                {
109
 
                                        $value2 = '';
110
 
                                }
111
 
                                if(@array_key_exists('null_' . $object->_get('datagridName'), $value) && $value['null_' . $object->_get('datagridName')] != '')
112
 
                                {
113
 
                                        
114
 
                                        $value3 = array('null'=>$value['null_' . $object->_get('datagridName')][0]);
115
 
                                }
116
 
                                else
117
 
                                {
118
 
                                        $value3 = null;
119
 
                                }
120
 
                                $wDateStart = new sfWidgetFormInput();
121
 
                                $wDateStop = new sfWidgetFormInput();
122
 
                                
123
 
                                $output = '<span style="padding-bottom: 5px; display: block;">';
124
 
                                $output.= $this->traduct(sfDatagrid::getConfig('text_from')) . ' ';
125
 
                                $output.= $wDateStart->render('search[' . $column . '][start_' . $object->_get('datagridName') . ']', $value1, array('onclick' => 'displayDatePicker(this.name)', 'style' => 'width: 75px;'));
126
 
                                $output.= '</span>';
127
 
                                $output.= ' ' .$this->traduct(sfDatagrid::getConfig('text_to')) . ' ';
128
 
                                $output.= $wDateStop->render('search[' . $column . '][stop_' . $object->_get('datagridName') . ']', $value2, array('type' => 'text', 'onclick' => 'displayDatePicker(this.name)', 'style' => 'width: 75px;'));
129
 
                                
130
 
                                if((($adminrelated instanceof ColumnMap)&&(!$adminrelated->isNotNull()))){
131
 
                                        $chk = new sfWidgetFormSelectCheckbox(array('choices'=>array('null'=>$this->traduct(sfDatagrid::getConfig('label_null')))));
132
 
                                        $output .= $chk->render('search[' . $column . '][null_'. $object->_get('datagridName') . ']',$value3,array());
133
 
                                }
134
 
                                break;
135
 
                                
136
 
                        default:
137
 
                                $wInput = new sfWidgetFormInput();
138
 
                                $url = $object->_get('moduleAction') . '?' . $this->P_PAGE . '=1' . $suffix . '&' . $this->P_SORT . '=' . $object->_get('sortBy') . '&' . $this->P_ORDER . '=' . $object->_get('sortOrder');
139
 
                                $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,'.(sfDatagrid::getConfig('freezepanes',false)?'true':'false').')'));
140
 
                                break;
141
 
                }
142
 
                
143
 
                return content_tag('div', $output);
144
 
        }
145
 
        
146
 
}
147
 
?>
 
 
b'\\ No newline at end of file'