~sense/ubuntu-wanted/drupal6-migration

« back to all changes in this revision

Viewing changes to module/wanted/models/model.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 Model extends Observer
 
23
abstract class WModel extends WObserver
24
24
{
25
25
        /**
26
26
         * URL agruments
76
76
         */
77
77
        function init($fields=null, $arguments=null, $order=null, $limit=null) {
78
78
                $this->_arguments = (is_array($arguments) ? array_merge($this->_arguments, $arguments) : $this->_arguments);
79
 
                $this->_fields = (is_array($fields) ? $fields : null);
80
 
                $this->_limit = (is_array($limit) ? $limit : null);
81
 
                $this->_order = (is_array($order)? $order : null);
 
79
                $this->_fields = (is_array($fields) ? $fields : $this->_fields);
 
80
                $this->_limit = (is_array($limit) ? $limit : $this->_limit);
 
81
                $this->_order = (is_array($order)? $order : $this->_order);
82
82
        }
83
83
        
84
84
        /**
124
124
         * Process dependencies of other modules
125
125
         */
126
126
        public function processDependencies($dep_array) {
127
 
                if(!empty($dep_array['fields'])) {
 
127
                $reload = false;
 
128
                if($dep_array['fields'] != null) {
128
129
            $fields = array_merge($this->_fields, $dep_array['fields']);
 
130
                $reload = true;
 
131
        }
 
132
        if($dep_array['arguments'] != null) {
129
133
            $arguments = array_merge($this->_arguments, $dep_array['arguments']);
130
 
            $order = array_merge($this->_order, $dep_array['order']);
131
 
            $limit = array_merge($this->_limit, $dep_array['order']);
132
 
            $this->init($fields, $arguments, $order, $limit);
 
134
            $reload = true;
133
135
        }
134
 
                $this->reload();
 
136
        if($dep_array['order'] != null) {
 
137
            $order = $dep_array['order'];
 
138
            $reload = true;
 
139
        } 
 
140
        if($dep_array['limit'] != null) {
 
141
            $limit = $dep_array['limit'];
 
142
            $reload = true;
 
143
                }
 
144
                if($reload) {
 
145
                    $this->init($fields, $arguments, $order, $limit);
 
146
                        $this->reload();
 
147
                }
135
148
        }
 
149
        
136
150
    /**
137
151
     * Build of field list of the query
138
152
     */
139
153
    protected function _queryField() {
140
154
                if(is_array($this->_fields)) {
141
 
                        if(in_array('id', $this->_fields)) {
 
155
                        if(in_array('id', $this->_fields) AND in_array($this->array_name, $this->_fields)) {
 
156
                        // Make sure the id and array_name fields are requested
142
157
                                return implode(", ", $this->_fields);
143
158
                        } else {
144
 
                                // The id field, which is required, wasn't requested
145
 
                                // so it's added now
146
 
                                return "id, " . implode(", ", $this->_fields);
 
159
                                if(!in_array('id', $this->_fields) AND !in_array($this->array_name, $this->_fields) AND $this->array_name != 'id') {
 
160
                                // Both the id and the array_name weren't there, which is required, wasn't requested
 
161
                                        // so it's added now
 
162
                                        return "id, " . $this->array_name . ", " . implode(", ", $this->_fields);
 
163
                                } elseif(!in_array('id', $this->_fields) AND $this->array_name == 'id') {
 
164
                                        // add the id field
 
165
                                        return "id, " . implode(", ", $this->_fields);
 
166
                                } else {
 
167
                                        return $this->array_name . ", " . implode(", ", $this->_fields);
 
168
                                }
147
169
                        }
148
170
                } else {
149
171
                        return "*";
161
183
     * Build the ORDER part of the query
162
184
     */
163
185
     protected function _queryOrder() {
164
 
         return ($this->order != null) ? "ORDER BY ".$this->_order[0]." ".$this->_order[1] : "";
 
186
         return ($this->_order != null) ? "ORDER BY ".$this->_order[0]." ".$this->_order[1] : "";
165
187
     }
166
188
 
167
189
        /**
172
194
        $i = 1;
173
195
                foreach($this->_arguments as $key => $value) {
174
196
                        if(is_array($value)) {
175
 
                                $where .= (($i == 1) ? " ( " : " AND ( ");
176
 
                                $i = 0;
 
197
                                $where .= (($i == 1) ? " ( " : " AND ( ");              
 
198
                                $j = 1;
177
199
                                foreach($value as $subkey => $subvalue) {
178
 
                                        $operator = ((is_numeric($subkey)) ? '=' : $subkey);
179
 
                                        $where .= (($i > 0 ) ? " OR ".$key." ".$operator." ".$subvalue : $key." ".$operator." ".$subvalue);
180
 
                                        $i++;
 
200
                                        $operator = ((is_int($subkey)) ? '=' : $subkey);
 
201
                                        $where .= (($j > 1 ) ? " OR " . $key . " " . $operator . " '" . $subvalue . "'" : $key . " " . $operator . " '" . $subvalue . "'");
 
202
                                        $j++;
181
203
                                }
182
204
                                $where .= ")";
183
205
                        } else {
184
 
                                $where .= (($i == 1) ? " ".$key." = ".$value : " AND ".$key." = ".$value);
 
206
                                $where .= (($i == 1) ? " " . $key . " = '" . $value . "'" : " AND ".$key." = '" . $value . "'");
185
207
                        }
186
208
                        $i++;
187
209
                }
320
342
                }
321
343
        }
322
344
}
323
 
?>
 
 
b'\\ No newline at end of file'
 
345
?>