r114514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114513‎ | r114514 | r114515 >
Date:11:10, 27 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
match renaming in core
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndeleteAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPViewAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EditCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewOrgAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/compat/DBDataObject.php (deleted) (history)
  • /trunk/extensions/EducationProgram/compat/DBTable.php (deleted) (history)
  • /trunk/extensions/EducationProgram/compat/ORMResult.php (added) (history)
  • /trunk/extensions/EducationProgram/compat/ORMRow.php (added) (history)
  • /trunk/extensions/EducationProgram/compat/ORMTable.php (added) (history)
  • /trunk/extensions/EducationProgram/docs/schema.txt (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticle.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticles.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCAs.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPInstructors.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOAPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOAs.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgs.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageTable.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevision.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisions.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudents.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/sql/EducationProgram.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/compat/DBTable.php
@@ -1,658 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Abstract base class for representing a single database table.
6 - *
7 - * @since 1.20
8 - *
9 - * @file DBTable.php
10 - *
11 - * @licence GNU GPL v2 or later
12 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
13 - */
14 -abstract class DBTable {
15 -
16 - /**
17 - * Returns the name of the database table objects of this type are stored in.
18 - *
19 - * @since 1.20
20 - *
21 - * @return string
22 - */
23 - public abstract function getDBTable();
24 -
25 - /**
26 - * Returns the name of a DBDataObject deriving class that
27 - * represents single rows in this table.
28 - *
29 - * @since 1.20
30 - *
31 - * @return string
32 - */
33 - public abstract function getDataObjectClass();
34 -
35 - /**
36 - * Gets the db field prefix.
37 - *
38 - * @since 1.20
39 - *
40 - * @return string
41 - */
42 - protected abstract function getFieldPrefix();
43 -
44 - /**
45 - * Returns an array with the fields and their types this object contains.
46 - * This corresponds directly to the fields in the database, without prefix.
47 - *
48 - * field name => type
49 - *
50 - * Allowed types:
51 - * * id
52 - * * str
53 - * * int
54 - * * float
55 - * * bool
56 - * * array
57 - *
58 - * @since 1.20
59 - *
60 - * @return array
61 - */
62 - public abstract function getFieldTypes();
63 -
64 - /**
65 - * The database connection to use for read operations.
66 - * Can be changed via @see setReadDb.
67 - *
68 - * @since 1.20
69 - * @var integer DB_ enum
70 - */
71 - protected $readDb = DB_SLAVE;
72 -
73 - /**
74 - * Returns a list of default field values.
75 - * field name => field value
76 - *
77 - * @since 1.20
78 - *
79 - * @return array
80 - */
81 - public function getDefaults() {
82 - return array();
83 - }
84 -
85 - /**
86 - * Returns a list of the summary fields.
87 - * These are fields that cache computed values, such as the amount of linked objects of $type.
88 - * This is relevant as one might not want to do actions such as log changes when these get updated.
89 - *
90 - * @since 1.20
91 - *
92 - * @return array
93 - */
94 - public function getSummaryFields() {
95 - return array();
96 - }
97 -
98 - /**
99 - * Selects the the specified fields of the records matching the provided
100 - * conditions and returns them as DBDataObject. Field names get prefixed.
101 - *
102 - * @since 1.20
103 - *
104 - * @param array|string|null $fields
105 - * @param array $conditions
106 - * @param array $options
107 - * @param string|null $functionName
108 - *
109 - * @return array of self
110 - */
111 - public function select( $fields = null, array $conditions = array(), array $options = array(), $functionName = null ) {
112 - $result = $this->selectFields( $fields, $conditions, $options, false, $functionName );
113 -
114 - $objects = array();
115 -
116 - foreach ( $result as $record ) {
117 - $objects[] = $this->newFromArray( $record );
118 - }
119 -
120 - return $objects;
121 - }
122 -
123 - /**
124 - * Selects the the specified fields of the records matching the provided
125 - * conditions and returns them as associative arrays.
126 - * Provided field names get prefixed.
127 - * Returned field names will not have a prefix.
128 - *
129 - * When $collapse is true:
130 - * If one field is selected, each item in the result array will be this field.
131 - * If two fields are selected, each item in the result array will have as key
132 - * the first field and as value the second field.
133 - * If more then two fields are selected, each item will be an associative array.
134 - *
135 - * @since 1.20
136 - *
137 - * @param array|string|null $fields
138 - * @param array $conditions
139 - * @param array $options
140 - * @param boolean $collapse Set to false to always return each result row as associative array.
141 - * @param string|null $functionName
142 - *
143 - * @return array of array
144 - */
145 - public function selectFields( $fields = null, array $conditions = array(), array $options = array(), $collapse = true, $functionName = null ) {
146 - if ( is_null( $fields ) ) {
147 - $fields = array_keys( $this->getFieldTypes() );
148 - }
149 - else {
150 - $fields = (array)$fields;
151 - }
152 -
153 - $dbr = wfGetDB( $this->getReadDb() );
154 - $result = $dbr->select(
155 - $this->getDBTable(),
156 - $this->getPrefixedFields( $fields ),
157 - $this->getPrefixedValues( $conditions ),
158 - is_null( $functionName ) ? __METHOD__ : $functionName,
159 - $options
160 - );
161 -
162 - $objects = array();
163 -
164 - foreach ( $result as $record ) {
165 - $objects[] = $this->getFieldsFromDBResult( $record );
166 - }
167 -
168 - if ( $collapse ) {
169 - if ( count( $fields ) === 1 ) {
170 - $objects = array_map( 'array_shift', $objects );
171 - }
172 - elseif ( count( $fields ) === 2 ) {
173 - $o = array();
174 -
175 - foreach ( $objects as $object ) {
176 - $o[array_shift( $object )] = array_shift( $object );
177 - }
178 -
179 - $objects = $o;
180 - }
181 - }
182 -
183 - return $objects;
184 - }
185 -
186 - /**
187 - * Selects the the specified fields of the first matching record.
188 - * Field names get prefixed.
189 - *
190 - * @since 1.20
191 - *
192 - * @param array|string|null $fields
193 - * @param array $conditions
194 - * @param array $options
195 - * @param string|null $functionName
196 - *
197 - * @return DBObject|bool False on failure
198 - */
199 - public function selectRow( $fields = null, array $conditions = array(), array $options = array(), $functionName = null ) {
200 - $options['LIMIT'] = 1;
201 -
202 - $objects = $this->select( $fields, $conditions, $options, $functionName );
203 -
204 - return empty( $objects ) ? false : $objects[0];
205 - }
206 -
207 - /**
208 - * Selects the the specified fields of the records matching the provided
209 - * conditions. Field names do NOT get prefixed.
210 - *
211 - * @since 1.20
212 - *
213 - * @param array $fields
214 - * @param array $conditions
215 - * @param array $options
216 - * @param string|null $functionName
217 - *
218 - * @return ResultWrapper
219 - */
220 - public function rawSelectRow( array $fields, array $conditions = array(), array $options = array(), $functionName = null ) {
221 - $dbr = wfGetDB( $this->getReadDb() );
222 -
223 - return $dbr->selectRow(
224 - $this->getDBTable(),
225 - $fields,
226 - $conditions,
227 - is_null( $functionName ) ? __METHOD__ : $functionName,
228 - $options
229 - );
230 - }
231 -
232 - /**
233 - * Selects the the specified fields of the first record matching the provided
234 - * conditions and returns it as an associative array, or false when nothing matches.
235 - * This method makes use of selectFields and expects the same parameters and
236 - * returns the same results (if there are any, if there are none, this method returns false).
237 - * @see DBDataObject::selectFields
238 - *
239 - * @since 1.20
240 - *
241 - * @param array|string|null $fields
242 - * @param array $conditions
243 - * @param array $options
244 - * @param boolean $collapse Set to false to always return each result row as associative array.
245 - * @param string|null $functionName
246 - *
247 - * @return mixed|array|bool False on failure
248 - */
249 - public function selectFieldsRow( $fields = null, array $conditions = array(), array $options = array(), $collapse = true, $functionName = null ) {
250 - $options['LIMIT'] = 1;
251 -
252 - $objects = $this->selectFields( $fields, $conditions, $options, $collapse, $functionName );
253 -
254 - return empty( $objects ) ? false : $objects[0];
255 - }
256 -
257 - /**
258 - * Returns if there is at least one record matching the provided conditions.
259 - * Condition field names get prefixed.
260 - *
261 - * @since 1.20
262 - *
263 - * @param array $conditions
264 - *
265 - * @return boolean
266 - */
267 - public function has( array $conditions = array() ) {
268 - return $this->selectRow( array( 'id' ), $conditions ) !== false;
269 - }
270 -
271 - /**
272 - * Returns the amount of matching records.
273 - * Condition field names get prefixed.
274 - *
275 - * Note that this can be expensive on large tables.
276 - * In such cases you might want to use DatabaseBase::estimateRowCount instead.
277 - *
278 - * @since 1.20
279 - *
280 - * @param array $conditions
281 - * @param array $options
282 - *
283 - * @return integer
284 - */
285 - public function count( array $conditions = array(), array $options = array() ) {
286 - $res = $this->rawSelectRow(
287 - array( 'COUNT(*) AS rowcount' ),
288 - $this->getPrefixedValues( $conditions ),
289 - $options
290 - );
291 -
292 - return $res->rowcount;
293 - }
294 -
295 - /**
296 - * Removes the object from the database.
297 - *
298 - * @since 1.20
299 - *
300 - * @param array $conditions
301 - * @param string|null $functionName
302 - *
303 - * @return boolean Success indicator
304 - */
305 - public function delete( array $conditions, $functionName = null ) {
306 - return wfGetDB( DB_MASTER )->delete(
307 - $this->getDBTable(),
308 - $this->getPrefixedValues( $conditions ),
309 - $functionName
310 - );
311 - }
312 -
313 - /**
314 - * Get API parameters for the fields supported by this object.
315 - *
316 - * @since 1.20
317 - *
318 - * @param boolean $requireParams
319 - * @param boolean $setDefaults
320 - *
321 - * @return array
322 - */
323 - public function getAPIParams( $requireParams = false, $setDefaults = false ) {
324 - $typeMap = array(
325 - 'id' => 'integer',
326 - 'int' => 'integer',
327 - 'float' => 'NULL',
328 - 'str' => 'string',
329 - 'bool' => 'integer',
330 - 'array' => 'string',
331 - 'blob' => 'string',
332 - );
333 -
334 - $params = array();
335 - $defaults = $this->getDefaults();
336 -
337 - foreach ( $this->getFieldTypes() as $field => $type ) {
338 - if ( $field == 'id' ) {
339 - continue;
340 - }
341 -
342 - $hasDefault = array_key_exists( $field, $defaults );
343 -
344 - $params[$field] = array(
345 - ApiBase::PARAM_TYPE => $typeMap[$type],
346 - ApiBase::PARAM_REQUIRED => $requireParams && !$hasDefault
347 - );
348 -
349 - if ( $type == 'array' ) {
350 - $params[$field][ApiBase::PARAM_ISMULTI] = true;
351 - }
352 -
353 - if ( $setDefaults && $hasDefault ) {
354 - $default = is_array( $defaults[$field] ) ? implode( '|', $defaults[$field] ) : $defaults[$field];
355 - $params[$field][ApiBase::PARAM_DFLT] = $default;
356 - }
357 - }
358 -
359 - return $params;
360 - }
361 -
362 - /**
363 - * Returns an array with the fields and their descriptions.
364 - *
365 - * field name => field description
366 - *
367 - * @since 1.20
368 - *
369 - * @return array
370 - */
371 - public function getFieldDescriptions() {
372 - return array();
373 - }
374 -
375 - /**
376 - * Get the database type used for read operations.
377 - *
378 - * @since 1.20
379 - *
380 - * @return integer DB_ enum
381 - */
382 - public function getReadDb() {
383 - return $this->readDb;
384 - }
385 -
386 - /**
387 - * Set the database type to use for read operations.
388 - *
389 - * @param integer $db
390 - *
391 - * @since 1.20
392 - */
393 - public function setReadDb( $db ) {
394 - $this->readDb = $db;
395 - }
396 -
397 - /**
398 - * Update the records matching the provided conditions by
399 - * setting the fields that are keys in the $values param to
400 - * their corresponding values.
401 - *
402 - * @since 1.20
403 - *
404 - * @param array $values
405 - * @param array $conditions
406 - *
407 - * @return boolean Success indicator
408 - */
409 - public function update( array $values, array $conditions = array() ) {
410 - $dbw = wfGetDB( DB_MASTER );
411 -
412 - return $dbw->update(
413 - $this->getDBTable(),
414 - $this->getPrefixedValues( $values ),
415 - $this->getPrefixedValues( $conditions ),
416 - __METHOD__
417 - );
418 - }
419 -
420 - /**
421 - * Computes the values of the summary fields of the objects matching the provided conditions.
422 - *
423 - * @since 1.20
424 - *
425 - * @param array|string|null $summaryFields
426 - * @param array $conditions
427 - */
428 - public function updateSummaryFields( $summaryFields = null, array $conditions = array() ) {
429 - $this->setReadDb( DB_MASTER );
430 -
431 - foreach ( $this->select( null, $conditions ) as /* DBDataObject */ $item ) {
432 - $item->loadSummaryFields( $summaryFields );
433 - $item->setSummaryMode( true );
434 - $item->save();
435 - }
436 -
437 - $this->setReadDb( DB_SLAVE );
438 - }
439 -
440 - /**
441 - * Takes in an associative array with field names as keys and
442 - * their values as value. The field names are prefixed with the
443 - * db field prefix.
444 - *
445 - * Field names can also be provided as an array with as first element a table name, such as
446 - * $conditions = array(
447 - * array( array( 'tablename', 'fieldname' ), $value ),
448 - * );
449 - *
450 - * @since 1.20
451 - *
452 - * @param array $values
453 - *
454 - * @return array
455 - */
456 - public function getPrefixedValues( array $values ) {
457 - $prefixedValues = array();
458 -
459 - foreach ( $values as $field => $value ) {
460 - if ( is_integer( $field ) ) {
461 - if ( is_array( $value ) ) {
462 - $field = $value[0];
463 - $value = $value[1];
464 - }
465 - else {
466 - $value = explode( ' ', $value, 2 );
467 - $value[0] = $this->getPrefixedField( $value[0] );
468 - $prefixedValues[] = implode( ' ', $value );
469 - continue;
470 - }
471 - }
472 -
473 - $prefixedValues[$this->getPrefixedField( $field )] = $value;
474 - }
475 -
476 - return $prefixedValues;
477 - }
478 -
479 - /**
480 - * Takes in a field or array of fields and returns an
481 - * array with their prefixed versions, ready for db usage.
482 - *
483 - * @since 1.20
484 - *
485 - * @param array|string $fields
486 - *
487 - * @return array
488 - */
489 - public function getPrefixedFields( array $fields ) {
490 - foreach ( $fields as &$field ) {
491 - $field = $this->getPrefixedField( $field );
492 - }
493 -
494 - return $fields;
495 - }
496 -
497 - /**
498 - * Takes in a field and returns an it's prefixed version, ready for db usage.
499 - *
500 - * @since 1.20
501 - *
502 - * @param string|array $field
503 - *
504 - * @return string
505 - */
506 - public function getPrefixedField( $field ) {
507 - return $this->getFieldPrefix() . $field;
508 - }
509 -
510 - /**
511 - * Takes an array of field names with prefix and returns the unprefixed equivalent.
512 - *
513 - * @since 1.20
514 - *
515 - * @param array $fieldNames
516 - *
517 - * @return array
518 - */
519 - public function unprefixFieldNames( array $fieldNames ) {
520 - return array_map( array( $this, 'unprefixFieldName' ), $fieldNames );
521 - }
522 -
523 - /**
524 - * Takes a field name with prefix and returns the unprefixed equivalent.
525 - *
526 - * @since 1.20
527 - *
528 - * @param string $fieldName
529 - *
530 - * @return string
531 - */
532 - public function unprefixFieldName( $fieldName ) {
533 - return substr( $fieldName, strlen( $this->getFieldPrefix() ) );
534 - }
535 -
536 - public function __construct() {
537 -
538 - }
539 -
540 - /**
541 - * Get an instance of this class.
542 - *
543 - * @since 1.20
544 - *
545 - * @return DBtable
546 - */
547 - public static function singleton() {
548 - static $instance;
549 -
550 - if ( !isset( $instance ) ) {
551 - $class = function_exists( 'get_called_class' ) ? get_called_class() : self::get_called_class();
552 - $instance = new $class;
553 - }
554 -
555 - return $instance;
556 - }
557 -
558 - /**
559 - * Compatibility fallback function so the singleton method works on PHP < 5.3.
560 - * Code borrowed from http://www.php.net/manual/en/function.get-called-class.php#107445
561 - *
562 - * @since 1.20
563 - *
564 - * @return string
565 - */
566 - protected static function get_called_class() {
567 - $bt = debug_backtrace();
568 - $l = count($bt) - 1;
569 - $matches = array();
570 - while(empty($matches) && $l > -1){
571 - $lines = file($bt[$l]['file']);
572 - $callerLine = $lines[$bt[$l]['line']-1];
573 - preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l--]['function'].'/',
574 - $callerLine,
575 - $matches);
576 - }
577 - if (!isset($matches[1])) $matches[1]=NULL; //for notices
578 - if ($matches[1] == 'self') {
579 - $line = $bt[$l]['line']-1;
580 - while ($line > 0 && strpos($lines[$line], 'class') === false) {
581 - $line--;
582 - }
583 - preg_match('/class[\s]+(.+?)[\s]+/si', $lines[$line], $matches);
584 - }
585 - return $matches[1];
586 - }
587 -
588 - /**
589 - * Get an array with fields from a database result,
590 - * that can be fed directly to the constructor or
591 - * to setFields.
592 - *
593 - * @since 1.20
594 - *
595 - * @param stdClass $result
596 - *
597 - * @return array
598 - */
599 - public function getFieldsFromDBResult( stdClass $result ) {
600 - $result = (array)$result;
601 - return array_combine(
602 - $this->unprefixFieldNames( array_keys( $result ) ),
603 - array_values( $result )
604 - );
605 - }
606 -
607 - /**
608 - * Get a new instance of the class from a database result.
609 - *
610 - * @since 1.20
611 - *
612 - * @param stdClass $result
613 - *
614 - * @return DBDataObject
615 - */
616 - public function newFromDBResult( stdClass $result ) {
617 - return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
618 - }
619 -
620 - /**
621 - * Get a new instance of the class from an array.
622 - *
623 - * @since 1.20
624 - *
625 - * @param array $data
626 - * @param boolean $loadDefaults
627 - *
628 - * @return DBDataObject
629 - */
630 - public function newFromArray( array $data, $loadDefaults = false ) {
631 - $class = $this->getDataObjectClass();
632 - return new $class( $this, $data, $loadDefaults );
633 - }
634 -
635 - /**
636 - * Return the names of the fields.
637 - *
638 - * @since 1.20
639 - *
640 - * @return array
641 - */
642 - public function getFieldNames() {
643 - return array_keys( $this->getFieldTypes() );
644 - }
645 -
646 - /**
647 - * Gets if the object can take a certain field.
648 - *
649 - * @since 1.20
650 - *
651 - * @param string $name
652 - *
653 - * @return boolean
654 - */
655 - public function canHaveField( $name ) {
656 - return array_key_exists( $name, $this->getFieldTypes() );
657 - }
658 -
659 -}
Index: trunk/extensions/EducationProgram/compat/DBDataObject.php
@@ -1,667 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Abstract base class for representing objects that are stored in some DB table.
6 - * This is basically an ORM-like wrapper around rows in database tables that
7 - * aims to be both simple and very flexible. It is centered around an associative
8 - * array of fields and various methods to do common interaction with the database.
9 - *
10 - * These methods must be implemented in deriving classes:
11 - * * getDBTable
12 - * * getFieldPrefix
13 - * * getFieldTypes
14 - *
15 - * These methods are likely candidates for overriding:
16 - * * getDefaults
17 - * * remove
18 - * * insert
19 - * * saveExisting
20 - * * loadSummaryFields
21 - * * getSummaryFields
22 - *
23 - * Main instance methods:
24 - * * getField(s)
25 - * * setField(s)
26 - * * save
27 - * * remove
28 - *
29 - * Main static methods:
30 - * * select
31 - * * update
32 - * * delete
33 - * * count
34 - * * has
35 - * * selectRow
36 - * * selectFields
37 - * * selectFieldsRow
38 - *
39 - * @since 1.20
40 - *
41 - * @file DBDataObject.php
42 - *
43 - * @licence GNU GPL v2 or later
44 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
45 - */
46 -abstract class DBDataObject {
47 -
48 - /**
49 - * The fields of the object.
50 - * field name (w/o prefix) => value
51 - *
52 - * @since 1.20
53 - * @var array
54 - */
55 - protected $fields = array( 'id' => null );
56 -
57 - /**
58 - * @since 1.20
59 - * @var DBTable
60 - */
61 - protected $table;
62 -
63 - /**
64 - * If the object should update summaries of linked items when changed.
65 - * For example, update the course_count field in universities when a course in courses is deleted.
66 - * Settings this to false can prevent needless updating work in situations
67 - * such as deleting a university, which will then delete all it's courses.
68 - *
69 - * @since 1.20
70 - * @var bool
71 - */
72 - protected $updateSummaries = true;
73 -
74 - /**
75 - * Indicates if the object is in summary mode.
76 - * This mode indicates that only summary fields got updated,
77 - * which allows for optimizations.
78 - *
79 - * @since 1.20
80 - * @var bool
81 - */
82 - protected $inSummaryMode = false;
83 -
84 - /**
85 - * Constructor.
86 - *
87 - * @since 1.20
88 - *
89 - * @param DBTable $table
90 - * @param array|null $fields
91 - * @param boolean $loadDefaults
92 - */
93 - public function __construct( DBTable $table, $fields = null, $loadDefaults = false ) {
94 - $this->table = $table;
95 -
96 - if ( !is_array( $fields ) ) {
97 - $fields = array();
98 - }
99 -
100 - if ( $loadDefaults ) {
101 - $fields = array_merge( $this->table->getDefaults(), $fields );
102 - }
103 -
104 - $this->setFields( $fields );
105 - }
106 -
107 - /**
108 - * Load the specified fields from the database.
109 - *
110 - * @since 1.20
111 - *
112 - * @param array|null $fields
113 - * @param boolean $override
114 - * @param boolean $skipLoaded
115 - *
116 - * @return bool Success indicator
117 - */
118 - public function loadFields( $fields = null, $override = true, $skipLoaded = false ) {
119 - if ( is_null( $this->getId() ) ) {
120 - return false;
121 - }
122 -
123 - if ( is_null( $fields ) ) {
124 - $fields = array_keys( $this->table->getFieldTypes() );
125 - }
126 -
127 - if ( $skipLoaded ) {
128 - $fields = array_diff( $fields, array_keys( $this->fields ) );
129 - }
130 -
131 - if ( !empty( $fields ) ) {
132 - $result = $this->table->rawSelectRow(
133 - $this->table->getPrefixedFields( $fields ),
134 - array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
135 - array( 'LIMIT' => 1 )
136 - );
137 -
138 - if ( $result !== false ) {
139 - $this->setFields( $this->table->getFieldsFromDBResult( $result ), $override );
140 - return true;
141 - }
142 -
143 - return false;
144 - }
145 -
146 - return true;
147 - }
148 -
149 - /**
150 - * Gets the value of a field.
151 - *
152 - * @since 1.20
153 - *
154 - * @param string $name
155 - * @param mixed $default
156 - *
157 - * @throws MWException
158 - * @return mixed
159 - */
160 - public function getField( $name, $default = null ) {
161 - if ( $this->hasField( $name ) ) {
162 - return $this->fields[$name];
163 - } elseif ( !is_null( $default ) ) {
164 - return $default;
165 - } else {
166 - throw new MWException( 'Attempted to get not-set field ' . $name );
167 - }
168 - }
169 -
170 - /**
171 - * Gets the value of a field but first loads it if not done so already.
172 - *
173 - * @since 1.20
174 - *
175 - * @param string$name
176 - *
177 - * @return mixed
178 - */
179 - public function loadAndGetField( $name ) {
180 - if ( !$this->hasField( $name ) ) {
181 - $this->loadFields( array( $name ) );
182 - }
183 -
184 - return $this->getField( $name );
185 - }
186 -
187 - /**
188 - * Remove a field.
189 - *
190 - * @since 1.20
191 - *
192 - * @param string $name
193 - */
194 - public function removeField( $name ) {
195 - unset( $this->fields[$name] );
196 - }
197 -
198 - /**
199 - * Returns the objects database id.
200 - *
201 - * @since 1.20
202 - *
203 - * @return integer|null
204 - */
205 - public function getId() {
206 - return $this->getField( 'id' );
207 - }
208 -
209 - /**
210 - * Sets the objects database id.
211 - *
212 - * @since 1.20
213 - *
214 - * @param integer|null $id
215 - */
216 - public function setId( $id ) {
217 - return $this->setField( 'id', $id );
218 - }
219 -
220 - /**
221 - * Gets if a certain field is set.
222 - *
223 - * @since 1.20
224 - *
225 - * @param string $name
226 - *
227 - * @return boolean
228 - */
229 - public function hasField( $name ) {
230 - return array_key_exists( $name, $this->fields );
231 - }
232 -
233 - /**
234 - * Gets if the id field is set.
235 - *
236 - * @since 1.20
237 - *
238 - * @return boolean
239 - */
240 - public function hasIdField() {
241 - return $this->hasField( 'id' )
242 - && !is_null( $this->getField( 'id' ) );
243 - }
244 -
245 - /**
246 - * Sets multiple fields.
247 - *
248 - * @since 1.20
249 - *
250 - * @param array $fields The fields to set
251 - * @param boolean $override Override already set fields with the provided values?
252 - */
253 - public function setFields( array $fields, $override = true ) {
254 - foreach ( $fields as $name => $value ) {
255 - if ( $override || !$this->hasField( $name ) ) {
256 - $this->setField( $name, $value );
257 - }
258 - }
259 - }
260 -
261 - /**
262 - * Gets the fields => values to write to the table.
263 - *
264 - * @since 1.20
265 - *
266 - * @return array
267 - */
268 - protected function getWriteValues() {
269 - $values = array();
270 -
271 - foreach ( $this->table->getFieldTypes() as $name => $type ) {
272 - if ( array_key_exists( $name, $this->fields ) ) {
273 - $value = $this->fields[$name];
274 -
275 - switch ( $type ) {
276 - case 'array':
277 - $value = (array)$value;
278 - case 'blob':
279 - $value = serialize( $value );
280 - }
281 -
282 - $values[$this->table->getPrefixedField( $name )] = $value;
283 - }
284 - }
285 -
286 - return $values;
287 - }
288 -
289 - /**
290 - * Serializes the object to an associative array which
291 - * can then easily be converted into JSON or similar.
292 - *
293 - * @since 1.20
294 - *
295 - * @param null|array $fields
296 - * @param boolean $incNullId
297 - *
298 - * @return array
299 - */
300 - public function toArray( $fields = null, $incNullId = false ) {
301 - $data = array();
302 - $setFields = array();
303 -
304 - if ( !is_array( $fields ) ) {
305 - $setFields = $this->getSetFieldNames();
306 - } else {
307 - foreach ( $fields as $field ) {
308 - if ( $this->hasField( $field ) ) {
309 - $setFields[] = $field;
310 - }
311 - }
312 - }
313 -
314 - foreach ( $setFields as $field ) {
315 - if ( $incNullId || $field != 'id' || $this->hasIdField() ) {
316 - $data[$field] = $this->getField( $field );
317 - }
318 - }
319 -
320 - return $data;
321 - }
322 -
323 - /**
324 - * Load the default values, via getDefaults.
325 - *
326 - * @since 1.20
327 - *
328 - * @param boolean $override
329 - */
330 - public function loadDefaults( $override = true ) {
331 - $this->setFields( $this->table->getDefaults(), $override );
332 - }
333 -
334 - /**
335 - * Writes the answer to the database, either updating it
336 - * when it already exists, or inserting it when it doesn't.
337 - *
338 - * @since 1.20
339 - *
340 - * @param string|null $functionName
341 - *
342 - * @return boolean Success indicator
343 - */
344 - public function save( $functionName = null ) {
345 - if ( $this->hasIdField() ) {
346 - return $this->saveExisting( $functionName );
347 - } else {
348 - return $this->insert( $functionName );
349 - }
350 - }
351 -
352 - /**
353 - * Updates the object in the database.
354 - *
355 - * @since 1.20
356 - *
357 - * @param string|null $functionName
358 - *
359 - * @return boolean Success indicator
360 - */
361 - protected function saveExisting( $functionName = null ) {
362 - $dbw = wfGetDB( DB_MASTER );
363 -
364 - $success = $dbw->update(
365 - $this->table->getDBTable(),
366 - $this->getWriteValues(),
367 - $this->table->getPrefixedValues( $this->getUpdateConditions() ),
368 - is_null( $functionName ) ? __METHOD__ : $functionName
369 - );
370 -
371 - return $success;
372 - }
373 -
374 - /**
375 - * Returns the WHERE considtions needed to identify this object so
376 - * it can be updated.
377 - *
378 - * @since 1.20
379 - *
380 - * @return array
381 - */
382 - protected function getUpdateConditions() {
383 - return array( 'id' => $this->getId() );
384 - }
385 -
386 - /**
387 - * Inserts the object into the database.
388 - *
389 - * @since 1.20
390 - *
391 - * @param string|null $functionName
392 - * @param array|null $options
393 - *
394 - * @return boolean Success indicator
395 - */
396 - protected function insert( $functionName = null, array $options = null ) {
397 - $dbw = wfGetDB( DB_MASTER );
398 -
399 - $result = $dbw->insert(
400 - $this->table->getDBTable(),
401 - $this->getWriteValues(),
402 - is_null( $functionName ) ? __METHOD__ : $functionName,
403 - is_null( $options ) ? array( 'IGNORE' ) : $options
404 - );
405 -
406 - if ( $result ) {
407 - $this->setField( 'id', $dbw->insertId() );
408 - }
409 -
410 - return $result;
411 - }
412 -
413 - /**
414 - * Removes the object from the database.
415 - *
416 - * @since 1.20
417 - *
418 - * @return boolean Success indicator
419 - */
420 - public function remove() {
421 - $this->beforeRemove();
422 -
423 - $success = $this->table->delete( array( 'id' => $this->getId() ) );
424 -
425 - if ( $success ) {
426 - $this->onRemoved();
427 - }
428 -
429 - return $success;
430 - }
431 -
432 - /**
433 - * Gets called before an object is removed from the database.
434 - *
435 - * @since 1.20
436 - */
437 - protected function beforeRemove() {
438 - $this->loadFields( $this->getBeforeRemoveFields(), false, true );
439 - }
440 -
441 - /**
442 - * Before removal of an object happens, @see beforeRemove gets called.
443 - * This method loads the fields of which the names have been returned by this one (or all fields if null is returned).
444 - * This allows for loading info needed after removal to get rid of linked data and the like.
445 - *
446 - * @since 1.20
447 - *
448 - * @return array|null
449 - */
450 - protected function getBeforeRemoveFields() {
451 - return array();
452 - }
453 -
454 - /**
455 - * Gets called after successfull removal.
456 - * Can be overriden to get rid of linked data.
457 - *
458 - * @since 1.20
459 - */
460 - protected function onRemoved() {
461 - $this->setField( 'id', null );
462 - }
463 -
464 - /**
465 - * Return the names and values of the fields.
466 - *
467 - * @since 1.20
468 - *
469 - * @return array
470 - */
471 - public function getFields() {
472 - return $this->fields;
473 - }
474 -
475 - /**
476 - * Return the names of the fields.
477 - *
478 - * @since 1.20
479 - *
480 - * @return array
481 - */
482 - public function getSetFieldNames() {
483 - return array_keys( $this->fields );
484 - }
485 -
486 - /**
487 - * Sets the value of a field.
488 - * Strings can be provided for other types,
489 - * so this method can be called from unserialization handlers.
490 - *
491 - * @since 1.20
492 - *
493 - * @param string $name
494 - * @param mixed $value
495 - *
496 - * @throws MWException
497 - */
498 - public function setField( $name, $value ) {
499 - $fields = $this->table->getFieldTypes();
500 -
501 - if ( array_key_exists( $name, $fields ) ) {
502 - switch ( $fields[$name] ) {
503 - case 'int':
504 - $value = (int)$value;
505 - break;
506 - case 'float':
507 - $value = (float)$value;
508 - break;
509 - case 'bool':
510 - if ( is_string( $value ) ) {
511 - $value = $value !== '0';
512 - } elseif ( is_int( $value ) ) {
513 - $value = $value !== 0;
514 - }
515 - break;
516 - case 'array':
517 - if ( is_string( $value ) ) {
518 - $value = unserialize( $value );
519 - }
520 -
521 - if ( !is_array( $value ) ) {
522 - $value = array();
523 - }
524 - break;
525 - case 'blob':
526 - if ( is_string( $value ) ) {
527 - $value = unserialize( $value );
528 - }
529 - break;
530 - case 'id':
531 - if ( is_string( $value ) ) {
532 - $value = (int)$value;
533 - }
534 - break;
535 - }
536 -
537 - $this->fields[$name] = $value;
538 - } else {
539 - throw new MWException( 'Attempted to set unknown field ' . $name );
540 - }
541 - }
542 -
543 - /**
544 - * Add an amount (can be negative) to the specified field (needs to be numeric).
545 - *
546 - * @since 1.20
547 - *
548 - * @param string $field
549 - * @param integer $amount
550 - *
551 - * @return boolean Success indicator
552 - */
553 - public function addToField( $field, $amount ) {
554 - if ( $amount == 0 ) {
555 - return true;
556 - }
557 -
558 - if ( !$this->hasIdField() ) {
559 - return false;
560 - }
561 -
562 - $absoluteAmount = abs( $amount );
563 - $isNegative = $amount < 0;
564 -
565 - $dbw = wfGetDB( DB_MASTER );
566 -
567 - $fullField = $this->table->getPrefixedField( $field );
568 -
569 - $success = $dbw->update(
570 - $this->table->getDBTable(),
571 - array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
572 - array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
573 - __METHOD__
574 - );
575 -
576 - if ( $success && $this->hasField( $field ) ) {
577 - $this->setField( $field, $this->getField( $field ) + $amount );
578 - }
579 -
580 - return $success;
581 - }
582 -
583 - /**
584 - * Return the names of the fields.
585 - *
586 - * @since 1.20
587 - *
588 - * @return array
589 - */
590 - public function getFieldNames() {
591 - return array_keys( $this->table->getFieldTypes() );
592 - }
593 -
594 - /**
595 - * Computes and updates the values of the summary fields.
596 - *
597 - * @since 1.20
598 - *
599 - * @param array|string|null $summaryFields
600 - */
601 - public function loadSummaryFields( $summaryFields = null ) {
602 -
603 - }
604 -
605 - /**
606 - * Sets the value for the @see $updateSummaries field.
607 - *
608 - * @since 1.20
609 - *
610 - * @param boolean $update
611 - */
612 - public function setUpdateSummaries( $update ) {
613 - $this->updateSummaries = $update;
614 - }
615 -
616 - /**
617 - * Sets the value for the @see $inSummaryMode field.
618 - *
619 - * @since 1.20
620 - *
621 - * @param boolean $summaryMode
622 - */
623 - public function setSummaryMode( $summaryMode ) {
624 - $this->inSummaryMode = $summaryMode;
625 - }
626 -
627 - /**
628 - * Return if any fields got changed.
629 - *
630 - * @since 1.20
631 - *
632 - * @param DBDataObject $object
633 - * @param boolean|array $excludeSummaryFields
634 - * When set to true, summary field changes are ignored.
635 - * Can also be an array of fields to ignore.
636 - *
637 - * @return boolean
638 - */
639 - protected function fieldsChanged( DBDataObject $object, $excludeSummaryFields = false ) {
640 - $exclusionFields = array();
641 -
642 - if ( $excludeSummaryFields !== false ) {
643 - $exclusionFields = is_array( $excludeSummaryFields ) ? $excludeSummaryFields : $this->table->getSummaryFields();
644 - }
645 -
646 - foreach ( $this->fields as $name => $value ) {
647 - $excluded = $excludeSummaryFields && in_array( $name, $exclusionFields );
648 -
649 - if ( !$excluded && $object->getField( $name ) !== $value ) {
650 - return true;
651 - }
652 - }
653 -
654 - return false;
655 - }
656 -
657 - /**
658 - * Returns the table this DBDataObject is a row in.
659 - *
660 - * @since 1.20
661 - *
662 - * @return DBTable
663 - */
664 - public function getTable() {
665 - return $this->table;
666 - }
667 -
668 -}
Index: trunk/extensions/EducationProgram/compat/ORMResult.php
@@ -0,0 +1,104 @@
 2+<?php
 3+
 4+/**
 5+ * Result of a ORMTable::select, which returns ORMRow objects.
 6+ *
 7+ * @since 1.20
 8+ *
 9+ * @file ORMResult.php
 10+ *
 11+ * @licence GNU GPL v2 or later
 12+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 13+ */
 14+class ORMResult implements Iterator {
 15+
 16+ /**
 17+ * @var ResultWrapper
 18+ */
 19+ protected $res;
 20+
 21+ /**
 22+ * @var integer
 23+ */
 24+ protected $key;
 25+
 26+ /**
 27+ * @var ORMRow
 28+ */
 29+ protected $current;
 30+
 31+ /**
 32+ * @var ORMTable
 33+ */
 34+ protected $table;
 35+
 36+ /**
 37+ * @param ORMTable $table
 38+ * @param ResultWrapper $res
 39+ */
 40+ public function __construct( ORMTable $table, ResultWrapper $res ) {
 41+ $this->table = $table;
 42+ $this->res = $res;
 43+ $this->key = 0;
 44+ $this->setCurrent( $this->res->current() );
 45+ }
 46+
 47+ /**
 48+ * @param $row
 49+ */
 50+ protected function setCurrent( $row ) {
 51+ if ( $row === false ) {
 52+ $this->current = false;
 53+ } else {
 54+ $this->current = $this->table->newFromDBResult( $row );
 55+ }
 56+ }
 57+
 58+ /**
 59+ * @return integer
 60+ */
 61+ public function count() {
 62+ return $this->res->numRows();
 63+ }
 64+
 65+ /**
 66+ * @return boolean
 67+ */
 68+ public function isEmpty() {
 69+ return $this->res->numRows() === 0;
 70+ }
 71+
 72+ /**
 73+ * @return ORMRow
 74+ */
 75+ public function current() {
 76+ return $this->current;
 77+ }
 78+
 79+ /**
 80+ * @return integer
 81+ */
 82+ public function key() {
 83+ return $this->key;
 84+ }
 85+
 86+ public function next() {
 87+ $row = $this->res->next();
 88+ $this->setCurrent( $row );
 89+ $this->key++;
 90+ }
 91+
 92+ public function rewind() {
 93+ $this->res->rewind();
 94+ $this->key = 0;
 95+ $this->setCurrent( $this->res->current() );
 96+ }
 97+
 98+ /**
 99+ * @return boolean
 100+ */
 101+ public function valid() {
 102+ return $this->current !== false;
 103+ }
 104+
 105+}
