예제 #1
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;
 }
예제 #2
0
 /**
  * Get assigned to user RBAC elements
  *
  * @access public
  *
  * @param integer $userId user ID
  *
  * @return mixed
  * @throws \Micro\Base\Exception
  */
 public function assigned($userId)
 {
     $query = new Query($this->db);
     $query->distinct = true;
     $query->select = $this->db->getDriverType() === 'pgsql' ? '"role" AS "name"' : '`role` AS `name`';
     $query->table = $this->db->getDriverType() === 'pgsql' ? '"rbac_user"' : '`rbac_user`';
     $query->addWhere(($this->db->getDriverType() === 'pgsql' ? '"user"=' : '`user`=') . $userId);
     $query->single = false;
     return $query->run(\PDO::FETCH_ASSOC);
 }