예제 #1
0
 /**
  * Base constructor for ACL, make acl_user table if exists
  *
  * @access public
  *
  * @param Adapter $db
  * @param array $params config array
  *
  * @result void
  */
 public function __construct(Adapter $db, array $params = [])
 {
     $this->db = $db->getDriver();
     if (!empty($params['groupTable'])) {
         $this->groupTable = $params['groupTable'];
     }
     if (!$this->db->tableExists('acl_user')) {
         $this->db->createTable('acl_user', ['`id` int(10) unsigned NOT NULL AUTO_INCREMENT', '`user` int(11) unsigned NOT NULL', '`role` int(11) unsigned DEFAULT NULL', '`perm` int(11) unsigned DEFAULT NULL', 'PRIMARY KEY (`id`)'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     }
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function getQuery()
 {
     $query = 'SELECT ';
     $query .= $this->distinct ? 'DISTINCT ' : '';
     $query .= $this->select . ' FROM ' . $this->table;
     $query .= $this->join ? ' ' . $this->join : '';
     $query .= $this->where ? ' WHERE ' . $this->where : '';
     $query .= $this->group ? ' GROUP BY ' . $this->group : '';
     $query .= $this->having ? ' HAVING ' . $this->having : '';
     $query .= $this->order ? ' ORDER BY ' . $this->order : '';
     if ($this->db->getDriverType() === 'pgsql') {
         if ($this->limit !== -1) {
             $query .= ' LIMIT ' . $this->limit . ' ';
         }
         if ($this->offset !== -1) {
             $query .= ' OFFSET ' . $this->offset . ' ';
         }
     } else {
         if ($this->limit !== -1) {
             $query .= ' LIMIT ';
             if ($this->offset !== -1) {
                 $query .= $this->offset . ',';
             }
             $query .= $this->limit;
         }
     }
     return $query;
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 public function decrement($name, $offset = 1)
 {
     return $this->driver->update($this->table, ['value' => 'value-' . $offset], 'name="' . $name . '"');
 }
예제 #4
0
 /**
  * Revoke RBAC element from user
  *
  * @access public
  *
  * @param integer $userId user id
  * @param string $name element name
  *
  * @return bool
  */
 public function revoke($userId, $name)
 {
     return $this->db->delete('rbac_user', 'name=:name AND user=:user', ['name' => $name, 'user' => $userId]);
 }