Index: trunk/extensions/EducationProgram/compat/ORMRow.php
@@ -0,0 +1,662 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract base class for representing objects that are stored in some DB table.
 6+ * This is basically an ORM-like wrapper around rows in database tables that
 7+ * aims to be both simple and very flexible. It is centered around an associative
 8+ * array of fields and various methods to do common interaction with the database.
 9+ *
 10+ * These methods are likely candidates for overriding:
 11+ * * getDefaults
 12+ * * remove
 13+ * * insert
 14+ * * saveExisting
 15+ * * loadSummaryFields
 16+ * * getSummaryFields
 17+ *
 18+ * Main instance methods:
 19+ * * getField(s)
 20+ * * setField(s)
 21+ * * save
 22+ * * remove
 23+ *
 24+ * Main static methods:
 25+ * * select
 26+ * * update
 27+ * * delete
 28+ * * count
 29+ * * has
 30+ * * selectRow
 31+ * * selectFields
 32+ * * selectFieldsRow
 33+ *
 34+ * @since 1.20
 35+ *
 36+ * @file ORMRow.php
 37+ *
 38+ * @licence GNU GPL v2 or later
 39+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 40+ */
 41+abstract class ORMRow {
 42+
 43+ /**
 44+ * The fields of the object.
 45+ * field name (w/o prefix) => value
 46+ *
 47+ * @since 1.20
 48+ * @var array
 49+ */
 50+ protected $fields = array( 'id' => null );
 51+
 52+ /**
 53+ * @since 1.20
 54+ * @var ORMTable
 55+ */
 56+ protected $table;
 57+
 58+ /**
 59+ * If the object should update summaries of linked items when changed.
 60+ * For example, update the course_count field in universities when a course in courses is deleted.
 61+ * Settings this to false can prevent needless updating work in situations
 62+ * such as deleting a university, which will then delete all it's courses.
 63+ *
 64+ * @since 1.20
 65+ * @var bool
 66+ */
 67+ protected $updateSummaries = true;
 68+
 69+ /**
 70+ * Indicates if the object is in summary mode.
 71+ * This mode indicates that only summary fields got updated,
 72+ * which allows for optimizations.
 73+ *
 74+ * @since 1.20
 75+ * @var bool
 76+ */
 77+ protected $inSummaryMode = false;
 78+
 79+ /**
 80+ * Constructor.
 81+ *
 82+ * @since 1.20
 83+ *
 84+ * @param ORMTable $table
 85+ * @param array|null $fields
 86+ * @param boolean $loadDefaults
 87+ */
 88+ public function __construct( ORMTable $table, $fields = null, $loadDefaults = false ) {
 89+ $this->table = $table;
 90+
 91+ if ( !is_array( $fields ) ) {
 92+ $fields = array();
 93+ }
 94+
 95+ if ( $loadDefaults ) {
 96+ $fields = array_merge( $this->table->getDefaults(), $fields );
 97+ }
 98+
 99+ $this->setFields( $fields );
 100+ }
 101+
 102+ /**
 103+ * Load the specified fields from the database.
 104+ *
 105+ * @since 1.20
 106+ *
 107+ * @param array|null $fields
 108+ * @param boolean $override
 109+ * @param boolean $skipLoaded
 110+ *
 111+ * @return bool Success indicator
 112+ */
 113+ public function loadFields( $fields = null, $override = true, $skipLoaded = false ) {
 114+ if ( is_null( $this->getId() ) ) {
 115+ return false;
 116+ }
 117+
 118+ if ( is_null( $fields ) ) {
 119+ $fields = array_keys( $this->table->getFields() );
 120+ }
 121+
 122+ if ( $skipLoaded ) {
 123+ $fields = array_diff( $fields, array_keys( $this->fields ) );
 124+ }
 125+
 126+ if ( !empty( $fields ) ) {
 127+ $result = $this->table->rawSelectRow(
 128+ $this->table->getPrefixedFields( $fields ),
 129+ array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
 130+ array( 'LIMIT' => 1 )
 131+ );
 132+
 133+ if ( $result !== false ) {
 134+ $this->setFields( $this->table->getFieldsFromDBResult( $result ), $override );
 135+ return true;
 136+ }
 137+
 138+ return false;
 139+ }
 140+
 141+ return true;
 142+ }
 143+
 144+ /**
 145+ * Gets the value of a field.
 146+ *
 147+ * @since 1.20
 148+ *
 149+ * @param string $name
 150+ * @param mixed $default
 151+ *
 152+ * @throws MWException
 153+ * @return mixed
 154+ */
 155+ public function getField( $name, $default = null ) {
 156+ if ( $this->hasField( $name ) ) {
 157+ return $this->fields[$name];
 158+ } elseif ( !is_null( $default ) ) {
 159+ return $default;
 160+ } else {
 161+ throw new MWException( 'Attempted to get not-set field ' . $name );
 162+ }
 163+ }
 164+
 165+ /**
 166+ * Gets the value of a field but first loads it if not done so already.
 167+ *
 168+ * @since 1.20
 169+ *
 170+ * @param string$name
 171+ *
 172+ * @return mixed
 173+ */
 174+ public function loadAndGetField( $name ) {
 175+ if ( !$this->hasField( $name ) ) {
 176+ $this->loadFields( array( $name ) );
 177+ }
 178+
 179+ return $this->getField( $name );
 180+ }
 181+
 182+ /**
 183+ * Remove a field.
 184+ *
 185+ * @since 1.20
 186+ *
 187+ * @param string $name
 188+ */
 189+ public function removeField( $name ) {
 190+ unset( $this->fields[$name] );
 191+ }
 192+
 193+ /**
 194+ * Returns the objects database id.
 195+ *
 196+ * @since 1.20
 197+ *
 198+ * @return integer|null
 199+ */
 200+ public function getId() {
 201+ return $this->getField( 'id' );
 202+ }
 203+
 204+ /**
 205+ * Sets the objects database id.
 206+ *
 207+ * @since 1.20
 208+ *
 209+ * @param integer|null $id
 210+ */
 211+ public function setId( $id ) {
 212+ return $this->setField( 'id', $id );
 213+ }
 214+
 215+ /**
 216+ * Gets if a certain field is set.
 217+ *
 218+ * @since 1.20
 219+ *
 220+ * @param string $name
 221+ *
 222+ * @return boolean
 223+ */
 224+ public function hasField( $name ) {
 225+ return array_key_exists( $name, $this->fields );
 226+ }
 227+
 228+ /**
 229+ * Gets if the id field is set.
 230+ *
 231+ * @since 1.20
 232+ *
 233+ * @return boolean
 234+ */
 235+ public function hasIdField() {
 236+ return $this->hasField( 'id' )
 237+ && !is_null( $this->getField( 'id' ) );
 238+ }
 239+
 240+ /**
 241+ * Sets multiple fields.
 242+ *
 243+ * @since 1.20
 244+ *
 245+ * @param array $fields The fields to set
 246+ * @param boolean $override Override already set fields with the provided values?
 247+ */
 248+ public function setFields( array $fields, $override = true ) {
 249+ foreach ( $fields as $name => $value ) {
 250+ if ( $override || !$this->hasField( $name ) ) {
 251+ $this->setField( $name, $value );
 252+ }
 253+ }
 254+ }
 255+
 256+ /**
 257+ * Gets the fields => values to write to the table.
 258+ *
 259+ * @since 1.20
 260+ *
 261+ * @return array
 262+ */
 263+ protected function getWriteValues() {
 264+ $values = array();
 265+
 266+ foreach ( $this->table->getFields() as $name => $type ) {
 267+ if ( array_key_exists( $name, $this->fields ) ) {
 268+ $value = $this->fields[$name];
 269+
 270+ switch ( $type ) {
 271+ case 'array':
 272+ $value = (array)$value;
 273+ case 'blob':
 274+ $value = serialize( $value );
 275+ }
 276+
 277+ $values[$this->table->getPrefixedField( $name )] = $value;
 278+ }
 279+ }
 280+
 281+ return $values;
 282+ }
 283+
 284+ /**
 285+ * Serializes the object to an associative array which
 286+ * can then easily be converted into JSON or similar.
 287+ *
 288+ * @since 1.20
 289+ *
 290+ * @param null|array $fields
 291+ * @param boolean $incNullId
 292+ *
 293+ * @return array
 294+ */
 295+ public function toArray( $fields = null, $incNullId = false ) {
 296+ $data = array();
 297+ $setFields = array();
 298+
 299+ if ( !is_array( $fields ) ) {
 300+ $setFields = $this->getSetFieldNames();
 301+ } else {
 302+ foreach ( $fields as $field ) {
 303+ if ( $this->hasField( $field ) ) {
 304+ $setFields[] = $field;
 305+ }
 306+ }
 307+ }
 308+
 309+ foreach ( $setFields as $field ) {
 310+ if ( $incNullId || $field != 'id' || $this->hasIdField() ) {
 311+ $data[$field] = $this->getField( $field );
 312+ }
 313+ }
 314+
 315+ return $data;
 316+ }
 317+
 318+ /**
 319+ * Load the default values, via getDefaults.
 320+ *
 321+ * @since 1.20
 322+ *
 323+ * @param boolean $override
 324+ */
 325+ public function loadDefaults( $override = true ) {
 326+ $this->setFields( $this->table->getDefaults(), $override );
 327+ }
 328+
 329+ /**
 330+ * Writes the answer to the database, either updating it
 331+ * when it already exists, or inserting it when it doesn't.
 332+ *
 333+ * @since 1.20
 334+ *
 335+ * @param string|null $functionName
 336+ *
 337+ * @return boolean Success indicator
 338+ */
 339+ public function save( $functionName = null ) {
 340+ if ( $this->hasIdField() ) {
 341+ return $this->saveExisting( $functionName );
 342+ } else {
 343+ return $this->insert( $functionName );
 344+ }
 345+ }
 346+
 347+ /**
 348+ * Updates the object in the database.
 349+ *
 350+ * @since 1.20
 351+ *
 352+ * @param string|null $functionName
 353+ *
 354+ * @return boolean Success indicator
 355+ */
 356+ protected function saveExisting( $functionName = null ) {
 357+ $dbw = wfGetDB( DB_MASTER );
 358+
 359+ $success = $dbw->update(
 360+ $this->table->getName(),
 361+ $this->getWriteValues(),
 362+ $this->table->getPrefixedValues( $this->getUpdateConditions() ),
 363+ is_null( $functionName ) ? __METHOD__ : $functionName
 364+ );
 365+
 366+ return $success;
 367+ }
 368+
 369+ /**
 370+ * Returns the WHERE considtions needed to identify this object so
 371+ * it can be updated.
 372+ *
 373+ * @since 1.20
 374+ *
 375+ * @return array
 376+ */
 377+ protected function getUpdateConditions() {
 378+ return array( 'id' => $this->getId() );
 379+ }
 380+
 381+ /**
 382+ * Inserts the object into the database.
 383+ *
 384+ * @since 1.20
 385+ *
 386+ * @param string|null $functionName
 387+ * @param array|null $options
 388+ *
 389+ * @return boolean Success indicator
 390+ */
 391+ protected function insert( $functionName = null, array $options = null ) {
 392+ $dbw = wfGetDB( DB_MASTER );
 393+
 394+ $result = $dbw->insert(
 395+ $this->table->getName(),
 396+ $this->getWriteValues(),
 397+ is_null( $functionName ) ? __METHOD__ : $functionName,
 398+ is_null( $options ) ? array( 'IGNORE' ) : $options
 399+ );
 400+
 401+ if ( $result ) {
 402+ $this->setField( 'id', $dbw->insertId() );
 403+ }
 404+
 405+ return $result;
 406+ }
 407+
 408+ /**
 409+ * Removes the object from the database.
 410+ *
 411+ * @since 1.20
 412+ *
 413+ * @return boolean Success indicator
 414+ */
 415+ public function remove() {
 416+ $this->beforeRemove();
 417+
 418+ $success = $this->table->delete( array( 'id' => $this->getId() ) );
 419+
 420+ if ( $success ) {
 421+ $this->onRemoved();
 422+ }
 423+
 424+ return $success;
 425+ }
 426+
 427+ /**
 428+ * Gets called before an object is removed from the database.
 429+ *
 430+ * @since 1.20
 431+ */
 432+ protected function beforeRemove() {
 433+ $this->loadFields( $this->getBeforeRemoveFields(), false, true );
 434+ }
 435+
 436+ /**
 437+ * Before removal of an object happens, @see beforeRemove gets called.
 438+ * This method loads the fields of which the names have been returned by this one (or all fields if null is returned).
 439+ * This allows for loading info needed after removal to get rid of linked data and the like.
 440+ *
 441+ * @since 1.20
 442+ *
 443+ * @return array|null
 444+ */
 445+ protected function getBeforeRemoveFields() {
 446+ return array();
 447+ }
 448+
 449+ /**
 450+ * Gets called after successfull removal.
 451+ * Can be overriden to get rid of linked data.
 452+ *
 453+ * @since 1.20
 454+ */
 455+ protected function onRemoved() {
 456+ $this->setField( 'id', null );
 457+ }
 458+
 459+ /**
 460+ * Return the names and values of the fields.
 461+ *
 462+ * @since 1.20
 463+ *
 464+ * @return array
 465+ */
 466+ public function getFields() {
 467+ return $this->fields;
 468+ }
 469+
 470+ /**
 471+ * Return the names of the fields.
 472+ *
 473+ * @since 1.20
 474+ *
 475+ * @return array
 476+ */
 477+ public function getSetFieldNames() {
 478+ return array_keys( $this->fields );
 479+ }
 480+
 481+ /**
 482+ * Sets the value of a field.
 483+ * Strings can be provided for other types,
 484+ * so this method can be called from unserialization handlers.
 485+ *
 486+ * @since 1.20
 487+ *
 488+ * @param string $name
 489+ * @param mixed $value
 490+ *
 491+ * @throws MWException
 492+ */
 493+ public function setField( $name, $value ) {
 494+ $fields = $this->table->getFields();
 495+
 496+ if ( array_key_exists( $name, $fields ) ) {
 497+ switch ( $fields[$name] ) {
 498+ case 'int':
 499+ $value = (int)$value;
 500+ break;
 501+ case 'float':
 502+ $value = (float)$value;
 503+ break;
 504+ case 'bool':
 505+ if ( is_string( $value ) ) {
 506+ $value = $value !== '0';
 507+ } elseif ( is_int( $value ) ) {
 508+ $value = $value !== 0;
 509+ }
 510+ break;
 511+ case 'array':
 512+ if ( is_string( $value ) ) {
 513+ $value = unserialize( $value );
 514+ }
 515+
 516+ if ( !is_array( $value ) ) {
 517+ $value = array();
 518+ }
 519+ break;
 520+ case 'blob':
 521+ if ( is_string( $value ) ) {
 522+ $value = unserialize( $value );
 523+ }
 524+ break;
 525+ case 'id':
 526+ if ( is_string( $value ) ) {
 527+ $value = (int)$value;
 528+ }
 529+ break;
 530+ }
 531+
 532+ $this->fields[$name] = $value;
 533+ } else {
 534+ throw new MWException( 'Attempted to set unknown field ' . $name );
 535+ }
 536+ }
 537+
 538+ /**
 539+ * Add an amount (can be negative) to the specified field (needs to be numeric).
 540+ *
 541+ * @since 1.20
 542+ *
 543+ * @param string $field
 544+ * @param integer $amount
 545+ *
 546+ * @return boolean Success indicator
 547+ */
 548+ public function addToField( $field, $amount ) {
 549+ if ( $amount == 0 ) {
 550+ return true;
 551+ }
 552+
 553+ if ( !$this->hasIdField() ) {
 554+ return false;
 555+ }
 556+
 557+ $absoluteAmount = abs( $amount );
 558+ $isNegative = $amount < 0;
 559+
 560+ $dbw = wfGetDB( DB_MASTER );
 561+
 562+ $fullField = $this->table->getPrefixedField( $field );
 563+
 564+ $success = $dbw->update(
 565+ $this->table->getName(),
 566+ array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
 567+ array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
 568+ __METHOD__
 569+ );
 570+
 571+ if ( $success && $this->hasField( $field ) ) {
 572+ $this->setField( $field, $this->getField( $field ) + $amount );
 573+ }
 574+
 575+ return $success;
 576+ }
 577+
 578+ /**
 579+ * Return the names of the fields.
 580+ *
 581+ * @since 1.20
 582+ *
 583+ * @return array
 584+ */
 585+ public function getFieldNames() {
 586+ return array_keys( $this->table->getFields() );
 587+ }
 588+
 589+ /**
 590+ * Computes and updates the values of the summary fields.
 591+ *
 592+ * @since 1.20
 593+ *
 594+ * @param array|string|null $summaryFields
 595+ */
 596+ public function loadSummaryFields( $summaryFields = null ) {
 597+
 598+ }
 599+
 600+ /**
 601+ * Sets the value for the @see $updateSummaries field.
 602+ *
 603+ * @since 1.20
 604+ *
 605+ * @param boolean $update
 606+ */
 607+ public function setUpdateSummaries( $update ) {
 608+ $this->updateSummaries = $update;
 609+ }
 610+
 611+ /**
 612+ * Sets the value for the @see $inSummaryMode field.
 613+ *
 614+ * @since 1.20
 615+ *
 616+ * @param boolean $summaryMode
 617+ */
 618+ public function setSummaryMode( $summaryMode ) {
 619+ $this->inSummaryMode = $summaryMode;
 620+ }
 621+
 622+ /**
 623+ * Return if any fields got changed.
 624+ *
 625+ * @since 1.20
 626+ *
 627+ * @param ORMRow $object
 628+ * @param boolean|array $excludeSummaryFields
 629+ * When set to true, summary field changes are ignored.
 630+ * Can also be an array of fields to ignore.
 631+ *
 632+ * @return boolean
 633+ */
 634+ protected function fieldsChanged( ORMRow $object, $excludeSummaryFields = false ) {
 635+ $exclusionFields = array();
 636+
 637+ if ( $excludeSummaryFields !== false ) {
 638+ $exclusionFields = is_array( $excludeSummaryFields ) ? $excludeSummaryFields : $this->table->getSummaryFields();
 639+ }
 640+
 641+ foreach ( $this->fields as $name => $value ) {
 642+ $excluded = $excludeSummaryFields && in_array( $name, $exclusionFields );
 643+
 644+ if ( !$excluded && $object->getField( $name ) !== $value ) {
 645+ return true;
 646+ }
 647+ }
 648+
 649+ return false;
 650+ }
 651+
 652+ /**
 653+ * Returns the table this ORMRow is a row in.
 654+ *
 655+ * @since 1.20
 656+ *
 657+ * @return ORMTable
 658+ */
 659+ public function getTable() {
 660+ return $this->table;
 661+ }
 662+
 663+}
