/** * @return bool */ public static function validate($params) { $dataformid = $params['dataformid']; $viewid = $params['viewid']; $df = \mod_dataform_dataform::instance($dataformid); $view = $df->view_manager->get_view_by_id($viewid); // Views manager can access any view in any mode. if (has_capability('mod/dataform:manageviews', $df->context)) { return true; } // Visible/Hidden view. $params['capabilities'] = array('mod/dataform:viewaccess'); if ($view->visible and !parent::validate($params)) { return false; } // Disabled view. $params['capabilities'] = array('mod/dataform:viewaccessdisabled'); if (!$view->visible and !parent::validate($params)) { return false; } // Early access. $params['capabilities'] = array('mod/dataform:viewaccessearly'); if ($df->is_early() and !parent::validate($params)) { return false; } // Late access. $params['capabilities'] = array('mod/dataform:viewaccesslate'); if ($df->is_past_due() and !parent::validate($params)) { return false; } return true; }
/** * Validates that current user can view the field content. * * @return bool */ public static function validate($params) { global $USER; $dataformid = $params['dataformid']; $df = \mod_dataform_dataform::instance($dataformid); // Must have fieldid. if (empty($params['fieldid'])) { return false; } $field = $df->field_manager->get_field_by_id($params['fieldid']); $params['field'] = $field; // Must have entry. $entry = $params['entry']; // Get blank instance for new entries. if ($entry->id < 0) { $entry = \mod_dataform\pluginbase\dataformentry::blank_instance($df); } if ($field->visible != $field::VISIBLE_ALL) { // Entry managers can access any field. if (!($canmanageentries = has_capability('mod/dataform:manageentries', $field->df->context))) { if ($field->visible == $field::VISIBLE_NONE) { return false; } $userid = !empty($entry->userid) ? $entry->userid : 0; $isentryowner = $USER->id == $userid; if ($field->visible == $field::VISIBLE_OWNER and !$isentryowner) { return false; } } } // Early access. if ($df->is_early()) { $params['capabilities'] = array('mod/dataform:entryearlyview'); if (!parent::validate($params)) { return false; } } // Late access. if ($df->is_past_due()) { $params['capabilities'] = array('mod/dataform:entrylateview'); if (!parent::validate($params)) { return false; } } // Own entry. if (\mod_dataform\pluginbase\dataformentry::is_own($entry)) { $params['capabilities'] = array('mod/dataform:entryownview'); return parent::validate($params); } // Group entry. if (\mod_dataform\pluginbase\dataformentry::is_grouped($entry)) { $params['capabilities'] = array('mod/dataform:entrygroupview'); return parent::validate($params); } // Anonymous entry. if (\mod_dataform\pluginbase\dataformentry::is_anonymous($entry)) { $params['capabilities'] = array('mod/dataform:entryanonymousview'); return parent::validate($params); } // Any entry. if (\mod_dataform\pluginbase\dataformentry::is_others($entry)) { $params['capabilities'] = array('mod/dataform:entryanyview'); return parent::validate($params); } return false; }
/** * @return bool */ public static function validate($params) { $dataformid = $params['dataformid']; $df = \mod_dataform_dataform::instance($dataformid); // Must have fieldid. if (empty($params['fieldid'])) { return false; } $field = $df->field_manager->get_field_by_id($params['fieldid']); $params['field'] = $field; if (!$field->editable and !has_capability('mod/dataform:manageentries', $field->df->context)) { return false; } // Must have entry. $entry = $params['entry']; // Get blank instance for new entries. if ($entry->id < 0) { $entry = \mod_dataform\pluginbase\dataformentry::blank_instance($df); } // Early access. if ($df->is_early()) { $params['capabilities'] = array('mod/dataform:entryearlyupdate'); if (!parent::validate($params)) { return false; } } // Late access. if ($df->is_past_due()) { $params['capabilities'] = array('mod/dataform:entrylateupdate'); if (!parent::validate($params)) { return false; } } // Own entry. if (\mod_dataform\pluginbase\dataformentry::is_own($entry)) { $params['capabilities'] = array('mod/dataform:entryownupdate'); return parent::validate($params); } // Group entry. if (\mod_dataform\pluginbase\dataformentry::is_grouped($entry)) { $params['capabilities'] = array('mod/dataform:entrygroupupdate'); return parent::validate($params); } // Anonymous entry. if (\mod_dataform\pluginbase\dataformentry::is_anonymous($entry)) { $params['capabilities'] = array('mod/dataform:entryanonymousupdate'); return parent::validate($params); } // Any entry. if (\mod_dataform\pluginbase\dataformentry::is_others($entry)) { $params['capabilities'] = array('mod/dataform:entryanyupdate'); return parent::validate($params); } return false; }