original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Returns true if an event in a particular course has a subscription.
  
  @param string $eventname the name of the event
  @param int $courseid the course id
  @return bool returns true if the event has subscriptions in a given course, false otherwise.
docstring_tokens: Returns true if an event in a particular course has a subscription .