protected function verifyToken(\core_kernel_classes_Resource $delivery, User $user)
    {
        $propMaxExec = $delivery->getOnePropertyValue($this->getProperty(DeliveryContainerService::PROPERTY_MAX_EXEC));
        $maxExec = is_null($propMaxExec) ? 0 : $propMaxExec->literal;

        $currentSession = $this->getServiceLocator()->get(SessionService::SERVICE_ID)->getCurrentSession();

        if ($currentSession instanceof TaoLtiSession) {
            $launchData = $currentSession->getLaunchData();
            if ($launchData->hasVariable(self::LTI_MAX_ATTEMPTS_VARIABLE)) {
                $val = $launchData->getVariable(self::LTI_MAX_ATTEMPTS_VARIABLE);
                if (!is_numeric($val)) {
                    throw new LtiException(
                        __('"max_attempts" variable must me numeric.'),
                        LtiErrorMessage::ERROR_INVALID_PARAMETER
                    );
                }
                $maxExec = (integer) $val;
            }
        }

        //check Tokens
        $usedTokens = count($this->getServiceLocator()->get(AttemptServiceInterface::SERVICE_ID)
            ->getAttempts($delivery->getUri(), $user));

        if (($maxExec != 0) && ($usedTokens >= $maxExec)) {
            $this->logDebug("Attempt to start the compiled delivery ".$delivery->getUri(). " without tokens");
            throw new LtiException(
                __('Attempts limit has been reached.'),
                LtiErrorMessage::ERROR_LAUNCH_FORBIDDEN
            );
        }
        return true;
    }
protected function verifyToken(\core_kernel_classes_Resource $delivery, User $user)
    {
        $propMaxExec = $delivery->getOnePropertyValue($this->getProperty(DeliveryContainerService::PROPERTY_MAX_EXEC));
        $maxExec = is_null($propMaxExec) ? 0 : $propMaxExec->literal;

        $currentSession = $this->getServiceLocator()->get(SessionService::SERVICE_ID)->getCurrentSession();

        if ($currentSession instanceof TaoLtiSession) {
            $launchData = $currentSession->getLaunchData();
            if ($launchData->hasVariable(self::LTI_MAX_ATTEMPTS_VARIABLE)) {
                $val = $launchData->getVariable(self::LTI_MAX_ATTEMPTS_VARIABLE);
                if (!is_numeric($val)) {
                    throw new LtiException(
                        __('"max_attempts" variable must me numeric.'),
                        LtiErrorMessage::ERROR_INVALID_PARAMETER
                    );
                }
                $maxExec = (integer) $val;
            }
        }

        //check Tokens
        $usedTokens = count($this->getServiceLocator()->get(AttemptServiceInterface::SERVICE_ID)
            ->getAttempts($delivery->getUri(), $user));

        if (($maxExec != 0) && ($usedTokens >= $maxExec)) {
            $this->logDebug("Attempt to start the compiled delivery ".$delivery->getUri(). " without tokens");
            throw new LtiException(
                __('Attempts limit has been reached.'),
                LtiErrorMessage::ERROR_LAUNCH_FORBIDDEN
            );
        }
        return true;
    }
protected function verifyToken ( \ core_kernel_classes_Resource $ delivery , User $ user ) { $ propMaxExec = $ delivery -> getOnePropertyValue ( $ this -> getProperty ( DeliveryContainerService :: PROPERTY_MAX_EXEC ) ) ; $ maxExec = is_null ( $ propMaxExec ) ? 0 : $ propMaxExec -> literal ; $ currentSession = $ this -> getServiceLocator ( ) -> get ( SessionService :: SERVICE_ID ) -> getCurrentSession ( ) ; if ( $ currentSession instanceof TaoLtiSession ) { $ launchData = $ currentSession -> getLaunchData ( ) ; if ( $ launchData -> hasVariable ( self :: LTI_MAX_ATTEMPTS_VARIABLE ) ) { $ val = $ launchData -> getVariable ( self :: LTI_MAX_ATTEMPTS_VARIABLE ) ; if ( ! is_numeric ( $ val ) ) { throw new LtiException ( __ ( '"max_attempts" variable must me numeric.' ) , LtiErrorMessage :: ERROR_INVALID_PARAMETER ) ; } $ maxExec = ( integer ) $ val ; } } //check Tokens $ usedTokens = count ( $ this -> getServiceLocator ( ) -> get ( AttemptServiceInterface :: SERVICE_ID ) -> getAttempts ( $ delivery -> getUri ( ) , $ user ) ) ; if ( ( $ maxExec != 0 ) && ( $ usedTokens >= $ maxExec ) ) { $ this -> logDebug ( "Attempt to start the compiled delivery " . $ delivery -> getUri ( ) . " without tokens" ) ; throw new LtiException ( __ ( 'Attempts limit has been reached.' ) , LtiErrorMessage :: ERROR_LAUNCH_FORBIDDEN ) ; } return true ; }
Check Max. number of executions

@param \core_kernel_classes_Resource $delivery
@param User $user
@return bool
@throws LtiException
@throws \common_exception_Error
@throws \core_kernel_persistence_Exception
@throws \oat\taoLti\models\classes\LtiVariableMissingException
Check Max . number of executions