Esempio n. 1
0
 /**
  * Performs database insert (can be customized)
  *
  * @param Entity $entity
  * @return mixed
  */
 protected function insertIntoDatabase(Entity $entity)
 {
     $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
     $values = $entity->getModifiedRowData();
     $this->connection->query('INSERT INTO %n %v', $this->getTable(), $values);
     return isset($values[$primaryKey]) ? $values[$primaryKey] : $this->connection->getInsertId();
 }
Esempio n. 2
0
 /**
  * @param $username
  * @param $email
  * @return \App\Model\Entities\User
  * @throws DibiException
  */
 public function generateUser($username, $email = null)
 {
     $values = ['username' => $username, 'password' => \Nette\Security\Passwords::hash('abcd'), 'ip' => '127.0.0.1', 'lastLogin' => '2015-05-01 06:00:00', 'lastIP' => '127.0.0.1'];
     if ($email === null) {
         $email = $username . '@' . $username . '.abc';
     }
     $values['email'] = $email;
     $this->connection->insert('user', $values)->execute();
     $id = $this->connection->getInsertId();
     $user = new \App\Model\Entities\User($values['username'], $values['password'], $values['email'], $values['ip']);
     $this->makeEntityAlive($user, $id);
     return $user;
 }