/** * */ protected function definition_appearance() { global $COURSE; // We want to hide that when using the singleactivity course format because it is confusing. if (!$this->courseformat->has_view_page()) { return; } $mform =& $this->_form; $mform->addElement('header', 'coursedisplayhdr', get_string('appearance')); // Activity icon. $options = array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes, 'maxfiles' => 1, 'accepted_types' => array('image')); $draftitemid = file_get_submitted_draft_itemid('activityicon'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_dataform', 'activityicon', 0, $options); $mform->addElement('filemanager', 'activityicon', get_string('activityicon', 'dataform'), null, $options); $mform->setDefault('activityicon', $draftitemid); $mform->addHelpButton('activityicon', 'activityicon', 'mod_dataform'); // Displayed view. $options = array(0 => get_string('choosedots')); if ($this->_instance) { if ($views = mod_dataform_view_manager::instance($this->_instance)->views_menu) { $options = $options + $views; } } $mform->addElement('select', 'inlineview', get_string('inlineview', 'mod_dataform'), $options); $mform->addHelpButton('inlineview', 'inlineview', 'mod_dataform'); // Embedded. $mform->addElement('selectyesno', 'embedded', get_string('embedded', 'mod_dataform')); $mform->addHelpButton('embedded', 'embedded', 'mod_dataform'); $mform->disabledIf('embedded', 'inlineview', 'eq', 0); }
/** * */ protected function field_definition_action($action) { global $CFG; $field = $this->_field; $mform =& $this->_form; // Header. $mform->addElement('header', '', get_string($action, 'dataformfield_entryactions')); // Target view (param1). $viewman = mod_dataform_view_manager::instance($field->dataid); $options = array('' => get_string('default')); if ($viewsmenu = $viewman->views_menu) { $options = $options + $viewsmenu; } $mform->addElement('select', "targetview_{$action}", get_string('targetview', 'dataformfield_entryactions'), $options); $mform->addHelpButton("targetview_{$action}", 'targetview', 'dataformfield_entryactions'); // Additional action params. $mform->addElement('text', "actionparams_{$action}", get_string('actionparams', 'dataformfield_entryactions')); $mform->setType("actionparams_{$action}", PARAM_TEXT); $mform->addHelpButton("actionparams_{$action}", 'targetview', 'dataformfield_entryactions'); // Theme icon. $mform->addElement('text', "themeicon_{$action}", get_string('themeicon', 'dataformfield_entryactions')); $mform->setType("themeicon_{$action}", PARAM_TEXT); $mform->addHelpButton("themeicon_{$action}", 'targetview', 'dataformfield_entryactions'); /* // Custom icon. $options = array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes, 'maxfiles' => 1, 'accepted_types' => array('image')); $draftitemid = file_get_submitted_draft_itemid('customicon'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_dataform', "field_{$action}icon", 0, $options); $mform->addElement('filemanager', 'customicon', get_string('activityicon', 'dataform'), null, $options); $mform->setDefault('customicon', $draftitemid); // Entry condition (filter). */ }
/** * */ public static function general_definition($mform, $dataformid, $prefix = null) { global $CFG; $paramtext = !empty($CFG->formatstringstriptags) ? PARAM_TEXT : PARAM_CLEAN; $mform->addElement('header', 'general', get_string('general', 'form')); // Name. $mform->addElement('text', $prefix . 'name', get_string('name'), array('size' => '32')); $mform->addRule($prefix . 'name', null, 'required', null, 'client'); $mform->setType($prefix . 'name', $paramtext); // Description. $mform->addElement('text', $prefix . 'description', get_string('description'), array('size' => '64')); $mform->setType($prefix . 'description', PARAM_CLEAN); // Enabled. $mform->addElement('selectyesno', $prefix . 'enabled', get_string('ruleenabled', 'dataform')); $mform->setDefault($prefix . 'enabled', 1); // Time from. $mform->addElement('date_time_selector', $prefix . 'timefrom', get_string('from'), array('optional' => true)); // Time to. $mform->addElement('date_time_selector', $prefix . 'timeto', get_string('to'), array('optional' => true)); // Views. $options = array(0 => get_string('all'), 1 => get_string('selected', 'form')); $mform->addElement('select', $prefix . 'viewselection', get_string('views', 'dataform'), $options); $items = array(); if ($items = \mod_dataform_view_manager::instance($dataformid)->views_menu) { $items = array_combine($items, $items); } $select =& $mform->addElement('select', $prefix . 'views', null, $items); $select->setMultiple(true); $mform->disabledIf($prefix . 'views', $prefix . 'viewselection', 'eq', 0); }
/** * */ public static function notification_definition($mform, $dataformid, $prefix = null) { global $DB; $paramtext = !empty($CFG->formatstringstriptags) ? PARAM_TEXT : PARAM_CLEAN; $mform->addElement('header', 'messagehdr', get_string('message', 'message')); $mform->setExpanded('messagehdr'); // Message type. $options = array(0 => get_string('notification', 'dataform'), 1 => get_string('conversation', 'dataform')); $mform->addElement('select', $prefix . 'messagetype', get_string('type', 'dataform'), $options); // Subject. $mform->addElement('text', $prefix . 'subject', get_string('subject', 'dataform')); $mform->setType($prefix . 'subject', $paramtext); // Content. $mform->addElement('textarea', $prefix . 'contenttext', get_string('content')); $mform->setType($prefix . 'contenttext', $paramtext); // Content from view. $options = array('' => get_string('choosedots')); if ($items = \mod_dataform_view_manager::instance($dataformid)->views_menu) { $items = array_combine($items, $items); $options = array_merge($options, $items); } $label = get_string('contentview', 'mod_dataform'); $mform->addElement('select', $prefix . 'contentview', $label, $options); // Format. $options = array(FORMAT_PLAIN => get_string('formatplain'), FORMAT_HTML => get_string('formathtml')); $mform->addElement('select', $prefix . 'messageformat', get_string('format'), $options); // Sender: Entry author, manager. $mform->addElement('header', 'senderhdr', get_string('sender', 'mod_dataform')); $mform->setExpanded('senderhdr'); $admin = get_admin(); $options = array(\core_user::NOREPLY_USER => get_string('noreply', 'dataform'), \core_user::SUPPORT_USER => get_string('supportcontact', 'admin'), $admin->id => get_string('admin'), 'author' => get_string('author', 'dataform'), 'event' => get_string('event', 'dataform')); $mform->addElement('select', $prefix . 'sender', get_string('from'), $options); // Recipient. $mform->addElement('header', 'recipientshdr', get_string('recipient', 'mod_dataform')); $mform->setExpanded('recipientshdr'); // Admin. $mform->addElement('advcheckbox', $prefix . 'recipient[admin]', get_string('admin')); // Support. $mform->addElement('advcheckbox', $prefix . 'recipient[support]', get_string('supportcontact', 'admin')); // Entry author. $mform->addElement('advcheckbox', $prefix . 'recipient[author]', get_string('author', 'dataform')); // Role (mod/dataform:notification permission in context). $mform->addElement('advcheckbox', $prefix . 'recipient[role]', get_string('role')); // Username (comma delimited). $mform->addElement('text', $prefix . 'recipient[username]', get_string('username')); $mform->setType($prefix . 'recipient[username]', $paramtext); // Email (comma delimited). $mform->addElement('text', $prefix . 'recipient[email]', get_string('email')); $mform->setType($prefix . 'recipient[email]', $paramtext); }
/** * Deletes plugin instances. * * @return void */ public function delete_instances() { global $DB; $params = array('type' => $this->name); if (!($instances = $DB->get_records_menu('dataform_views', $params, 'dataid', 'id,dataid'))) { return; } $bydataform = array(); foreach ($instances as $instanceid => $dataformid) { if (empty($bydataform[$dataformid])) { $bydataform[$dataformid] = array(); } $bydataform[$dataformid][] = $instanceid; } foreach ($bydataform as $dataformid => $instanceids) { $entryman = \mod_dataform_view_manager::instance($dataformid); $entryman->process_views('delete', $instanceids, null, true); } }
/** * Generates the RSS Feed * * @param strClass $context the context the feed should be created under * @param array $args array of arguments to be used in the creation of the RSS Feed * @return NULL|string NULL if there is nothing to return, or the file path of the cached file if there is */ function dataform_rss_get_feed($context, $args) { global $CFG, $DB; // Check CFG->data_enablerssfeeds. if (empty($CFG->dataform_enablerssfeeds)) { debugging("DISABLED (module configuration)"); return null; } // Validate context. $dataformid = clean_param($args[3], PARAM_INT); $cm = get_coursemodule_from_instance('dataform', $dataformid, 0, false, MUST_EXIST); if ($cm) { $modcontext = context_module::instance($cm->id); // Context id from db should match the submitted one. if ($context->id != $modcontext->id) { return null; } } // Check RSS enbabled for instance. $dataform = $DB->get_record('dataform', array('id' => $dataformid), '*', MUST_EXIST); if (!rss_enabled_for_mod('dataform', $dataform, false, false)) { return null; } // Get the target view. $viewid = clean_param($args[4], PARAM_INT); $viewdata = $DB->get_record('dataform_views', array('id' => $viewid), '*', MUST_EXIST); $viewman = mod_dataform_view_manager::instance($dataformid); $view = $viewman->get_view_by_id($viewid); // If (!($view instanceof 'mod_dataform\interfaces\rss')) { // return null; // }. // Get the cache file info // The cached file name is formatted dfid_viewid_contentstamp, // where contentstamp is provided by the view. $componentid = $dataformid . "_{$viewid}"; $cachedfilepath = dataform_rss_get_cached_file_path($componentid); $contentstamp = $cachedfilepath ? dataform_rss_get_cached_content_stamp($cachedfilepath) : null; $newcontentstamp = $view->get_content_stamp(); $hasnewcontent = $newcontentstamp !== $contentstamp; // Neither existing nor new. if (!$cachedfilepath and !$hasnewcontent) { return null; } if ($cachedfilepath) { // Use cache under 60 seconds. $cachetime = filemtime($cachedfilepath); if (time() - $cachetime < 60) { return $cachedfilepath; } // Use cache if there is nothing new. if (!$hasnewcontent) { return $cachedfilepath; } // Cached file is outdated so delete it. $instance = (object) array('id' => $componentid); rss_delete_file('mod_dataform', $instance); } // Still here, fetch new content. // Each article is an stdclass {title, descrition, pubdate, entrylink}. if (!($items = $view->get_rss_items())) { return null; } // First all rss feeds common headers. $headertitle = $view->get_rss_header_title(); $headerlink = $view->get_rss_header_link(); $headerdescription = $view->get_rss_header_description(); $header = rss_standard_header($headertitle, $headerlink, $headerdescription); if (empty($header)) { return null; } // Now all rss feeds common footers. $footer = rss_standard_footer(); if (empty($footer)) { return null; } // All's good, save the content to file. $articles = rss_add_items($items); $rss = $header . $articles . $footer; $filename = $componentid . "_{$newcontentstamp}"; $status = rss_save_file('mod_dataform', $filename, $rss); $dirpath = dataform_rss_get_cache_dir_path(); return "{$dirpath}/{$filename}.xml"; }
/** * */ protected function definition_view_submission() { $view = $this->_view; $mform =& $this->_form; $paramtext = !empty($CFG->formatstringstriptags) ? PARAM_TEXT : PARAM_CLEAN; $settings = $view->submission_settings; // Header. $mform->addElement('header', 'viewsubmissionhdr', get_string('submission', 'dataform')); // What to display when editing. $options = array('' => get_string('modeeditonly', 'dataform'), dataformview::EDIT_SEPARATE => get_string('modeeditseparate', 'dataform'), dataformview::EDIT_INLINE => get_string('modeeditinline', 'dataform')); $mform->addElement('select', 'submissiondisplay', get_string('submissiondisplay', 'dataform'), $options); if (!empty($settings['display'])) { $mform->setDefault('submissiondisplay', $settings['display']); } // Save buttons. $buttons = $view->submission_buttons; foreach ($buttons as $name) { $grp = array(); $grp[] =& $mform->createElement('text', $name . 'button_label', null); $grp[] =& $mform->createElement('checkbox', $name . 'buttonenable', null, get_string('enable')); $mform->addGroup($grp, $name . 'buttongrp', get_string($name . 'button', 'dataform'), ' ', false); $mform->addHelpButton($name . 'buttongrp', $name . 'button', 'dataform'); $mform->setType($name . 'button_label', $paramtext); $mform->disabledIf($name . 'button_label', $name . 'buttonenable', 'notchecked'); // Button settings. if (is_array($settings) and array_key_exists($name, $settings)) { $mform->setDefault($name . 'buttonenable', 1); $mform->setDefault($name . 'button_label', $settings[$name]); } } // Redirect view after submission. $options = array('' => get_string('choosedots')); if ($viewsmenu = \mod_dataform_view_manager::instance($view->df->id)->views_menu) { // Remove this view. if ($view->id and !empty($viewsmenu[$view->id])) { unset($viewsmenu[$view->id]); } $options = $options + $viewsmenu; } $mform->addElement('select', 'submissionredirect', get_string('submissionredirect', 'dataform'), $options); $mform->addHelpButton('submissionredirect', 'submissionredirect', 'dataform'); if (!empty($settings['redirect'])) { $mform->setDefault('submissionredirect', $settings['redirect']); } // Response timeout. $options = range(0, 20); $options[0] = get_string('none'); $mform->addElement('select', 'submissiontimeout', get_string('submissiontimeout', 'dataform'), $options); $mform->addHelpButton('submissiontimeout', 'submissiontimeout', 'dataform'); // Response for submission. $mform->addElement('textarea', 'submissionmessage', get_string('submissionmessage', 'dataform')); $mform->setType('submissionmessage', $paramtext); $mform->disabledIf('submissionmessage', 'submissiontimeout', 'eq', 0); $mform->addHelpButton('submissionmessage', 'submissionmessage', 'dataform'); // Set default save and cancel for new views. if (!$view->id) { $mform->setDefault('savebuttonenable', 1); $mform->setDefault('cancelbuttonenable', 1); $mform->setDefault('submissiontimeout', 1); } }
// Re/set view filter (confirmed by default). $viewman->process_views('filter', $urlparams->setfilter, null, true); } } } } } } // Any notifications? $df->notifications = array('problem' => array('defaultview' => null)); if (!($views = $viewman->get_views(array('forceget' => true, 'sort' => 'name')))) { $df->notifications = array('problem' => array('getstartedviews' => get_string('viewnoneindataform', 'dataform'))); } else { if (!$df->defaultview) { $df->notifications = array('problem' => array('defaultview' => get_string('viewnodefault', 'dataform', ''))); } } $output = $df->get_renderer(); echo $output->header(array('tab' => 'views', 'heading' => $df->name, 'urlparams' => $urlparams)); // Try cleanup first. if ($patternscleanup = optional_param('patternscleanup', 0, PARAM_INT)) { mod_dataform_view_manager::patterns_cleanup($df->id, $patternscleanup); } // If not cleaning patterns, display view list. if (!$patternscleanup) { // Display subplugin selector. echo $output->subplugin_select('view'); // Print admin style list of views. echo $output->views_admin_list(null, $views); } echo $output->footer();
/** * Returns the view manager of the Dataform this mannager works for. * * @return mod_dataform_view_manager */ public function get_view_manager() { return mod_dataform_view_manager::instance($this->dataformid); }
/** * */ public function render_views_menu($view) { $viewman = mod_dataform_view_manager::instance($view->dataid); $filter = $view->get_filter(); $baseurl = $view->get_baseurl(); $viewjump = ''; if ($menuviews = $viewman->views_navigation_menu) { if (count($menuviews) == 1) { $viewjump = reset($menuviews); } else { // Display the view form jump list. $baseurl = $baseurl->out_omit_querystring(); $baseurlparams = array('d' => $view->dataid, 'filter' => $filter->id); $select = new single_select(new moodle_url($baseurl, $baseurlparams), 'view', $menuviews, $view->id, null, 'viewbrowse_jump'); $select->attributes = array('id' => 'id_viewsmenu'); $viewjump = $this->render($select); } } return $viewjump; }
/** * Prepare the package for export. * * @return stored_file object */ public function prepare_package() { // Set the exported view content. $df = mod_dataform_dataform::instance(null, $this->id); $viewman = mod_dataform_view_manager::instance($df->id); $view = $viewman->get_view_by_id($this->vid); $view->set_viewfilter(array('filterid' => $this->fid, 'eids' => $this->eids)); // Export to spreadsheet. if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_SPREADSHEET) { $content = $view->display(array('controls' => false)); $filename = clean_filename($view->name . '-full.' . $this->get_export_config('spreadsheettype')); $this->exporter->write_new_file($content, $filename); return; } // Export to html. if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_RICHHTML) { $exportfiles = $this->get_export_config('contentformat'); // Collate embedded files (view and field). if ($exportfiles) { if ($files = $view->get_embedded_files()) { foreach ($files as $file) { $this->exporter->copy_existing_file($file); } } } // Export content. if ($exportfiles != self::CONTENT_FILESONLY) { $content = $view->display(array('controls' => false, 'pluginfileurl' => $this->exporter->get('format')->get_file_directory())); $filename = clean_filename($view->name . '-full.htm'); $this->exporter->write_new_file($content, $filename); } return; } }
/** * Assigns/unassigned the specified user as the entry author. * Only current user can unassign him/her self. * Unassigning sets the entry userid to 0. Possible conflicts need to examined. * Gradebook users can assign only to entries not currently owned by gradebook users. * * @param int $userid The user to assign as the entry owner (0 for unassign). * @param int $entryid The entry to be assigned. * @param int * @param int * @return bool */ public function assign_user($userid, $entryid, $viewid) { global $DB, $USER; // Get the entry. if (!($entry = $DB->get_record('dataform_entries', array('id' => $entryid)))) { return false; } $dataformid = $entry->dataid; // The view must have the assignme pattern. $view = \mod_dataform_view_manager::instance($dataformid)->get_view_by_id($viewid); $patterns = $view->get_pattern_set('field'); if (!$patterns or empty($patterns[$this->id])) { return false; } $fieldname = $this->name; if (!in_array("[[{$fieldname}:assignme]]", $patterns[$this->id])) { return false; } // If same user (for some reason), no need to do anything. if ($entry->userid == $userid) { return true; } // UNASSIGN. // Only the current user can unassign him/her self. if ($userid == 0) { if ($entry->userid != $USER->id) { return false; } // Try to get a teacher id for the user id. if ($roles = $DB->get_records('role', array('archetype' => 'editingteacher'))) { foreach ($roles as $role) { $teachers = get_role_users($role->id, $this->df->context, true, user_picture::fields('u'), 'u.lastname ASC', false); if ($teachers) { $userid = key($teachers); break; } } } // If no teachers, get admin id. if (!($userid = $userid ? $userid : get_admin()->id)) { return false; } $DB->set_field('dataform_entries', 'userid', $userid, array('id' => $entryid)); // Notify. return true; } // ASSIGN. // Self assign of gradebook user can only be allowed when the current // entry user is not gradebook user. // In other words, a student cannot override another student's selection. if ($gbusers = $this->df->grade_manager->get_gradebook_users(array($entry->userid, $userid))) { if (array_key_exists($entry->userid, $gbusers)) { if (array_key_exists($userid, $gbusers)) { return false; } } } // Set the user as entry owner. $DB->set_field('dataform_entries', 'userid', $userid, array('id' => $entryid)); // Update the entry the standard way, to trigger events. $eids = array($entryid); $data = (object) array('submitbutton_save' => 'Save'); $processed = $view->entry_manager->process_entries('update', $eids, $data, true); return true; }
/** * Returns the list of views the rule applies to. * * @return array|null */ public function get_applicable_views() { if (!$this->is_enabled()) { return null; } if (!empty($this->_block->config->views)) { return $this->_block->config->views; } // Return all views. return \mod_dataform_view_manager::instance($this->_dataformid)->views_menu; }
/** * */ protected function get_views_menu() { if ($this->_viewsmenu === null) { $field = $this->_field; $viewman = mod_dataform_view_manager::instance($this->_field->df->id); $this->_viewsmenu = $viewman->views_menu; } return $this->_viewsmenu; }