These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | // This file is part of Moodle - http://moodle.org/ |
||
3 | // |
||
4 | // Moodle is free software: you can redistribute it and/or modify |
||
5 | // it under the terms of the GNU General Public License as published by |
||
6 | // the Free Software Foundation, either version 3 of the License, or |
||
7 | // (at your option) any later version. |
||
8 | // |
||
9 | // Moodle is distributed in the hope that it will be useful, |
||
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | // GNU General Public License for more details. |
||
13 | // |
||
14 | // You should have received a copy of the GNU General Public License |
||
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||
16 | |||
17 | /** |
||
18 | * Relationship listing page |
||
19 | * can be reached by the "Administration" block on category listing |
||
20 | * |
||
21 | * @package local_relationship |
||
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||
23 | */ |
||
24 | |||
25 | require_once(__DIR__.'/../../config.php'); |
||
26 | require($CFG->dirroot.'/local/relationship/lib.php'); |
||
27 | require_once($CFG->dirroot.'/local/relationship/locallib.php'); |
||
28 | |||
29 | require_login(); |
||
30 | $contextid = required_param('contextid', PARAM_INT); |
||
31 | $context = context::instance_by_id($contextid, MUST_EXIST); |
||
32 | require_capability('local/relationship:view', $context); |
||
33 | |||
34 | $page = optional_param('page', 0, PARAM_INT); |
||
35 | $searchquery = optional_param('searchquery', '', PARAM_RAW); |
||
36 | $params = array('page' => $page, 'contextid' => $contextid); |
||
37 | if ($searchquery) { |
||
38 | $params['searchquery'] = $searchquery; |
||
39 | } |
||
40 | $baseurl = new moodle_url('/local/relationship/index.php', $params); |
||
41 | |||
42 | relationship_set_header($context, $baseurl); |
||
43 | relationship_set_title(); |
||
44 | |||
45 | $manager = has_capability('local/relationship:manage', $context); |
||
46 | |||
47 | if ($relationshipid = optional_param('relationshipid', 0, PARAM_INT)) { |
||
48 | $relationship = relationship_get_relationship($relationshipid); |
||
49 | echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); |
||
50 | echo $OUTPUT->heading(get_string('coursesusing', 'local_relationship', $relationship->name), 3, 'main'); |
||
51 | echo html_writer::start_tag('OL'); |
||
52 | foreach (relationship_get_courses($relationshipid) AS $c) { |
||
53 | $link = html_writer::link(new moodle_url('/enrol/instances.php', array('id' => $c->id)), $c->fullname, array('target' => '_new')); |
||
0 ignored issues
–
show
|
|||
54 | echo html_writer::tag('LI', $link); |
||
55 | } |
||
56 | echo html_writer::end_tag('OL'); |
||
57 | echo $OUTPUT->box_end(); |
||
58 | } |
||
59 | |||
60 | $relationships = relationship_search_relationships($contextid, $page, 25, $searchquery); |
||
61 | $count = ''; |
||
62 | if ($relationships['allrelationships'] > 0) { |
||
63 | if ($searchquery === '') { |
||
64 | $count = ' ('.$relationships['allrelationships'].')'; |
||
65 | } else { |
||
66 | $count = ' ('.$relationships['totalrelationships'].'/'.$relationships['allrelationships'].')'; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | // Add search form. |
||
71 | $search = html_writer::start_tag('form', array('id' => 'searchrelationshipquery', 'method' => 'get')); |
||
72 | $search .= html_writer::start_tag('div'); |
||
73 | $search .= html_writer::label(get_string('searchrelationship', 'local_relationship'), 'relationship_search_q'); |
||
74 | $search .= html_writer::empty_tag('input', array('id' => 'relationship_search_q', 'type' => 'text', 'name' => 'searchquery', 'value' => $searchquery)); |
||
0 ignored issues
–
show
|
|||
75 | $search .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('search', 'local_relationship'))); |
||
0 ignored issues
–
show
|
|||
76 | $search .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'contextid', 'value' => $contextid)); |
||
77 | $search .= html_writer::end_tag('div'); |
||
78 | $search .= html_writer::end_tag('form'); |
||
79 | echo $search; |
||
80 | |||
81 | echo $OUTPUT->paging_bar($relationships['totalrelationships'], $page, 25, $baseurl); |
||
82 | |||
83 | $data = array(); |
||
84 | foreach ($relationships['relationships'] as $relationship) { |
||
85 | $line = array(); |
||
86 | |||
87 | $line[] = format_string($relationship->name); |
||
88 | |||
89 | $sql = "SELECT count(DISTINCT rm.userid) |
||
90 | FROM {relationship_groups} rg |
||
91 | JOIN {relationship_members} rm |
||
92 | ON (rm.relationshipgroupid = rg.id) |
||
93 | WHERE rg.relationshipid = :relationshipid"; |
||
94 | $line[] = $DB->count_records_sql($sql, array('relationshipid' => $relationship->id)); |
||
95 | |||
96 | $course_count = $DB->count_records('enrol', array('enrol' => 'relationship', 'customint1' => $relationship->id)); |
||
97 | if ($course_count > 0) { |
||
98 | $url = new moodle_url('/local/relationship/index.php', array('contextid' => $contextid, 'relationshipid' => $relationship->id)); |
||
0 ignored issues
–
show
|
|||
99 | $link = html_writer::link($url, get_string('list', 'local_relationship')); |
||
100 | $line[] = $course_count.' ('.$link.')'; |
||
101 | } else { |
||
102 | $line[] = $course_count; |
||
103 | } |
||
104 | |||
105 | $line[] = implode(', ', $relationship->tags); |
||
106 | $line[] = empty($relationship->component) ? get_string('nocomponent', 'local_relationship') : get_string('pluginname', $relationship->component); |
||
0 ignored issues
–
show
|
|||
107 | |||
108 | $buttons = array(); |
||
109 | if (empty($relationship->component)) { |
||
110 | View Code Duplication | if ($manager) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
111 | if ($course_count == 0) { |
||
112 | $buttons[] = html_writer::link(new moodle_url('/local/relationship/edit.php', array('relationshipid' => $relationship->id, 'delete' => 1)), |
||
0 ignored issues
–
show
|
|||
113 | html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'title' => get_string('delete'), 'class' => 'iconsmall'))); |
||
0 ignored issues
–
show
|
|||
114 | } |
||
115 | $buttons[] = html_writer::link(new moodle_url('/local/relationship/edit.php', array('relationshipid' => $relationship->id)), |
||
0 ignored issues
–
show
|
|||
116 | html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'title' => get_string('edit'), 'class' => 'iconsmall'))); |
||
0 ignored issues
–
show
|
|||
117 | } |
||
118 | } |
||
119 | $buttons[] = html_writer::link(new moodle_url('/local/relationship/cohorts.php', array('relationshipid' => $relationship->id)), |
||
0 ignored issues
–
show
|
|||
120 | html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/cohort'), 'alt' => get_string('cohorts', 'local_relationship'), 'title' => get_string('cohorts', 'local_relationship'), 'class' => 'iconsmall'))); |
||
0 ignored issues
–
show
|
|||
121 | $buttons[] = html_writer::link(new moodle_url('/local/relationship/groups.php', array('relationshipid' => $relationship->id)), |
||
0 ignored issues
–
show
|
|||
122 | html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/groups'), 'alt' => get_string('groups'), 'title' => get_string('groups'), 'class' => 'iconsmall'))); |
||
0 ignored issues
–
show
|
|||
123 | $line[] = implode(' ', $buttons); |
||
124 | |||
125 | $data[] = $line; |
||
126 | } |
||
127 | |||
128 | echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); |
||
129 | echo $OUTPUT->heading(get_string('relationships', 'local_relationship', $count), 3, 'main'); |
||
130 | |||
131 | $table = new html_table(); |
||
132 | $table->head = array( |
||
133 | get_string('name', 'local_relationship'), |
||
134 | get_string('memberscount', 'local_relationship'), |
||
135 | get_string('courses'), |
||
136 | get_string('tags', 'tag'), |
||
137 | get_string('component', 'local_relationship'), |
||
138 | get_string('edit') |
||
139 | ); |
||
140 | $table->colclasses = array('leftalign name', 'leftalign description', 'leftalign size', 'centeralign', 'centeralign source', 'centeralign action'); |
||
0 ignored issues
–
show
|
|||
141 | $table->id = 'relationships'; |
||
142 | $table->attributes['class'] = 'admintable generaltable'; |
||
143 | $table->data = $data; |
||
144 | echo html_writer::table($table); |
||
145 | |||
146 | if ($manager) { |
||
147 | echo $OUTPUT->single_button(new moodle_url('/local/relationship/edit.php', array('contextid' => $context->id)), get_string('add')); |
||
0 ignored issues
–
show
|
|||
148 | } |
||
149 | echo $OUTPUT->box_end(); |
||
150 | |||
151 | echo $OUTPUT->paging_bar($relationships['totalrelationships'], $page, 25, $baseurl); |
||
152 | |||
153 | echo $OUTPUT->footer(); |
||
154 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.