Exemplo n.º 1
0
 public function __construct($id_or_array = NULL)
 {
     global $g_itemperson_fields;
     $this->fields =& $g_itemperson_fields;
     /**
      *  this->_type holds a string for the current type
      *  which is used for accessing db-tables and
      *  form-parameter-passing (therefore it has to be lowercase)
      */
     $this->_type = strtolower(get_class($this));
     /**
      * add default fields if not overwritten by derived class
      */
     if (!$this->fields) {
         global $g_itemperson_fields;
         $this->fields =& $g_itemperson_fields;
     }
     /**
      * if array is passed, create a new empty object with default-values
      */
     parent::__construct();
     if (is_array($id_or_array)) {
         parent::__construct();
         foreach ($id_or_array as $key => $value) {
             is_null($this->{$key});
             ### cause E_NOTICE on undefined properties
             $this->{$key} = $value;
         }
     } else {
         if (is_int($id_or_array)) {
             parent::__construct($id_or_array);
         } else {
             trigger_error("can't construct zero-id item", E_USER_WARNING);
             parent::__construct();
             return NULL;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * create empty project-item or querry database
  */
 public function __construct($id_or_array = NULL)
 {
     /**
      *  this->_type holds a string for the current type
      *  which is used for accessing db-tables and
      *  form-parameter-passing (therefore it has to be lowercase)
      */
     $this->_type = strtolower(get_class($this));
     /**
      * add default fields if not overwritten by derived class
      */
     if (!$this->fields) {
         global $g_item_fields;
         $this->fields =& $g_item_fields;
     }
     /**
      * if array is passed, create a new empty object with default-values
      */
     if (is_array($id_or_array)) {
         parent::__construct();
         foreach ($id_or_array as $key => $value) {
             is_null($this->{$key});
             ### cause E_NOTICE on undefined properties
             $this->_values_org[$key] = $this->{$key} = $value;
         }
     } else {
         if (is_int($id_or_array) || (is_string($id_or_array) and $id_or_array !== "0")) {
             parent::__construct();
             # call constructor to initialize members from field-array
             $id = intval($id_or_array);
             # construction-param was an id
             if (!$id) {
                 return;
             }
             global $g_item_fields;
             $dbh = new DB_Mysql();
             $str_download_fields = "";
             $str_delimiter = '';
             foreach ($g_item_fields as $f) {
                 $str_download_fields .= $str_delimiter . $f->name;
                 $str_delimiter = ',';
             }
             $prefix = confGet('DB_TABLE_PREFIX');
             $query = "SELECT {$str_download_fields} from {$prefix}item WHERE id = {$id}";
             $data = $dbh->prepare($query)->execute()->fetch_assoc();
             if ($data) {
                 foreach ($data as $attr => $value) {
                     is_null($this->{$attr});
                     # cause E_NOTICE if member not defined
                     $this->_values_org[$attr] = $this->{$attr} = $value;
                 }
             } else {
                 /**
                  * this might happen very often (like when searching for id)
                  */
                 #trigger_error("item id='$id' not found in table", E_USER_WARNING);
                 unset($this);
                 #@@@ not sure if abort called construction like this works
                 return NULL;
             }
             #--- now find the other fields in the appropriate table ---
             if ($this->_type && $this->_type != 'dbprojectitem') {
                 $dbh = new DB_Mysql();
                 $str_download_fields = "";
                 $str_delimiter = '';
                 foreach ($this->fields as $f) {
                     #--- ignore project item fields ---
                     if (!isset($g_item_fields[$f->name])) {
                         $str_download_fields .= $str_delimiter . $f->name;
                         $str_delimiter = ',';
                     }
                 }
                 $prefix = confGet('DB_TABLE_PREFIX');
                 $query = "SELECT {$str_download_fields} from {$prefix}{$this->_type} WHERE id = {$id}";
                 $data = $dbh->prepare($query)->execute()->fetch_assoc();
                 if ($data) {
                     foreach ($data as $attr => $value) {
                         is_null($this->{$attr});
                         # cause E_NOTICE if member not defined
                         $this->_values_org[$attr] = $this->{$attr} = $value;
                     }
                 } else {
                     trigger_error("item #{$id} not found in db-table '{$this->_type}'", E_USER_WARNING);
                     return NULL;
                 }
             }
         } else {
             /**
              * this error might occure frequently
              */
             #trigger_error("can't construct zero-id item",E_USER_WARNING);
             parent::__construct();
             return NULL;
         }
     }
 }