aboutsummaryrefslogtreecommitdiff
path: root/lib/elearning/PmWikiContentModule.class.php
blob: 06533dda93f730136c5853a5c707a29044b4fdb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO

/*
 * PmWikiContentModule.class.php - Provides access PmWiki Modules
 *
 * Copyright (C) 2006 - Marco Diedrich (mdiedric@uos.de)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */

/**
*
* This class contains methods to handle PmWiki learning modules
*
* @author   Marco Diedrich <mdiedric@uos.de>
* @access   public
* @modulegroup  elearning_interface_modules
* @module       PmWikiContentModule
* @package  ELearning-Interface
*/

class PmWikiContentModule extends ContentModule
{
    public $link;
    public $client;
    public $chdate;
    public $accepted_users;

    /**
    * constructor
    *
    * init class.
    * @access public
    * @param string $module_id module-id
    * @param string $module_type module-type
    * @param string $cms_type system-type
    */

    function __construct($module_id, $module_type, $cms_type)
    {
        parent::__construct($module_id, $module_type, $cms_type);
        $this->link = $GLOBALS['connected_cms'][$this->cms_type]->ABSOLUTE_PATH_ELEARNINGMODULES.$this->id."/";
        $this->client = WebserviceClient::instance( $this->link. '?' .
                                                    $GLOBALS['ELEARNING_INTERFACE_MODULES'][$this->cms_type]['URL_PARAMS'],
                                                    $GLOBALS['ELEARNING_INTERFACE_MODULES'][$this->cms_type]['WEBSERVICE_CLASS']);
    }

    /**
    * reads data for content module
    *
    */

    function readData()
    {
        global $connected_cms, $view, $search_key, $cms_select, $current_module;

        $args = [$GLOBALS['ELEARNING_INTERFACE_MODULES'][$this->cms_type]['soap_data']['api-key'], $this->id];

        $field_data = $connected_cms[$this->cms_type]->client->call('get_field_info', $args);

        $this->title = $field_data['field_title'];
        $this->authors = $field_data['field_author'];
        $this->chdate = $field_data['change_date'];

        $this->accepted_users = $field_data['field_accepted_users'];

        return false;
    }

    /**
    * get permission-status
    *
    * returns true, if operation is allowed
    * @access public
    * @param string $operation operation
    * @return boolean allowed
    */

    function isAllowed($operation)
    {
        global $connected_cms, $view, $search_key, $cms_select, $current_module;

        if (Config::get()->STUDIP_INSTALLATION_ID)
        {
            $username = Config::get()->STUDIP_INSTALLATION_ID."#".$GLOBALS['auth']->auth['uname'];
        } else
        {
            $username = $GLOBALS['auth']->auth['uname'];
        }

        $args = [$GLOBALS['ELEARNING_INTERFACE_MODULES'][$this->cms_type]['soap_data']['api-key'],$this->id, $username];

        $authorized = $connected_cms[$this->cms_type]->client->call('field_accessable_by_user', $args);

        if ($authorized)
        {
            return true;
        } else
        {
            # old authorization
            if (is_array($this->accepted_users) && in_array($username, $this->accepted_users))
                return true;
            else
                return false;
        }

    }
}