Method which is called in case a user visits a route which cost a
specific amount of points. This method decreases the points from the
user account

@param integer $points
@param \Fusio\Engine\ContextInterface $context
186899
public function pay($points, ContextInterface $context)
    {
        // decrease user points
        $this->userTable->payPoints($context->getUser()->getId(), $points);

        // add usage entry
        $this->usageTable->create([
            'route_id' => $context->getRouteId(),
            'user_id' => $context->getUser()->getId(),
            'app_id' => $context->getApp()->getId(),
            'points' => $points,
            'insert_date' => new \DateTime(),
        ]);

        // dispatch payed event
        $userContext = UserContext::newContext(
            $context->getUser()->getId(),
            $context->getApp()->getId()
        );

        $this->eventDispatcher->dispatch(PlanEvents::PAY, new PayedEvent($points, $userContext));
    }
403943
public function setContext($context)
    {
        $contexts = array(self::CONTEXT_CREDITCARD, self::CONTEXT_TOKEN);
        if (!in_array($context, $contexts)) {
            throw new RuntimeException(
                sprintf("Invalid validation context '%s'", $context)
            );
        }

        $this->context = $context;
    }
383700
public function initialize(ContextInterface $context)
    {
        $context->setDatabase($this->databaseName);
        $context->setAjaxSteps($this->ajaxSteps);
        $context->setAjaxTimeout($this->ajaxTimeout);
        $context->setScreenshotPath($this->screenshotPath);
        $context->setRegionMap($this->regionMap);
        $context->setAdminUrl($this->adminUrl);
        $context->setLoginUrl($this->loginUrl);
    }
1250055
public function addContext(Context $context) {
    $contexts = $this->get('contextOut');
    $contexts[] = $context;
    $this->add('contextOut', $contexts);
  }
925649
protected function _actionXpayment($context)
    {
        $data = $context->data;
        $package = $this->getItem();
        $gateway = $this->getService('com:subscriptions.controller.subscription')->getGateway();

        try {

            $payload = $this->order->getPayload();
            $confirm = route('option=com_subscriptions&view=signup&action=confirm&xpayment=true&id='.$package->id, true);
            $cancel = route('option=com_subscriptions&view=signup&action=cancel&xpayment=true&id='.$package->id, true);
            $url = $gateway->getAuthorizationURL($payload, $confirm, $cancel);
            $context->response->setRedirect($url, AnHttpResponse::SEE_OTHER);

        } catch (Exception $error) {
            throw new RuntimeException($error->getMessage());
        }
    }
312584
public static function delete_data_for_all_users_in_context(context $context) {
        global $DB;

        switch ($context->contextlevel) {
            case CONTEXT_USER:
                // The user context is only reported when there are orphan historical grades, so we only delete those.
                static::delete_orphan_historical_grades($context->instanceid);
                break;

            case CONTEXT_COURSE:
                // We must not change the structure of the course, so we only delete user content.
                $itemids = static::get_item_ids_from_course_ids([$context->instanceid]);
                if (empty($itemids)) {
                    return;
                }

                self::delete_files($itemids, true);
                self::delete_files($itemids, false);

                list($insql, $inparams) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED);
                $DB->delete_records_select('grade_grades', "itemid $insql", $inparams);
                $DB->delete_records_select('grade_grades_history', "itemid $insql", $inparams);
                break;
        }

    }
804391
protected function _beforeAdd(KControllerContextInterface $context)
    {
        $context->request->data->ip = $this->getObject('request')->getAddress();
    }
289507
public function earn_points($points)
    {
        $this->score += $points;
        $this->say(sprintf(
            __("earns %s points"),
            $points
        ));
    }
1095938
public function setPoint(PointInterface $point)
    {
        if (isset($this->points[$point->getName()])) {
            throw new \InvalidArgumentException(
                sprintf(
                    'The point %s already exists in the profiler %s.',
                    $point->getName(),
                    $this->name
                )
            );
        }

        // Add it in the lookup table.
        $this->points[$point->getName()] = $point;

        return $this;
    }
