src/bbn/user/preferences.php
public function get(string $id, bool $with_config = true): ?array
  {
    if ( bbn\str::is_uid($id) ){
      $cols = implode(', ', array_map(function($a){
        return $a;
      }, $this->fields));
      $table = $this->db->tsn($this->class_cfg['table'], true);
      $uid = $this->db->csn($this->fields['id'], true);
      $id_user = $this->db->csn($this->fields['id_user'], true);
      $id_group = $this->db->csn($this->fields['id_group'], true);
      $public = $this->db->csn($this->fields['public'], true);
      $sql = <<< MYSQL
SELECT $cols
FROM $table
WHERE $uid = UNHEX(?)
AND ($id_user = UNHEX(?)
OR $id_group = UNHEX(?)
OR $public = 1)
MYSQL;
      if ( $row = $this->db->get_row($sql, $id, $this->id_user, $this->id_group) ){
        $cfg = $row['cfg'];
        unset($row['cfg']);
        if ( ($cfg = json_decode($cfg, true)) && $with_config ){
          $row = bbn\x::merge_arrays($cfg, $row);
        }
        return $row;
      }
    }
    return null;
  }
public function get(string $id, bool $with_config = true): ?array
  {
    if ( bbn\str::is_uid($id) ){
      $cols = implode(', ', array_map(function($a){
        return $a;
      }, $this->fields));
      $table = $this->db->tsn($this->class_cfg['table'], true);
      $uid = $this->db->csn($this->fields['id'], true);
      $id_user = $this->db->csn($this->fields['id_user'], true);
      $id_group = $this->db->csn($this->fields['id_group'], true);
      $public = $this->db->csn($this->fields['public'], true);
      $sql = <<< MYSQL
SELECT $cols
FROM $table
WHERE $uid = UNHEX(?)
AND ($id_user = UNHEX(?)
OR $id_group = UNHEX(?)
OR $public = 1)
MYSQL;
      if ( $row = $this->db->get_row($sql, $id, $this->id_user, $this->id_group) ){
        $cfg = $row['cfg'];
        unset($row['cfg']);
        if ( ($cfg = json_decode($cfg, true)) && $with_config ){
          $row = bbn\x::merge_arrays($cfg, $row);
        }
        return $row;
      }
    }
    return null;
  }
public function get ( string $ id , bool $ with_config = true ) : ? array { if ( bbn \ str :: is_uid ( $ id ) ) { $ cols = implode ( ', ' , array_map ( function ( $ a ) { return $ a ; } , $ this -> fields ) ) ; $ table = $ this -> db -> tsn ( $ this -> class_cfg [ 'table' ] , true ) ; $ uid = $ this -> db -> csn ( $ this -> fields [ 'id' ] , true ) ; $ id_user = $ this -> db -> csn ( $ this -> fields [ 'id_user' ] , true ) ; $ id_group = $ this -> db -> csn ( $ this -> fields [ 'id_group' ] , true ) ; $ public = $ this -> db -> csn ( $ this -> fields [ 'public' ] , true ) ; $ sql =  <<< MYSQL
SELECT $cols
FROM $table
WHERE $uid = UNHEX(?)
AND ($id_user = UNHEX(?)
OR $id_group = UNHEX(?)
OR $public = 1)
MYSQL ; if ( $ row = $ this -> db -> get_row ( $ sql , $ id , $ this -> id_user , $ this -> id_group ) ) { $ cfg = $ row [ 'cfg' ] ; unset ( $ row [ 'cfg' ] ) ; if ( ( $ cfg = json_decode ( $ cfg , true ) ) && $ with_config ) { $ row = bbn \ x :: merge_arrays ( $ cfg , $ row ) ; } return $ row ; } } return null ; }
Returns the current user's preference based on the given id, his own profile and his group's
@param string $id
@param bool $with_config
@return array|null
Returns the current user s preference based on the given id his own profile and his group s