Index: trunk/extensions/EducationProgram/compat/ORMTable.php
@@ -0,0 +1,658 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract base class for representing a single database table.
 6+ *
 7+ * @since 1.20
 8+ *
 9+ * @file ORMTable.php
 10+ *
 11+ * @licence GNU GPL v2 or later
 12+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 13+ */
 14+abstract class ORMTable {
 15+
 16+ /**
 17+ * Returns the name of the database table objects of this type are stored in.
 18+ *
 19+ * @since 1.20
 20+ *
 21+ * @return string
 22+ */
 23+ public abstract function getName();
 24+
 25+ /**
 26+ * Returns the name of a ORMRow deriving class that
 27+ * represents single rows in this table.
 28+ *
 29+ * @since 1.20
 30+ *
 31+ * @return string
 32+ */
 33+ public abstract function getRowClass();
 34+
 35+ /**
 36+ * Gets the db field prefix.
 37+ *
 38+ * @since 1.20
 39+ *
 40+ * @return string
 41+ */
 42+ protected abstract function getFieldPrefix();
 43+
 44+ /**
 45+ * Returns an array with the fields and their types this object contains.
 46+ * This corresponds directly to the fields in the database, without prefix.
 47+ *
 48+ * field name => type
 49+ *
 50+ * Allowed types:
 51+ * * id
 52+ * * str
 53+ * * int
 54+ * * float
 55+ * * bool
 56+ * * array
 57+ *
 58+ * @since 1.20
 59+ *
 60+ * @return array
 61+ */
 62+ public abstract function getFields();
 63+
 64+ /**
 65+ * The database connection to use for read operations.
 66+ * Can be changed via @see setReadDb.
 67+ *
 68+ * @since 1.20
 69+ * @var integer DB_ enum
 70+ */
 71+ protected $readDb = DB_SLAVE;
 72+
 73+ /**
 74+ * Returns a list of default field values.
 75+ * field name => field value
 76+ *
 77+ * @since 1.20
 78+ *
 79+ * @return array
 80+ */
 81+ public function getDefaults() {
 82+ return array();
 83+ }
 84+
 85+ /**
 86+ * Returns a list of the summary fields.
 87+ * These are fields that cache computed values, such as the amount of linked objects of $type.
 88+ * This is relevant as one might not want to do actions such as log changes when these get updated.
 89+ *
 90+ * @since 1.20
 91+ *
 92+ * @return array
 93+ */
 94+ public function getSummaryFields() {
 95+ return array();
 96+ }
 97+
 98+ /**
 99+ * Selects the the specified fields of the records matching the provided
 100+ * conditions and returns them as ORMRow. Field names get prefixed.
 101+ *
 102+ * @since 1.20
 103+ *
 104+ * @param array|string|null $fields
 105+ * @param array $conditions
 106+ * @param array $options
 107+ * @param string|null $functionName
 108+ *
 109+ * @return array of self
 110+ */
 111+ public function select( $fields = null, array $conditions = array(), array $options = array(), $functionName = null ) {
 112+ $result = $this->selectFields( $fields, $conditions, $options, false, $functionName );
 113+
 114+ $objects = array();
 115+
 116+ foreach ( $result as $record ) {
 117+ $objects[] = $this->newFromArray( $record );
 118+ }
 119+
 120+ return $objects;
 121+ }
 122+
 123+ /**
 124+ * Selects the the specified fields of the records matching the provided
 125+ * conditions and returns them as associative arrays.
 126+ * Provided field names get prefixed.
 127+ * Returned field names will not have a prefix.
 128+ *
 129+ * When $collapse is true:
 130+ * If one field is selected, each item in the result array will be this field.
 131+ * If two fields are selected, each item in the result array will have as key
 132+ * the first field and as value the second field.
 133+ * If more then two fields are selected, each item will be an associative array.
 134+ *
 135+ * @since 1.20
 136+ *
 137+ * @param array|string|null $fields
 138+ * @param array $conditions
 139+ * @param array $options
 140+ * @param boolean $collapse Set to false to always return each result row as associative array.
 141+ * @param string|null $functionName
 142+ *
 143+ * @return array of array
 144+ */
 145+ public function selectFields( $fields = null, array $conditions = array(), array $options = array(), $collapse = true, $functionName = null ) {
 146+ if ( is_null( $fields ) ) {
 147+ $fields = array_keys( $this->getFields() );
 148+ }
 149+ else {
 150+ $fields = (array)$fields;
 151+ }
 152+
 153+ $dbr = wfGetDB( $this->getReadDb() );
 154+ $result = $dbr->select(
 155+ $this->getName(),
 156+ $this->getPrefixedFields( $fields ),
 157+ $this->getPrefixedValues( $conditions ),
 158+ is_null( $functionName ) ? __METHOD__ : $functionName,
 159+ $options
 160+ );
 161+
 162+ $objects = array();
 163+
 164+ foreach ( $result as $record ) {
 165+ $objects[] = $this->getFieldsFromDBResult( $record );
 166+ }
 167+
 168+ if ( $collapse ) {
 169+ if ( count( $fields ) === 1 ) {
 170+ $objects = array_map( 'array_shift', $objects );
 171+ }
 172+ elseif ( count( $fields ) === 2 ) {
 173+ $o = array();
 174+
 175+ foreach ( $objects as $object ) {
 176+ $o[array_shift( $object )] = array_shift( $object );
 177+ }
 178+
 179+ $objects = $o;
 180+ }
 181+ }
 182+
 183+ return $objects;
 184+ }
 185+
 186+ /**
 187+ * Selects the the specified fields of the first matching record.
 188+ * Field names get prefixed.
 189+ *
 190+ * @since 1.20
 191+ *
 192+ * @param array|string|null $fields
 193+ * @param array $conditions
 194+ * @param array $options
 195+ * @param string|null $functionName
 196+ *
 197+ * @return DBObject|bool False on failure
 198+ */
 199+ public function selectRow( $fields = null, array $conditions = array(), array $options = array(), $functionName = null ) {
 200+ $options['LIMIT'] = 1;
 201+
 202+ $objects = $this->select( $fields, $conditions, $options, $functionName );
 203+
 204+ return empty( $objects ) ? false : $objects[0];
 205+ }
 206+
 207+ /**
 208+ * Selects the the specified fields of the records matching the provided
 209+ * conditions. Field names do NOT get prefixed.
 210+ *
 211+ * @since 1.20
 212+ *
 213+ * @param array $fields
 214+ * @param array $conditions
 215+ * @param array $options
 216+ * @param string|null $functionName
 217+ *
 218+ * @return ResultWrapper
 219+ */
 220+ public function rawSelectRow( array $fields, array $conditions = array(), array $options = array(), $functionName = null ) {
 221+ $dbr = wfGetDB( $this->getReadDb() );
 222+
 223+ return $dbr->selectRow(
 224+ $this->getName(),
 225+ $fields,
 226+ $conditions,
 227+ is_null( $functionName ) ? __METHOD__ : $functionName,
 228+ $options
 229+ );
 230+ }
 231+
 232+ /**
 233+ * Selects the the specified fields of the first record matching the provided
 234+ * conditions and returns it as an associative array, or false when nothing matches.
 235+ * This method makes use of selectFields and expects the same parameters and
 236+ * returns the same results (if there are any, if there are none, this method returns false).
 237+ * @see ORMTable::selectFields
 238+ *
 239+ * @since 1.20
 240+ *
 241+ * @param array|string|null $fields
 242+ * @param array $conditions
 243+ * @param array $options
 244+ * @param boolean $collapse Set to false to always return each result row as associative array.
 245+ * @param string|null $functionName
 246+ *
 247+ * @return mixed|array|bool False on failure
 248+ */
 249+ public function selectFieldsRow( $fields = null, array $conditions = array(), array $options = array(), $collapse = true, $functionName = null ) {
 250+ $options['LIMIT'] = 1;
 251+
 252+ $objects = $this->selectFields( $fields, $conditions, $options, $collapse, $functionName );
 253+
 254+ return empty( $objects ) ? false : $objects[0];
 255+ }
 256+
 257+ /**
 258+ * Returns if there is at least one record matching the provided conditions.
 259+ * Condition field names get prefixed.
 260+ *
 261+ * @since 1.20
 262+ *
 263+ * @param array $conditions
 264+ *
 265+ * @return boolean
 266+ */
 267+ public function has( array $conditions = array() ) {
 268+ return $this->selectRow( array( 'id' ), $conditions ) !== false;
 269+ }
 270+
 271+ /**
 272+ * Returns the amount of matching records.
 273+ * Condition field names get prefixed.
 274+ *
 275+ * Note that this can be expensive on large tables.
 276+ * In such cases you might want to use DatabaseBase::estimateRowCount instead.
 277+ *
 278+ * @since 1.20
 279+ *
 280+ * @param array $conditions
 281+ * @param array $options
 282+ *
 283+ * @return integer
 284+ */
 285+ public function count( array $conditions = array(), array $options = array() ) {
 286+ $res = $this->rawSelectRow(
 287+ array( 'COUNT(*) AS rowcount' ),
 288+ $this->getPrefixedValues( $conditions ),
 289+ $options
 290+ );
 291+
 292+ return $res->rowcount;
 293+ }
 294+
 295+ /**
 296+ * Removes the object from the database.
 297+ *
 298+ * @since 1.20
 299+ *
 300+ * @param array $conditions
 301+ * @param string|null $functionName
 302+ *
 303+ * @return boolean Success indicator
 304+ */
 305+ public function delete( array $conditions, $functionName = null ) {
 306+ return wfGetDB( DB_MASTER )->delete(
 307+ $this->getName(),
 308+ $this->getPrefixedValues( $conditions ),
 309+ $functionName
 310+ );
 311+ }
 312+
 313+ /**
 314+ * Get API parameters for the fields supported by this object.
 315+ *
 316+ * @since 1.20
 317+ *
 318+ * @param boolean $requireParams
 319+ * @param boolean $setDefaults
 320+ *
 321+ * @return array
 322+ */
 323+ public function getAPIParams( $requireParams = false, $setDefaults = false ) {
 324+ $typeMap = array(
 325+ 'id' => 'integer',
 326+ 'int' => 'integer',
 327+ 'float' => 'NULL',
 328+ 'str' => 'string',
 329+ 'bool' => 'integer',
 330+ 'array' => 'string',
 331+ 'blob' => 'string',
 332+ );
 333+
 334+ $params = array();
 335+ $defaults = $this->getDefaults();
 336+
 337+ foreach ( $this->getFields() as $field => $type ) {
 338+ if ( $field == 'id' ) {
 339+ continue;
 340+ }
 341+
 342+ $hasDefault = array_key_exists( $field, $defaults );
 343+
 344+ $params[$field] = array(
 345+ ApiBase::PARAM_TYPE => $typeMap[$type],
 346+ ApiBase::PARAM_REQUIRED => $requireParams && !$hasDefault
 347+ );
 348+
 349+ if ( $type == 'array' ) {
 350+ $params[$field][ApiBase::PARAM_ISMULTI] = true;
 351+ }
 352+
 353+ if ( $setDefaults && $hasDefault ) {
 354+ $default = is_array( $defaults[$field] ) ? implode( '|', $defaults[$field] ) : $defaults[$field];
 355+ $params[$field][ApiBase::PARAM_DFLT] = $default;
 356+ }
 357+ }
 358+
 359+ return $params;
 360+ }
 361+
 362+ /**
 363+ * Returns an array with the fields and their descriptions.
 364+ *
 365+ * field name => field description
 366+ *
 367+ * @since 1.20
 368+ *
 369+ * @return array
 370+ */
 371+ public function getFieldDescriptions() {
 372+ return array();
 373+ }
 374+
 375+ /**
 376+ * Get the database type used for read operations.
 377+ *
 378+ * @since 1.20
 379+ *
 380+ * @return integer DB_ enum
 381+ */
 382+ public function getReadDb() {
 383+ return $this->readDb;
 384+ }
 385+
 386+ /**
 387+ * Set the database type to use for read operations.
 388+ *
 389+ * @param integer $db
 390+ *
 391+ * @since 1.20
 392+ */
 393+ public function setReadDb( $db ) {
 394+ $this->readDb = $db;
 395+ }
 396+
 397+ /**
 398+ * Update the records matching the provided conditions by
 399+ * setting the fields that are keys in the $values param to
 400+ * their corresponding values.
 401+ *
 402+ * @since 1.20
 403+ *
 404+ * @param array $values
 405+ * @param array $conditions
 406+ *
 407+ * @return boolean Success indicator
 408+ */
 409+ public function update( array $values, array $conditions = array() ) {
 410+ $dbw = wfGetDB( DB_MASTER );
 411+
 412+ return $dbw->update(
 413+ $this->getName(),
 414+ $this->getPrefixedValues( $values ),
 415+ $this->getPrefixedValues( $conditions ),
 416+ __METHOD__
 417+ );
 418+ }
 419+
 420+ /**
 421+ * Computes the values of the summary fields of the objects matching the provided conditions.
 422+ *
 423+ * @since 1.20
 424+ *
 425+ * @param array|string|null $summaryFields
 426+ * @param array $conditions
 427+ */
 428+ public function updateSummaryFields( $summaryFields = null, array $conditions = array() ) {
 429+ $this->setReadDb( DB_MASTER );
 430+
 431+ foreach ( $this->select( null, $conditions ) as /* ORMRow */ $item ) {
 432+ $item->loadSummaryFields( $summaryFields );
 433+ $item->setSummaryMode( true );
 434+ $item->save();
 435+ }
 436+
 437+ $this->setReadDb( DB_SLAVE );
 438+ }
 439+
 440+ /**
 441+ * Takes in an associative array with field names as keys and
 442+ * their values as value. The field names are prefixed with the
 443+ * db field prefix.
 444+ *
 445+ * Field names can also be provided as an array with as first element a table name, such as
 446+ * $conditions = array(
 447+ * array( array( 'tablename', 'fieldname' ), $value ),
 448+ * );
 449+ *
 450+ * @since 1.20
 451+ *
 452+ * @param array $values
 453+ *
 454+ * @return array
 455+ */
 456+ public function getPrefixedValues( array $values ) {
 457+ $prefixedValues = array();
 458+
 459+ foreach ( $values as $field => $value ) {
 460+ if ( is_integer( $field ) ) {
 461+ if ( is_array( $value ) ) {
 462+ $field = $value[0];
 463+ $value = $value[1];
 464+ }
 465+ else {
 466+ $value = explode( ' ', $value, 2 );
 467+ $value[0] = $this->getPrefixedField( $value[0] );
 468+ $prefixedValues[] = implode( ' ', $value );
 469+ continue;
 470+ }
 471+ }
 472+
 473+ $prefixedValues[$this->getPrefixedField( $field )] = $value;
 474+ }
 475+
 476+ return $prefixedValues;
 477+ }
 478+
 479+ /**
 480+ * Takes in a field or array of fields and returns an
 481+ * array with their prefixed versions, ready for db usage.
 482+ *
 483+ * @since 1.20
 484+ *
 485+ * @param array|string $fields
 486+ *
 487+ * @return array
 488+ */
 489+ public function getPrefixedFields( array $fields ) {
 490+ foreach ( $fields as &$field ) {
 491+ $field = $this->getPrefixedField( $field );
 492+ }
 493+
 494+ return $fields;
 495+ }
 496+
 497+ /**
 498+ * Takes in a field and returns an it's prefixed version, ready for db usage.
 499+ *
 500+ * @since 1.20
 501+ *
 502+ * @param string|array $field
 503+ *
 504+ * @return string
 505+ */
 506+ public function getPrefixedField( $field ) {
 507+ return $this->getFieldPrefix() . $field;
 508+ }
 509+
 510+ /**
 511+ * Takes an array of field names with prefix and returns the unprefixed equivalent.
 512+ *
 513+ * @since 1.20
 514+ *
 515+ * @param array $fieldNames
 516+ *
 517+ * @return array
 518+ */
 519+ public function unprefixFieldNames( array $fieldNames ) {
 520+ return array_map( array( $this, 'unprefixFieldName' ), $fieldNames );
 521+ }
 522+
 523+ /**
 524+ * Takes a field name with prefix and returns the unprefixed equivalent.
 525+ *
 526+ * @since 1.20
 527+ *
 528+ * @param string $fieldName
 529+ *
 530+ * @return string
 531+ */
 532+ public function unprefixFieldName( $fieldName ) {
 533+ return substr( $fieldName, strlen( $this->getFieldPrefix() ) );
 534+ }
 535+
 536+ public function __construct() {
 537+
 538+ }
 539+
 540+ /**
 541+ * Get an instance of this class.
 542+ *
 543+ * @since 1.20
 544+ *
 545+ * @return ORMTable
 546+ */
 547+ public static function singleton() {
 548+ static $instance;
 549+
 550+ if ( !isset( $instance ) ) {
 551+ $class = function_exists( 'get_called_class' ) ? get_called_class() : self::get_called_class();
 552+ $instance = new $class;
 553+ }
 554+
 555+ return $instance;
 556+ }
 557+
 558+ /**
 559+ * Compatibility fallback function so the singleton method works on PHP < 5.3.
 560+ * Code borrowed from http://www.php.net/manual/en/function.get-called-class.php#107445
 561+ *
 562+ * @since 1.20
 563+ *
 564+ * @return string
 565+ */
 566+ protected static function get_called_class() {
 567+ $bt = debug_backtrace();
 568+ $l = count($bt) - 1;
 569+ $matches = array();
 570+ while(empty($matches) && $l > -1){
 571+ $lines = file($bt[$l]['file']);
 572+ $callerLine = $lines[$bt[$l]['line']-1];
 573+ preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l--]['function'].'/',
 574+ $callerLine,
 575+ $matches);
 576+ }
 577+ if (!isset($matches[1])) $matches[1]=NULL; //for notices
 578+ if ($matches[1] == 'self') {
 579+ $line = $bt[$l]['line']-1;
 580+ while ($line > 0 && strpos($lines[$line], 'class') === false) {
 581+ $line--;
 582+ }
 583+ preg_match('/class[\s]+(.+?)[\s]+/si', $lines[$line], $matches);
 584+ }
 585+ return $matches[1];
 586+ }
 587+
 588+ /**
 589+ * Get an array with fields from a database result,
 590+ * that can be fed directly to the constructor or
 591+ * to setFields.
 592+ *
 593+ * @since 1.20
 594+ *
 595+ * @param stdClass $result
 596+ *
 597+ * @return array
 598+ */
 599+ public function getFieldsFromDBResult( stdClass $result ) {
 600+ $result = (array)$result;
 601+ return array_combine(
 602+ $this->unprefixFieldNames( array_keys( $result ) ),
 603+ array_values( $result )
 604+ );
 605+ }
 606+
 607+ /**
 608+ * Get a new instance of the class from a database result.
 609+ *
 610+ * @since 1.20
 611+ *
 612+ * @param stdClass $result
 613+ *
 614+ * @return ORMRow
 615+ */
 616+ public function newFromDBResult( stdClass $result ) {
 617+ return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
 618+ }
 619+
 620+ /**
 621+ * Get a new instance of the class from an array.
 622+ *
 623+ * @since 1.20
 624+ *
 625+ * @param array $data
 626+ * @param boolean $loadDefaults
 627+ *
 628+ * @return ORMRow
 629+ */
 630+ public function newFromArray( array $data, $loadDefaults = false ) {
 631+ $class = $this->getRowClass();
 632+ return new $class( $this, $data, $loadDefaults );
 633+ }
 634+
 635+ /**
 636+ * Return the names of the fields.
 637+ *
 638+ * @since 1.20
 639+ *
 640+ * @return array
 641+ */
 642+ public function getFieldNames() {
 643+ return array_keys( $this->getFields() );
 644+ }
 645+
 646+ /**
 647+ * Gets if the object can take a certain field.
 648+ *
 649+ * @since 1.20
 650+ *
 651+ * @param string $name
 652+ *
 653+ * @return boolean
 654+ */
 655+ public function canHaveField( $name ) {
 656+ return array_key_exists( $name, $this->getFields() );
 657+ }
 658+
 659+}
