예제 #1
0
 /**
  * Takes notification data and sends a message or email.
  * Expected data:
  * - sender => stdClass (User object)
  * - subject => string
  * - content => string
  * - contentformat => int (e.g. FORMAT_HTML). Optional; default FORMAT_PLAIN
  * - notification => bool|int
  * - recipients => array (Array of user objects)
  * - recipientemails => array (Array of email addresses)
  *
  * @param array $data Notification data
  * @return array
  */
 public static function notify(\core\event\base $event)
 {
     $dataformid = $event->other['dataid'];
     $man = \mod_dataform_notification_manager::instance($dataformid);
     $result = false;
     if ($rules = $man->get_type_rules_enabled()) {
         $params = array();
         $params['event'] = $event->eventname;
         $params['dataformid'] = $dataformid;
         $params['viewid'] = !empty($event->other['viewid']) ? $event->other['viewid'] : null;
         $params['entryid'] = !empty($event->other['entryid']) ? $event->other['entryid'] : null;
         foreach ($rules as $rule) {
             if ($rule->is_applicable($params)) {
                 $notification = new notification();
                 $message = $notification->prepare_data($event, $rule);
                 $result = ($result or $notification->send_message($message));
             }
         }
     }
     return $result;
 }
예제 #2
0
 /**
  * Returns html for admin style list of fields.
  *
  * @param string $extorint Subset type external|internal
  * @param string $heading Title of list
  * @param array $fields List of available fields
  * @return string HTML fragment of html_table
  */
 public function fields_admin_list($extorint, $heading, $fields)
 {
     if (!$this->_dataformid) {
         return null;
     }
     $df = mod_dataform_dataform::instance($this->_dataformid);
     // External or internal.
     $external = $extorint == 'external';
     $editbaseurl = new moodle_url('/mod/dataform/field/edit.php', array('d' => $this->_dataformid));
     $actionbaseurl = new moodle_url('/mod/dataform/field/index.php', array('d' => $this->_dataformid));
     $sessparam = array('sesskey' => sesskey());
     $strname = get_string('name');
     $strdescription = get_string('description');
     $strtype = get_string('type', 'dataform');
     $stredit = get_string('edit');
     $strduplicate = get_string('duplicate');
     $strdelete = get_string('delete');
     $strhide = get_string('hide');
     $strshow = get_string('show');
     $strlock = get_string('lock', 'dataform');
     $strunlock = get_string('unlock', 'dataform');
     $strpermissions = get_string('permissions', 'role');
     $strnotifications = get_string('notifications');
     // Icons.
     $editicon = $this->output->pix_icon('t/edit', $stredit);
     $duplicateicon = $this->output->pix_icon('t/copy', $strduplicate);
     $deleteicon = $this->output->pix_icon('t/delete', $strdelete);
     $notificationicon = $this->output->pix_icon('notification', $strnotifications, 'dataform');
     $nonotificationicon = $this->output->pix_icon('nonotification', $strnotifications, 'dataform');
     $accessicon = $this->output->pix_icon('access', $strpermissions, 'dataform');
     $noaccessicon = $this->output->pix_icon('noaccess', $strpermissions, 'dataform');
     // The default value of the type attr of a button is submit, so set it to button so that
     // it doesn't submit the form.
     $selectallnone = html_writer::checkbox('fieldselectallnone', null, false, null, array('id' => 'id_fieldselectallnone'));
     $this->page->requires->js_init_call('M.mod_dataform.util.init_select_allnone', array('field'));
     $multiactionurl = new moodle_url($actionbaseurl, $sessparam);
     // Bulk delete.
     $icon = new pix_icon('t/delete', get_string('multidelete', 'dataform'));
     $multidelete = $this->output->action_icon($actionbaseurl, $icon, null, array('id' => 'id_field_bulkaction_delete'));
     $this->page->requires->js_init_call('M.mod_dataform.util.init_bulk_action', array('field', 'delete', $multiactionurl->out(false)));
     // Bulk duplicate.
     $icon = new pix_icon('t/copy', get_string('multiduplicate', 'dataform'));
     $multiduplicate = $this->output->action_icon($actionbaseurl, $icon, null, array('id' => 'id_field_bulkaction_duplicate'));
     $this->page->requires->js_init_call('M.mod_dataform.util.init_bulk_action', array('field', 'duplicate', $multiactionurl->out(false)));
     // Table headers.
     $headers = array('name' => array($strname, 'left', false), 'type' => array($strtype, 'left', false), 'description' => array($strdescription, 'left', false), 'visible' => array(get_string('visible'), 'center', false), 'editable' => array(get_string('fieldeditable', 'dataform'), 'center', false), 'info' => array(null, 'left', false), 'actions' => array("{$multiduplicate} {$multidelete}  {$selectallnone}", 'right', false));
     if (!$external) {
         unset($headers['actions']);
         unset($headers['visible']);
         unset($headers['editable']);
     }
     // Access manager.
     $aman = mod_dataform_access_manager::instance($this->_dataformid);
     // Notification manager.
     $nman = mod_dataform_notification_manager::instance($this->_dataformid);
     if (!$fields) {
         $fields = array();
     }
     $rows = array();
     foreach ($fields as $fieldid => $field) {
         if (!$field) {
             continue;
         }
         // Name.
         if ($field instanceof \mod_dataform\pluginbase\dataformfield_internal) {
             $fieldname = $field->name;
         } else {
             $fieldname = html_writer::link(new moodle_url($editbaseurl, $sessparam + array('fid' => $fieldid)), $field->name);
         }
         // Type.
         $fieldtype = $field->image . ' ' . $field->typename;
         // Description.
         $fielddescription = shorten_text($field->description, 30);
         // Visible.
         if ($visible = $field->visible) {
             $visibleicon = $this->output->pix_icon('t/hide', $strhide);
             $visibleicon = $visible == 1 ? "({$visibleicon})" : $visibleicon;
         } else {
             $visibleicon = $this->output->pix_icon('t/show', $strshow);
         }
         $fieldvisible = html_writer::link(new moodle_url($actionbaseurl, $sessparam + array('visible' => $fieldid)), $visibleicon);
         // Editable.
         if ($editable = $field->editable) {
             $editableicon = $this->output->pix_icon('t/lock', $strlock);
         } else {
             $editableicon = $this->output->pix_icon('t/unlock', $strunlock);
         }
         $fieldeditable = html_writer::link(new moodle_url($actionbaseurl, $sessparam + array('editable' => $fieldid)), $editableicon);
         // INFO
         // Access rules.
         if ($rulenames = $aman->get_field_rules($field->name)) {
             $fieldaccess = $accessicon;
             // Html_writer::alist($rulenames);.
         } else {
             $fieldaccess = $noaccessicon;
         }
         // Notification rules.
         if ($rulenames = $nman->get_field_rules($field->name)) {
             $fieldnotifications = $notificationicon;
             // Html_writer::alist($rulenames);.
         } else {
             $fieldnotifications = $nonotificationicon;
         }
         $fieldinfo = implode('  ', array($fieldaccess, $fieldnotifications));
         // ACTIONS.
         if ($field instanceof \mod_dataform\pluginbase\dataformfield_internal) {
             $fieldactions = null;
         } else {
             $url = new moodle_url($editbaseurl, $sessparam + array('fid' => $fieldid));
             $linkparams = array('id' => "id_editfield{$fieldid}", 'title' => "{$stredit} {$field->name}");
             $fieldedit = html_writer::link($url, $editicon, $linkparams);
             $url = new moodle_url($actionbaseurl, $sessparam + array('duplicate' => $fieldid));
             $linkparams = array('id' => "id_duplicatefield{$fieldid}", 'title' => "{$strduplicate} {$field->name}");
             $fieldduplicate = html_writer::link($url, $duplicateicon, $linkparams);
             $url = new moodle_url($actionbaseurl, $sessparam + array('delete' => $fieldid));
             $linkparams = array('id' => "id_deletefield{$fieldid}", 'title' => "{$strdelete} {$field->name}");
             $fielddelete = html_writer::link($url, $deleteicon, $linkparams);
             $fieldselector = html_writer::checkbox("fieldselector", $fieldid, false, null, array('class' => 'fieldselector'));
             $fieldactions = implode('   ', array($fieldedit, $fieldduplicate, $fielddelete, $fieldselector));
         }
         $data = array();
         foreach (array_keys($headers) as $key) {
             $data[] = ${"field{$key}"};
         }
         $rows[] = $data;
     }
     // Generate the table.
     $table = new html_table();
     foreach ($headers as $header) {
         list($table->head[], $table->align[], $table->wrap[]) = $header;
     }
     $table->data = $rows;
     $title = $heading ? html_writer::tag('h3', $heading) : null;
     return $title . html_writer::table($table);
 }
