Exemplo n.º 1
0
 public function deleteRole($id, $role)
 {
     if (!$this->db->tableExists($this->table)) {
         return false;
     }
     $query = "DELETE FROM :::table WHERE id=:id AND role=:role";
     $bindings = array(':::table' => $this->table, ':id' => $id, ':role' => $role);
     $this->db->getResult($query, $bindings);
     if ($this->db->affectedRows() > 0) {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 public function deleteToken($gid, $token)
 {
     if (!$this->db->tableExists($this->table)) {
         return false;
     }
     $query = "SELECT id, token FROM :::table WHERE gid=:gid";
     $bindings = array(':::table' => $this->table, ':gid' => $gid);
     $result = $this->db->getResult($query, $bindings);
     $toDelete = array();
     while ($row = $result->getNext()) {
         if ($this->hashFunction->checkPasswordHash($token, $row['token'], $this->hmacKey)) {
             $toDelete[] = $row['id'];
         }
     }
     $n = count($toDelete);
     if ($n > 0) {
         $query = "DELETE FROM :::table WHERE ";
         $bindings = array(':::table' => $this->table);
         for ($i = 0; $i < $n; $i++) {
             $query .= "id=:id{$i}";
             if ($i < $n - 1) {
                 $query .= ' OR ';
             }
             $bindings[':id' . $i] = $toDelete[$i];
         }
         $this->db->execute($query, $bindings);
         assert($this->db->affectedRows() === $n);
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 public function fetchResult()
 {
     $tableName = $this->table;
     if ($this->db->tableExists($tableName)) {
         $query = "SELECT idx AS 'key', data FROM :::table";
         $bindings = array(':::table' => $tableName);
         return $this->db->getResult($query, $bindings);
     }
     return new ArrayResult(array());
 }
Exemplo n.º 4
0
 public function loadTable()
 {
     $res = array();
     if ($this->db->tableExists($this->table)) {
         $query = 'SELECT role, page, task FROM :::table ORDER BY role, page, task';
         $bindings = array(':::table' => $this->table);
         $result = $this->db->getResult($query, $bindings);
         $res = array();
         while ($row = $result->getNext()) {
             $res[$row['role']][$row['page']][] = $row['task'];
         }
         foreach ($res as $role => $pages) {
             foreach ($pages as $page => $tasks) {
                 if (count($tasks) === 1 && $tasks[0] === '*') {
                     $res[$role][$page] = '*';
                 }
             }
         }
     }
     return new RulesTable($res);
 }