Index: trunk/extensions/EducationProgram/docs/schema.txt
@@ -21,7 +21,7 @@
2222 * Revision storage is the ep_revisions table which contains blobs with the
2323 relational data for one particular object.
2424
25 -The extension uses the DBDataObject and DBTable classes for virtually all
 25+The extension uses the ORMRow and ORMTable classes for virtually all
2626 it's database interaction. These have mechanisms for distinguishing between
2727 relational and denormalized data (referred to as "summary data" in their docs).
2828 All revisioning work is done through EPRevision and EPRevisions using EPRevisionedObject.
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -146,8 +146,9 @@
147147
148148 // Compat classes
149149 foreach ( array(
150 - 'DBDataObject' => 'DBDataObject.php',
151 - 'DBTable' => 'DBTable.php',
 150+ 'ORMResult' => 'ORMResult.php',
 151+ 'ORMRow' => 'ORMRow.php',
 152+ 'ORMTable' => 'ORMTable.php',
152153 'CacheHelper' => 'CacheHelper.php',
153154 'ICacheHelper' => 'CacheHelper.php',
154155 'CachedAction' => 'CachedAction.php',
Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql
@@ -18,7 +18,7 @@
1919 org_ca_count INT unsigned NOT NULL, -- Amount of campus ambassadors
2020 org_student_count INT unsigned NOT NULL, -- Amount of students
2121 org_courses BLOB NOT NULL -- The ids of the courses (linking ep_courses.course_id)
22 -) /*$wgDBTableOptions*/;
 22+) /*$wgORMTableOptions*/;
