Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public function flush()
 {
     if ($this->db->tableExists($this->table)) {
         $query = "DELETE FROM :::table";
         $bindings = array(':::table' => $this->table);
         $this->db->execute($query, $bindings);
     }
 }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
 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;
     }
 }
Exemplo n.º 5
0
 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;
     }
 }