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_tag\reportbuilder\local\entities;
19
namespace core_tag\reportbuilder\local\entities;
20
 
20
 
21
use context_system;
-
 
22
use core_tag_tag;
-
 
23
use html_writer;
21
use context_system;
-
 
22
use core_tag_tag;
-
 
23
use stdClass;
24
use lang_string;
24
use core\lang_string;
25
use stdClass;
25
use core\output\html_writer;
26
use core_reportbuilder\local\entities\base;
26
use core_reportbuilder\local\entities\base;
27
use core_reportbuilder\local\filters\{boolean_select, date, number, tags};
27
use core_reportbuilder\local\filters\{boolean_select, date, number, tags};
Línea 43... Línea 43...
43
     * @return string[]
43
     * @return string[]
44
     */
44
     */
45
    protected function get_default_tables(): array {
45
    protected function get_default_tables(): array {
46
        return [
46
        return [
47
            'tag',
47
            'tag',
-
 
48
            'tag_instance',
48
        ];
49
        ];
49
    }
50
    }
Línea 50... Línea 51...
50
 
51
 
51
    /**
52
    /**
Línea 83... Línea 84...
83
     * Returns list of all available columns
84
     * Returns list of all available columns
84
     *
85
     *
85
     * @return column[]
86
     * @return column[]
86
     */
87
     */