2323
2424 CREATE UNIQUE INDEX /*i*/ep_org_name ON /*_*/ep_orgs (org_name);
2525 CREATE INDEX /*i*/ep_org_city ON /*_*/ep_orgs (org_city);
@@ -57,7 +57,7 @@
5858 course_oa_count SMALLINT unsigned NOT NULL, -- Amount of online ambassadors
5959 course_ca_count SMALLINT unsigned NOT NULL, -- Amount of campus ambassadors
6060 course_student_count SMALLINT unsigned NOT NULL -- Amount of students
61 -) /*$wgDBTableOptions*/;
 61+) /*$wgORMTableOptions*/;
6262
6363 CREATE INDEX /*i*/ep_course_org_id ON /*_*/ep_courses (course_org_id);
6464 CREATE INDEX /*i*/ep_course_name ON /*_*/ep_courses (course_name);
@@ -86,7 +86,7 @@
8787 article_page_title varchar(255) binary NOT NULL, -- Full title of the page, to allow for associating non-existing pages
8888
8989 article_reviewers BLOB NOT NULL -- List of reviewers for this article (linking user.user_id)
90 -) /*$wgDBTableOptions*/;
 90+) /*$wgORMTableOptions*/;
9191
9292 CREATE INDEX /*i*/ep_articles_user_id ON /*_*/ep_articles (article_user_id);
9393 CREATE INDEX /*i*/ep_articles_course_id ON /*_*/ep_articles (article_course_id);
@@ -102,7 +102,7 @@
103103 upc_course_id INT unsigned NOT NULL, -- Foreign key on ep_courses.course_id
104104 upc_role TINYINT unsigned NOT NULL, -- The role the user has for the course
105105 upc_time varbinary(14) NOT NULL -- Time at which the link was made
106 -) /*$wgDBTableOptions*/;
 106+) /*$wgORMTableOptions*/;
