ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCalendarAppointmentColors.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
25 {
26  protected static array $colors = array(
27  'crs' => array(
28  "#ADD8E6",
29  "#BFEFFF",
30  "#B2DFEE",
31  "#9AC0CD",
32  "#475A5F",
33  "#E0FFFF",
34  "#D1EEEE",
35  "#B4CDCD",
36  "#7A8B8B",
37  "#87CEFA",
38  "#B0E2FF",
39  "#A4D3EE",
40  "#8DB6CD",
41  "#607B8B",
42  "#B0C4DE",
43  "#CAE1FF",
44  "#BCD2EE",
45  "#A2B5CD"
46  ),
47  'grp' => array(
48  "#EEDD82",
49  "#FFEC8B",
50  "#EEDC82",
51  "#CDBE70",
52  "#8B814C",
53  "#FAFAD2",
54  "#FFFFE0",
55  "#FFF8DC",
56  "#EEEED1",
57  "#CDCDB4"
58  ),
59  'sess' => array(
60  "#C1FFC1",
61  "#B4EEB4",
62  "#98FB98",
63  "#90EE90"
64  ),
65  'exc' => array(
66  "#BC6F16",
67  "#BA7832",
68  "#B78B4D",
69  "#B59365"
70  ),
71  'tals' => array(
72  "#BC6F16",
73  "#BA7832",
74  "#B78B4D",
75  "#B59365"
76  ),
77  'etal' => array(
78  "#BC6F16",
79  "#BA7832",
80  "#B78B4D",
81  "#B59365"
82  )
83  );
84 
85  protected ilDBInterface $db;
87 
88  private array $appointment_colors = [];
89  private array $cat_substitutions_colors = [];
90  private array $cat_substitutions = [];
91  private array $cat_app_ass = [];
92 
93  public function __construct($a_user_id)
94  {
95  global $DIC;
96 
97  $this->db = $DIC->database();
98  $this->categories = ilCalendarCategories::_getInstance();
99  $this->read();
100  }
101 
108  public function getColorByAppointment($a_cal_id)
109  {
110  $cat_id = $this->cat_app_ass[$a_cal_id];
111  $cat_id = $this->cat_substitutions[$cat_id];
112  #21078
113  if (isset($this->appointment_colors[$cat_id])) {
114  return $this->appointment_colors[$cat_id];
115  } elseif (isset($this->cat_substitutions_colors[$cat_id])) {
116  return $this->cat_substitutions_colors[$cat_id];
117  } else {
118  return 'red';
119  }
120  }
121 
122  private function read()
123  {
124  // Store assignment of subitem categories
125  foreach ($this->categories->getCategoriesInfo() as $c_data) {
126  if (isset($c_data['subitem_ids']) and count($c_data['subitem_ids'])) {
127  foreach ($c_data['subitem_ids'] as $sub_item_id) {
128  $this->cat_substitutions[$sub_item_id] = $c_data['cat_id'];
129  }
130  }
131  $this->cat_substitutions[$c_data['cat_id']] = $c_data['cat_id'];
132  #21078
133  $this->cat_substitutions_colors[$c_data['cat_id']] = $c_data['color'];
134  }
135 
136  $query = "SELECT cat.cat_id,cat.color, ass.cal_id FROM cal_categories cat " .
137  "JOIN cal_cat_assignments ass ON cat.cat_id = ass.cat_id " .
138  "WHERE " . $this->db->in('cat.cat_id', $this->categories->getCategories(true), false, 'integer');
139 
140  $res = $this->db->query($query);
141  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
142  $this->appointment_colors[$row->cat_id] = $row->color;
143  $this->cat_app_ass[$row->cal_id] = $row->cat_id;
144  }
145  }
146 
147  public static function _getRandomColorByType(string $a_type): string
148  {
149  $random = new \Random\Randomizer();
150  return self::$colors[$a_type][$random->getInt(0, count(self::$colors[$a_type]) - 1)];
151  }
152 
156  public static function _getColorsByType(string $a_type): array
157  {
158  return self::$colors[$a_type];
159  }
160 }
class for calendar categories
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
getColorByAppointment($a_cal_id)
get color by appointment public
static _getInstance($a_usr_id=0)
get singleton instance
static _getColorsByType(string $a_type)
get selectable colors