Beispiel #1
0
 /**
  * Get value(s) of primary key(s)
  * 
  * @param  mixed $table  Table index or name
  * @return mixed
  */
 public function getId($table = null)
 {
     if (!isset($table)) {
         $table = isset($this->_baseTable) ? $this->_baseTable->getTablename() : 0;
     }
     if (is_int($table) && !empty($this->_tablerefs)) {
         $tables = array_keys($this->_tablerefs);
         if (!isset($tables[$table])) {
             throw new DB_Exception("Unable to get id of table number {$table}: Record only holds fields of " . count($tables) . " tables.");
         }
         $table = $tables[$table];
     }
     if (!isset($this->_primaryKeyFields)) {
         $this->indexPrimairyKeyFields();
     }
     if (!isset($this->_primaryKeyFields[$table])) {
         throw new DB_Exception("Unable to get id of table '{$table}': Record does not hold the fields for the primary key(s).");
     }
     if (count($this->_primaryKeyFields[$table]) === 1) {
         return $this->_primaryKeyFields[$table][0]->getValue();
     }
     foreach ($this->_primaryKeyFields[$table] as $field) {
         $ids[] = $field->getValue();
     }
     return $ids;
 }