Generate content for course column.

@param \tool_monitor\subscription $sub subscription object
@return string html used to display the course name.
166150
public function col_course(\tool_monitor\subscription $sub) {
        $coursename = $sub->get_course_name($this->context);

        $courseid = $sub->courseid;
        if (empty($courseid)) {
            return $coursename;
        } else {
            return \html_writer::link(new \moodle_url('/course/view.php', array('id' => $courseid)), $coursename);
        }
    }
416666
public function subscribe($destination, $subscriptionId = null, $ack = 'auto', $selector = null, array $header = [])
    {
        return $this->client->sendFrame(
            $this->getProtocol()->getSubscribeFrame($destination, $subscriptionId, $ack, $selector)->addHeaders($header)
        );
    }
600658
def newsletter(campaign, subscription)
      subscriber = subscription.subscriber

      return if subscriber.blank?

      content_type  = "text/html"

      attrs = subscriber.attributes

      @campaign = campaign

      @subscriber = subscriber

      @body = campaign.compiled_template_for(subscriber).html_safe

      mail( from: "#{campaign.from_name}<#{campaign.from_email}>",
            to: subscriber.email,
            subject: campaign.subject,
            content_type: content_type,
            return_path: campaign.reply_email )
    end
1342085
public function createMultiple(array $subscribers)
    {
        $defaults = ['language' => 'sv', 'update_on_duplicate' => true, 'tags' => [], 'automation' => false];

        $subscribers = array_merge($defaults, $subscribers);

        foreach ($subscribers['subscribers'] as $subscriber) {
            $this->assertValidSubscriberParams($subscriber);
        }

        $params = [
            'automation' =>  $subscribers['automation'],
            'update_on_duplicate' => $subscribers['update_on_duplicate'],
            'tags' => $subscribers['tags']
        ];

        $params['subscribers'] = array_map(function($subscriber){
            return $this->getSubscriberParams($subscriber);
        }, $subscribers['subscribers']);

        $request = new Request('subscribers');
        $request->setParams($params);

        $response = $this->client->post($request);

        $this->assertSuccessResponse($response);

        return $response->getData();
    }
534094
private function _createSubscription(array $response)
    {
        $model = new Subscription();
        $model->setId($response['id']);
        $model->setOffer($this->_convertResponseToModel($response['offer'], 'offer'));
        $model->setLivemode($response['livemode']);
        $model->setTrialStart($response['trial_start']);
        $model->setTrialEnd($response['trial_end']);
        $model->setPeriodOfValidity($response['period_of_validity']);
        $model->setEndOfPeriod($response['end_of_period']);
        $model->setNextCaptureAt($response['next_capture_at']);
        $model->setCreatedAt($response['created_at']);
        $model->setUpdatedAt($response['updated_at']);
        $model->setCanceledAt($response['canceled_at']);
        $model->setPayment($this->_convertResponseToModel($response['payment'], "payment"));
        $model->setClient($this->_convertResponseToModel($response['client'], "client"));
        $model->setAppId($response['app_id']);
        $model->setIsCanceled($response['is_canceled']);
        $model->setIsDeleted($response['is_deleted']);
        $model->setStatus($response['status']);
        $model->setAmount($response['amount']);
        $model->setTempAmount($response['temp_amount']);
        return $model;
    }
716224
public function getSubscriptionById($subscriptionId)
    {
        $subscriptions = $this
            ->getSubscriptions(null, null, null, $subscriptionId)
            ->getResponse()
            ->getSubscriptions();

        return count($subscriptions) ? reset($subscriptions) : null;
    }
1035318
public function getPath($sub = null)
    {
        if (is_array($sub)) {
            $sub = implode(DIRECTORY_SEPARATOR, $sub);
        }

        $path = $this->path;
        if (!is_null($sub)) {
            $path .= DIRECTORY_SEPARATOR.$sub;
        }

        return $path;
    }
