Proyectos de Subversion Moodle

Rev

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

Rev 172 Rev 182
Línea 1... Línea 1...
1
<?php
1
<?php
2
//namespace Cesa;
2
//namespace Cesa;
3
require_once(__DIR__ . '/../config.php');
3
require_once(__DIR__ . '/../config.php');
4
require_once($CFG->libdir . '/navigationlib.php');
4
require_once($CFG->libdir . '/navigationlib.php');
5
require_once($CFG->libdir.'/blocklib.php');
5
require_once($CFG->libdir . '/blocklib.php');
-
 
6
 
6
use \require_login_exception;
7
use \require_login_exception;
7
use \core_user;
8
use \core_user;
8
use \moodle_exception;
9
use \moodle_exception;
9
use \context_user;
10
use \context_user;
Línea 12... Línea 13...
12
 *
13
 *
13
 * Cesa 
14
 * Cesa 
14
 *
15
 *
15
 */
16
 */
Línea 16... Línea 17...
16
 
17
 
-
 
18
class Cesa
Línea 17... Línea 19...
17
class Cesa {
19
{
18
 
20
 
19
	public $user;
21
    public $user;
20
    public $title;
22
    public $title;
21
    public $blocks;
23
    public $blocks;
22
    public $userID;
24
    public $userID;
23
    public $currentUser;
25
    public $currentUser;
24
    public $blockManager;
26
    public $blockManager;
25
    public $blockExists;
27
    public $blockExists;
Línea 26... Línea 28...
26
    public $blockName;
28
    public $blockName;
27
    public $regionName;
29
    public $regionName;
28
 
-
 
29
	public function __construct($title, $blockName, $regionName)
-
 
30
	{
-
 
31
	    
30
 
32
 
31
    public function __construct($title, $blockNames, $regionName)
Línea 33... Línea 32...
33
	    
32
    {
34
		global $USER, $PAGE, $SITE;
33
        global $USER, $PAGE, $SITE;
35
        require_login(null, false);
34
        require_login(null, false);
Línea 42... Línea 41...
42
        $this->currentUser = $this->userID == $USER->id;
41
        $this->currentUser = $this->userID == $USER->id;
43
        $this->user = core_user::get_user($this->userID);
42
        $this->user = core_user::get_user($this->userID);
44
        $this->title = get_string($title);
43
        $this->title = get_string($title);
45
        $this->blockManager = $PAGE->blocks;
44
        $this->blockManager = $PAGE->blocks;
46
        $this->regionName = $regionName;
45
        $this->regionName = $regionName;
47
        $this->blockName = $blockName;
46
        $this->blockNames = is_array($blockNames) ? $blockNames : [$blockNames];
48
        $this->blockExists = true; // habilitar o deshabilitar
47
        $this->blockExists = true;
Línea 49... Línea 48...
49
 
48
 
50
        if (!$this->user || !core_user::is_real_user($this->userID)) {
49
        if (!$this->user || !core_user::is_real_user($this->userID)) {
51
            throw new moodle_exception('invaliduser', 'error');
50
            throw new moodle_exception('invaliduser', 'error');
Línea 52... Línea 51...
52
        }
51
        }
53
 
52
 
54
        $PAGE->set_context(context_user::instance($this->userID));
53
        $PAGE->set_context(context_user::instance($this->userID));
55
        $PAGE->set_pagelayout('mydashboard');
-
 
56
        $PAGE->set_title("{$SITE->shortname}: " . $this->title);
54
        $PAGE->set_pagelayout('mydashboard');
Línea 57... Línea 55...
57
        // $PAGE->navbar->add($this->title);
55
        $PAGE->set_title("{$SITE->shortname}: " . $this->title);
58
	}
56
    }
59
 
57
 
60
	public function addRegion()
58
    public function addRegion()
61
	{
59
    {
62
		if(!in_array($this->regionName, $this->blockManager->get_regions())) {
60
        if (!in_array($this->regionName, $this->blockManager->get_regions())) {
Línea 63... Línea 61...
63
            $this->blockManager->add_region($this->regionName);
61
            $this->blockManager->add_region($this->regionName);
64
        }		
62
        }
65
	}
63
    }
66
 
64
 
-
 
65
    public function validateIfExistBlocks()
-
 
66
    {
67
	public function validateIfExistBlock()
67
        $this->blockExists = true;
68
	{
-
 
69
	    $this->blockExists = false;
68
        $this->blocks = $this->blockManager->get_blocks_for_region($this->regionName);
70
		$this->blocks = $this->blockManager->get_blocks_for_region($this->regionName);
69
        foreach ($this->blockNames as $blockName) {
-
 
70
            $blockFound = false;
-
 
71
            foreach ($this->blocks as $block) {
-
 
72
                $blockclass = get_class($block);
-
 
73
                if ($blockclass == 'block_' . $blockName) {
-
 
74
                    $blockFound = true;
71
        foreach($this->blocks as $key => $block) {
75
                    break;
-
 
76
                }
72
            
77
            }
73
            $blockclass = get_class($block);  
78
            if (!$blockFound) {
74
            if($blockclass == 'block_' . $this->blockName) {
-
 
75
                $this->blockExists = true;
-
 
76
            }
-
 
77
        }
79
                $this->blockExists = false;
78
        
80
                break; // Si un bloque no existe, no es necesario seguir buscando
Línea 79... Línea 81...
79
        
81
            }
80
       
82
        }
81
        return $this->blockExists;
83
        return $this->blockExists;
82
	}
-
 
-
 
84
    }
83
 
85
 
-
 
86
    public function addBlocksIfNotExist($page = 'courses')
84
	public function redirectIfNotExistBlock($page = 'courses')
87
    {
85
	{
88
        if (!$this->blockExists) {
86
	    if(!$this->blockExists) {
89
            foreach ($this->blockNames as $blockName) {
87
		   
90
                $this->blockManager->add_block($blockName, $this->regionName, 1, true);
88
            $this->blockManager->add_block($this->blockName, $this->regionName, 1, true);
91
            }