ILIAS  release_4-4 Revision
class.ilCalendarAppointmentColors.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
25 
35 {
36  protected static $colors = array('crs' => array(
37  "#ADD8E6",
38  "#BFEFFF",
39  "#B2DFEE",
40  "#9AC0CD",
41  "#68838B",
42  "#E0FFFF",
43  "#D1EEEE",
44  "#B4CDCD",
45  "#7A8B8B",
46  "#87CEFA",
47  "#B0E2FF",
48  "#A4D3EE",
49  "#8DB6CD",
50  "#607B8B",
51  "#B0C4DE",
52  "#CAE1FF",
53  "#BCD2EE",
54  "#A2B5CD"),
55  'grp' => array(
56  "#EEDD82",
57  "#FFEC8B",
58  "#EEDC82",
59  "#CDBE70",
60  "#8B814C",
61  "#FAFAD2",
62  "#FFFFE0",
63  "#FFF8DC",
64  "#EEEED1",
65  "#CDCDB4"),
66  'sess' => array(
67  "#C1FFC1",
68  "#B4EEB4",
69  "#98FB98",
70  "#90EE90"));
71 
72 
73 
74  protected $db;
75  protected $user_id;
77 
85  public function __construct($a_user_id)
86  {
87  global $ilDB;
88 
89  $this->db = $ilDB;
90 
91  $this->user_id = $a_user_id;
92 
93  $this->categories = ilCalendarCategories::_getInstance();
94  $this->read();
95  }
96 
104  public function getColorByAppointment($a_cal_id)
105  {
106  $cat_id = $this->cat_app_ass[$a_cal_id];
107  $cat_id = $this->cat_substitutions[$cat_id];
108 
109  return isset($this->appointment_colors[$cat_id]) ? $this->appointment_colors[$cat_id] : 'red';
110  }
111 
119  private function read()
120  {
121  global $ilDB;
122 
123  // Store assignment of subitem categories
124  foreach($this->categories->getCategoriesInfo() as $c_data)
125  {
126  if(isset($c_data['subitem_ids']) and count($c_data['subitem_ids']))
127  {
128  foreach($c_data['subitem_ids'] as $sub_item_id)
129  {
130  $this->cat_substitutions[$sub_item_id] = $c_data['cat_id'];
131  }
132 
133  }
134  $this->cat_substitutions[$c_data['cat_id']] = $c_data['cat_id'];
135  }
136 
137  $query = "SELECT cat.cat_id,cat.color, ass.cal_id FROM cal_categories cat ".
138  "JOIN cal_cat_assignments ass ON cat.cat_id = ass.cat_id ".
139  "WHERE ".$ilDB->in('cat.cat_id',$this->categories->getCategories(true),false,'integer');
140 
141  $res = $this->db->query($query);
142  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
143  {
144  $this->appointment_colors[$row->cat_id] = $row->color;
145  $this->cat_app_ass[$row->cal_id] = $row->cat_id;
146  }
147  }
148 
157  public static function _getRandomColorByType($a_type)
158  {
159  return self::$colors[$a_type][rand(0,count(self::$colors[$a_type]) - 1)];
160  }
161 
170  public static function dumpColors()
171  {
172  foreach(self::$colors['grp'] as $color)
173  {
174  echo '<font color="'.$color.'">HALLO</font><br/>';
175  }
176  foreach(self::$colors['crs'] as $color)
177  {
178  echo '<font color="'.$color.'">HALLO</font><br/>';
179  }
180  }
181 
190  public static function _getColorsByType($a_type)
191  {
192  return self::$colors[$a_type];
193  }
194 }
195 ?>
static _getColorsByType($a_type)
get selectable colors
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getColorByAppointment($a_cal_id)
get color by appointment
static _getInstance($a_usr_id=0)
get singleton instance
static _getRandomColorByType($a_type)
get random color entry for type