예제 #3
0
 /**
  * Deletes all this instance's structure and user data and resets its settings to defaults.
  *
  * @return bool Always true
  */
 protected function reset()
 {
     // Must have manage templates capability.
     require_capability('mod/dataform:managetemplates', $this->context);
     // Reset settings.
     $this->reset_settings();
     // Delete all component items.
     mod_dataform_field_manager::instance($this->id)->delete_fields();
     mod_dataform_view_manager::instance($this->id)->delete_views();
     mod_dataform_filter_manager::instance($this->id)->delete_filters();
     mod_dataform_filter_manager::instance($this->id)->delete_advanced_filters();
     mod_dataform_access_manager::instance($this->id)->delete_rules();
     mod_dataform_notification_manager::instance($this->id)->delete_rules();
     // Reset user data.
     $this->reset_user_data();
     // Delete remaining files (e.g. css, js).
     $fs = get_file_storage();
     $fs->delete_area_files($this->context->id, 'mod_dataform');
     // Clean up gradebook.
     mod_dataform_grade_manager::instance($this->id)->delete_grade_items();
     // Refresh events.
     dataform_refresh_events($this->course->id);
     // Delete context content.
     $this->context->delete_content();
     // Update instance store.
     if (\mod_dataform_instance_store::instance($this->id, 'dataform')) {
         \mod_dataform_instance_store::register($this->id, 'dataform', $this);
     }
     return true;
 }
