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

updatePreferences() public method

Store preferences for a user
public updatePreferences ( integer $userId, array $preferences = [] ) : boolean
$userId integer
$preferences array
return boolean
    public function updatePreferences(int $userId, array $preferences = []) : bool
    {
        $this->db->beginTransaction();
        $queryString = 'SELECT
            count(preferenceid)
        FROM
            airship_user_preferences
        WHERE
            userid = ?';
        if ($this->db->exists($queryString, $userId)) {
            $this->db->update('airship_user_preferences', ['preferences' => \json_encode($preferences)], ['userid' => $userId]);
        } else {
            $this->db->insert('airship_user_preferences', ['userid' => $userId, 'preferences' => \json_encode($preferences)]);
        }
        return $this->db->commit();
    }

Usage Example

コード例 #1
0
ファイル: Account.php プロジェクト: paragonie/airship
 /**
  * Save a user's preferences
  *
  * @param array $prefs
  * @param array $cabins
  * @param array $motifs
  * @return bool
  */
 protected function savePreferences(array $prefs = [], array $cabins = [], array $motifs = []) : bool
 {
     // Validate the motifs
     foreach ($prefs['motif'] as $cabin => $selectedMotif) {
         if (!\in_array($cabin, $cabins)) {
             unset($prefs['motif'][$cabin]);
             continue;
         }
         if (empty($selectedMotif)) {
             $prefs['motif'][$cabin] = null;
             continue;
         }
         list($supplier, $motifName) = \explode('/', $selectedMotif);
         if (!$this->findMotif($motifs[$cabin], $supplier, $motifName)) {
             $prefs['motif'][$cabin] = null;
             continue;
         }
     }
     if ($this->acct->updatePreferences($this->getActiveUserId(), $prefs)) {
         $this->storeLensVar('post_response', ['message' => \__('Preferences saved successfully.'), 'status' => 'success']);
         return true;
     }
     return false;
 }