Airship\Cabin\Bridge\Blueprint\UserAccounts::getUserPreferences PHP Method

getUserPreferences() public method

Get a user's preferences
public getUserPreferences ( integer $userId ) : array
$userId integer
return array
    public function getUserPreferences(int $userId) : array
    {
        $prefs = $this->db->cell('SELECT preferences FROM airship_user_preferences WHERE userid = ?', $userId);
        if (empty($prefs)) {
            return [];
        }
        return \json_decode($prefs, true);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Allows users to select which Motif to use
  *
  * @route my/preferences
  */
 public function preferences()
 {
     if (!$this->isLoggedIn()) {
         \Airship\redirect($this->airship_cabin_prefix);
     }
     $prefs = $this->acct->getUserPreferences($this->getActiveUserId());
     $cabins = [];
     $motifs = [];
     foreach ($this->getCabinNamespaces() as $cabin) {
         $cabins[] = $cabin;
         $filename = ROOT . '/tmp/cache/' . $cabin . '.motifs.json';
         if (\file_exists($filename)) {
             $motifs[$cabin] = \Airship\loadJSON($filename);
         } else {
             $motifs[$cabin] = [];
         }
     }
     $post = $this->post(PreferencesFilter::fromConfig($cabins, $motifs));
     if (!empty($post)) {
         if ($this->savePreferences($post['prefs'], $cabins, $motifs)) {
             \Airship\redirect($this->airship_cabin_prefix . '/my/preferences');
         }
     }
     $this->lens('preferences', ['prefs' => $prefs, 'motifs' => $motifs]);
 }