Permalink
Browse files

field list getter and some exception catchers implemented

  • Loading branch information...
1 parent 4e49876 commit 9d3e04aa691e35c119fd29cd92709194c171bbb6 @mstdokumaci committed Jul 16, 2012
Showing with 21 additions and 4 deletions.
  1. +12 −2 lib/adb.php
  2. +9 −2 lib/item.php
View
@@ -88,6 +88,12 @@ function create_tables () {
$ddl->create_tables();
}
+ function fields ($name) {
+ if (!isset($this->DM[$name])) throw new \Exception('Undefined item name: ' . $name);
+
+ return array_keys($this->DM[$name]['fields']);
+ }
+
function load ($name, $id) {
if (!isset($this->DM[$name])) throw new \Exception('Undefined item name: ' . $name);
@@ -135,8 +141,12 @@ function delete ($name, $id, $delete_belongings=false) {
$item=$this->load($name, $id);
foreach (array_filter($item_model['fields'], function ($el) {return $el['foreign']!==false;}) as $k=>$f) {
- $foreign_item=$this->load($f['foreign']['type'], intval($item[$k]));
- $foreign_item->delete_relation($f['foreign']['field'], $id);
+ try {
+ $foreign_item=$this->load($f['foreign']['type'], intval($item[$k]));
+ $foreign_item->delete_relation($f['foreign']['field'], $id);
+ } catch (\Exception $e) {
+ continue;
+ }
}
foreach ($item_model['has_many'] as $has_many) {
foreach ($item[$has_many['local_name']] as $foreign_id) {
View
@@ -82,8 +82,11 @@ function offsetset ($field, $value) {
$this->db->update($this->name, $update, "id='" . $this->id . "'");
if ($field_model['foreign']!==false) {
- $foreign_item=$this->adb->load($field_model['foreign']['type'], intval($this->data[$field]));
- $foreign_item->delete_relation($field_model['foreign']['field'], $this->id);
+ try {
+ $foreign_item=$this->adb->load($field_model['foreign']['type'], intval($this->data[$field]));
+ $foreign_item->delete_relation($field_model['foreign']['field'], $this->id);
+ } catch (\Exception $e) {
+ }
if ($value!=0) {
$foreign_item=$this->adb->load($field_model['foreign']['type'], intval($value));
@@ -101,6 +104,10 @@ function offsetunset ($field) {
throw new \Exception('Field unset is not allowed.');
}
+ function to_array () {
+ return $this->data;
+ }
+
function add_relation ($field, $id) {
$id=intval($id);
if (!isset($this->data[$field]) || !is_array($this->data[$field]))

0 comments on commit 9d3e04a

Please sign in to comment.