/*
check ticket availability
@return bool
557572
private function checkTicket($ticketId)
	{
		$signature = $this->signature();
		$url = $this->_config['checkTicketUrl'].$this->signature().'&ticketId='.$ticketId;
		$result = $this->getUrl($url);
		return $result;
	}
1071017
public function getStatus($ticket)
    {
        $sender = new ExtService();
        $sender->setClient($this->wsClient);

        return $sender->getStatus($ticket);
    }
443682
public function isPassedDue()
    {
        if (empty($this->end)) {
            return false;
        }
        $dueDate = DateHelper::endOfDay($this->end);

        return DateHelper::inPast($dueDate);
    }
919187
public function is_available() {
        $target = $this->get_target();
        if (!$target) {
            return false;
        }

        $classname = $target->get_analyser_class();
        if (!class_exists($classname)) {
            return false;
        }

        return true;
    }
1346922
public function validate($ticketCode = null)
    {
        if (filter_var($ticketCode, FILTER_VALIDATE_URL)) {
            $asURL = explode('/', parse_url($ticketCode, PHP_URL_PATH));
            $ticketCode = end($asURL);
        }

        // Check if a code is given to the validator
        if (!isset($ticketCode)) {
            return $result = array(
                'Code' => self::MESSAGE_NO_CODE,
                'Message' => self::message(self::MESSAGE_NO_CODE, $ticketCode),
                'Type' => self::MESSAGE_TYPE_BAD,
                'Ticket' => $ticketCode,
                'Attendee' => null
            );
        }

        // Check if a ticket exists with the given ticket code
        if (!$this->attendee = Attendee::get()->find('TicketCode', $ticketCode)) {
            return $result = array(
                'Code' => self::MESSAGE_CODE_NOT_FOUND,
                'Message' => self::message(self::MESSAGE_CODE_NOT_FOUND, $ticketCode),
                'Type' => self::MESSAGE_TYPE_BAD,
                'Ticket' => $ticketCode,
                'Attendee' => null
            );
        } else {
            $name = $this->attendee->getName();
        }

        // Check if the reservation is not canceled
        if (!(bool)$this->attendee->Event()->getGuestList()->find('ID', $this->attendee->ID)) {
            return $result = array(
                'Code' => self::MESSAGE_TICKET_CANCELLED,
                'Message' => self::message(self::MESSAGE_TICKET_CANCELLED, $name),
                'Type' => self::MESSAGE_TYPE_BAD,
                'Ticket' => $ticketCode,
                'Attendee' => $this->attendee
            );
        }

        // Check if the ticket is already checked in and not allowed to check out
        elseif ((bool)$this->attendee->CheckedIn && !(bool)self::config()->get('allow_checkout')) {
            return $result = array(
                'Code' => self::MESSAGE_ALREADY_CHECKED_IN,
                'Message' => self::message(self::MESSAGE_ALREADY_CHECKED_IN, $name),
                'Type' => self::MESSAGE_TYPE_BAD,
                'Ticket' => $ticketCode,
                'Attendee' => $this->attendee
            );
        }

        // Successfully checked out
        elseif ((bool)$this->attendee->CheckedIn && (bool)self::config()->get('allow_checkout')) {
            return $result = array(
                'Code' => self::MESSAGE_CHECK_OUT_SUCCESS,
                'Message' => self::message(self::MESSAGE_CHECK_OUT_SUCCESS, $name),
                'Type' => self::MESSAGE_TYPE_WARNING,
                'Ticket' => $ticketCode,
                'Attendee' => $this->attendee
            );
        }

        // Successfully checked in
        else {
            return $result = array(
                'Code' => self::MESSAGE_CHECK_IN_SUCCESS,
                'Message' => self::message(self::MESSAGE_CHECK_IN_SUCCESS, $name),
                'Type' => self::MESSAGE_TYPE_GOOD,
                'Ticket' => $ticketCode,
                'Attendee' => $this->attendee
            );
        }
    }
1189773
public function isLogin()
	{
		$ticket = $this->getTicket();
		logger('用户凭证：'.var_export($ticket,true)); // debug
		if(isset($ticket['id'])){
			logger('存在用户凭证....');
			if(($ticket['expire_time']+$ticket['create_at']) > time()){
				logger('用户凭证在有效期内....');
				$leftTimes = (time()-$ticket['check_at'])/$this->_reCheckTime;
				if($leftTimes < 1){
					logger('检查时间间隔：'.$this->_reCheckTime);
					logger('不需要向服务器核验用户凭证...'."\n");
					return true;
				}else{
					logger('需要向服务器核验用户凭证...'."\n");
					$this->toServerIsLogin();
					return;
				}
			}
			logger('用户凭证bu在有效期内....'."\n");
			$this->toServerIsLogin();
			return;
		}
		logger('bu存在用户凭证....'."\n");
		$this->toServerIsLogin();
		return;
	}
1367688
public function ticket($forceRefresh = false)
    {
        $cacheKey = [__CLASS__, 'appId' => Yii::$app->wechat->appId];
        if ($forceRefresh || ($ticket = Yii::$app->wechat->cache->get($cacheKey)) === false) {
            $response = $this->post(self::API_TICKET, ['type' => 'jsapi']);
            Yii::$app->wechat->cache->set($cacheKey, $response['ticket'], $response['expires_in'] - 500);
            return $response['ticket'];
        }
        return $ticket;
    }
1288860
public function check_capabilities() {
		if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) {
			return false;
		}

		if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) {
			return false;
		}

		return true;
	}
47009
public function isSelfIssued()
    {
        if (!$this->issuer) {
            return false;
        }
        if (!$this->contact) {
            return false;
        }
        if (!$this->contact->user) {
            return false;
        }

        return $this->issuer->id == $this->contact->user->id;
    }
741277
public function check(): bool
    {
        try {
            DB::connection()->getPdo();
        } catch (PDOException $e) {
            $this->error = $e->getMessage();

            return false;
        }

        return true;
    }
297117
protected function refresh_js_api_ticket(){
        $config = $this -> config;
        if(!isset($config['app_id']) || !isset($config['app_secret']) || empty($config['app_id']) || empty($config['app_secret'])){
            if ($this->business_interface) $this->business_interface->log('refresh_js_api_ticket APP_ID or APP_SECRET must be set');
            return null;
        }
        $access_token = $this -> get_access_token();
        if (empty($access_token)){
            if ($this->business_interface) $this->business_interface->log('refresh_js_api_ticket access_token is null');
            return null;
        }
        $url = self::API_GET_TICKET."access_token={$access_token}&type=jsapi";
        $result = $this -> curl($url);
        if (isset($result['errcode']) && $result['errcode'] == 0 && isset($result['ticket'])){
            if ($this->business_interface)$this->business_interface->cache_js_api_ticket($result);
            return $result['ticket'];
        }elseif (isset($result['errmsg']) && $result['errmsg'] && $this->business_interface){
            $this->business_interface->log("refresh_js_api_ticket exception:{$result['errmsg']}");
        }
        return null;
    }
467056
public function getTicket()
    {
        if ($this->ticket) {
            return $this->ticket;
        }

        $key = 'gibson.wechat.card.api_ticket';

        // for php 5.3
        $http = $this->http;
        $apiTicket = self::API_TICKET;

        return $this->ticket = Cache::get($key, function () use ($key, $http, $apiTicket) {
            $result = $http->get($apiTicket);

            Cache::put($key, $result['ticket'], $result['expires_in']);

            return $result['ticket'];
        });
    }
84600
public function check()
    {
        $result = true;

        $configurationSettings = [
            'Database.Host',
            'Database.Username',
            'Database.Password',
            'Database.Port',
            'Database.Name',
        ];

        foreach ($configurationSettings as $setting) {
            if ($this->configuration->hasConfigurationKey($setting) === false) {
                $this->missingConfiguration[] = $setting;
                $result = false;
            }
        }

        return $result;
    }
1117131
public function is_accessible() {
        $available = $this->properties->available;
        $deadline = $this->properties->deadline;
        return (($available == 0 || time() >= $available) && ($deadline == 0 || time() < $deadline));
    }
1040034
public function getTicketSaleStartDate()
    {
        $saleStart = null;
        if (($tickets = $this->owner->Tickets())) {
            /** @var Ticket $ticket */
            foreach ($tickets as $ticket) {
                if (($date = $ticket->getAvailableFrom()) && strtotime($date) < strtotime($saleStart) || $saleStart === null) {
                    $saleStart = $date;
                }
            }
        }

        return $saleStart;
    }