예제 #4
0
$urlparams->cancel = optional_param('cancel', 0, PARAM_BOOL);
$urlparams->enable = optional_param('enable', 0, PARAM_INT);
// Enable context (show block).
$urlparams->disable = optional_param('disable', 0, PARAM_INT);
// Disable context (hide block).
$urlparams->delete = optional_param('delete', 0, PARAM_INT);
// Delete context (delete block).
$urlparams->confirmed = optional_param('confirmed', 0, PARAM_INT);
// Set a dataform object.
$df = mod_dataform_dataform::instance($urlparams->d, $urlparams->id);
$df->require_manage_permission('notifications');
$df->set_page('notification/index', array('urlparams' => $urlparams));
$PAGE->set_context($df->context);
// Activate navigation node.
navigation_node::override_active_url(new moodle_url('/mod/dataform/notification/index.php', array('id' => $df->cm->id)));
$nman = mod_dataform_notification_manager::instance($df->id);
// DATA PROCESSING.
// Enable.
if ($urlparams->enable and confirm_sesskey()) {
    $nman->set_rule_visibility($urlparams->enable, 1);
}
// Disable..
if ($urlparams->disable and confirm_sesskey()) {
    $nman->set_rule_visibility($urlparams->disable, 0);
}
// Delete.
if ($urlparams->delete and confirm_sesskey()) {
    $nman->delete_rule($urlparams->delete);
}
$output = $df->get_renderer();
echo $output->header(array('tab' => 'notification', 'heading' => $df->name, 'urlparams' => $urlparams));