/**
  * Constructor that calls the parent Entity constructor and affect values if values are passed
  *
  * @param      array  $data   Array($columnName => $value) pairs to set the object DEFAULT null
  */
 public function __construct(array $data = null)
 {
     parent::__construct('RoomBan');
     if ($data !== null) {
         $this->setAttributes($data);
     }
 }
 /**
  * Utility method to set en return the table constraints to put in a SQL create table query
  *
  * @return     string  The formatted string to put in a SQL create table query
  */
 private function createTableConstraints() : string
 {
     $constraints = $this->entity->getConstraints();
     $sql = '';
     if (isset($constraints['primary'])) {
         $sql .= ',' . PHP_EOL . "\tCONSTRAINT `" . $constraints['primary']['name'] . '`';
         $sql .= ' PRIMARY KEY (' . $constraints['primary']['columns'] . ')';
     }
     if (isset($constraints['unique']) && $constraints['unique'] !== '') {
         $sql .= ',' . PHP_EOL . "\tUNIQUE `" . $this->entity->getTableName() . '_unique_constraint`';
         $sql .= ' (' . $constraints['unique'] . ')';
     }
     if (isset($constraints['foreignKey'])) {
         $names = array_keys($constraints['foreignKey']);
         foreach ($names as $name) {
             $sql .= ',' . PHP_EOL . "\tCONSTRAINT `" . $name . '`';
             $sql .= ' FOREIGN KEY (' . $constraints['foreignKey'][$name]['columns'] . ')';
             $sql .= PHP_EOL . "\t\tREFERENCES `" . $constraints['foreignKey'][$name]['tableRef'] . '`';
             $sql .= '(' . $constraints['foreignKey'][$name]['columnsRef'] . ')';
             if (isset($constraints['foreignKey'][$name]['match'])) {
                 $sql .= PHP_EOL . "\t\tMATCH " . $constraints['foreignKey'][$name]['match'];
             }
             if (isset($constraints['foreignKey'][$name]['onDelete'])) {
                 $sql .= PHP_EOL . "\t\tON DELETE " . $constraints['foreignKey'][$name]['onDelete'];
             }
             if (isset($constraints['foreignKey'][$name]['onUpdate'])) {
                 $sql .= PHP_EOL . "\t\tON UPDATE " . $constraints['foreignKey'][$name]['onUpdate'];
             }
         }
     }
     return $sql;
 }
Exemple #3
0
 /**
  * Get the room basic attributes only
  *
  * @return     array  The room basic attributes only
  */
 public function getRoomBasicAttributes()
 {
     return parent::__toArray();
 }
 /**
  * Set an entity which is already in the collection
  *
  * @param      Entity     $entity  The entity object
  * @param      string     $key     A key to save the entity DEFAULT null (auto generated)
  *
  * @throws     Exception  If the entity id is not already in the collection
  */
 public function set($entity, $key = null)
 {
     $id = $key ?? $this->parseId($entity->getIdValue());
     if (!array_key_exists($id, $this->indexId)) {
         throw new Exception('This entity id(' . static::formatVariable($id) . ') is not already in the collection ' . $this, Exception::$WARNING);
     } else {
         $this->collection[$this->indexId[$id]] = $entity;
     }
 }
Exemple #5
0
 /**
  * Return the user entity in an array format
  *
  * @return     array  Array with all users attributes
  */
 public function __toArray() : array
 {
     $user = parent::__toArray();
     $user['right'] = $this->right !== null ? $this->right->__toArray() : [];
     $user['roomRight'] = $this->roomRight !== null ? $this->roomRight->__toArray() : [];
     return $user;
 }