예제 #1
0
/**
 * Serves the dataformview_tabular template files.
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function dataformview_tabular_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    if (!in_array($filearea, dataformview_tabular_tabular::get_file_areas())) {
        return false;
    }
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_course_login($course, true, $cm);
        $viewid = (int) array_shift($args);
        $dataformid = $cm->instance;
        // Confirm user access.
        $params = array('dataformid' => $dataformid, 'viewid' => $viewid);
        if (!mod_dataform\access\view_access::validate($params)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/dataformview_tabular/{$filearea}/{$viewid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Finally send the file.
        send_stored_file($file, 0, 0, true);
        // Download MUST be forced - security!
    }
    return false;
}
예제 #2
0
 /**
  *
  */
 public function get_views_navigation_menu()
 {
     global $DB;
     $menu = array();
     $params = array('dataid' => $this->_dataformid);
     $views = $DB->get_records('dataform_views', $params, '', 'id,name,visible');
     // Check access to the view.
     $df = mod_dataform_dataform::instance($this->_dataformid);
     $manager = has_capability('mod/dataform:manageviews', $df->context);
     foreach ($views as $viewid => $view) {
         // Skip hidden views.
         if ($view->visible == \mod_dataform\pluginbase\dataformview::VISIBILITY_HIDDEN) {
             continue;
         }
         if (!$manager) {
             if (!$view->visible) {
                 continue;
             }
             $accessparams = array('dataformid' => $this->_dataformid, 'viewid' => $viewid);
             if (!mod_dataform\access\view_access::validate($accessparams)) {
                 continue;
             }
         }
         $menu[$view->id] = $view->name;
     }
     return $menu;
 }
예제 #3
0
 /**
  * Returns a list of rss view the current user has access to.
  *
  * @return array|bool Associative array viewid => dataformview_rss, false if no views
  */
 public function get_rss_views()
 {
     static $views;
     if (!isset($views)) {
         if ($views = $this->view_manager->get_views_by_instanceof('mod_dataform\\interfaces\\rss')) {
             // Remove unpermitted.
             foreach ($views as $viewid => $unused) {
                 $params = array('dataformid' => $this->id, 'viewid' => $viewid);
                 if (!mod_dataform\access\view_access::validate($params)) {
                     unset($views[$viewid]);
                 }
             }
         }
     }
     return $views;
 }