~sense/ubuntu-wanted/drupal6-migration

« back to all changes in this revision

Viewing changes to module/wanted/models/modellink.php

  • Committer: Sense Hofstede
  • Date: 2009-03-22 12:38:25 UTC
  • mfrom: (15.1.11 qevel)
  • Revision ID: sense@qense.nl-20090322123825-kxopq3eto0s5o968
* Skill overview page added
* Pagination now works (LP:332941)
* Skill lists are now properly ordered(LP:332439)
* Some too generic class names were adapted to prevent name collision in case another module uses the same name (Thanks to Sayak Banerjee for finding this one)
* The usual typos, small problems and error were solved

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
Ubuntu is a registered trademark of Canonical Ltd.
21
21
*/
22
22
 
23
 
abstract class ModelLink extends Model
 
23
abstract class WModelLink extends WModel
24
24
{
25
25
        /**
26
26
         * Contains the name of the left table to be linked
61
61
        /**
62
62
         * Initialize the model with the url parameters.
63
63
         */
64
 
        function init(Model &$leftModel, Model &$rightModel=null, $fields=null) {
65
 
                if(is_array($field)) {
 
64
        function init(WModel &$leftModel, WModel &$rightModel=null, $fields=null, $arguments=null) {
 
65
                // If a restricted set of fields is requested, save them
 
66
                if(is_array($fields)) {
66
67
                        // Make sure the two collumnns with the foreign keys are requested
67
68
                        if(!in_array($this->_left_collumn)) {
68
69
                                $fields[] = $this->_left_collumn;
71
72
                                $fields[] = $this->_right_collumn;
72
73
                        }
73
74
                        
74
 
                        $this->_fields == null;
75
 
                }
 
75
                        $this->_fields = $fields;
 
76
                }
 
77
                
 
78
                // Check for possible WHERE-additions
 
79
                if(is_array($arguments)) {
 
80
                        $this->_arguments = array_merge($this->_arguments, $arguments);
 
81
                }
 
82
                
76
83
                $this->_left_model = $leftModel;
77
84
                $this->_right_model = $rightModel;
78
85
        }
116
123
                        $where .= (($i == 1) ? "WHERE ".$this->_left_collumn." = ".$data['id']."" : " OR ".$this->_left_collumn." = ".$data['id']."");
117
124
                        $i++;
118
125
                }
 
126
                // Add manually added arguments
 
127
                if($this->_arguments != array()) {
 
128
                        foreach($this->_arguments as $key => $value) {
 
129
                                if(is_array($value)) {
 
130
                                        $where .= (($i == 1) ? " ( " : " AND ( ");
 
131
                                        $j = 1;
 
132
                                        foreach($value as $subkey => $subvalue) {
 
133
                                                $operator = ((is_numeric($subkey)) ? '=' : $subkey);
 
134
                                                $where .= (($j > 1 ) ? " OR ".$key." ".$operator." ".$subvalue : "WHERE ". $key." ".$operator." ".$subvalue);
 
135
                                                $j++;
 
136
                                        }
 
137
                                                $where .= ")";
 
138
                                } else {
 
139
                                        $where .= (($i == 1) ? "WHERE ".$key." = ".$value : " AND ".$key." = ".$value);
 
140
                                }
 
141
                                $i++;
 
142
                        }
 
143
                }
 
144
                
119
145
                return $where;
120
146
        }
121
147
        
124
150
         */
125
151
        public function returnDependencies() {
126
152
                // Generate an array of foreign keys for rightModel
127
 
                $id_lists = array();
 
153
                $id_list = array();
128
154
                foreach($this->data as $values) {
129
 
                        $id_lists[] = $values[$this->_right_collumn];
 
155
                        foreach($values as $right_collumn => $data) {
 
156
                                $id_list[] = $right_collumn;
 
157
                        }
130
158
                }
131
159
                
132
 
                $dep_list[$this->_right_slug] = array('field' => null,
133
 
                                                        'arguments' => array($this->_right_collumn => $id_lists),
 
160
                $dep_array[$this->_right_slug] = array(
 
161
                                                        'field' => null,
 
162
                                                        'arguments' => array('id' => $id_list),
134
163
                                                        'order' => null,
135
164
                                                        'limit' => null,
136
165
                                                );
137
 
                return $dep_list;
 
166
                return $dep_array;
138
167
        }
139
168
        
140
169
        /**
248
277
                }
249
278
        }
250
279
}
251
 
?>
 
 
b'\\ No newline at end of file'
 
280
?>