hasResult() public method

Checks if the result is valid
public hasResult ( ) : boolean
return boolean True if the result is valid else false
コード例 #1
0
ファイル: InstallShell.php プロジェクト: alescx/forum
 /**
  * Gather all the data for creating a new user.
  *
  * @param string $mode
  * @return string
  */
 protected function _newUser($mode)
 {
     $userMap = Configure::read('Forum.userMap');
     switch ($mode) {
         case 'username':
             $username = trim($this->in('<question>Username:</question>'));
             if (!$username) {
                 $username = $this->_newUser($mode);
             } else {
                 $result = $this->db->fetchRow(sprintf("SELECT COUNT(*) AS `count` FROM `%s` AS `User` WHERE `%s` = %s", $this->install['table'], $userMap['username'], $this->db->value($username)));
                 if ($this->db->hasResult() && $result[0]['count']) {
                     $this->out('<error>Username already exists, please try again</error>');
                     $username = $this->_newUser($mode);
                 }
             }
             return $username;
             break;
         case 'password':
             $password = trim($this->in('<question>Password:</question>'));
             if (!$password) {
                 $password = $this->_newUser($mode);
             }
             return $password;
             break;
         case 'email':
             $email = trim($this->in('<question>Email:</question>'));
             if (!$email) {
                 $email = $this->_newUser($mode);
             } else {
                 if (!Validation::email($email)) {
                     $this->out('<error>Invalid email address, please try again</error>');
                     $email = $this->_newUser($mode);
                 } else {
                     $result = $this->db->fetchRow(sprintf("SELECT COUNT(*) AS `count` FROM `%s` AS `User` WHERE `%s` = %s", $this->install['table'], $userMap['email'], $this->db->value($email)));
                     if ($this->db->hasResult() && $result[0]['count']) {
                         $this->out('<error>Email already exists, please try again</error>');
                         $email = $this->_newUser($mode);
                     }
                 }
             }
             return $email;
             break;
     }
     return null;
 }