25942
public function addSubscription( $email, $user, $contentID, $languageID, $subscriptionType, $currentTime, $activate = true )
    {
        //1. insert into subscriber
        $ezcommentsINI = eZINI::instance( 'ezcomments.ini' );
        $subscriber = ezcomSubscriber::fetchByEmail( $email );
        //if there is no data in subscriber for same email, save it
        if ( is_null( $subscriber ) )
        {
            $subscriber = ezcomSubscriber::create();
            $subscriber->setAttribute( 'user_id', $user->attribute( 'contentobject_id' ) );
            $subscriber->setAttribute( 'email', $email );
            if ( $user->isAnonymous() )
            {
                $util = ezcomUtility::instance();
                $hashString = $util->generateSusbcriberHashString( $subscriber );
                $subscriber->setAttribute( 'hash_string', $hashString );
            }
            $subscriber->store();
            eZDebugSetting::writeNotice( 'extension-ezcomments', 'Subscriber does not exist, added one', __METHOD__ );
            $subscriber = ezcomSubscriber::fetchByEmail( $email );
        }
        else
        {
            if ( $subscriber->attribute( 'enabled' ) == false )
            {
                throw new Exception('Subscription can not be added because the subscriber is disabled.', self::ERROR_SUBSCRIBER_DISABLED );
            }
        }
        //3 insert into subscription table
        // if there is no data in ezcomment_subscription with given contentobject_id and subscriber_id
        $hasSubscription = ezcomSubscription::exists( $contentID,
                                                      $languageID,
                                                      $subscriptionType,
                                                      $email );
        if ( $hasSubscription === false )
        {
            $subscription = ezcomSubscription::create();
            $subscription->setAttribute( 'user_id', $user->attribute( 'contentobject_id' ) );
            $subscription->setAttribute( 'subscriber_id', $subscriber->attribute( 'id' ) );
            $subscription->setAttribute( 'subscription_type', $subscriptionType );
            $subscription->setAttribute( 'content_id', $contentID );
            $subscription->setAttribute( 'language_id', $languageID );
            $subscription->setAttribute( 'subscription_time', $currentTime );
            $defaultActivated = $ezcommentsINI->variable( 'CommentSettings', 'SubscriptionActivated' );

            if ( $user->isAnonymous() && $defaultActivated !== 'true' && $activate === true )
            {
                $subscription->setAttribute( 'enabled', 0 );
                $utility = ezcomUtility::instance();
                $subscription->setAttribute( 'hash_string', $utility->generateSubscriptionHashString( $subscription ) );
                $subscription->store();

                $result = ezcomSubscriptionManager::sendActivationEmail( eZContentObject::fetch( $contentID ),
                                                                         $subscriber,
                                                                         $subscription );
                if ( !$result )
                {
                    eZDebug::writeError( "Error sending mail to '$email'", __METHOD__ );
                }
            }
            else
            {
                $subscription->setAttribute( 'enabled', 1 );
                $subscription->store();
            }
            eZDebugSetting::writeNotice( 'extension-ezcomments', 'No existing subscription for this content and user, added one', __METHOD__ );
        }
    }
1372494
public static function get_subscriptions_by_event(\stdClass $event) {
        global $DB;

        $sql = self::get_subscription_join_rule_sql();
        if ($event->contextlevel == CONTEXT_MODULE && $event->contextinstanceid != 0) {
            $sql .= "WHERE r.eventname = :eventname AND s.courseid = :courseid AND (s.cmid = :cmid OR s.cmid = 0)";
            $params = array('eventname' => $event->eventname, 'courseid' => $event->courseid, 'cmid' => $event->contextinstanceid);
        } else {
            $sql .= "WHERE r.eventname = :eventname AND (s.courseid = :courseid OR s.courseid = 0)";
            $params = array('eventname' => $event->eventname, 'courseid' => $event->courseid);
        }
        return self::get_instances($DB->get_records_sql($sql, $params));
    }
862613
public static function createSubscriptionFromSubscribeMessage(Session $session, SubscribeMessage $msg)
    {
        $options      = $msg->getOptions();
        $subscription = new Subscription($msg->getTopicName(), $session, $options);

        if (isset($options->disclose_publisher) && $options->disclose_publisher === true) {
            $subscription->setDisclosePublisher(true);
        }

        return $subscription;
    }
832401
protected function export_content(workshop_submission $workshopsubmission) {

        $output = '';

        if (!$workshopsubmission->is_anonymous()) {
            $author = username_load_fields_from_object((object)[], $workshopsubmission, 'author');
            $output .= html_writer::div(get_string('byfullnamewithoutlink', 'mod_workshop', fullname($author)));
        }

        $content = $this->format_exported_text($workshopsubmission->content, $workshopsubmission->contentformat);
        $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop',
            'submission_content', $workshopsubmission->id, $this->exporter->get('format'));
        $output .= html_writer::div($content);

        $output .= $this->export_files_list('submission_attachment');

        $strategy = $this->workshop->grading_strategy_instance();

        $canviewauthornames = has_capability('mod/workshop:viewauthornames', $this->workshop->context, $this->get('user'));
        $canviewreviewernames = has_capability('mod/workshop:viewreviewernames', $this->workshop->context, $this->get('user'));

        foreach ($this->assessments as $assessment) {
            $mform = $strategy->get_assessment_form(null, 'assessment', $assessment, false);
            $options = [
                'showreviewer' => $canviewreviewernames,
                'showauthor' => $canviewauthornames,
                'showform' => true,
                'showweight' => true,
            ];
            if ($assessment->reviewerid == $this->get('user')->id) {
                $options['showreviewer'] = true;
            }

            $workshopassessment = $this->workshop->prepare_assessment($assessment, $mform, $options);

            if ($assessment->reviewerid == $this->get('user')->id) {
                $workshopassessment->title = get_string('assessmentbyyourself', 'mod_workshop');
            } else {
                $workshopassessment->title = get_string('assessment', 'mod_workshop');
            }

            $output .= html_writer::empty_tag('hr');
            $output .= $this->export_assessment($workshopassessment);
        }

        if (trim($this->workshop->instructauthors)) {
            $output .= html_writer::tag('h3', get_string('instructauthors', 'mod_workshop'));
            $content = $this->format_exported_text($this->workshop->instructauthors, $this->workshop->instructauthorsformat);
            $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop',
                'instructauthors', 0, $this->exporter->get('format'));
            $output .= $content;
        }

        return html_writer::div($output);
    }