107107
108108 CREATE UNIQUE INDEX /*i*/ep_users_per_course ON /*_*/ep_users_per_course (upc_user_id, upc_course_id, upc_role);
109109 CREATE INDEX /*i*/ep_upc_course_id ON /*_*/ep_users_per_course (upc_course_id);
@@ -123,7 +123,7 @@
124124 student_last_course INT unsigned NOT NULL, -- Last course the user enrolled in
125125 student_last_active varbinary(14) NOT NULL, -- Time of last activity in article NS
126126 student_active_enroll TINYINT unsigned NOT NULL -- If the student is enrolled in any active courses
127 -) /*$wgDBTableOptions*/;
 127+) /*$wgORMTableOptions*/;
128128
129129 CREATE UNIQUE INDEX /*i*/ep_students_user_id ON /*_*/ep_students (student_user_id);
130130 CREATE INDEX /*i*/ep_students_first_enroll ON /*_*/ep_students (student_first_enroll);
@@ -139,7 +139,7 @@
140140 CREATE TABLE IF NOT EXISTS /*_*/ep_instructors (
141141 instructor_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
142142 instructor_user_id INT unsigned NOT NULL -- Foreign key on user.user_id
143 -) /*$wgDBTableOptions*/;
 143+) /*$wgORMTableOptions*/;
