Proyectos de Subversion Moodle

Rev

Rev 259 | Rev 264 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
177 ariadna 1
<?php
2
require_once(__DIR__ . '/cesa.php');
183 ariadna 3
 
177 ariadna 4
class StaticsBlocks extends Cesa
5
{
261 ariadna 6
 
254 ariadna 7
    public function __construct($title)
177 ariadna 8
    {
255 ariadna 9
        global $USER, $PAGE, $SITE;
10
        require_login(null, false);
11
 
12
        if (isguestuser()) {
13
            throw new require_login_exception('Guests are not allowed here.');
14
        }
15
 
16
        $this->userID = optional_param('userid', $USER->id, PARAM_INT);
17
        $this->currentUser = $this->userID == $USER->id;
18
        $this->user = core_user::get_user($this->userID);
19
        $this->title = get_string($title);
20
        $this->blockManager = $PAGE->blocks;
261 ariadna 21
 
22
        // Definimos varias regiones
23
        $regions = ['side-pre', 'side-post'];
24
 
25
        // Definir los nombres de los bloques
26
        $this->blockNames = ['cesa_course_rating', 'comments', 'messageteacher'];
255 ariadna 27
        $this->blockExists = true;
28
 
29
        if (!$this->user || !core_user::is_real_user($this->userID)) {
30
            throw new moodle_exception('invaliduser', 'error');
31
        }
261 ariadna 32
 
33
        // Asignar los bloques a las dos regiones
34
        foreach ($regions as $region) {
35
            foreach ($this->blockNames as $blockName) {
36
                // Añadir el bloque a la región actual
37
                $this->blockManager->add_block($blockName, $region);
38
            }
39
        }
177 ariadna 40
    }
41
 
187 ariadna 42
    public function renderBlocks()
177 ariadna 43
    {
224 ariadna 44
        global $OUTPUT;
177 ariadna 45
 
183 ariadna 46
        // Añadimos la región si no existe
177 ariadna 47
        $this->addRegion();
48
 
183 ariadna 49
        // Cargamos los bloques existentes
231 ariadna 50
        $this->blockManager->load_blocks(true);
177 ariadna 51
 
183 ariadna 52
        // Validamos si los bloques existen y los agregamos si es necesario
53
        $this->validateIfExistBlocks();
209 ariadna 54
        $this->addBlocksIfNotExist($this->title);
177 ariadna 55
 
187 ariadna 56
        // Renderizamos los bloques en la región específica, sin header ni footer
57
        $blocksView = $OUTPUT->blocks_for_region($this->regionName);
177 ariadna 58
 
187 ariadna 59
        return $blocksView;
177 ariadna 60
    }
61
}
62
 
193 ariadna 63
/* // Instanciamos y renderizamos la página con los bloques estáticos
177 ariadna 64
$statics_blocks = new StaticsBlocks();
193 ariadna 65
echo $statics_blocks->renderBlocks(); */