Skip to content

Commit

Permalink
added groups to core information access
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyLSB committed Feb 23, 2012
1 parent 9bcf48f commit 589e095
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
22 changes: 14 additions & 8 deletions _bundle.php
Expand Up @@ -13,12 +13,13 @@
*/
class Bundle extends SQLBundle {

public function __callBundle() {
return $this;
public function __callBundle($group = false) {
if(!$group) return $this;
else return new Accessor('information.record', $group);
}

public function __getBundle($method = true) {
return new Accessor('information.record', 'core');
return new Accessor('information.record', '/');
}

public function accessor(Model $model) {
Expand Down Expand Up @@ -51,32 +52,37 @@ public function b64() {

public function getRecord($field) {
$field = mysql_escape_string($field);
$owner = is_numeric($this->id) ? " AND `owner` = '$this->id'" : '';
$owner = is_numeric($this->id) ? "AND `owner` = '$this->id'" : "AND `category` = '$this->id'";
if(!is_numeric($this->id) && $this->id == '*') return false;
return e::$sql->query("SELECT `field`, `value` FROM `$this->table` WHERE `field` = '$field' $owner")->row();
}

public function listRecords() {
$owner = is_numeric($this->id) ? " WHERE `owner` = '$this->id'" : '';
$owner = is_numeric($this->id) ? "WHERE `owner` = '$this->id'" : "WHERE `category` = '$this->id'";
if(!is_numeric($this->id) && $this->id == '*') $owner = '';
return e::$sql->query("SELECT `field`, `value`, `updated_timestamp` FROM `$this->table` $owner")->all();
}

public function delRecord($field) {
$field = mysql_escape_string($field);
$owner = is_numeric($this->id) ? " AND `owner` = '$this->id'" : '';
$owner = is_numeric($this->id) ? "AND `owner` = '$this->id'" : "AND `category` = '$this->id'";
if(!is_numeric($this->id) && $this->id == '*') return false;
return e::$sql->query("DELETE FROM `$this->table` WHERE `field` = '$field' $owner");
}

public function updateRecord($field, $value) {
$field = mysql_escape_string($field);
$value = mysql_escape_string($value);
$owner = is_numeric($this->id) ? " AND `owner` = '$this->id'" : '';
$owner = is_numeric($this->id) ? "AND `owner` = '$this->id'" : "AND `category` = '$this->id'";
if(!is_numeric($this->id) && $this->id == '*') return false;
return e::$sql->query("UPDATE `$this->table` SET `value` = '$value' WHERE `field` = '$field' $owner");
}

public function createRecord($field, $value) {
$field = mysql_escape_string($field);
$value = mysql_escape_string($value);
$owner = is_numeric($this->id) ? ", `owner` = '$this->id'" : '';
$owner = is_numeric($this->id) ? ", `owner` = '$this->id'" : ", `category` = '$this->id'";
if(!is_numeric($this->id) && $this->id == '*') return false;
return e::$sql->query("INSERT INTO `$this->table` SET `field` = '$field', `value` = '$value' $owner");
}

Expand Down
1 change: 1 addition & 0 deletions configure/sql_structure.yaml
Expand Up @@ -4,5 +4,6 @@ record:
fields:
id: _suppress
created_timestamp: _suppress
category: string
field: string
value: text

0 comments on commit 589e095

Please sign in to comment.