Proyectos de Subversion Moodle

Rev

Rev 255 | Rev 261 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php
require_once(__DIR__ . '/cesa.php');

class StaticsBlocks extends Cesa
{
    public function __construct($title)
    {
        global $USER, $PAGE, $SITE;
        require_login(null, false);

        if (isguestuser()) {
            throw new require_login_exception('Guests are not allowed here.');
        }

        $this->userID = optional_param('userid', $USER->id, PARAM_INT);
        $this->currentUser = $this->userID == $USER->id;
        $this->user = core_user::get_user($this->userID);
        $this->title = get_string($title);
        $this->blockManager = $PAGE->blocks;
        $this->regionName = 'side-pre'; // Puedes cambiar la región si lo necesitas
        $this->blockNames = ['cesa_course_rating', 'comments', 'mynotes'];
        $this->blockExists = true;

        if (!$this->user || !core_user::is_real_user($this->userID)) {
            throw new moodle_exception('invaliduser', 'error');
        }
    }

    public function renderBlocks()
    {
        global $OUTPUT;

        // Añadimos la región si no existe
        $this->addRegion();

        // Cargamos los bloques existentes
        $this->blockManager->load_blocks(true);

        // Validamos si los bloques existen y los agregamos si es necesario
        $this->validateIfExistBlocks();
        $this->addBlocksIfNotExist($this->title);

        // Renderizamos los bloques en la región específica, sin header ni footer
        $blocksView = $OUTPUT->blocks_for_region($this->regionName);

        return $blocksView;
    }
}

/* // Instanciamos y renderizamos la página con los bloques estáticos
$statics_blocks = new StaticsBlocks();
echo $statics_blocks->renderBlocks(); */