Skip to content

Commit

Permalink
Refactor _editentries variable in view class
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed Dec 16, 2024
1 parent ce24e84 commit 89b9cc9
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 129 deletions.
12 changes: 5 additions & 7 deletions classes/datalynx.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,15 +768,13 @@ public function set_content() {
*
* @throws \coding_exception
*/
public function display() {
public function display(): void {
global $PAGE;
if (!empty($this->_currentview)) {

$event = event\course_module_viewed::create(
array('objectid' => $PAGE->cm->instance, 'context' => $PAGE->context));
$event->add_record_snapshot('course', $PAGE->course);
$event->trigger();

$this->_currentview->display();
}
}
Expand All @@ -787,11 +785,11 @@ public function display() {
*
* @param int $datalynxid The id of the datalynx whose content should be displayed.
* @param int $viewid The id of the datalynx's view whose content should be displayed.
* @param int $eids The id of the datalynx entrie that should be displayed.
* @param ?int $eids The id of the datalynx entrie that should be displayed.
* @param array $options bool skiplogincheck, bool tohtml, string pagelayout.
* @return string
*/
public static function get_content_inline(int $datalynxid, int $viewid = 0, ?int $eids = null, array $options = array('tohtml' => true)) {
public static function get_content_inline(int $datalynxid, int $viewid = 0, ?int $eids = null, array $options = ['tohtml' => true]) {
global $CFG;
require_once($CFG->dirroot . '/mod/datalynx/classes/view/base.php');
$urlparams = new stdClass();
Expand Down Expand Up @@ -843,7 +841,7 @@ public static function get_content_inline(int $datalynxid, int $viewid = 0, ?int
*
* @return array
*/
public function get_internal_fields() {
public function get_internal_fields(): array {
global $CFG;

if (!$this->internalfields) {
Expand All @@ -869,7 +867,7 @@ public function get_internal_fields() {
* Return the names of the internal fields
* @return array
*/
public function get_internal_fields_names() {
public function get_internal_fields_names(): array {
global $CFG;

$fieldplugins = get_list_of_plugins('mod/datalynx/field/');
Expand Down
172 changes: 87 additions & 85 deletions classes/view/base.php

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions entries_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,28 +508,25 @@ public function get_contentinfo(array $fids) {
* Process entries when after editing content for saving into db
*
* @param string $action
* @param string||array $eids
* @param string $eids
* @param null $data
* @param bool $confirmed
* @return array notificationstrings, list of processed ids
* @throws coding_exception
* @throws dml_exception
* @throws moodle_exception
*/
public function process_entries(string $action, $eids, $data = null, bool $confirmed = false): array {
global $DB, $USER, $OUTPUT, $PAGE;
$dl = $this->datalynx;
$errorstring = '';

$entries = array();
$entries = [];
// Some entries may be specified for action.
if ($eids) {
$importentryids = array();
$importentryids = [];
// Adding or updating entries.
if ($action == 'update') {
if (!is_array($eids)) {
// Adding new entries.
if ($eids < 0) {
if ((int)$eids < 0) {
$eids = array_reverse(range($eids, -1));
// Editing existing entries.
} else {
Expand Down Expand Up @@ -746,7 +743,6 @@ public function process_entries(string $action, $eids, $data = null, bool $confi
}
$contents = $newcontents;

global $DB;
// Now update entry and contents TODO: TEAM_CHANGED - check this!
$addorupdate = '';
foreach ($entries as $eid => $entry) {
Expand Down
2 changes: 2 additions & 0 deletions filter/filter_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public function __construct($filterdata) {
}
$this->contentfields = empty($filterdata->contentfields) ? null : $filterdata->contentfields;

// TODO: Make eids string only and then do ? '' instead of null value.
$this->eids = empty($filterdata->eids) ? null : $filterdata->eids;

$this->users = empty($filterdata->users) ? null : $filterdata->users;
$this->groups = empty($filterdata->groups) ? null : $filterdata->groups;
$this->page = empty($filterdata->page) ? 0 : $filterdata->page;
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/fieldgroup_field.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature: Create entry and add fieldgroups
# | select | Select | | Option X,Option Y,Option Z | | |
| teammemberselect | Team member select | 3 | 20 | 1,2,4,8 | |
And I add to "Datalynx Test Instance" datalynx the view of "Grid" type with:
| name | Gridview |
| name | Gridview |
| description | Testgrid |
And I follow "Set as default view"
And I follow "Set as edit view"
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'mod_datalynx';
$plugin->version = 2024091200;
$plugin->version = 2024092000;
$plugin->release = 'v4.6-DataTreasure'; // Data words like data science, data mining.
$plugin->requires = 2022112800;
$plugin->maturity = MATURITY_STABLE;
Expand Down
7 changes: 3 additions & 4 deletions view/csv/view_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function apply_entry_group_layout($entriesset, $name = '') {
/**
* process any view specific actions
*/
public function process_data() {
public function process_data(): void {
global $CFG;

// Proces csv export request.
Expand Down Expand Up @@ -233,15 +233,14 @@ protected function set__patterns() {
/**
* Overridden to show import form without entries
* @param array $options
* @return string|void
* @throws moodle_exception
* @return string
*/
public function display(array $options = []): string {
if ($this->_showimportform) {

$mform = $this->get_import_form();

$tohtml = isset($params['tohtml']) ? $params['tohtml'] : false;
$tohtml = $params['tohtml'] ?? false;
// Print view.
$viewname = 'datalynxview-' . preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $this->name()));
if ($tohtml) {
Expand Down
4 changes: 3 additions & 1 deletion view/csv/view_patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ public function get_replacements($tags = null, $entry = null, array $options = [
}

/**
* @param $checkvisibility
* @return array
*/
protected function patterns($checkvisibility = true) {
protected function patterns($checkvisibility = true): array {
$patterns = parent::patterns($checkvisibility);
$cat = get_string('pluginname', 'datalynxview_csv');
$patterns['##export:all##'] = array(true, $cat);
Expand Down
10 changes: 6 additions & 4 deletions view/pdf/view_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ public function __construct($df = 0, $view = 0) {
/**
* process any view specific actions
*/
public function process_data() {

public function process_data(): void {
// Process pdf export request.
if (optional_param('pdfexportall', 0, PARAM_INT)) {
$this->process_export(self::EXPORT_ALL);
Expand All @@ -151,7 +150,7 @@ public function process_data() {
}

// Do standard view processing.
return parent::process_data();
parent::process_data();
}

/**
Expand Down Expand Up @@ -453,7 +452,7 @@ public function generate_default_view() {
// Fields.
foreach ($fields as $field) {

if ($field->field->id > 0) {
if (is_numeric($field->field->id) && $field->field->id > 0) {
$name = new html_table_cell($field->name() . ':');
$name->style = 'text-align:right;';
if ($field->type == "userinfo") {
Expand All @@ -478,6 +477,9 @@ public function generate_default_view() {
}

/**
* @param $entriesset
* @param $name string
* @return array
*/
protected function apply_entry_group_layout($entriesset, $name = '') {
global $OUTPUT;
Expand Down
2 changes: 1 addition & 1 deletion view/pdf/view_patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function get_replacements($tags = null, $entry = null, array $options = [

/**
*/
protected function patterns($checkvisibility = true) {
protected function patterns($checkvisibility = true): array {
$patterns = parent::patterns($checkvisibility);
$cat = get_string('pluginname', 'datalynxview_pdf');
$patterns['##export:all##'] = array(true, $cat);
Expand Down
8 changes: 0 additions & 8 deletions view/report/view_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ protected function new_entry_definition($entryid = -1) {
return [];
}

/**
* Process any view specific data.
* @return array|bool|mixed
*/
public function process_data() {
return parent::process_data();
}

/**
* @param $fielddefinitions
* @return array
Expand Down
4 changes: 2 additions & 2 deletions view/report/view_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class datalynxview_report_form extends datalynxview_base_form {
*/
public function view_definition_after_gps(): void {
$mform = &$this->_form;

$options = [];
$mform->addElement('header', 'settingshdr', get_string('settings'));

// Report count for this field (only select supported right now: A sum of the values choson for this field is being created.
Expand All @@ -48,7 +48,7 @@ public function view_definition_after_gps(): void {
}
if (!empty($fieldnames)) {
asort($fieldnames);
$options = array('multiple' => false);
$options = ['multiple' => false];
$mform->addElement('autocomplete', 'param1', get_string('fieldtobecounted', 'datalynxview_report'),
$fieldnames, $options);
$mform->addHelpButton('param1', 'fieldtobecounted', 'datalynxview_report');
Expand Down
4 changes: 3 additions & 1 deletion view/report/view_patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ public function get_replacements($tags = null, $entry = null, array $options = [
}

/**
* @param $checkvisibility
* @return array
*/
protected function patterns($checkvisibility = true) {
protected function patterns($checkvisibility = true): array {
$patterns = parent::patterns($checkvisibility);
$cat = get_string('pluginname', 'datalynxview_report');
$patterns['##export:all##'] = array(true, $cat);
Expand Down
6 changes: 3 additions & 3 deletions view/view_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ public function validation($data, $files) {
foreach ($fields['Fields']['Fields'] as $field) {

// Error when we find more than one instance of this tag.
if (substr_count($entryview, $field) > 1) {
if (is_array($field)) {

// Make sure multiple errors are shown.
if (!array_key_exists('eparam2_editor', $errors)) {
$errors['eparam2_editor'] = get_string('viewrepeatedfields', 'datalynx', substr($field, 2, -2));
$errors['eparam2_editor'] = get_string('viewrepeatedfields', 'datalynx', substr($field[0], 2, -2));
} else {
$errors['eparam2_editor'] .= "<br>" . get_string('viewrepeatedfields', 'datalynx', substr($field, 2, -2));
$errors['eparam2_editor'] .= "<br>" . get_string('viewrepeatedfields', 'datalynx', substr($field[0], 2, -2));
}

}
Expand Down
6 changes: 3 additions & 3 deletions view/view_patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ protected function get_userpref_replacements($tag, array $options = null) {
case '##advancedfilter##':
return $this->print_advanced_filter($filter, true);
}
if (strpos($tag, '##customfilter') !== false && !$view->user_is_editing()) {
if (strpos($tag, '##customfilter') !== false && empty($view->user_is_editing())) {
return $this->print_custom_filter($tag, true);
}
}
Expand Down Expand Up @@ -653,7 +653,7 @@ protected function get_viewcontent_replacement(?string $viewname = null): string
* @param boolean $checkvisibility if true only views visible to user are considered
* @return array of tags/patterns
*/
protected function patterns($checkvisibility = true) {
protected function patterns($checkvisibility = true): array {
$patterns = array_merge($this->info_patterns(), $this->ref_patterns($checkvisibility),
$this->userpref_patterns(), $this->action_patterns(), $this->paging_patterns(),
$this->bulkedit_patterns());
Expand Down Expand Up @@ -899,7 +899,7 @@ protected function print_filters_menu($options, $return = false) {
$view = $this->_view;

// If in edit view filters should never be displayed.
if ($view->user_is_editing()) {
if (!empty($view->user_is_editing())) {
return '';
}

Expand Down

0 comments on commit 89b9cc9

Please sign in to comment.