| 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
 | 
        
           | 271 | ariadna | 23 |         $this->regions = ['side-post'];
 | 
        
           |  |  | 24 |         $this->blockNames = ['cesa_course_rating', 'comments', 'messageteacher', 'mynotes'];
 | 
        
           | 255 | ariadna | 25 |         $this->blockExists = true;
 | 
        
           |  |  | 26 |   | 
        
           |  |  | 27 |         if (!$this->user || !core_user::is_real_user($this->userID)) {
 | 
        
           |  |  | 28 |             throw new moodle_exception('invaliduser', 'error');
 | 
        
           |  |  | 29 |         }
 | 
        
           | 261 | ariadna | 30 |   | 
        
           | 264 | ariadna | 31 |         // Asignar y validar los bloques en todas las regiones
 | 
        
           |  |  | 32 |         foreach ($this->regions as $region) {
 | 
        
           |  |  | 33 |             $this->regionName = $region;
 | 
        
           |  |  | 34 |             $this->addRegion(); // Añadir la región si no existe
 | 
        
           |  |  | 35 |             $this->validateIfExistBlocks(); // Validar si los bloques existen
 | 
        
           |  |  | 36 |             $this->addBlocksIfNotExist(); // Añadir bloques si no existen
 | 
        
           | 261 | ariadna | 37 |         }
 | 
        
           | 177 | ariadna | 38 |     }
 | 
        
           |  |  | 39 |   | 
        
           | 269 | ariadna | 40 |     public function renderBlocks()
 | 
        
           |  |  | 41 |     {
 | 
        
           |  |  | 42 |         global $OUTPUT;
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 |         $blocksView = '';
 | 
        
           |  |  | 45 |         // Renderizar bloques para cada región
 | 
        
           |  |  | 46 |         foreach ($this->regions as $region) {
 | 
        
           |  |  | 47 |             $this->regionName = $region;
 | 
        
           |  |  | 48 |             $this->blockManager->load_blocks(true); // Cargar bloques en la región
 | 
        
           |  |  | 49 |             $blocksView .= $OUTPUT->blocks_for_region($this->regionName); // Renderizar bloques
 | 
        
           |  |  | 50 |         }
 | 
        
           |  |  | 51 |   | 
        
           |  |  | 52 |         return $blocksView; // Devolver bloques renderizados
 | 
        
           |  |  | 53 |     }
 | 
        
           | 177 | ariadna | 54 | }
 | 
        
           |  |  | 55 |   | 
        
           | 269 | ariadna | 56 |   | 
        
           |  |  | 57 |   | 
        
           | 193 | ariadna | 58 | /* // Instanciamos y renderizamos la página con los bloques estáticos
 | 
        
           | 177 | ariadna | 59 | $statics_blocks = new StaticsBlocks();
 | 
        
           | 193 | ariadna | 60 | echo $statics_blocks->renderBlocks(); */
 |