original_string: protected function get_structural_changes() {
          global $DB;
          $course = $this->page->course;
          $context = context_course::instance($course->id);
          $canviewdeleted = has_capability('block/recent_activity:viewdeletemodule', $context);
          $canviewupdated = has_capability('block/recent_activity:viewaddupdatemodule', $context);
          if (!$canviewdeleted && !$canviewupdated) {
              return;
          }
  
          $timestart = $this->get_timestart();
          $changelist = array();
          // The following query will retrieve the latest action for each course module in the specified course.
          // Also the query filters out the modules that were created and then deleted during the given interval.
          $sql = "SELECT
                      cmid, MIN(action) AS minaction, MAX(action) AS maxaction, MAX(modname) AS modname
                  FROM {block_recent_activity}
                  WHERE timecreated > ? AND courseid = ?
                  GROUP BY cmid
                  ORDER BY MAX(timecreated) ASC";
          $params = array($timestart, $course->id);
          $logs = $DB->get_records_sql($sql, $params);
          if (isset($logs[0])) {
              // If special record for this course and cmid=0 is present, migrate logs.
              self::migrate_logs($course);
              $logs = $DB->get_records_sql($sql, $params);
          }
          if ($logs) {
              $modinfo = get_fast_modinfo($course);
              foreach ($logs as $log) {
                  // We used aggregate functions since constants CM_CREATED, CM_UPDATED and CM_DELETED have ascending order (0,1,2).
                  $wasdeleted = ($log->maxaction == block_recent_activity_observer::CM_DELETED);
                  $wascreated = ($log->minaction == block_recent_activity_observer::CM_CREATED);
  
                  if ($wasdeleted && $wascreated) {
                      // Activity was created and deleted within this interval. Do not show it.
                      continue;
                  } else if ($wasdeleted && $canviewdeleted) {
                      if (plugin_supports('mod', $log->modname, FEATURE_NO_VIEW_LINK, false)) {
                          // Better to call cm_info::has_view() because it can be dynamic.
                          // But there is no instance of cm_info now.
                          continue;
                      }
                      // Unfortunately we do not know if the mod was visible.
                      $modnames = get_module_types_names();
                      $changelist[$log->cmid] = array('action' => 'delete mod',
                          'module' => (object)array(
                              'modname' => $log->modname,
                              'modfullname' => isset($modnames[$log->modname]) ? $modnames[$log->modname] : $log->modname
                           ));
  
                  } else if (!$wasdeleted && isset($modinfo->cms[$log->cmid]) && $canviewupdated) {
                      // Module was either added or updated during this interval and it currently exists.
                      // If module was both added and updated show only "add" action.
                      $cm = $modinfo->cms[$log->cmid];
                      if ($cm->has_view() && $cm->uservisible) {
                          $changelist[$log->cmid] = array(
                              'action' => $wascreated ? 'add mod' : 'update mod',
                              'module' => $cm
                          );
                      }
                  }
              }
          }
          return $changelist;
      }
code: protected function get_structural_changes() {
          global $DB;
          $course = $this->page->course;
          $context = context_course::instance($course->id);
          $canviewdeleted = has_capability('block/recent_activity:viewdeletemodule', $context);
          $canviewupdated = has_capability('block/recent_activity:viewaddupdatemodule', $context);
          if (!$canviewdeleted && !$canviewupdated) {
              return;
          }
  
          $timestart = $this->get_timestart();
          $changelist = array();
          // The following query will retrieve the latest action for each course module in the specified course.
          // Also the query filters out the modules that were created and then deleted during the given interval.
          $sql = "SELECT
                      cmid, MIN(action) AS minaction, MAX(action) AS maxaction, MAX(modname) AS modname
                  FROM {block_recent_activity}
                  WHERE timecreated > ? AND courseid = ?
                  GROUP BY cmid
                  ORDER BY MAX(timecreated) ASC";
          $params = array($timestart, $course->id);
          $logs = $DB->get_records_sql($sql, $params);
          if (isset($logs[0])) {
              // If special record for this course and cmid=0 is present, migrate logs.
              self::migrate_logs($course);
              $logs = $DB->get_records_sql($sql, $params);
          }
          if ($logs) {
              $modinfo = get_fast_modinfo($course);
              foreach ($logs as $log) {
                  // We used aggregate functions since constants CM_CREATED, CM_UPDATED and CM_DELETED have ascending order (0,1,2).
                  $wasdeleted = ($log->maxaction == block_recent_activity_observer::CM_DELETED);
                  $wascreated = ($log->minaction == block_recent_activity_observer::CM_CREATED);
  
                  if ($wasdeleted && $wascreated) {
                      // Activity was created and deleted within this interval. Do not show it.
                      continue;
                  } else if ($wasdeleted && $canviewdeleted) {
                      if (plugin_supports('mod', $log->modname, FEATURE_NO_VIEW_LINK, false)) {
                          // Better to call cm_info::has_view() because it can be dynamic.
                          // But there is no instance of cm_info now.
                          continue;
                      }
                      // Unfortunately we do not know if the mod was visible.
                      $modnames = get_module_types_names();
                      $changelist[$log->cmid] = array('action' => 'delete mod',
                          'module' => (object)array(
                              'modname' => $log->modname,
                              'modfullname' => isset($modnames[$log->modname]) ? $modnames[$log->modname] : $log->modname
                           ));
  
                  } else if (!$wasdeleted && isset($modinfo->cms[$log->cmid]) && $canviewupdated) {
                      // Module was either added or updated during this interval and it currently exists.
                      // If module was both added and updated show only "add" action.
                      $cm = $modinfo->cms[$log->cmid];
                      if ($cm->has_view() && $cm->uservisible) {
                          $changelist[$log->cmid] = array(
                              'action' => $wascreated ? 'add mod' : 'update mod',
                              'module' => $cm
                          );
                      }
                  }
              }
          }
          return $changelist;
      }