1350715
@Deactivate
    protected void deactivate(ComponentContext context) {
        SibTr.entry(tc, CLASS_NAME + "deactivate", context);

        runtimeSecurityService.modifyMessagingServices(null);
        queuePermissions = null;
        topicPermissions = null;
        temporaryDestinationPermissions = null;
        sibAuthenticationService = null;
        sibAuthorizationService = null;
        this.bundleLocation = null;
        
        SibTr.exit(tc, CLASS_NAME + "deactivate");
    }
180413
@JsonIgnore
    public void setPoints(int[] points) {
        this.points = new ArrayList<>();
        for (int i = 0; i < points.length; i++) {
            this.points.add(points[i]);
        }
    }
654938
public void setPoints(List<GeoPoint> points) {
        mOutline.clearPath();
        mOriginalPoints = new ArrayList<>(points.size());
        for (GeoPoint p:points) {
            mOriginalPoints.add(p);
        }
        mOutline.setPoints(points);
        setDefaultInfoWindowLocation();
    }
179037
protected static function cache_add(context $context) {
        if (isset(self::$cache_contextsbyid[$context->id])) {
            // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow
            return;
        }

        if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) {
            $i = 0;
            foreach(self::$cache_contextsbyid as $ctx) {
                $i++;
                if ($i <= 100) {
                    // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later
                    continue;
                }
                if ($i > (CONTEXT_CACHE_MAX_SIZE / 3)) {
                    // we remove oldest third of the contexts to make room for more contexts
                    break;
                }
                unset(self::$cache_contextsbyid[$ctx->id]);
                unset(self::$cache_contexts[$ctx->contextlevel][$ctx->instanceid]);
                self::$cache_count--;
            }
        }

        self::$cache_contexts[$context->contextlevel][$context->instanceid] = $context;
        self::$cache_contextsbyid[$context->id] = $context;
        self::$cache_count++;
    }
1279242
public function deleteContext($context) {
        global $DB;

        $contextid = $context->getRecordId();

        $params = ['id' => $contextid];

        // Delete any outstanding share keys for resource links for this context.
        $where = "resourcelinkid IN (
                    SELECT rl.id
                      FROM {{$this->resourcelinktable}} rl
                     WHERE rl.contextid = :id
               )";
        $DB->delete_records_select($this->sharekeytable, $where, $params);

        // Delete any users in resource links for this context.
        $DB->delete_records_select($this->userresulttable, $where, $params);

        // Update any resource links for which this consumer is acting as a primary resource link.
        $where = "primaryresourcelinkid IN (
                    SELECT rl.id
                      FROM {{$this->resourcelinktable}} rl
                     WHERE rl.contextid = :id
               )";
        $updaterecords = $DB->get_records_select($this->resourcelinktable, $where, $params);
        foreach ($updaterecords as $record) {
            $record->primaryresourcelinkid = null;
            $record->shareapproved = null;
            $DB->update_record($this->resourcelinktable, $record);
        }

        // Delete any resource links for this context.
        $DB->delete_records($this->resourcelinktable, ['contextid' => $contextid]);

        // Delete context.
        $DB->delete_records($this->contexttable, $params);

        $context->initialize();

        return true;
    }
3724
@Deactivate
    protected void deactivate(ComponentContext context) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "Deactivating");
        }
        instance.get().compareAndSet(this, null);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "Destroying all endpoints");
        }
        EndPointMgrImpl.destroyEndpoints();

        try {
            this.chfw.destroy();
        } catch (Throwable t) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(this, tc, "Error destroying framework: " + t);
            }
        }

        this.chfw.deregisterFactory("TCPChannel");
        this.chfw.deregisterFactory("UDPChannel");
    }
662223
public function setContext(array $context)
    {
        $this->clearContext();
        foreach ($context as $key => $value) {
            $this->setContextValue($key, $value);
        }
    }
26180
public static function delete_data_for_all_users_in_context(\context $context) {
        global $DB;

        if (!$context instanceof \context_module) {
            return;
        }

        if ($cm = get_coursemodule_from_id('choice', $context->instanceid)) {
            $DB->delete_records('choice_answers', ['choiceid' => $cm->instance]);
        }
    }