Esempio n. 1
0
 static function findLatestPages($course_id)
 {
     $query = "SELECT\n                    range_id,\n                    keyword,\n                    MAX(version) as version\n                  FROM wiki\n                  WHERE range_id = ?\n                  GROUP BY keyword\n                  ORDER BY keyword ASC";
     $st = DBManager::get()->prepare($query);
     $st->execute(array($course_id));
     $ids = $st->fetchAll(PDO::FETCH_NUM);
     $pages = new SimpleORMapCollection();
     $pages->setClassName(__CLASS__);
     foreach ($ids as $id) {
         $pages[] = self::find($id);
     }
     return $pages;
 }
 /**
  * creates a collection from an array of objects
  * all objects should be of the same type
  *
  * @throws InvalidArgumentException if first entry is not SimpleOrMap
  * @param array $data array with SimpleORMap objects
  * @param bool $strict check every element for correct type and unique pk
  * @return SimpleORMapCollection
  */
 public static function createFromArray(array $data, $strict = true)
 {
     $ret = new SimpleORMapCollection();
     if (count($data)) {
         $first = current($data);
         if ($first instanceof SimpleORMap) {
             $ret->setClassName(get_class($first));
             if ($strict) {
                 foreach ($data as $one) {
                     $ret[] = $one;
                 }
             } else {
                 $ret->exchangeArray($data);
             }
         } else {
             throw new InvalidArgumentException('This collection only accepts objects derived from SimpleORMap', self::WRONG_OBJECT_TYPE);
         }
     }
     return $ret;
 }