Proyectos de Subversion Moodle

Rev

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

Rev 271 Rev 279
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
-
 
3
use lbuchs\WebAuthn\Attestation\Format\None;
-
 
4
 
2
require_once(__DIR__ . '/cesa.php');
5
require_once(__DIR__ . '/cesa.php');
Línea 3... Línea 6...
3
 
6
 
4
class StaticsBlocks extends Cesa
7
class StaticsBlocks extends Cesa
Línea 29... Línea 32...
29
        }
32
        }
Línea 30... Línea 33...
30
 
33
 
31
        // Asignar y validar los bloques en todas las regiones
34
        // Asignar y validar los bloques en todas las regiones
32
        foreach ($this->regions as $region) {
35
        foreach ($this->regions as $region) {
-
 
36
            $this->regionName = $region;
33
            $this->regionName = $region;
37
 
-
 
38
            // Añadir la región si no existe
-
 
39
            $this->addRegion($this->regionName);
-
 
40
 
34
            $this->addRegion(); // Añadir la región si no existe
41
            // Validar si los bloques existen
35
            $this->validateIfExistBlocks(); // Validar si los bloques existen
42
            if (!$this->validateIfExistBlocks($this->regionName)) {
-
 
43
                // Añadir bloques si no existen
-
 
44
                $this->addBlocksIfNotExist($this->regionName);
36
            $this->addBlocksIfNotExist(); // Añadir bloques si no existen
45
            }
37
        }
46
        }
Línea -... Línea 47...
-
 
47
    }
-
 
48
 
-
 
49
    public function addRegion($region)
-
 
50
    {
-
 
51
        // Si la región no está presente en el bloque de la página, la añadimos.
-
 
52
        if (!$this->blockManager->region_exists($region)) {
-
 
53
            $this->blockManager->add_region($region);
-
 
54
        }
-
 
55
    }
-
 
56
 
-
 
57
    public function validateIfExistBlocks($region)
-
 
58
    {
-
 
59
        // Obtener los bloques de la región actual.
-
 
60
        $blocks = $this->blockManager->get_blocks_for_region($region);
-
 
61
 
-
 
62
        // Validar si todos los bloques especificados existen en esta región.
-
 
63
        foreach ($this->blockNames as $blockName) {
-
 
64
            $blockFound = false;
-
 
65
            foreach ($blocks as $block) {
-
 
66
                if (get_class($block) == 'block_' . $blockName) {
-
 
67
                    $blockFound = true;
-
 
68
                    break;
-
 
69
                }
-
 
70
            }
-
 
71
            // Si algún bloque no se encuentra, devolvemos false.
-
 
72
            if (!$blockFound) {
-
 
73
                return false;
-
 
74
            }
-
 
75
        }
-
 
76
 
-
 
77
        // Si todos los bloques existen, devolvemos true.
-
 
78
        return true;
-
 
79
    }
-
 
80
 
-
 
81
    public function addBlocksIfNotExist($region)
-
 
82
    {
-
 
83
        // Obtener los bloques de la región actual.
-
 
84
        $blocks = $this->blockManager->get_blocks_for_region($region);
-
 
85
 
-
 
86
        foreach ($this->blockNames as $blockName) {
-
 
87
            $blockFound = false;
-
 
88
 
-
 
89
            // Buscar si el bloque ya está presente en la región.
-
 
90
            foreach ($blocks as $block) {
-
 
91
                if (get_class($block) == 'block_' . $blockName) {
-
 
92
                    $blockFound = true;
-
 
93
                    break;
-
 
94
                }
-
 
95
            }
-
 
96
 
-
 
97
            // Si el bloque no está presente, lo añadimos.
-
 
98
            if (!$blockFound) {
-
 
99
                $this->blockManager->add_block('block_' . $blockName, $region);
-
 
100
            }
-
 
101
        }
-
 
102
    }
38
    }
103
 
39
 
104
 
40
    public function renderBlocks()
105
    public function renderBlocks()
Línea 41... Línea 106...
41
    {
106
    {