144144
145145 CREATE UNIQUE INDEX /*i*/ep_instructors_user_id ON /*_*/ep_instructors (instructor_user_id);
146146
@@ -153,7 +153,7 @@
154154 ca_visible TINYINT unsigned NOT NULL, -- If the profile should be public
155155 ca_bio TEXT NOT NULL, -- Bio of the ambassador
156156 ca_photo VARCHAR(255) NOT NULL -- Name of a photo of the ambassador on commons
157 -) /*$wgDBTableOptions*/;
 157+) /*$wgORMTableOptions*/;
158158
159159 CREATE UNIQUE INDEX /*i*/ep_cas_user_id ON /*_*/ep_cas (ca_user_id);
160160 CREATE INDEX /*i*/ep_cas_visible ON /*_*/ep_cas (ca_visible);
@@ -168,7 +168,7 @@
169169 oa_visible TINYINT unsigned NOT NULL, -- If the profile should be public
170170 oa_bio TEXT NOT NULL, -- Bio of the ambassador
171171 oa_photo VARCHAR(255) NOT NULL -- Name of a photo of the ambassador on commons
172 -) /*$wgDBTableOptions*/;
 172+) /*$wgORMTableOptions*/;
173173
174174 CREATE UNIQUE INDEX /*i*/ep_oas_user_id ON /*_*/ep_oas (oa_user_id);
175175 CREATE INDEX /*i*/ep_oas_visible ON /*_*/ep_oas (oa_visible);
@@ -215,10 +215,10 @@
216216
217217 -- The actual revision content. This is a blob containing the fields
218218 -- of the object (array) passed to PHPs serialize().
219 - -- A new DBDataObject of it's type can be constructed by passing
 219+ -- A new ORMRow of it's type can be constructed by passing
220220 -- it the result of unserialize on this blob.
221221 rev_data BLOB NOT NULL
222 -) /*$wgDBTableOptions*/;
 222+) /*$wgORMTableOptions*/;