1014952
public function subscribers(Request $request)
    {
        $order  = $request->input('order');
        $search = $request->input('search',null);
        $search = ($search ? $search['value'] : null);

        return $this->subscriber->get_ajax(
            $request->input('draw'), $request->input('start'), $request->input('length'), $order[0]['column'], $order[0]['dir'], $search
        );
    }
110928
private function processGeneralSubscription()
    {
        $customerId = $this->customerSession->getCustomerId();
        if ($customerId === null) {
            $this->messageManager->addError(__('Something went wrong while saving your subscription.'));
        } else {
            try {
                $customer = $this->customerRepository->getById($customerId);
                $storeId = $this->helper->storeManager->getStore()->getId();
                $customer->setStoreId($storeId);
                $isSubscribedState = $customer->getExtensionAttributes()
                    ->getIsSubscribed();
                $isSubscribedParam = (boolean)$this->getRequest()
                    ->getParam('is_subscribed', false);
                if ($isSubscribedParam !== $isSubscribedState) {
                    $this->customerRepository->save($customer);
                    if ($isSubscribedParam) {
                        $subscribeModel = $this->subscriberFactory->create()
                            ->subscribeCustomerById($customerId);
                        $subscribeStatus = $subscribeModel->getStatus();
                        if ($subscribeStatus == Subscriber::STATUS_SUBSCRIBED) {
                            $this->messageManager->addSuccess(__('We have saved your subscription.'));
                        } else {
                            $this->messageManager->addSuccess(__('A confirmation request has been sent.'));
                        }
                    } else {
                        $this->subscriberFactory->create()
                            ->unsubscribeCustomerById($customerId);
                        $this->messageManager->addSuccess(__('We have removed your newsletter subscription.'));
                    }
                } else {
                    $this->messageManager->addSuccess(__('We have updated your subscription.'));
                }
            } catch (\Exception $e) {
                $this->messageManager->addError(__('Something went wrong while saving your subscription.'));
            }
        }
    }
726525
public static function event_has_subscriptions($eventname, $courseid) {
        global $DB;

        // Check if we can return these from cache.
        $cache = \cache::make('tool_monitor', 'eventsubscriptions');

        // The SQL we will be using to fill the cache if it is empty.
        $sql = "SELECT DISTINCT(r.eventname)
                  FROM {tool_monitor_subscriptions} s
            INNER JOIN {tool_monitor_rules} r
                    ON s.ruleid = r.id
                 WHERE s.courseid = :courseid";

        $sitesubscriptions = $cache->get(0);
        // If we do not have the site subscriptions in the cache then return them from the DB.
        if ($sitesubscriptions === false) {
            // Set the array for the cache.
            $sitesubscriptions = array();
            if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => 0))) {
                foreach ($subscriptions as $subscription) {
                    $sitesubscriptions[$subscription->eventname] = true;
                }
            }
            $cache->set(0, $sitesubscriptions);
        }

        // Check if a subscription exists for this event site wide.
        if (isset($sitesubscriptions[$eventname])) {
            return true;
        }

        // If the course id is for the site, and we reached here then there is no site wide subscription for this event.
        if (empty($courseid)) {
            return false;
        }

        $coursesubscriptions = $cache->get($courseid);
        // If we do not have the course subscriptions in the cache then return them from the DB.
        if ($coursesubscriptions === false) {
            // Set the array for the cache.
            $coursesubscriptions = array();
            if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => $courseid))) {
                foreach ($subscriptions as $subscription) {
                    $coursesubscriptions[$subscription->eventname] = true;
                }
            }
            $cache->set($courseid, $coursesubscriptions);
        }

        // Check if a subscription exists for this event in this course.
        if (isset($coursesubscriptions[$eventname])) {
            return true;
        }

        return false;
    }
354236
public function buildSql($sub = true)
    {
        return $sub ? '( ' . $this->select(false) . ' )' : $this->select(false);
    }
956131
public function getSubscriptionUsageData(
        $subscriptionId,
        \DateTime $subscriptionStart = null,
        \DateTime $subscriptionEnd = null
    ) {
        $requestData = new GetUsageData\RequestData($subscriptionId);

        $requestData->setSubscriptionId($subscriptionId);
        $requestData->setSubscriptionStart($subscriptionStart);
        $requestData->setSubscriptionEnd($subscriptionEnd);

        $request = new GetUsageData\Request($requestData);

        return $this->sendRequest($request, GetUsageData\ApiResponse::class);
    }
733247
public function getSubscription()
    {
        if (null === $this->_subscription) {
            $this->_subscription = Subscription::find()->id($this->subscriptionId)->one();
        }

        return $this->_subscription;
    }