Example #1
0
 /**
  * Overrides parent for buffering
  * 
  * See <PDOStatement::fetchall>
  * @param int $fetch_style See php.net docs
  * @param int $column_index See php.net docs
  * @param mixed $ctor_args See php.net docs
  * @return mixed See php.net docs
  */
 function fetchAll($fetch_style = null, $column_index = null, $ctor_args = null)
 {
     $this->_data_fetched = true;
     if ($this->_loaded_from_cache) {
         return $this->_rowbuffer;
     }
     if ($fetch_style == null && $this->FetchMode) {
         $fetch_style = $this->FetchMode;
     }
     // we need to set the default datasource as it is not passed thru ctor in all cases
     // so we just remember the default here and set it to this ones if they differ
     if ($fetch_style == PDO::FETCH_CLASS && Model::$DefaultDatasource != $this->_ds) {
         $mem_def_db = Model::$DefaultDatasource;
         Model::$DefaultDatasource = $this->_ds;
     }
     // weird calling because PHP doesnt know the nullarray type so we cannot just put null valued arguments to the parent
     if (is_null($ctor_args)) {
         if (is_null($column_index)) {
             if (is_null($fetch_style)) {
                 $this->_rowbuffer = $this->_stmt->fetchAll();
             } else {
                 $this->_rowbuffer = $this->_stmt->fetchAll($fetch_style);
             }
         } else {
             $this->_rowbuffer = $this->_stmt->fetchAll($fetch_style, $column_index);
         }
     } else {
         $this->_rowbuffer = $this->_stmt->fetchAll($fetch_style, $column_index, $ctor_args);
     }
     if (count($this->_rowbuffer) > 0) {
         $this->_index = 0;
         $this->_current = $this->_rowbuffer[$this->_index];
     }
     // call init method on objects after they are loaded. Other methods do not work as documented :(
     if ($fetch_style == PDO::FETCH_CLASS) {
         $cnt = count($this->_rowbuffer);
         for ($i = 0; $i < $cnt; $i++) {
             $this->_rowbuffer[$i]->__initialize($this->_ds);
             $this->_rowbuffer[$i]->__init_db_values();
         }
         if (isset($mem_def_db)) {
             Model::$DefaultDatasource = $mem_def_db;
         }
     }
     return $this->_rowbuffer;
 }
 /**
  * Sets the default datasource.
  * 
  * This is nicer alternative to setting <Model>::$DefaultDatasource manually.
  * <code php>
  * $ds = Datasource::SetDefault('system');
  * // or
  * $ds = model_datasource('system');
  * Datasource::SetDefault($ds);
  * // or
  * $ds = Model::$DefaultDatasource = model_datasource('system');
  * </code>
  * @param mixed $ds The default datasource or it's aliasname
  * @return DataSource The newly set default <DataSource> object
  */
 public static function SetDefault($ds)
 {
     if (!$ds instanceof DataSource) {
         $ds = model_datasource($ds);
     }
     Model::$DefaultDatasource = $ds;
     return $ds;
 }