Exemplo n.º 1
0
 /**
  * Check email rule
  */
 public function checkEmail() {
     if ($this->email != '') {
         $pattern = '/^([0-9a-zA-Z]([\-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][\-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/';
         if(!preg_match($pattern, $this->email)) {
             $this->addError('email','Email is not valid');
         } else {
             $person = Persons::model()->find('Email=:email',
                 array(':email'=>$this->email));
             if (!$person) {
                 $this->addError('email','Email does not exists');
             }
         }
     }
 }
Exemplo n.º 2
0
 public function checkWcaId()
 {
     $user = Yii::app()->controller->user;
     if ($user->wcaid === '' && $this->wcaid !== '') {
         $person = Persons::model()->findByAttributes(array('id' => $this->wcaid, 'subid' => 1));
         if ($person !== null) {
             $name = $user->name;
             if ($user->name_zh !== '') {
                 $name .= ' (' . $user->name_zh . ')';
             }
             if ($name !== $person->name && $user->name !== $person->name) {
                 $this->addError('wcaid', Yii::t('common', 'Wrong WCA ID'));
             }
         } else {
             $this->addError('wcaid', Yii::t('common', 'Wrong WCA ID'));
         }
     }
 }
Exemplo n.º 3
0
 public function checkWcaId()
 {
     $this->wcaid = strtoupper($this->wcaid);
     if ($this->wcaid !== '') {
         switch ($this->step) {
             case 1:
                 $person = Persons::model()->findByAttributes(array('id' => $this->wcaid));
                 if ($person === null) {
                     $this->addError('wcaid', Yii::t('common', 'Wrong WCA ID'));
                     return false;
                 }
                 Yii::app()->session->add(self::REGISTER_WCAID, $this->wcaid);
             case 2:
                 $user = User::model()->findByAttributes(array('wcaid' => $this->wcaid, 'status' => User::STATUS_NORMAL));
                 if ($user !== null) {
                     $this->addError('wcaid', Yii::t('common', 'The WCA ID {wcaid} has been registered.', array('{wcaid}' => $this->wcaid)));
                     return false;
                 }
                 break;
         }
     }
 }
Exemplo n.º 4
0
    /**
     * Get filtered users list by lastname to users_type_mgmt tab
     */
    public function actionGetFilteredUsersToTypeList()
    {
        if (Yii::app()->request->isAjaxRequest && isset($_POST['lastname'])) {
            $lastname = strtolower(trim($_POST['lastname']));

            if ($lastname != '') {
                $criteria=new CDbCriteria;
                if ($lastname != '*') {
                    $criteria->compare('Last_Name', $lastname, true);
                }
                $criteria->order = 'Last_Name ASC';
                $all_users = Persons::model()->with('user')->findAll($criteria);
                $find = true;
            } else {
                $all_users = array();
                $find = false;
            }
            $this->renderPartial('filtered_users_to_type_list' , array(
                'all_users' => $all_users,
                'find' => $find,
            ));
        }
    }
Exemplo n.º 5
0
 public function actionBattle()
 {
     $ids = array_unique(array_map('strtoupper', $this->aGet('ids')));
     $ids = array_slice($ids, 0, 4);
     $persons = array();
     $names = array();
     foreach ($ids as $id) {
         $person = Persons::model()->findByAttributes(array('id' => $id));
         if ($person !== null) {
             $persons[] = array('person' => $person, 'results' => Yii::app()->cache->getData(array('Persons', 'getResults'), $id));
             $names[] = $person->name;
         }
     }
     if (count($persons) === 1 && !Yii::app()->user->isGuest && $this->user->wcaid != '' && $persons[0]['person']->id !== $this->user->wcaid) {
         $person = Persons::model()->findByAttributes(array('id' => $this->user->wcaid));
         if ($person !== null) {
             $persons[] = array('person' => $person, 'results' => Yii::app()->cache->getData(array('Persons', 'getResults'), $this->user->wcaid));
             $names[] = $person->name;
         }
     }
     switch (count($persons)) {
         case 0:
             $this->redirect(array('/results/person'));
             break;
         case 1:
             $this->redirect(array('/results/p', 'id' => $persons[0]['person']->id));
             break;
     }
     $persons = array_slice($persons, 0, 4);
     $data = $this->handlePKPersons($persons);
     $this->breadcrumbs = array('Results' => array('/results/index'), 'Persons' => array('/results/person'), 'Battle');
     $names[] = 'Battle';
     $this->pageTitle = $names;
     $this->title = Yii::t('common', 'Battle');
     $this->render('battle', $data);
 }