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
            );
        }
    }
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
            );
        }
    }
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 ) ; } }
Validate the given ticket code

@param null|string $ticketCode

@return array
Validate the given ticket code