public function storeTable(RulesTable $table) { $table = $table->getTable(); if (!empty($table)) { if (!$this->db->tableExists($this->table)) { $this->createTable(); } $query = 'INSERT INTO :::table (role, page, task) VALUES'; $bindings = array(':::table' => $this->table); $i = 0; foreach ($table as $role => $pages) { foreach ($pages as $page => $tasks) { if (is_string($tasks)) { assert($tasks === '*'); $query .= " (:role{$i}, :page{$i}, :task{$i}),"; $bindings['role' . $i] = $role; $bindings['page' . $i] = $page; $bindings['task' . $i] = $tasks; $i++; } else { assert(is_array($tasks)); foreach ($tasks as $task) { $query .= " (:role{$i}, :page{$i}, :task{$i}),"; $bindings['role' . $i] = $role; $bindings['page' . $i] = $page; $bindings['task' . $i] = $task; $i++; } } } } $query = rtrim($query, ','); $this->db->execute($query, $bindings); } }
/** * Tests creating the table. * * @covers empire\framework\mvc\model\DbStorageModel::create */ public function testCreate() { $this->instance->create(); $this->assertTrue(self::$db->tableExists('mod_mock_testdbstorage')); $tables = self::$db->getFieldNames('mod_mock_testdbstorage'); $this->assertContains('name', $tables); $this->assertContains('length', $tables); }
private function getEntireSize() { if ($this->db->tableExists($this->tableName)) { $query = 'SELECT count(id) AS numberOfEntries FROM :::table'; $bindings = array(':::table' => $this->tableName); $res = $this->db->fetch($query, $bindings); return (int) $res[0]['numberOfEntries']; } return 0; }
public function size() { $tableName = $this->table; if ($this->db->tableExists($tableName)) { $query = "SELECT count(idx) as numberOfEntries FROM :::table"; $res = $this->db->fetch($query, array(':::table' => $tableName)); return (int) $res[0]['numberOfEntries']; } return 0; }
/** * Tests removing the storage. * * @covers empire\framework\authorization\rolebased\DbRoleStorage::remove */ public function testRemove() { $this->instance->addRole('peterchen', 'editor'); $this->instance->addRole('fritzchen', 'editor'); $this->instance->addRole('fritzchen', 'admin'); $this->instance->addRole('fritzchen', 'reader'); $this->instance->addRole('hänschen', 'reader'); $this->instance->remove(); $this->assertEmpty($this->instance->getRoles('fritzchen')); $this->assertEmpty($this->instance->getRoles('peterchen')); $this->assertEmpty($this->instance->getRoles('hänschen')); $this->assertFalse($this->db->tableExists(self::TABLE)); }
/** * Fetches a user by a unique property (ID, e-mail address, username). * * @param string $property the name of the property * @param mixed $value the value * @return User null user object or <code>null</code> */ private function fetchByProperty($property, $value) { if (!$this->db->tableExists($this->table)) { return null; } $query = "SELECT * FROM :::table WHERE ::field=:value"; $bindings = array(':::table' => $this->table, '::field' => $property, ':value' => $value); $result = $this->db->fetch($query, $bindings); if (count($result) !== 1) { return null; } $user = new User($result[0]['id']); $user->setUsername($result[0]['username']); $user->setFullName($result[0]['fullName']); $user->setEmail($result[0]['email']); $user->setBirthdate($result[0]['birthdate']); $user->setGender($result[0]['gender']); $user->setTimezoneOffset($result[0]['timezoneOffset']); $user->setLocale($result[0]['locale']); $user->setLastLogin($result[0]['lastLogin']); $user->setSecret($result[0]['secret']); return $user; }
public function remove() { if ($this->db->tableExists($this->table)) { $this->db->dropTable($this->table); } }