87
    protected function get_all_columns(): array {
88
    protected function get_all_columns(): array {
88
        global $DB;
-
 
89
 
-
 
90
        $tagalias = $this->get_table_alias('tag');
89
        $tagalias = $this->get_table_alias('tag');
Línea 91... Línea 90...
91
 
90
 
92
        // Name.
91
        // Name.
93
        $columns[] = (new column(
92
        $columns[] = (new column(
94
            'name',
93
            'name',
95
            new lang_string('name', 'core_tag'),
94
            new lang_string('name', 'core_tag'),
96
            $this->get_entity_name()
95
            $this->get_entity_name()
97
        ))
96
        ))
98
            ->add_joins($this->get_joins())
-
 
99
            ->set_type(column::TYPE_TEXT)
97
            ->add_joins($this->get_joins())
100
            ->add_fields("{$tagalias}.rawname, {$tagalias}.name")
98
            ->add_fields("{$tagalias}.rawname, {$tagalias}.name")
101
            ->set_is_sortable(true)
99
            ->set_is_sortable(true)
102
            ->add_callback(static function($rawname, stdClass $tag): string {
100
            ->add_callback(static function($rawname, stdClass $tag): string {
103
                if ($rawname === null) {
101
                if ($rawname === null) {
104
                    return '';
102
                    return '';
105
                }
103
                }
106
                return core_tag_tag::make_display_name($tag);
104
                return core_tag_tag::make_display_name($tag);
Línea -... Línea 105...
-
 
105
            });
-
 
106
 
-
 
107
        // Name with badge.
-
 
108
        $columns[] = (new column(
-
 
109
            'namewithbadge',
-
 
110
            new lang_string('namewithbadge', 'core_tag'),
-
 
111
            $this->get_entity_name()
-
 
112
        ))
-
 
113
            ->add_joins($this->get_joins())
-
 
114
            ->add_fields("{$tagalias}.rawname, {$tagalias}.name, {$tagalias}.flag, {$tagalias}.isstandard")
-
 
115
            ->set_is_sortable(true)
-
 
116
            ->set_aggregation_options('groupconcat', ['separator' => ' '])
-
 
117
            ->set_aggregation_options('groupconcatdistinct', ['separator' => ' '])
-
 
118
            ->add_callback(static function($rawname, stdClass $tag): string {
-
 
119
                if ($rawname === null) {
-
 
120
                    return '';
-
 
121
                }
-
 
122
 
-
 
123
                $displayname = core_tag_tag::make_display_name($tag);
-
 
124
                if ($tag->flag > 0) {
-
 
125
                    $displayname = html_writer::span($displayname, 'flagged-tag');
-
 
126
                }
-
 
127
 
-
 
128
                $class = 'badge bg-info text-white';
-
 
129
                if ($tag->isstandard) {
-
 
130
                    $class .= ' standardtag';
-
 
131
                }
-
 
132
 
-
 
133
                return html_writer::span($displayname, $class);
107
            });
134
            });
108
 
135
 
109
        // Name with link.
136
        // Name with link.
110
        $columns[] = (new column(
137
        $columns[] = (new column(
111
            'namewithlink',
138
            'namewithlink',
112
            new lang_string('namewithlink', 'core_tag'),
139
            new lang_string('namewithlink', 'core_tag'),
113
            $this->get_entity_name()
140
            $this->get_entity_name()
114
        ))
-
 
115
            ->add_joins($this->get_joins())
141
        ))
116
            ->set_type(column::TYPE_TEXT)
142
            ->add_joins($this->get_joins())
117
            ->add_fields("{$tagalias}.rawname, {$tagalias}.name, {$tagalias}.tagcollid")
143
            ->add_fields("{$tagalias}.rawname, {$tagalias}.name, {$tagalias}.tagcollid")
118
            ->set_is_sortable(true)
144
            ->set_is_sortable(true)
119
            ->add_callback(static function($rawname, stdClass $tag): string {
145
            ->add_callback(static function($rawname, stdClass $tag): string {
Línea 123... Línea 149...
123
                return html_writer::link(core_tag_tag::make_url($tag->tagcollid, $tag->rawname),
149
                return html_writer::link(core_tag_tag::make_url($tag->tagcollid, $tag->rawname),
124
                    core_tag_tag::make_display_name($tag));
150
                    core_tag_tag::make_display_name($tag));
125
            });
151
            });
Línea 126... Línea 152...
126
 
152
 
127
        // Description.
-
 
128
        $descriptionfieldsql = "{$tagalias}.description";
-
 
129
        if ($DB->get_dbfamily() === 'oracle') {
-
 
130
            $descriptionfieldsql = $DB->sql_order_by_text($descriptionfieldsql, 1024);
-
 
131
        }
153
        // Description.
132
        $columns[] = (new column(
154
        $columns[] = (new column(
133
            'description',
155
            'description',
134
            new lang_string('tagdescription', 'core_tag'),
156
            new lang_string('tagdescription', 'core_tag'),
135
            $this->get_entity_name()
157
            $this->get_entity_name()
136
        ))
158
        ))
137
            ->add_joins($this->get_joins())
159
            ->add_joins($this->get_joins())
138
            ->set_type(column::TYPE_LONGTEXT)
160
            ->set_type(column::TYPE_LONGTEXT)
139
            ->add_field($descriptionfieldsql, 'description')
161
            ->add_fields("{$tagalias}.description, {$tagalias}.descriptionformat, {$tagalias}.id")
140
            ->add_fields("{$tagalias}.descriptionformat, {$tagalias}.id")
162
            ->set_is_sortable(true)
141
            ->add_callback(static function(?string $description, stdClass $tag): string {
163
            ->add_callback(static function(?string $description, stdClass $tag): string {
142
                global $CFG;
164
                global $CFG;
Línea 143... Línea 165...
143
                require_once("{$CFG->libdir}/filelib.php");
165
                require_once("{$CFG->libdir}/filelib.php");
Línea 172... Línea 194...
172
            $this->get_entity_name()
194
            $this->get_entity_name()
173
        ))
195
        ))
174
            ->add_joins($this->get_joins())
196
            ->add_joins($this->get_joins())
175
            ->set_type(column::TYPE_BOOLEAN)
197
            ->set_type(column::TYPE_BOOLEAN)
176
            ->add_field("CASE WHEN {$tagalias}.flag > 0 THEN 1 ELSE {$tagalias}.flag END", 'flag')
198
            ->add_field("CASE WHEN {$tagalias}.flag > 0 THEN 1 ELSE {$tagalias}.flag END", 'flag')
177
            ->set_is_sortable(true, ["{$tagalias}.flag"])
199
            ->set_is_sortable(true)
178
            ->add_callback([format::class, 'boolean_as_text']);
200
            ->add_callback([format::class, 'boolean_as_text']);
Línea 179... Línea 201...
179
 
201
 
180
        // Flag count.
202
        // Flag count.
181
        $columns[] = (new column(
203
        $columns[] = (new column(
Línea 267... Línea 289...
267
                date::DATE_RANGE,
289
                date::DATE_RANGE,
268
            ]);
290
            ]);
Línea 269... Línea 291...
269
 
291
 
270
        return $filters;
292
        return $filters;
-
 
293
    }
-
 
294
 
-
 
295
    /**
-
 
296
     * Return joins necessary for retrieving tags
-
 
297
     *
-
 
298
     * @param string $component
-
 
299
     * @param string $itemtype
-
 
300
     * @param string $itemidfield
-
 
301
     * @return string[]
-
 
302
     */
-
 
303
    public function get_tag_joins(string $component, string $itemtype, string $itemidfield): array {
-
 
304
        return $this->get_tag_joins_for_entity($component, $itemtype, $itemidfield);
271
    }
305
    }