Frontend\Modules\Profiles\Engine\Model::existsDisplayName PHP 메소드

existsDisplayName() 공개 정적인 메소드

Check if a display name exists.
public static existsDisplayName ( string $displayName, integer $id = null ) : boolean
$displayName string Display name to check for existence.
$id integer Profile id to ignore.
리턴 boolean
    public static function existsDisplayName($displayName, $id = null)
    {
        return (bool) FrontendModel::getContainer()->get('database')->getVar('SELECT 1
             FROM profiles AS p
             WHERE p.id != ? AND p.display_name = ?
             LIMIT 1', array((int) $id, (string) $displayName));
    }

Usage Example

예제 #1
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtDisplayName = $this->frm->getField('display_name');
         $txtFirstName = $this->frm->getField('first_name');
         $txtLastName = $this->frm->getField('last_name');
         $txtCity = $this->frm->getField('city');
         $ddmCountry = $this->frm->getField('country');
         $ddmGender = $this->frm->getField('gender');
         $ddmDay = $this->frm->getField('day');
         $ddmMonth = $this->frm->getField('month');
         $ddmYear = $this->frm->getField('year');
         // get number of display name changes
         $nameChanges = (int) FrontendProfilesModel::getSetting($this->profile->getId(), 'display_name_changes');
         // has there been a valid display name change request?
         if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
             // display name filled in?
             if ($txtDisplayName->isFilled(FL::getError('FieldIsRequired'))) {
                 // display name exists?
                 if (FrontendProfilesModel::existsDisplayName($txtDisplayName->getValue(), $this->profile->getId())) {
                     // set error
                     $txtDisplayName->addError(FL::getError('DisplayNameExists'));
                 }
             }
         }
         // birthdate is not required but if one is filled we need all
         if ($ddmMonth->isFilled() || $ddmDay->isFilled() || $ddmYear->isFilled()) {
             // valid birth date?
             if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) {
                 // set error
                 $ddmYear->addError(FL::getError('DateIsInvalid'));
             }
         }
         // validate avatar when given
         $this->frm->getField('avatar')->isFilled();
         // no errors
         if ($this->frm->isCorrect()) {
             // init
             $values = array();
             $settings = array();
             // has there been a valid display name change request?
             if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
                 // get display name value
                 $values['display_name'] = $txtDisplayName->getValue();
                 // update url based on the new display name
                 $values['url'] = FrontendProfilesModel::getUrl($txtDisplayName->getValue(), $this->profile->getId());
                 // update display name count
                 $settings['display_name_changes'] = $nameChanges + 1;
             }
             // update values
             if (!empty($values)) {
                 FrontendProfilesModel::update($this->profile->getId(), $values);
             }
             // build settings
             $settings['first_name'] = $txtFirstName->getValue();
             $settings['last_name'] = $txtLastName->getValue();
             $settings['city'] = $txtCity->getValue();
             $settings['country'] = $ddmCountry->getValue();
             $settings['gender'] = $ddmGender->getValue();
             // birthday is filled in
             if ($ddmYear->isFilled()) {
                 // mysql format
                 $settings['birth_date'] = $ddmYear->getValue() . '-';
                 $settings['birth_date'] .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-';
                 $settings['birth_date'] .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT);
             } else {
                 // not filled in
                 $settings['birth_date'] = null;
             }
             // avatar
             $settings['avatar'] = $this->profile->getSetting('avatar');
             // create new filename
             if ($this->frm->getField('avatar')->isFilled()) {
                 // field value
                 $settings['avatar'] = \SpoonFilter::urlise($this->profile->getDisplayName()) . '.' . $this->frm->getField('avatar')->getExtension();
                 // move the file
                 $this->frm->getField('avatar')->generateThumbnails(FRONTEND_FILES_PATH . '/Profiles/Avatars/', $settings['avatar']);
             }
             // save settings
             $this->profile->setSettings($settings);
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_saved_settings', array('id' => $this->profile->getId()));
             // redirect
             $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Settings') . '?sent=true');
         } else {
             $this->tpl->assign('updateSettingsHasFormError', true);
         }
     }
 }