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); } }
public function flush() { if ($this->db->tableExists($this->table)) { $query = "DELETE FROM :::table"; $bindings = array(':::table' => $this->table); $this->db->execute($query, $bindings); } }
public function remove() { if ($this->db->tableExists($this->tableName)) { $query = 'DELETE FROM :::table WHERE parent=:parent'; $bindings = array(':::table' => $this->tableName, ':parent' => $this->parent); $this->db->execute($query, $bindings); if ($this->getEntireSize() === 0) { $this->db->dropTable($this->tableName); } } }
public function delete($id) { if (!$this->db->tableExists($this->table)) { return false; } $query = "DELETE from :::table WHERE id=:id"; $bindings = array(':::table' => $this->table, ':id' => $id); $this->db->execute($query, $bindings); if ($this->db->affectedRows() > 0) { return true; } }
public function deleteAll($gid) { if ($this->db->tableExists($this->table)) { $query = "DELETE FROM :::table WHERE gid=:gid"; $bindings = array(':::table' => $this->table, ':gid' => $gid); $this->db->execute($query, $bindings); if ($this->db->affectedRows() > 0) { return true; } return false; } }