223223
224224 CREATE INDEX /*i*/ep_revision_object_id ON /*_*/ep_revisions (rev_object_id);
225225 CREATE INDEX /*i*/ep_revision_type ON /*_*/ep_revisions (rev_type);
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -50,7 +50,7 @@
5151 * (non-PHPdoc)
5252 * @see EPViewAction::getPageHTML()
5353 */
54 - public function getPageHTML( DBDataObject $course ) {
 54+ public function getPageHTML( ORMRow $course ) {
5555 $html = parent::getPageHTML( $course );
5656
5757 $html .= Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) );
@@ -93,7 +93,7 @@
9494 *
9595 * @return array
9696 */
97 - protected function getSummaryData( DBDataObject $course ) {
 97+ protected function getSummaryData( ORMRow $course ) {
9898 $stats = array();
9999
100100 $orgName = EPOrgs::singleton()->selectFieldsRow( 'name', array( 'id' => $course->getField( 'org_id' ) ) );
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Abstract action for viewing DBDataObject items.
 5+ * Abstract action for viewing ORMRow items.
66 *
77 * @since 0.1
88 *
@@ -27,7 +27,7 @@
2828 *
2929 * @param Page $page
3030 * @param IContextSource $context
31 - * @param DBTable $table
 31+ * @param ORMTable $table
3232 */
3333 protected function __construct( Page $page, IContextSource $context = null, EPPageTable $table ) {
3434 $this->table = $table;
@@ -143,11 +143,11 @@
144144 *
145145 * @since 0.1
146146 *
147 - * @param DBDataObject $object
 147+ * @param ORMRow $object
148148 *
149149 * @return string
150150 */
151 - public function getPageHTML( DBDataObject $object ) {
 151+ public function getPageHTML( ORMRow $object ) {
152152 return $this->getSummary( $object );
153153 }
154154
@@ -181,13 +181,13 @@
182182 *
183183 * @since 0.1
184184 *
185 - * @param DBDataObject $item
 185+ * @param ORMRow $item
186186 * @param boolean $collapsed
187187 * @param array $summaryData
188188 *
189189 * @return string
190190 */
191 - protected function getSummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) {
 191+ protected function getSummary( ORMRow $item, $collapsed = false, array $summaryData = null ) {
192192 $html = '';
193193
194194 $class = 'wikitable ep-summary mw-collapsible';
@@ -231,11 +231,11 @@
232232 *
233233 * @since 0.1
234234 *
235 - * @param DBDataObject $item
 235+ * @param ORMRow $item
236236 *
237237 * @return array
238238 */
239 - protected function getSummaryData( DBDataObject $item ) {
 239+ protected function getSummaryData( ORMRow $item ) {
240240 return array();
241241 }
242242
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php
@@ -121,7 +121,7 @@
122122 protected function getFormFields() {
123123 $fields = parent::getFormFields();
124124
125 - $orgOptions = EPOrgs::singleton()->getOrgOptions();
 125+ $orgOptions = EPOrgs::singleton()->selectFields( array( 'name', 'id' ) );
126126
127127 $fields['name'] = array (
128128 'type' => 'text',
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -43,7 +43,7 @@
4444 *
4545 * @param Page $page
4646 * @param IContextSource $context
47 - * @param DBTable $table
 47+ * @param ORMTable $table
4848 */
4949 protected function __construct( Page $page, IContextSource $context = null, EPPageTable $table ) {
5050 $this->table = $table;
@@ -432,11 +432,11 @@
433433 *$title = SpecialPage::getTitleFor( $this->itemPage, $this->subPage )->getLocalURL();
434434 * @since 0.1
435435 *
436 - * @param DBDataObject $item
 436+ * @param ORMRow $item
437437 * @param string $name
438438 * @param string $value This is a string, since it comes from request data, but might be a number or other type.
439439 */
440 - protected function handleUnknownField( DBDataObject $item, $name, $value ) {
 440+ protected function handleUnknownField( ORMRow $item, $name, $value ) {
441441 // Override to use.
442442 }
443443
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
@@ -51,7 +51,7 @@
5252 * @see EPViewAction::getPageHTML()
5353 * @return string
5454 */
55 - public function getPageHTML( DBDataObject $org ) {
 55+ public function getPageHTML( ORMRow $org ) {
5656 $html = parent::getPageHTML( $org );
5757
5858 $html .= Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) );
@@ -75,7 +75,7 @@
7676 *
7777 * @return array
7878 */
79 - protected function getSummaryData( DBDataObject $org ) {
 79+ protected function getSummaryData( ORMRow $org ) {
8080 $stats = array();
8181
8282 $stats['name'] = $org->getField( 'name' );
Index: trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
@@ -50,7 +50,7 @@
5151 if ( $object === false ) {
5252 $revision = EPRevisions::singleton()->getLatestRevision( array(
5353 'object_identifier' => $this->getTitle()->getText(),
54 - 'type' => $this->page->getTable()->getDataObjectClass(),
 54+ 'type' => $this->page->getTable()->getRowClass(),
5555 ) );
5656
5757 if ( $revision === false ) {
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php
@@ -145,11 +145,11 @@
146146 *
147147 * @since 0.1
148148 *
149 - * @param DBDataObject $item
 149+ * @param ORMRow $item
150150 * @param boolean $collapsed
151151 * @param array $summaryData
152152 */
153 - protected function displaySummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) {
 153+ protected function displaySummary( ORMRow $item, $collapsed = false, array $summaryData = null ) {
154154 $this->getOutput()->addHTML( $item, $collapsed, $summaryData );
155155 }
156156
@@ -158,13 +158,13 @@
159159 *
160160 * @since 0.1
161161 *
162 - * @param DBDataObject $item
 162+ * @param ORMRow $item
163163 * @param boolean $collapsed
164164 * @param array $summaryData
165165 *
166166 * @return string
167167 */
168 - protected function getSummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) {
 168+ protected function getSummary( ORMRow $item, $collapsed = false, array $summaryData = null ) {
169169 $html = '';
170170
171171 $class = 'wikitable ep-summary mw-collapsible';
@@ -208,11 +208,11 @@
209209 *
210210 * @since 0.1
211211 *
212 - * @param DBDataObject $item
 212+ * @param ORMRow $item
213213 *
214214 * @return array
215215 */
216 - protected function getSummaryData( DBDataObject $item ) {
 216+ protected function getSummaryData( ORMRow $item ) {
217217 return array();
218218 }
219219
Index: trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php
@@ -260,7 +260,7 @@
261261 $orgs = array_unique( $orgs );
262262
263263 $term = array(
264 - 'courses' => count( $courses ),
 264+ 'courses' => $courses->count(),
265265 'students' => count( $students ),
266266 'instructors' => count( $instructors ),
267267 'oas' => count( $oas ),
Index: trunk/extensions/EducationProgram/specials/SpecialStudent.php
@@ -141,7 +141,7 @@
142142 *
143143 * @return array
144144 */
145 - protected function getSummaryData( DBDataObject $student ) {
 145+ protected function getSummaryData( ORMRow $student ) {
146146 $stats = array();
147147
148148 $id = $student->getUser()->getId();
Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -136,7 +136,7 @@
137137 * (non-PHPdoc)
138138 * @see EPPager::getControlLinks()
139139 */
140 - protected function getControlLinks( DBDataObject $item ) {
 140+ protected function getControlLinks( ORMRow $item ) {
141141 $links = parent::getControlLinks( $item );
142142
143143 $links[] = $item->getLink( 'view', wfMsgHtml( 'view' ) );
Index: trunk/extensions/EducationProgram/includes/EPArticles.php
@@ -11,21 +11,21 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPArticles extends DBTable {
 15+class EPArticles extends ORMTable {
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_articles';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPArticle';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
@@ -63,7 +63,7 @@
6464
6565 /**
6666 * (non-PHPdoc)
67 - * @see DBTable::getDefaults()
 67+ * @see ORMTable::getDefaults()
6868 * @since 0.1
6969 * @return array
7070 */
Index: trunk/extensions/EducationProgram/includes/EPOrgs.php
@@ -15,17 +15,17 @@
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_orgs';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPOrg';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
@@ -69,7 +69,7 @@
7070
7171 /**
7272 * (non-PHPdoc)
73 - * @see DBTable::getDefaults()
 73+ * @see ORMTable::getDefaults()
7474 * @since 0.1
7575 * @return array
7676 */
@@ -95,14 +95,14 @@
9696 */
9797 public function getRevertableFields() {
9898 return array_diff(
99 - array_keys( $this->getFieldTypes() ),
 99+ array_keys( $this->getFields() ),
100100 array_merge( array( 'id', $this->getSummaryFields() ) )
101101 );
102102 }
103103
104104 /**
105105 * (non-PHPdoc)
106 - * @see DBTable::getSummaryFields()
 106+ * @see ORMTable::getSummaryFields()
107107 * @since 0.1
108108 * @return array
109109 */
@@ -119,29 +119,6 @@
120120 }
121121
122122 /**
123 - * Returns a list of orgs in an array that can be fed to select inputs.
124 - *
125 - * @since 0.1
126 - *
127 - * @param array|null $orgs
128 - *
129 - * @return array
130 - */
131 - public function getOrgOptions( array /* EPOrg */ $orgs = null ) {
132 - $options = array();
133 -
134 - if ( is_null( $orgs ) ) {
135 - $orgs = $this->select( array( 'name', 'id' ) );
136 - }
137 -
138 - foreach ( $orgs as /* EPOrg */ $org ) {
139 - $options[$org->getField( 'name' )] = $org->getId();
140 - }
141 -
142 - return $options;
143 - }
144 -
145 - /**
146123 * (non-PHPdoc)
147124 * @see EPPageObject::getIdentifierField()
148125 */
Index: trunk/extensions/EducationProgram/includes/EPPageTable.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Abstract base class DBDataObjects that have associated page views.
 5+ * Abstract base class ORMRows that have associated page views.
66 *
77 * @since 0.1
88 *
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -abstract class EPPageTable extends DBTable {
 15+abstract class EPPageTable extends ORMTable {
1616
1717 /**
1818 * Returns the field use to identify this object, ie the part used as page title.
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -abstract class EPRoleObject extends DBDataObject implements EPIRole {
 15+abstract class EPRoleObject extends ORMRow implements EPIRole {
1616
1717 /**
1818 * Field for caching the linked user.
@@ -294,7 +294,7 @@
295295 }
296296
297297 /**
298 - * @see DBDataObject::getUpdateConditions()
 298+ * @see ORMRow::getUpdateConditions()
299299 *
300300 * Always adding the user ID to the list of consitions,
301301 * even when not loaded yet (a new query will be done),
Index: trunk/extensions/EducationProgram/includes/EPInstructors.php
@@ -11,21 +11,21 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPInstructors extends DBTable {
 15+class EPInstructors extends ORMTable {
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_instructors';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPInstructor';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
Index: trunk/extensions/EducationProgram/includes/EPPageObject.php
@@ -56,7 +56,7 @@
5757
5858 /**
5959 * (non-PHPdoc)
60 - * @see DBDataObject::save()
 60+ * @see ORMRow::save()
6161 */
6262 public function save( $functionName = null ) {
6363 if ( $this->hasField( $this->table->getIdentifierField() ) && is_null( $this->getTitle() ) ) {
@@ -87,7 +87,7 @@
8888
8989 /**
9090 * (non-PHPdoc)
91 - * @see DBDataObject::setField()
 91+ * @see ORMRow::setField()
9292 */
9393 public function setField( $name, $value ) {
9494 if ( $name === $this->table->getIdentifierField() ) {
Index: trunk/extensions/EducationProgram/includes/EPCAs.php
@@ -11,21 +11,21 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPCAs extends DBTable {
 15+class EPCAs extends ORMTable {
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_cas';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPCA';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
@@ -63,7 +63,7 @@
6464
6565 /**
6666 * (non-PHPdoc)
67 - * @see DBTable::getDefaults()
 67+ * @see ORMTable::getDefaults()
6868 * @since 0.1
6969 * @return array
7070 */
Index: trunk/extensions/EducationProgram/includes/EPStudents.php
@@ -11,21 +11,21 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPStudents extends DBTable {
 15+class EPStudents extends ORMTable {
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_students';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPStudent';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
@@ -65,7 +65,7 @@
6666
6767 /**
6868 * (non-PHPdoc)
69 - * @see DBTable::getSummaryFields()
 69+ * @see ORMTable::getSummaryFields()
7070 * @since 0.1
7171 * @return array
7272 */
Index: trunk/extensions/EducationProgram/includes/EPRevisionPager.php
@@ -162,10 +162,10 @@
163163 function getQueryInfo() {
164164 $table = EPRevisions::singleton();
165165 return array(
166 - 'tables' => $table->getDBTable(),
 166+ 'tables' => $table->getName(),
167167 'fields' => $table->getPrefixedFields( $table->getFieldNames() ),
168168 'conds' => $table->getPrefixedValues( $this->conds ),
169 - 'options' => array( 'USE INDEX' => array( $table->getDBTable() => $table->getPrefixedField( 'time' ) ) ),
 169+ 'options' => array( 'USE INDEX' => array( $table->getName() => $table->getPrefixedField( 'time' ) ) ),
170170 );
171171 }
172172
Index: trunk/extensions/EducationProgram/includes/EPOAPager.php
@@ -18,9 +18,9 @@
1919 *
2020 * @param IContextSource $context
2121 * @param array $conds
22 - * @param DBTable|null $table
 22+ * @param ORMTable|null $table
2323 */
24 - public function __construct( IContextSource $context, array $conds = array(), DBTable $table = null ) {
 24+ public function __construct( IContextSource $context, array $conds = array(), ORMTable $table = null ) {
2525 $this->mDefaultDirection = true;
2626
2727 $conds = array_merge(
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -155,7 +155,7 @@
156156 'type' => 'select',
157157 'options' => array_merge(
158158 array( '' => '' ),
159 - $orgs->getOrgOptions( $orgs->select( array( 'name', 'id' ) ) )
 159+ $orgs->selectFields( array( 'name', 'id' ) )
160160 ),
161161 'value' => '',
162162 'datatype' => 'int',
@@ -195,7 +195,7 @@
196196 * (non-PHPdoc)
197197 * @see EPPager::getControlLinks()
198198 */
199 - protected function getControlLinks( DBDataObject $item ) {
 199+ protected function getControlLinks( ORMRow $item ) {
200200 $links = parent::getControlLinks( $item );
201201
202202 $links[] = $item->getLink( 'view', wfMsgHtml( 'view' ) );
Index: trunk/extensions/EducationProgram/includes/EPRevisions.php
@@ -11,21 +11,21 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPRevisions extends DBTable {
 15+class EPRevisions extends ORMTable {
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_revisions';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPRevision';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
@@ -72,7 +72,7 @@
7373 *
7474 * @since 0.1
7575 *
76 - * @param DBDataObject $object
 76+ * @param ORMRow $object
7777 * @param EPRevisionAction $revAction
7878 *
7979 * @return EPRevision
Index: trunk/extensions/EducationProgram/includes/EPOAs.php
@@ -11,21 +11,21 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPOAs extends DBTable {
 15+class EPOAs extends ORMTable {
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_oas';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPOA';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
@@ -63,7 +63,7 @@
6464
6565 /**
6666 * (non-PHPdoc)
67 - * @see DBTable::getDefaults()
 67+ * @see ORMTable::getDefaults()
6868 * @since 0.1
6969 * @return array
7070 */
Index: trunk/extensions/EducationProgram/includes/EPCourses.php
@@ -15,17 +15,17 @@
1616
1717 /**
1818 * (non-PHPdoc)
19 - * @see DBTable::getDBTable()
 19+ * @see ORMTable::getName()
2020 * @since 0.1
2121 * @return string
2222 */
23 - public function getDBTable() {
 23+ public function getName() {
2424 return 'ep_courses';
2525 }
2626
2727 /**
2828 * (non-PHPdoc)
29 - * @see DBTable::getFieldPrefix()
 29+ * @see ORMTable::getFieldPrefix()
3030 * @since 0.1
3131 * @return string
3232 */
@@ -35,21 +35,21 @@
3636
3737 /**
3838 * (non-PHPdoc)
39 - * @see DBTable::getDataObjectClass()
 39+ * @see ORMTable::getRowClass()
4040 * @since 0.1
4141 * @return string
4242 */
43 - public function getDataObjectClass() {
 43+ public function getRowClass() {
4444 return 'EPCourse';
4545 }
4646
4747 /**
4848 * (non-PHPdoc)
49 - * @see DBTable::getFieldTypes()
 49+ * @see ORMTable::getFields()
5050 * @since 0.1
5151 * @return array
5252 */
53 - public function getFieldTypes() {
 53+ public function getFields() {
5454 return array(
5555 'id' => 'id',
5656
@@ -78,7 +78,7 @@
7979
8080 /**
8181 * (non-PHPdoc)
82 - * @see DBTable::getDefaults()
 82+ * @see ORMTable::getDefaults()
8383 * @since 0.1
8484 * @return array
8585 */
@@ -108,7 +108,7 @@
109109
110110 /**
111111 * (non-PHPdoc)
112 - * @see DBTable::getSummaryFields()
 112+ * @see ORMTable::getSummaryFields()
113113 * @since 0.1
114114 * @return array
115115 */
Index: trunk/extensions/EducationProgram/includes/EPArticle.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -class EPArticle extends DBDataObject {
 16+class EPArticle extends ORMRow {
1717
1818 /**
1919 * Cached user object for this article.
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -50,7 +50,7 @@
5151
5252 /**
5353 * (non-PHPdoc)
54 - * @see DBDataObject::loadSummaryFields()
 54+ * @see ORMRow::loadSummaryFields()
5555 */
5656 public function loadSummaryFields( $summaryFields = null ) {
5757 if ( is_null( $summaryFields ) ) {
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -23,7 +23,7 @@
2424
2525 /**
2626 * (non-PHPdoc)
27 - * @see DBDataObject::loadSummaryFields()
 27+ * @see ORMRow::loadSummaryFields()
2828 */
2929 public function loadSummaryFields( $summaryFields = null ) {
3030 if ( is_null( $summaryFields ) ) {
@@ -96,7 +96,7 @@
9797
9898 /**
9999 * (non-PHPdoc)
100 - * @see DBDataObject::save()
 100+ * @see ORMRow::save()
101101 */
102102 public function save( $functionName = null ) {
103103 if ( $this->hasField( 'name' ) ) {
@@ -225,7 +225,7 @@
226226 */
227227 public function getCourses( array $fields = null ) {
228228 if ( $this->courses === false ) {
229 - $courses = EPCourses::singleton()->select( $fields, array( 'org_id' => $this->getId() ) );
 229+ $courses = EPCourses::singleton()->selectObjects( $fields, array( 'org_id' => $this->getId() ) );
230230
231231 if ( is_null( $fields ) ) {
232232 $this->courses = $courses;
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Abstract base class for DBDataObjects with revision history and logging support.
 5+ * Abstract base class for ORMRows with revision history and logging support.
66 *
77 * @since 0.1
88 *
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -abstract class EPRevisionedObject extends DBDataObject {
 15+abstract class EPRevisionedObject extends ORMRow {
1616
1717 /**
1818 * If the object should log changes.
@@ -132,7 +132,7 @@
133133
134134 /**
135135 * (non-PHPdoc)
136 - * @see DBDataObject::saveExisting()
 136+ * @see ORMRow::saveExisting()
137137 */
138138 protected function saveExisting( $functionName = null ) {
139139 if ( !$this->inSummaryMode ) {
@@ -173,7 +173,7 @@
174174
175175 /**
176176 * (non-PHPdoc)
177 - * @see DBDataObject::insert()
 177+ * @see ORMRow::insert()
178178 */
179179 protected function insert( $functionName = null, array $options = null ) {
180180 $result = parent::insert( $functionName, $options );
@@ -188,7 +188,7 @@
189189
190190 /**
191191 * Do logging and revision storage after a removal.
192 - * @see DBDataObject::onRemoved()
 192+ * @see ORMRow::onRemoved()
193193 *
194194 * @since 0.1
195195 */
@@ -238,7 +238,7 @@
239239
240240 /**
241241 * (non-PHPdoc)
242 - * @see DBDataObject::getBeforeRemoveFields()
 242+ * @see ORMRow::getBeforeRemoveFields()
243243 */
244244 protected function getBeforeRemoveFields() {
245245 return null;
@@ -260,7 +260,7 @@
261261 array( 'LIMIT' => 1 )
262262 );
263263
264 - return empty( $objects ) ? false : $objects[0];
 264+ return $objects->isEmpty() ? false : $objects->current();
265265 }
266266
267267 /**
@@ -272,7 +272,7 @@
273273 * @param array $conditions
274274 * @param array $options
275275 *
276 - * @return array of EPRevision
 276+ * @return ORMResult
277277 */
278278 public function getRevisions( array $conditions = array(), array $options = array() ) {
279279 return EPRevisions::singleton()->select( null, array_merge(
Index: trunk/extensions/EducationProgram/includes/EPRevision.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPRevision extends DBDataObject {
 15+class EPRevision extends ORMRow {
1616
1717 /**
1818 * Cached user object for this revision.
@@ -23,7 +23,7 @@
2424
2525 /**
2626 * (non-PHPdoc)
27 - * @see DBDataObject::getTable()
 27+ * @see ORMRow::getTable()
2828 */
2929 public function getTable() {
3030 return EPRevisions::singleton();
Index: trunk/extensions/EducationProgram/includes/EPPager.php
@@ -2,7 +2,7 @@
33
44 /**
55 * Abstract class extending the TablePager with common functions
6 - * for pagers listing DBDataObject deriving classes and some compatibility helpers.
 6+ * for pagers listing ORMRow deriving classes and some compatibility helpers.
77 *
88 * @since 0.1
99 *
@@ -23,14 +23,14 @@
2424
2525 /**
2626 * @since 0.1
27 - * @var DBTable
 27+ * @var ORMTable
2828 */
2929 protected $table;
3030
3131 /**
32 - * DBDataObject object constructed from $this->currentRow.
 32+ * ORMRow object constructed from $this->currentRow.
3333 * @since 0.1
34 - * @var DBDataObject
 34+ * @var ORMRow
3535 */
3636 protected $currentObject;
3737
@@ -53,9 +53,9 @@
5454 *
5555 * @param IContextSource $context
5656 * @param array $conds
57 - * @param DBTable $table
 57+ * @param ORMTable $table
5858 */
59 - public function __construct( IContextSource $context, array $conds, DBTable $table ) {
 59+ public function __construct( IContextSource $context, array $conds, ORMTable $table ) {
6060 $this->conds = $conds;
6161 $this->table = $table;
6262 $this->context = $context;
@@ -227,7 +227,7 @@
228228 */
229229 function getQueryInfo() {
230230 return array(
231 - 'tables' => array( $this->table->getDBTable() ),
 231+ 'tables' => array( $this->table->getName() ),
232232 'fields' => $this->table->getPrefixedFields( $this->table->getFieldNames() ),
233233 'conds' => $this->table->getPrefixedValues( $this->getConditions() ),
234234 );
@@ -446,7 +446,7 @@
447447 * @return string
448448 */
449449 protected function getMsg( $messageKey ) {
450 - return wfMsg( strtolower( $this->table->getDataObjectClass() ) . 'pager-' . str_replace( '_', '-', $messageKey ) );
 450+ return wfMsg( strtolower( $this->table->getRowClass() ) . 'pager-' . str_replace( '_', '-', $messageKey ) );
451451 }
452452
453453 /**
@@ -475,11 +475,11 @@
476476 *
477477 * @since 0.1
478478 *
479 - * @param DBDataObject $item
 479+ * @param ORMRow $item
480480 *
481481 * @return array
482482 */
483 - protected function getControlLinks( DBDataObject $item ) {
 483+ protected function getControlLinks( ORMRow $item ) {
484484 return array();
485485 }
486486
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -97,7 +97,7 @@
9898
9999 /**
100100 * (non-PHPdoc)
101 - * @see DBDataObject::loadSummaryFields()
 101+ * @see ORMRow::loadSummaryFields()
102102 */
103103 public function loadSummaryFields( $summaryFields = null ) {
104104 if ( is_null( $summaryFields ) ) {
@@ -118,7 +118,7 @@
119119
120120 /**
121121 * (non-PHPdoc)
122 - * @see DBDataObject::insert()
 122+ * @see ORMRow::insert()
123123 */
124124 protected function insert( $functionName = null, array $options = null ) {
125125 $success = parent::insert( $functionName, $options );
@@ -216,7 +216,7 @@
217217
218218 /**
219219 * (non-PHPdoc)
220 - * @see DBDataObject::save()
 220+ * @see ORMRow::save()
221221 */
222222 public function save( $functionName = null ) {
223223 if ( $this->hasField( 'name' ) ) {
@@ -325,7 +325,7 @@
326326 array_key_exists( 'org', $args ) ? $args['org'] : false
327327 );
328328
329 - $select->addOptions( EPOrgs::singleton()->getOrgOptions() );
 329+ $select->addOptions( EPOrgs::singleton()->selectFields( array( 'name', 'id' ) ) );
330330 $html .= $select->getHTML();
331331
332332 $html .= '&#160;' . Xml::inputLabel(
@@ -545,7 +545,7 @@
546546
547547 /**
548548 * (non-PHPdoc)
549 - * @see DBDataObject::setField()
 549+ * @see ORMRow::setField()
550550 */
551551 public function setField( $name, $value ) {
552552 switch ( $name ) {

Status & tagging log