1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('Services/WebServices/ECS/classes/class.ilRemoteObjectBase.php');
5
6/**
7* Remote group app class
8*
9* @author Stefan Meyer <meyer@leifos.com>
10* @version $Id$
11*
12* @ingroup ModulesRemoteGroup
13*/
14
15class ilObjRemoteGroup extends ilRemoteObjectBase
16{
17    const DB_TABLE_NAME = "rgrp_settings";
18
19    /** Fixed activation **/
20    const ACTIVATION_OFFLINE = 1;
21    const ACTIVATION_UNLIMITED = 0;
22    const ACTIVATION_LIMITED = 2;
23
24    protected $availability_type;
25    protected $end;
26    protected $start;
27
28    public function initType()
29    {
30        $this->type = "rgrp";
31    }
32
33    protected function getTableName()
34    {
35        return self::DB_TABLE_NAME;
36    }
37
38    protected function getECSObjectType()
39    {
40        return "/campusconnect/groups";
41    }
42
43    /**
44     * Set Availability type
45     *
46     * @param int $a_type availability type
47     */
48    public function setAvailabilityType($a_type)
49    {
50        $this->availability_type = $a_type;
51    }
52
53    /**
54     * get availability type
55     *
56     * @return int
57     */
58    public function getAvailabilityType()
59    {
60        return $this->availability_type;
61    }
62
63    /**
64     * set starting time
65     *
66     * @param timestamp $a_time starting time
67     */
68    public function setStartingTime($a_time)
69    {
70        $this->start = $a_time;
71    }
72
73    /**
74     * get starting time
75     *
76     * @return timestamp
77     */
78    public function getStartingTime()
79    {
80        return $this->start;
81    }
82
83    /**
84     * set ending time
85     *
86     * @param timestamp $a_time ending time
87     */
88    public function setEndingTime($a_time)
89    {
90        $this->end = $a_time;
91    }
92
93    /**
94     * get ending time
95     *
96     * @return timestamp
97     */
98    public function getEndingTime()
99    {
100        return $this->end;
101    }
102
103    /**
104     * Lookup online
105     *
106     * @param int $a_obj_id obj_id
107     * @return bool
108     */
109    public static function _lookupOnline($a_obj_id)
110    {
111        global $ilDB;
112
113        $query = "SELECT * FROM " . self::DB_TABLE_NAME .
114            " WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
115        $res = $ilDB->query($query);
116        $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
117        switch ($row->availability_type) {
118            case self::ACTIVATION_UNLIMITED:
119                return true;
120
121            case self::ACTIVATION_OFFLINE:
122                return false;
123
124            case self::ACTIVATION_LIMITED:
125                return time() > $row->r_start && time < $row->r_end;
126
127            default:
128                return false;
129        }
130
131        return false;
132    }
133
134    protected function doCreateCustomFields(array &$a_fields)
135    {
136        $a_fields["availability_type"] = array("integer", 0);
137        $a_fields["availability_start"] = array("integer", 0);
138        $a_fields["availability_end"] = array("integer", 0);
139    }
140
141    protected function doUpdateCustomFields(array &$a_fields)
142    {
143        $a_fields["availability_type"] = array("integer", $this->getAvailabilityType());
144        $a_fields["availability_start"] = array("integer", (int) $this->getStartingTime());
145        $a_fields["availability_end"] = array("integer", (int) $this->getEndingTime());
146    }
147
148    protected function doReadCustomFields($a_row)
149    {
150        $this->setAvailabilityType($a_row->availability_type);
151        $this->setStartingTime($a_row->availability_start);
152        $this->setEndingTime($a_row->availability_end);
153    }
154
155    protected function updateCustomFromECSContent(ilECSSetting $a_server, $a_ecs_content)
156    {
157        // add custom values
158        // $this->setAvailabilityType($a_ecs_content->status == 'online' ? self::ACTIVATION_UNLIMITED : self::ACTIVATION_OFFLINE);
159
160        // :TODO: ACTIVATION_LIMITED is currently not supported in ECS yet
161    }
162}
163