예제 #1
0
 public function testChainSQLAndOr()
 {
     $sql1 = new Pluf_SQL('title=%s', 'my title');
     $sql2 = Pluf::factory('Pluf_SQL');
     $sql1->Q('description=%s', '%par example')->Q('keywords=%s', "tag'gi`ng");
     $sql3 = Pluf::factory('Pluf_SQL');
     $sql3->Q('status=%s', '1');
     $sql1->SOr($sql3);
     if ($this->db->engine == 'SQLite') {
         $res = "(title='my title' AND description='%par example' AND keywords='tag''gi`ng')";
         $res .= " OR (status='1')";
     } else {
         $res = "(title='my title' AND description='%par example' AND keywords='tag\\''gi`ng')";
         $res .= " OR (status='1')";
     }
     $this->assertEquals($res, $sql1->gen());
 }
예제 #2
0
파일: User.php 프로젝트: burbuja/pluf
 /**
  * Get all the permissions of a user.
  *
  * @param bool Force the reload of the list of permissions (false)
  * @return array List of permissions
  */
 function getAllPermissions($force = false)
 {
     if ($force == false and !is_null($this->_cache_perms)) {
         return $this->_cache_perms;
     }
     $this->_cache_perms = array();
     $perms = (array) $this->get_permissions_list();
     $groups = $this->get_groups_list();
     $ids = array();
     foreach ($groups as $group) {
         $ids[] = $group->id;
     }
     if (count($ids) > 0) {
         $gperm = new Pluf_Permission();
         $f_name = strtolower(Pluf::f('pluf_custom_group', 'Pluf_Group')) . '_id';
         $perms = array_merge($perms, (array) $gperm->getList(array('filter' => $f_name . ' IN (' . join(', ', $ids) . ')', 'view' => 'join_group')));
     }
     foreach ($perms as $perm) {
         if (!in_array($perm->application . '.' . $perm->code_name, $this->_cache_perms)) {
             $this->_cache_perms[] = $perm->application . '.' . $perm->code_name;
         }
     }
     if (Pluf::f('pluf_use_rowpermission', false) and $this->id) {
         $growp = new Pluf_RowPermission();
         $sql = new Pluf_SQL('owner_id=%s AND owner_class=%s', array($this->id, 'Pluf_User'));
         if (count($ids) > 0) {
             $sql2 = new Pluf_SQL('owner_id IN (' . join(', ', $ids) . ') AND owner_class=%s', array(Pluf::f('pluf_custom_group', 'Pluf_Group')));
             $sql->SOr($sql2);
         }
         $perms = $growp->getList(array('filter' => $sql->gen(), 'view' => 'join_permission'));
         foreach ($perms as $perm) {
             $perm_string = $perm->application . '.' . $perm->code_name . '#' . $perm->model_class . '(' . $perm->model_id . ')';
             if ($perm->negative) {
                 $perm_string = '!' . $perm_string;
             }
             if (!in_array($perm_string, $this->_cache_perms)) {
                 $this->_cache_perms[] = $perm_string;
             }
         }
     }
     return $this->_cache_perms;
 }
예제 #3
0
파일: Paginator.php 프로젝트: burbuja/pluf
 /**
  * Generate the where clause.
  *
  * @return string The ready to use where clause.
  */
 function filter()
 {
     if (strlen($this->where_clause) > 0) {
         return $this->where_clause;
     }
     if (!is_null($this->forced_where) or strlen($this->search_string) > 0 && !empty($this->search_fields)) {
         $lastsql = new Pluf_SQL();
         $keywords = $lastsql->keywords($this->search_string);
         foreach ($keywords as $key) {
             $sql = new Pluf_SQL();
             foreach ($this->search_fields as $field) {
                 $sqlor = new Pluf_SQL();
                 $sqlor->Q($field . ' LIKE %s', '%' . $key . '%');
                 $sql->SOr($sqlor);
             }
             $lastsql->SAnd($sql);
         }
         if (!is_null($this->forced_where)) {
             $lastsql->SAnd($this->forced_where);
         }
         $this->where_clause = $lastsql->gen();
         if (strlen($this->where_clause) == 0) {
             $this->where_clause = null;
         }
     }
     return $this->where_clause;
 }