Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 18... Línea 18...
18
 
18
 
Línea 19... Línea 19...
19
namespace core_comment\reportbuilder\local\entities;
19
namespace core_comment\reportbuilder\local\entities;
20
 
20
 
21
use context;
-
 
22
use context_helper;
21
use context;
23
use html_writer;
22
use context_helper;
24
use lang_string;
23
use lang_string;
25
use stdClass;
24
use stdClass;
26
use core_reportbuilder\local\entities\base;
25
use core_reportbuilder\local\entities\base;
Línea 84... Línea 83...
84
     * Returns list of all available columns
83
     * Returns list of all available columns
85
     *
84
     *
86
     * @return column[]
85
     * @return column[]
87
     */
86
     */
88
    protected function get_all_columns(): array {
87
    protected function get_all_columns(): array {
89
        global $DB;
-
 
90
 
-
 
91
        $commentalias = $this->get_table_alias('comments');
88
        $commentalias = $this->get_table_alias('comments');
92
        $contextalias = $this->get_table_alias('context');
89
        $contextalias = $this->get_table_alias('context');
Línea 93... Línea 90...
93
 
90
 
94
        // Content.
-
 
95
        $contentfieldsql = "{$commentalias}.content";
-
 
96
        if ($DB->get_dbfamily() === 'oracle') {
-
 
97
            $contentfieldsql = $DB->sql_order_by_text($contentfieldsql, 1024);
-
 
98
        }
91
        // Content.
99
        $columns[] = (new column(
92
        $columns[] = (new column(
100
            'content',
93
            'content',
101
            new lang_string('content'),
94
            new lang_string('content'),
102
            $this->get_entity_name()
95
            $this->get_entity_name()
103
        ))
96
        ))
104
            ->add_joins($this->get_joins())
97
            ->add_joins($this->get_joins())
105
            ->set_type(column::TYPE_LONGTEXT)
98
            ->set_type(column::TYPE_LONGTEXT)
106
            ->add_join($this->get_context_join())
-
 
107
            ->add_field($contentfieldsql, 'content')
99
            ->add_join($this->get_context_join())
108
            ->add_fields("{$commentalias}.format, {$commentalias}.contextid, " .
100
            ->add_fields("{$commentalias}.content, {$commentalias}.format, {$commentalias}.contextid")
-
 
101
            ->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
109
                context_helper::get_preload_record_columns_sql($contextalias))
102
            ->set_is_sortable(true)
110
            ->add_callback(static function($content, stdClass $comment): string {
103
            ->add_callback(static function($content, stdClass $comment): string {
111
                if ($content === null) {
104
                if ($content === null) {
112
                    return '';
105
                    return '';
Línea 116... Línea 109...
116
                $context = context::instance_by_id($comment->contextid);
109
                $context = context::instance_by_id($comment->contextid);
Línea 117... Línea 110...
117
 
110
 
118
                return format_text($content, $comment->format, ['context' => $context]);
111
                return format_text($content, $comment->format, ['context' => $context]);
Línea 119... Línea -...
119
            });
-
 
120
 
-
 
121
        // Context.
-
 
122
        $columns[] = (new column(
-
 
123
            'context',
-
 
124
            new lang_string('context'),
-
 
125
            $this->get_entity_name()
-
 
126
        ))
-
 
127
            ->add_joins($this->get_joins())
-
 
128
            ->set_type(column::TYPE_TEXT)
-
 
129
            ->add_join($this->get_context_join())
-
 
130
            ->add_fields("{$commentalias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias))
-
 
131
            // Sorting may not order alphabetically, but will at least group contexts together.
-
 
132
            ->set_is_sortable(true)
-
 
133
            ->set_is_deprecated('See \'context:name\' for replacement')
-
 
134
            ->add_callback(static function($contextid, stdClass $context): string {
-
 
135
                if ($contextid === null) {
-
 
136
                    return '';
-
 
137
                }
-
 
138
 
-
 
139
                context_helper::preload_from_record($context);
-
 
140
                return context::instance_by_id($contextid)->get_context_name();
-
 
141
            });
-
 
142
 
-
 
143
        // Context URL.
-
 
144
        $columns[] = (new column(
-
 
145
            'contexturl',
-
 
146
            new lang_string('contexturl'),
-
 
147
            $this->get_entity_name()
-
 
148
        ))
-
 
149
            ->add_joins($this->get_joins())
-
 
150
            ->set_type(column::TYPE_TEXT)
-
 
151
            ->add_join($this->get_context_join())
-
 
152
            ->add_fields("{$commentalias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias))
-
 
153
            // Sorting may not order alphabetically, but will at least group contexts together.
-
 
154
            ->set_is_sortable(true)
-
 
155
            ->set_is_deprecated('See \'context:link\' for replacement')
-
 
156
            ->add_callback(static function($contextid, stdClass $context): string {
-
 
157
                if ($contextid === null) {
-
 
158
                    return '';
-
 
159
                }
-
 
160
 
-
 
161
                context_helper::preload_from_record($context);
-
 
162
                $context = context::instance_by_id($contextid);
-
 
163
 
-
 
164
                return html_writer::link($context->get_url(), $context->get_context_name());
-
 
165
            });
112
            });
166
 
113
 
167
        // Component.
114
        // Component.
168
        $columns[] = (new column(
115
        $columns[] = (new column(
169
            'component',
116
            'component',
Línea 191... Línea 138...
191
            'itemid',
138
            'itemid',
192
            new lang_string('pluginitemid'),
139
            new lang_string('pluginitemid'),
193
            $this->get_entity_name()
140
            $this->get_entity_name()
194
        ))
141
        ))
195
            ->add_joins($this->get_joins())
142
            ->add_joins($this->get_joins())
196
            ->set_type(column::TYPE_INTEGER)
-
 
197
            ->add_fields("{$commentalias}.itemid")
143
            ->add_fields("{$commentalias}.itemid")
198
            ->set_is_sortable(true)
144
            ->set_is_sortable(true);
199
            ->set_disabled_aggregation_all();
-
 
Línea 200... Línea 145...
200
 
145
 
201
        // Time created.
146
        // Time created.
202
        $columns[] = (new column(
147
        $columns[] = (new column(
203
            'timecreated',
148
            'timecreated',
Línea 217... Línea 162...
217
     * Return list of all available filters
162
     * Return list of all available filters
218
     *
163
     *
219
     * @return filter[]
164
     * @return filter[]
220
     */
165
     */
221
    protected function get_all_filters(): array {
166
    protected function get_all_filters(): array {
222
        global $DB;
-
 
223
 
-
 
224
        $commentalias = $this->get_table_alias('comments');
167
        $commentalias = $this->get_table_alias('comments');
Línea 225... Línea 168...
225
 
168
 
226
        // Content.
169
        // Content.
227
        $filters[] = (new filter(
170
        $filters[] = (new filter(
228
            text::class,
171
            text::class,
229
            'content',
172
            'content',
230
            new lang_string('content'),
173
            new lang_string('content'),
231
            $this->get_entity_name(),
174
            $this->get_entity_name(),
232
            $DB->sql_cast_to_char("{$commentalias}.content")
175
            "{$commentalias}.content"
233
        ))
176
        ))
Línea 234... Línea 177...
234
            ->add_joins($this->get_joins());
177
            ->add_joins($this->get_joins());
235
 
178