Inheritance: extends Controller_Base
Example #1
0
 function setSource($model, $table)
 {
     if (!is_array($table)) {
         throw $this->exception('Wrong type: expected array')->addMoreInfo('source', $table);
     }
     if (!$model->hasMethod('push')) {
         $model->addMethod('push', $this);
     }
     // convert single dimension arrays
     reset($table);
     list(, $firstrow) = each($table);
     if (!is_array($firstrow)) {
         // assuming that this array needs to be converted
         foreach ($table as $key => &$name) {
             $name = array($model->id_field => $key, $model->title_field => $name);
         }
         return parent::setSource($model, $table);
     }
     $data = array();
     foreach ($table as $key => $row) {
         $id = isset($row[$model->id_field]) ? $row[$model->id_field] : $key;
         $data[$id] = $row;
     }
     return parent::setSource($model, $data);
 }
Example #2
0
 function setSource($model, $data = undefined)
 {
     if (!$data || $data === undefined) {
         $data = array();
     }
     parent::setSource($model, $data);
     if (@$model->id_field && !$model->hasElement($model->id_field)) {
         $model->addField($model->id_field)->system(true);
     }
     return $this;
 }
Example #3
0
 public function setSource($model, $data = UNDEFINED)
 {
     parent::setSource($model, array('db' => new Memcached($x = $data . '_' . $model->table), 'prefix' => $model->table));
     if (!$model->_table[$this->short_name]['db']->getServerList()) {
         $model->_table[$this->short_name]['db']->addServer('localhost', 11211);
     }
     if (!$model->hasElement($model->id_field)) {
         $model->addField($model->id_field)->system(true);
     }
     return $this;
 }
Example #4
0
 function setSource($model, $table = null)
 {
     if (!$table) {
         $table = $model->table;
     }
     if (@(!$this->app->mongoclient)) {
         $m = new MongoClient($this->app->getConfig('mongo/url', null));
         $db = $this->app->getConfig('mongo/db');
         $this->app->mongoclient = $m->{$db};
     }
     parent::setSource($model, array('db' => $this->app->mongoclient->{$table}, 'conditions' => array(), 'collection' => $table));
     $model->addMethod('incr,decr', $this);
     //$model->data=$model->_table[$this->short_name]['db']->get($id);
 }
Example #5
0
 function setSource($model, $table)
 {
     if (!$model->collection_uri) {
         throw $this->exception('Define $collection_uri in your model');
     }
     if (!$model->element_uri) {
         throw $this->exception('Define $element_uri in your model');
     }
     $pest = new $this->transport_class($table);
     if ($auth = $model->auth ?: $this->app->getConfig('restapi/auth', null)) {
         // Per-URL authentication is defined
         if (is_array($auth) && isset($auth[$table])) {
             $auth = $auth[$table];
         }
         if (!is_array($auth)) {
             throw $this->exception('auth must be array("user","pass")');
         }
         $pest->setupAuth($auth[0], $auth[1], @$auth[2] ?: 'basic');
     }
     $model->addMethod('pest', function () use($pest) {
         return $pest;
     });
     parent::setSource($model, $pest);
 }
Example #6
0
File: Model.php Project: atk4/atk4
 public function next()
 {
     $this->hook('beforeLoad', array('iterating'));
     $this->controller->loadCurrent($this, $this->_cursor);
     if ($this->loaded()) {
         $this->hook('afterLoad');
     }
     return $this;
 }