93664
public function isAquired() {
        if (isset(self::$hSemaphores[$this->key]))
            return is_resource(self::$hSemaphores[$this->key]);
        return false;
    }
1125768
protected function check()
  {
    if ( $this->slugAble() ){
      if ( !$this->checkTitleUnique($this->row->get('id'), $this->row->get('title')) ){
        return false;
      }
      
      if ( !$this->checkSlugUnique($this->row->get('id'), $this->row->get('slug')) ){
        return false;
      }
    }
    
    if ( $this->orderingAble() ){
      if ( $this->shouldBeOrdered() ){
        $conditions = $this->getReorderConditions();
        $this->row->set('ordering', $this->getNextOrder($conditions));
      }
    }
    
    if ( $this->statesAble() ){
      $userId   = $this->db->getUid();
      $nullDate = $this->db->getNullDate();
      $nowDate  = Date::getInstance()->format($this->db->getDateFormat());
      
      if ( !$this->row->get($this->tbl_key) ){
        $this->row->set('created', $nowDate);
        $this->row->set('created_by', $userId); 
      }
      else {
        $this->row->set('modified', $nowDate);
        $this->row->set('modified_by', $userId); 
      }
    }
    
    if ( $this->versionAble() ){
      $version = (int)$this->row->get('version');
      $this->row->set('version', ++$version);
    }
    
    foreach($this->getFields() as $fieldName => $fieldInfos){
      $v = $this->row->get($fieldName);
      
      if ( 'YES' === $fieldInfos->Null ){
        switch($fieldInfos->Type){
          case 'bigint':
          case 'mediumint':
          case 'smallint':
          case 'tinyint':
            if ( 0 === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
          
          case 'datetime':
          case 'timestamp':
            if ( $this->db->getNullDate(true) === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
          
          case 'date':
            if ( $this->db->getNullDate(false) === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
          
          case 'time':
            if ( '00:00:00' === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
        }
      }
    }
    
    return true;
  }