Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Privacy Subsystem implementation for mod_forum.
19
 *
20
 * @package    mod_forum
21
 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_forum\privacy;
26
 
27
use \core_privacy\request\approved_contextlist;
28
use \core_privacy\request\writer;
29
use \core_privacy\metadata\item_collection;
30
 
31
defined('MOODLE_INTERNAL') || die();
32
 
33
/**
34
 * Subcontext helper trait.
35
 *
36
 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
trait subcontext_info {
40
    /**
41
     * Get the discussion part of the subcontext.
42
     *
43
     * @param   \stdClass   $discussion The discussion
44
     * @return  array
45
     */
46
    protected static function get_discussion_area(\stdClass $discussion): Array {
47
        $pathparts = [];
48
        if (!empty($discussion->groupname)) {
49
            $pathparts[] = get_string('groups');
50
            $pathparts[] = $discussion->groupname;
51
        }
52
 
53
        $parts = [
54
            $discussion->id,
55
            $discussion->name,
56
        ];
57
 
58
        $discussionname = implode('-', $parts);
59
 
60
        $pathparts[] = get_string('discussions', 'mod_forum');
61
        $pathparts[] = $discussionname;
62
 
63
        return $pathparts;
64
    }
65
 
66
    /**
67
     * Get the post part of the subcontext.
68
     *
69
     * @param   \stdClass   $post The post.
70
     * @return  array
71
     */
72
    protected static function get_post_area(\stdClass $post): Array {
73
        $parts = [
74
            $post->created,
75
            $post->subject,
76
            $post->id,
77
        ];
78
        $area[] = implode('-', $parts);
79
 
80
        return $area;
81
    }
82
 
83
    /**
84
     * Get the parent subcontext for the supplied forum, discussion, and post combination.
85
     *
86
     * @param   \stdClass   $post The post.
87
     * @return  array
88
     */
89
    protected static function get_post_area_for_parent(\stdClass $post) {
90
        global $DB;
91
 
92
        $subcontext = [];
93
        if ($parent = $DB->get_record('forum_posts', ['id' => $post->parent], 'id, created, subject')) {
94
            $subcontext = array_merge($subcontext, static::get_post_area($parent));
95
        }
96
        $subcontext = array_merge($subcontext, static::get_post_area($post));
97
 
98
        return $subcontext;
99
    }
100
 
101
    /**
102
     * Get the subcontext for the supplied forum, discussion, and post combination.
103
     *
104
     * @param   \stdClass   $forum The forum.
105
     * @param   \stdClass   $discussion The discussion
106
     * @param   \stdClass   $post The post.
107
     * @return  array
108
     */
109
    protected static function get_subcontext($forum, $discussion = null, $post = null) {
110
        $subcontext = [];
111
        if (null !== $discussion) {
112
            $subcontext += self::get_discussion_area($discussion);
113
 
114
            if (null !== $post) {
115
                $subcontext[] = get_string('posts', 'mod_forum');
116
                $subcontext = array_merge($subcontext, static::get_post_area_for_parent($post));
117
            }
118
        }
119
 
120
        return $subcontext;
121
 
122
    }
123
}