code_tokens: protected function get_structural_changes ( ) { global $ DB ; $ course = $ this -> page -> course ; $ context = context_course :: instance ( $ course -> id ) ; $ canviewdeleted = has_capability ( 'block/recent_activity:viewdeletemodule' , $ context ) ; $ canviewupdated = has_capability ( 'block/recent_activity:viewaddupdatemodule' , $ context ) ; if ( ! $ canviewdeleted && ! $ canviewupdated ) { return ; } $ timestart = $ this -> get_timestart ( ) ; $ changelist = array ( ) ; // The following query will retrieve the latest action for each course module in the specified course. // Also the query filters out the modules that were created and then deleted during the given interval. $ sql = "SELECT
                      cmid, MIN(action) AS minaction, MAX(action) AS maxaction, MAX(modname) AS modname
                  FROM {block_recent_activity}
                  WHERE timecreated > ? AND courseid = ?
                  GROUP BY cmid
                  ORDER BY MAX(timecreated) ASC" ; $ params = array ( $ timestart , $ course -> id ) ; $ logs = $ DB -> get_records_sql ( $ sql , $ params ) ; if ( isset ( $ logs [ 0 ] ) ) { // If special record for this course and cmid=0 is present, migrate logs. self :: migrate_logs ( $ course ) ; $ logs = $ DB -> get_records_sql ( $ sql , $ params ) ; } if ( $ logs ) { $ modinfo = get_fast_modinfo ( $ course ) ; foreach ( $ logs as $ log ) { // We used aggregate functions since constants CM_CREATED, CM_UPDATED and CM_DELETED have ascending order (0,1,2). $ wasdeleted = ( $ log -> maxaction == block_recent_activity_observer :: CM_DELETED ) ; $ wascreated = ( $ log -> minaction == block_recent_activity_observer :: CM_CREATED ) ; if ( $ wasdeleted && $ wascreated ) { // Activity was created and deleted within this interval. Do not show it. continue ; } else if ( $ wasdeleted && $ canviewdeleted ) { if ( plugin_supports ( 'mod' , $ log -> modname , FEATURE_NO_VIEW_LINK , false ) ) { // Better to call cm_info::has_view() because it can be dynamic. // But there is no instance of cm_info now. continue ; } // Unfortunately we do not know if the mod was visible. $ modnames = get_module_types_names ( ) ; $ changelist [ $ log -> cmid ] = array ( 'action' => 'delete mod' , 'module' => ( object ) array ( 'modname' => $ log -> modname , 'modfullname' => isset ( $ modnames [ $ log -> modname ] ) ? $ modnames [ $ log -> modname ] : $ log -> modname ) ) ; } else if ( ! $ wasdeleted && isset ( $ modinfo -> cms [ $ log -> cmid ] ) && $ canviewupdated ) { // Module was either added or updated during this interval and it currently exists. // If module was both added and updated show only "add" action. $ cm = $ modinfo -> cms [ $ log -> cmid ] ; if ( $ cm -> has_view ( ) && $ cm -> uservisible ) { $ changelist [ $ log -> cmid ] = array ( 'action' => $ wascreated ? 'add mod' : 'update mod' , 'module' => $ cm ) ; } } } } return $ changelist ; }
docstring: Returns list of recent changes in course structure
  
  It includes adding, editing or deleting of the resources or activities
  Excludes changes on modules without a view link (i.e. labels), and also
  if activity was both added and deleted
  
  @return array array of changes. Each element is an array containing attributes:
  'action' - one of: 'add mod', 'update mod', 'delete mod'
  'module' - instance of cm_info (for 'delete mod' it is an object with attributes modname and modfullname)
docstring_tokens: Returns list of recent changes in course structure