Exemplo n.º 1
0
 function Fill(\DBAL\DataSource\SQLDataSource $dataSource)
 {
     $roots = $this->getRoots($dataSource);
     $dataSource->clear();
     if (count($roots) > 0) {
         foreach ($roots as $root) {
             $this->setCommand(\ORM\Query::build($this->getResource(), \ORM\Query::HYDRATE_NESTEDSET)->select()->from($this->getResource())->where('lft', $root->lft, '>=')->where('rgt', $root->rgt, '<='));
             parent::Fill($dataSource);
         }
     }
     return $dataSource->Data;
 }
Exemplo n.º 2
0
 /**
  * Delete current object
  *
  * @param   mixed  $cascade
  *     null = use default config,
  *     bool = force/prevent cascade,
  *     array cascades only the relations that are in the array
  * @return  Model  this instance as a new object without primary key(s)
  */
 public function delete($cascade = null)
 {
     // New objects can't be deleted, neither can frozen
     if ($this->is_new() or $this->frozen()) {
         return false;
     }
     $this->observe('before_delete');
     $this->freeze();
     foreach ($this->relations() as $rel_name => $rel) {
         $rel->delete($this, $this->{$rel_name}, false, is_array($cascade) ? in_array($rel_name, $cascade) : $cascade);
     }
     $this->unfreeze();
     // Create the query and limit to primary key(s)
     $query = Query::factory(get_called_class())->limit(1);
     $primary_key = static::primary_key();
     foreach ($primary_key as $pk) {
         $query->where($pk, '=', $this->{$pk});
     }
     // Return success of update operation
     if (!$query->delete()) {
         return false;
     }
     $this->freeze();
     foreach ($this->relations() as $rel_name => $rel) {
         $rel->delete($this, $this->{$rel_name}, true, is_array($cascade) ? in_array($rel_name, $cascade) : $cascade);
     }
     $this->unfreeze();
     // Perform cleanup:
     // remove from internal object cache, remove PK's, set to non saved object, remove db original values
     if (array_key_exists(get_called_class(), static::$_cached_objects) and array_key_exists(static::implode_pk($this), static::$_cached_objects[get_called_class()])) {
         unset(static::$_cached_objects[get_called_class()][static::implode_pk($this)]);
     }
     foreach ($this->primary_key() as $pk) {
         unset($this->_data[$pk]);
     }
     $this->_is_new = true;
     $this->_original = array();
     $this->observe('after_delete');
     return $this;
 }
Exemplo n.º 3
0
 public static function add_query_where(\Orm\Query $query, $conditions = array())
 {
     if (!$conditions) {
         return $query;
     }
     if (count($conditions) == 3) {
         $query->where($conditions[0], $conditions[1], $conditions[2]);
     } else {
         $query->where($conditions);
     }
     return $query;
 }
Exemplo n.º 4
0
 protected static function set_where4not_multi(\Orm\Query $query, $params = array())
 {
     if (!$params) {
         return $query;
     }
     if (\Arr::is_assoc($params)) {
         $query->where($params);
         return $query;
     }
     if (count($params) == 2) {
         $query->where($params[0], $params[1]);
     } elseif (count($params) == 3) {
         $query->where($params[0], $params[1], $params[2]);
     } else {
         throw new \InvalidArgumentException('Second parameter is invalid.');
     }
     return $query;
 }