Exemplo n.º 1
0
 /**
  * Gets list of course-modules on the course which have search documents
  * and for which the user has accessallgroups OR the item is set to
  * visible groups.
  * @param int $courseid Course ID to check
  * @return array Array of course_module objects (id, course only)
  */
 public static function get_group_exceptions($courseid)
 {
     global $DB;
     $year = year_tables::get_year_for_course(get_course($courseid));
     $docstable = year_tables::get_docs_table($year);
     // Get all CMs that have a document.
     $possible = $DB->get_records_sql("\n                SELECT DISTINCT cm.id AS cmid, cm.course AS cmcourse, cm.groupmode AS cmgroupmode, x.*\n                  FROM {" . $docstable . "} bod\n                  JOIN {course_modules} cm ON bod.coursemoduleid = cm.id\n                  JOIN {context} x ON x.instanceid = cm.id AND x.contextlevel = " . CONTEXT_MODULE . "\n                 WHERE bod.courseid = ?", array($courseid));
     // Check accessallgroups on each one.
     $results = array();
     foreach ($possible as $record) {
         if ($record->cmgroupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', context_course::instance($record->cmcourse))) {
             $results[] = (object) array('id' => $record->cmid, 'course' => $record->cmcourse);
         }
     }
     return $results;
 }
Exemplo n.º 2
0
 /**
  * Static function that wipes document and words
  * @param int $id ID of document to wipe
  */
 public function wipe_document($id)
 {
     global $DB;
     // Delete existing document and occurrences.
     $DB->delete_records($this->get_occurrences_table(), array('documentid' => $id));
     $DB->delete_records($this->get_documents_table(), array('id' => $id));
     // If the course is currently being transferred we should get rid of it
     // from the new table too.
     if (isset($this->courseid) && year_tables::currently_transferring_course($this->courseid)) {
         $course = get_course($this->courseid);
         $year = year_tables::get_year_for_course($course);
         $otherdoc = new local_ousearch_document();
         $otherdoc->init_from_record($this);
         unset($otherdoc->id);
         if ($otherdoc->find('local_ousearch_docs_' . $year)) {
             $DB->delete_records($this->get_occurrences_table(), array('documentid' => $id));
             $DB->delete_records($this->get_documents_table(), array('id' => $id));
         }
     }
 }