Skip to content

Commit

Permalink
Make Store conform to the IContentStore interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
nevali committed Apr 8, 2012
1 parent eef76eb commit acb22f0
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions platform/store.php
Expand Up @@ -365,6 +365,7 @@ public function __construct($model, $args)
$this->storableClass = $args['storableClass'];
}
$this->total = $this->rs->total;
$this->count = count($this->rs);
if(isset($args['offset'])) $this->offset = $args['offset'];
if(isset($args['limit'])) $this->limit = $args['limit'];
$this->rewind();
Expand All @@ -377,7 +378,6 @@ protected function updateCurrent()
{
if($this->data['uuid'] != $this->key)
{
$this->count++;
$this->key = $this->data['uuid'];
if(!isset($this->data['data']))
{
Expand Down Expand Up @@ -423,14 +423,13 @@ public function next()

public function rewind()
{
$this->count = 0;
$this->rs->rewind();
$this->updateCurrent();
}

public function count()
{
return $this->count;
return count($this->rs);
}
}

Expand Down Expand Up @@ -458,6 +457,8 @@ class Store extends Model implements IContentStore
*/
protected $queriesGroupByUuid = true;

protected $insertedUuid = null;

public static function getInstance($args = null)
{
if(!isset($args['class'])) $args['class'] = 'Store';
Expand Down Expand Up @@ -766,6 +767,31 @@ public function objectForIri($iri, $owner = null, $kind = null, $firstOnly = fal
return call_user_func(array($this->storableClass, 'objectForData'), $data, $this, $this->storableClass);
}

public function /* IContentStore::*/insert($data)
{
return $this->setData($data);
}

public function /* IContentStore::*/update($what, $data)
{
$data['uuid'] = $what;
return $this->setData($data);
}

public function /* IContentStore::*/insertId()
{
return $this->insertedUuid;
}

public function /* IContentStore::*/fetch($what)
{
return $this->objectForUuid($what);
}

public function /* IContentStore::*/delete($what)
{
}

/* Store an object, which may be in associative array or instance form,
* or may be an (indexed) array of the same. In the latter case, the
* keys MUST begin at zero.
Expand Down Expand Up @@ -801,6 +827,7 @@ public function setData($data, $user = null, $lazy = false, $owner = null)
{
$uuid = UUID::generate();
}
$this->insertedUuid = $uuid;
$user_scheme = $user_uuid = null;
$uuid = strtolower($uuid);
if(isset($user))
Expand Down Expand Up @@ -1072,6 +1099,10 @@ public function query($query)
$qstr .= ' LIMIT ' . $limit;
}
}
if(defined('EREGANSU_DEBUG_STORE_QUERY'))
{
error_log($qstr);
}
if(($rs = $this->db->query($qstr)))
{
$query['recordSet'] = $rs;
Expand Down

0 comments on commit acb22f0

Please sign in to comment.