Proyectos de Subversion Moodle

Rev

Rev 261 | Rev 265 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 261 Rev 264
Línea 18... Línea 18...
18
        $this->user = core_user::get_user($this->userID);
18
        $this->user = core_user::get_user($this->userID);
19
        $this->title = get_string($title);
19
        $this->title = get_string($title);
20
        $this->blockManager = $PAGE->blocks;
20
        $this->blockManager = $PAGE->blocks;
Línea 21... Línea 21...
21
 
21
 
22
        // Definimos varias regiones
22
        // Definimos varias regiones
23
        $regions = ['side-pre', 'side-post'];
-
 
24
 
-
 
25
        // Definir los nombres de los bloques
23
        $this->regions = ['side-pre', 'side-post'];
26
        $this->blockNames = ['cesa_course_rating', 'comments', 'messageteacher'];
24
        $this->blockNames = ['cesa_course_rating', 'comments', 'mynotes'];
Línea 27... Línea 25...
27
        $this->blockExists = true;
25
        $this->blockExists = true;
28
 
26
 
29
        if (!$this->user || !core_user::is_real_user($this->userID)) {
27
        if (!$this->user || !core_user::is_real_user($this->userID)) {
Línea 30... Línea 28...
30
            throw new moodle_exception('invaliduser', 'error');
28
            throw new moodle_exception('invaliduser', 'error');
31
        }
29
        }
32
 
30
 
33
        // Asignar los bloques a las dos regiones
31
        // Asignar y validar los bloques en todas las regiones
34
        foreach ($regions as $region) {
32
        foreach ($this->regions as $region) {
35
            foreach ($this->blockNames as $blockName) {
33
            $this->regionName = $region;
36
                // Añadir el bloque a la región actual
34
            $this->addRegion(); // Añadir la región si no existe
37
                $this->blockManager->add_block($blockName, $region);
35
            $this->validateIfExistBlocks(); // Validar si los bloques existen
Línea 38... Línea 36...
38
            }
36
            $this->addBlocksIfNotExist(); // Añadir bloques si no existen
39
        }
37
        }
40
    }
38
    }
Línea -... Línea 39...
-
 
39
 
41
 
40
    public function renderBlocks()
-
 
41
    {
42
    public function renderBlocks()
42
        global $OUTPUT;
-
 
43
 
-
 
44
        $blocksView = '';
-
 
45
        // Renderizar bloques para cada región
Línea 43... Línea 46...
43
    {
46
        foreach ($this->regions as $region) {
44
        global $OUTPUT;
47
            $this->regionName = $region;
Línea -... Línea 48...
-
 
48
            $this->blockManager->load_blocks(true); // Cargar bloques en la región
-
 
49
            $blocksView .= $OUTPUT->blocks_for_region($this->regionName); // Renderizar bloques
45
 
50
        }
46
        // Añadimos la región si no existe
51
 
47
        $this->addRegion();
52
        return $blocksView; // Devolver bloques renderizados
-
 
53
    }
-
 
54
 
Línea 48... Línea 55...
48
 
55
    public function addRegion()
-
 
56
    {
-
 
57
        // Añadir la región si no existe en blockManager
49
        // Cargamos los bloques existentes
58
        if (!in_array($this->regionName, $this->blockManager->get_regions())) {
Línea -... Línea 59...
-
 
59
            $this->blockManager->add_region($this->regionName);
-
 
60
        }
-
 
61
    }
-
 
62
 
-
 
63
    public function validateIfExistBlocks()
-
 
64
    {
-
 
65
        $this->blockExists = true;
-
 
66
        $this->blocks = $this->blockManager->get_blocks_for_region($this->regionName);
-
 
67
 
-
 
68
        foreach ($this->blockNames as $blockName) {
-
 
69
            $blockFound = false;
-
 
70
            foreach ($this->blocks as $block) {
-
 
71
                $blockclass = get_class($block);
-
 
72
                if ($blockclass == 'block_' . $blockName) {
50
        $this->blockManager->load_blocks(true);
73
                    $blockFound = true;
-
 
74
                    break;
-
 
75
                }
-
 
76
            }
-
 
77
            if (!$blockFound) {
-
 
78
                $this->blockExists = false;
-
 
79
                break;
-
 
80
            }
-
 
81
        }
-
 
82
        return $this->blockExists;
51
 
83
    }
52
        // Validamos si los bloques existen y los agregamos si es necesario
84
 
Línea 53... Línea 85...
53
        $this->validateIfExistBlocks();
85
    public function addBlocksIfNotExist($page = 'courses')
54
        $this->addBlocksIfNotExist($this->title);
86
    {