Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Agenda often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Agenda, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class Agenda |
||
| 10 | { |
||
| 11 | public $events = array(); |
||
| 12 | /** @var string Current type */ |
||
| 13 | public $type = 'personal'; |
||
| 14 | public $types = array('personal', 'admin', 'course'); |
||
| 15 | public $sessionId = 0; |
||
| 16 | public $senderId; |
||
| 17 | /** @var array */ |
||
| 18 | public $course; |
||
| 19 | /** @var array */ |
||
| 20 | private $sessionInfo; |
||
| 21 | /** @var string */ |
||
| 22 | public $comment; |
||
| 23 | /** @var bool */ |
||
| 24 | private $isAllowedToEdit; |
||
| 25 | public $eventStudentPublicationColor; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Constructor |
||
| 29 | * @param string $type |
||
| 30 | * @param int $senderId Optional The user sender ID |
||
| 31 | * @param int $courseId Opitonal. The course ID |
||
| 32 | * @param int $sessionId Optional The session ID |
||
| 33 | */ |
||
| 34 | public function __construct( |
||
| 35 | $type, |
||
| 36 | $senderId = 0, |
||
| 37 | $courseId = 0, |
||
| 38 | $sessionId = 0 |
||
| 39 | ) { |
||
| 40 | // Table definitions |
||
| 41 | $this->tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); |
||
| 42 | $this->tbl_personal_agenda = Database::get_main_table(TABLE_PERSONAL_AGENDA); |
||
| 43 | $this->tbl_course_agenda = Database::get_course_table(TABLE_AGENDA); |
||
| 44 | $this->table_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT); |
||
| 45 | |||
| 46 | $this->setType($type); |
||
| 47 | $this->setSenderId($senderId ?: api_get_user_id()); |
||
| 48 | $isAllowToEdit = false; |
||
| 49 | |||
| 50 | switch ($type) { |
||
| 51 | case 'course': |
||
| 52 | $sessionId = $sessionId ?: api_get_session_id(); |
||
| 53 | $sessionInfo = api_get_session_info($sessionId); |
||
| 54 | $this->setSessionId($sessionId); |
||
| 55 | $this->setSessionInfo($sessionInfo); |
||
| 56 | |||
| 57 | // Setting the course object if we are in a course |
||
| 58 | $courseInfo = api_get_course_info_by_id($courseId); |
||
| 59 | if (!empty($courseInfo)) { |
||
| 60 | $this->set_course($courseInfo); |
||
| 61 | } |
||
| 62 | |||
| 63 | // Check if teacher |
||
| 64 | if (empty($sessionId)) { |
||
| 65 | $isAllowToEdit = api_is_allowed_to_edit(false, true); |
||
| 66 | } else { |
||
| 67 | $isAllowToEdit = api_is_allowed_to_session_edit( |
||
| 68 | false, |
||
| 69 | true |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Check |
||
| 74 | if (api_get_course_setting('allow_user_edit_agenda') && api_is_allowed_in_course()) { |
||
| 75 | $isAllowToEdit = true; |
||
| 76 | } |
||
| 77 | |||
| 78 | $groupId = api_get_group_id(); |
||
| 79 | if (!empty($groupId)) { |
||
| 80 | $groupInfo = GroupManager::get_group_properties($groupId); |
||
| 81 | $isGroupAccess = GroupManager::user_has_access( |
||
| 82 | api_get_user_id(), |
||
| 83 | $groupInfo['iid'], |
||
| 84 | GroupManager::GROUP_TOOL_CALENDAR |
||
| 85 | ) && |
||
| 86 | GroupManager::is_tutor_of_group( |
||
| 87 | api_get_user_id(), |
||
| 88 | $groupInfo |
||
| 89 | ); |
||
| 90 | if ($isGroupAccess) { |
||
| 91 | $isAllowToEdit = true; |
||
| 92 | } else { |
||
| 93 | $isAllowToEdit = false; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | break; |
||
| 98 | case 'admin': |
||
| 99 | $isAllowToEdit = api_is_platform_admin(); |
||
| 100 | break; |
||
| 101 | case 'personal': |
||
| 102 | $isAllowToEdit = !api_is_anonymous(); |
||
| 103 | break; |
||
| 104 | } |
||
| 105 | |||
| 106 | $this->setIsAllowedToEdit($isAllowToEdit); |
||
|
|
|||
| 107 | $this->events = []; |
||
| 108 | |||
| 109 | // Event colors |
||
| 110 | $this->event_platform_color = 'red'; //red |
||
| 111 | $this->event_course_color = '#458B00'; //green |
||
| 112 | $this->event_group_color = '#A0522D'; //siena |
||
| 113 | $this->event_session_color = '#00496D'; // kind of green |
||
| 114 | $this->eventOtherSessionColor = '#999'; |
||
| 115 | $this->event_personal_color = 'steel blue'; //steel blue |
||
| 116 | $this->eventStudentPublicationColor = '#FF8C00'; //DarkOrange |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @param int $senderId |
||
| 121 | */ |
||
| 122 | public function setSenderId($senderId) |
||
| 123 | { |
||
| 124 | $this->senderId = intval($senderId); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return int |
||
| 129 | */ |
||
| 130 | public function getSenderId() |
||
| 131 | { |
||
| 132 | return $this->senderId; |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param string $type can be 'personal', 'admin' or 'course' |
||
| 137 | */ |
||
| 138 | public function setType($type) |
||
| 139 | { |
||
| 140 | $typeList = $this->getTypes(); |
||
| 141 | if (in_array($type, $typeList)) { |
||
| 142 | $this->type = $type; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @param int $id |
||
| 148 | */ |
||
| 149 | public function setSessionId($id) |
||
| 150 | { |
||
| 151 | $this->sessionId = intval($id); |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param array $sessionInfo |
||
| 156 | */ |
||
| 157 | public function setSessionInfo($sessionInfo) |
||
| 158 | { |
||
| 159 | $this->sessionInfo = $sessionInfo; |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return int $id |
||
| 164 | */ |
||
| 165 | public function getSessionId() |
||
| 166 | { |
||
| 167 | return $this->sessionId; |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param array $courseInfo |
||
| 172 | */ |
||
| 173 | public function set_course($courseInfo) |
||
| 174 | { |
||
| 175 | $this->course = $courseInfo; |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return array |
||
| 180 | */ |
||
| 181 | public function getTypes() |
||
| 182 | { |
||
| 183 | return $this->types; |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Adds an event to the calendar |
||
| 188 | * @param string $start datetime format: 2012-06-14 09:00:00 |
||
| 189 | * @param string $end datetime format: 2012-06-14 09:00:00 |
||
| 190 | * @param string $allDay (true, false) |
||
| 191 | * @param string $title |
||
| 192 | * @param string $content |
||
| 193 | * @param array $usersToSend array('everyone') or a list of user/group ids |
||
| 194 | * @param bool $addAsAnnouncement event as a *course* announcement |
||
| 195 | * @param int $parentEventId |
||
| 196 | * @param array $attachmentArray array of $_FILES[''] |
||
| 197 | * @param array $attachmentCommentList |
||
| 198 | * @param string $eventComment |
||
| 199 | * @param string $color |
||
| 200 | * |
||
| 201 | * @return int |
||
| 202 | */ |
||
| 203 | public function addEvent( |
||
| 204 | $start, |
||
| 205 | $end, |
||
| 206 | $allDay, |
||
| 207 | $title, |
||
| 208 | $content, |
||
| 209 | $usersToSend = array(), |
||
| 210 | $addAsAnnouncement = false, |
||
| 211 | $parentEventId = null, |
||
| 212 | $attachmentArray = array(), |
||
| 213 | $attachmentCommentList = array(), |
||
| 214 | $eventComment = null, |
||
| 215 | $color = '' |
||
| 216 | ) { |
||
| 217 | $start = api_get_utc_datetime($start); |
||
| 218 | $end = api_get_utc_datetime($end); |
||
| 219 | $allDay = isset($allDay) && $allDay === 'true' ? 1 : 0; |
||
| 220 | $id = null; |
||
| 221 | |||
| 222 | switch ($this->type) { |
||
| 223 | case 'personal': |
||
| 224 | $attributes = array( |
||
| 225 | 'user' => api_get_user_id(), |
||
| 226 | 'title' => $title, |
||
| 227 | 'text' => $content, |
||
| 228 | 'date' => $start, |
||
| 229 | 'enddate' => $end, |
||
| 230 | 'all_day' => $allDay, |
||
| 231 | 'color' => $color |
||
| 232 | ); |
||
| 233 | |||
| 234 | $id = Database::insert( |
||
| 235 | $this->tbl_personal_agenda, |
||
| 236 | $attributes |
||
| 237 | ); |
||
| 238 | break; |
||
| 239 | case 'course': |
||
| 240 | $attributes = array( |
||
| 241 | 'title' => $title, |
||
| 242 | 'content' => $content, |
||
| 243 | 'start_date' => $start, |
||
| 244 | 'end_date' => $end, |
||
| 245 | 'all_day' => $allDay, |
||
| 246 | 'session_id' => $this->getSessionId(), |
||
| 247 | 'c_id' => $this->course['real_id'], |
||
| 248 | 'comment' => $eventComment, |
||
| 249 | 'color' => $color |
||
| 250 | ); |
||
| 251 | |||
| 252 | if (!empty($parentEventId)) { |
||
| 253 | $attributes['parent_event_id'] = $parentEventId; |
||
| 254 | } |
||
| 255 | |||
| 256 | $senderId = $this->getSenderId(); |
||
| 257 | $sessionId = $this->getSessionId(); |
||
| 258 | |||
| 259 | // Simple course event. |
||
| 260 | $id = Database::insert($this->tbl_course_agenda, $attributes); |
||
| 261 | |||
| 262 | if ($id) { |
||
| 263 | $sql = "UPDATE ".$this->tbl_course_agenda." SET id = iid WHERE iid = $id"; |
||
| 264 | Database::query($sql); |
||
| 265 | |||
| 266 | $groupId = api_get_group_id(); |
||
| 267 | $groupIid = 0; |
||
| 268 | if ($groupId) { |
||
| 269 | $groupInfo = GroupManager::get_group_properties( |
||
| 270 | $groupId |
||
| 271 | ); |
||
| 272 | if ($groupInfo) { |
||
| 273 | $groupIid = $groupInfo['iid']; |
||
| 274 | } |
||
| 275 | } |
||
| 276 | |||
| 277 | if (!empty($usersToSend)) { |
||
| 278 | $sendTo = $this->parseSendToArray($usersToSend); |
||
| 279 | |||
| 280 | if ($sendTo['everyone']) { |
||
| 281 | api_item_property_update( |
||
| 282 | $this->course, |
||
| 283 | TOOL_CALENDAR_EVENT, |
||
| 284 | $id, |
||
| 285 | 'AgendaAdded', |
||
| 286 | $senderId, |
||
| 287 | $groupIid, |
||
| 288 | '', |
||
| 289 | $start, |
||
| 290 | $end, |
||
| 291 | $sessionId |
||
| 292 | ); |
||
| 293 | api_item_property_update( |
||
| 294 | $this->course, |
||
| 295 | TOOL_CALENDAR_EVENT, |
||
| 296 | $id, |
||
| 297 | 'visible', |
||
| 298 | $senderId, |
||
| 299 | $groupIid, |
||
| 300 | '', |
||
| 301 | $start, |
||
| 302 | $end, |
||
| 303 | $sessionId |
||
| 304 | ); |
||
| 305 | } else { |
||
| 306 | // Storing the selected groups |
||
| 307 | if (!empty($sendTo['groups'])) { |
||
| 308 | foreach ($sendTo['groups'] as $group) { |
||
| 309 | $groupIidItem = 0; |
||
| 310 | if ($group) { |
||
| 311 | $groupInfo = GroupManager::get_group_properties( |
||
| 312 | $group |
||
| 313 | ); |
||
| 314 | if ($groupInfo) { |
||
| 315 | $groupIidItem = $groupInfo['iid']; |
||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | api_item_property_update( |
||
| 320 | $this->course, |
||
| 321 | TOOL_CALENDAR_EVENT, |
||
| 322 | $id, |
||
| 323 | 'AgendaAdded', |
||
| 324 | $senderId, |
||
| 325 | $groupIidItem, |
||
| 326 | 0, |
||
| 327 | $start, |
||
| 328 | $end, |
||
| 329 | $sessionId |
||
| 330 | ); |
||
| 331 | |||
| 332 | api_item_property_update( |
||
| 333 | $this->course, |
||
| 334 | TOOL_CALENDAR_EVENT, |
||
| 335 | $id, |
||
| 336 | 'visible', |
||
| 337 | $senderId, |
||
| 338 | $groupIidItem, |
||
| 339 | 0, |
||
| 340 | $start, |
||
| 341 | $end, |
||
| 342 | $sessionId |
||
| 343 | ); |
||
| 344 | } |
||
| 345 | } |
||
| 346 | |||
| 347 | // storing the selected users |
||
| 348 | if (!empty($sendTo['users'])) { |
||
| 349 | foreach ($sendTo['users'] as $userId) { |
||
| 350 | api_item_property_update( |
||
| 351 | $this->course, |
||
| 352 | TOOL_CALENDAR_EVENT, |
||
| 353 | $id, |
||
| 354 | 'AgendaAdded', |
||
| 355 | $senderId, |
||
| 356 | $groupIid, |
||
| 357 | $userId, |
||
| 358 | $start, |
||
| 359 | $end, |
||
| 360 | $sessionId |
||
| 361 | ); |
||
| 362 | |||
| 363 | api_item_property_update( |
||
| 364 | $this->course, |
||
| 365 | TOOL_CALENDAR_EVENT, |
||
| 366 | $id, |
||
| 367 | 'visible', |
||
| 368 | $senderId, |
||
| 369 | $groupIid, |
||
| 370 | $userId, |
||
| 371 | $start, |
||
| 372 | $end, |
||
| 373 | $sessionId |
||
| 374 | ); |
||
| 375 | } |
||
| 376 | } |
||
| 377 | } |
||
| 378 | } |
||
| 379 | |||
| 380 | // Add announcement. |
||
| 381 | if ($addAsAnnouncement) { |
||
| 382 | $this->storeAgendaEventAsAnnouncement( |
||
| 383 | $id, |
||
| 384 | $usersToSend |
||
| 385 | ); |
||
| 386 | } |
||
| 387 | |||
| 388 | // Add attachment. |
||
| 389 | View Code Duplication | if (isset($attachmentArray) && !empty($attachmentArray)) { |
|
| 390 | $counter = 0; |
||
| 391 | foreach ($attachmentArray as $attachmentItem) { |
||
| 392 | $this->addAttachment( |
||
| 393 | $id, |
||
| 394 | $attachmentItem, |
||
| 395 | $attachmentCommentList[$counter], |
||
| 396 | $this->course |
||
| 397 | ); |
||
| 398 | $counter++; |
||
| 399 | } |
||
| 400 | } |
||
| 401 | } |
||
| 402 | break; |
||
| 403 | case 'admin': |
||
| 404 | if (api_is_platform_admin()) { |
||
| 405 | $attributes = array( |
||
| 406 | 'title' => $title, |
||
| 407 | 'content' => $content, |
||
| 408 | 'start_date' => $start, |
||
| 409 | 'end_date' => $end, |
||
| 410 | 'all_day' => $allDay, |
||
| 411 | 'access_url_id' => api_get_current_access_url_id() |
||
| 412 | ); |
||
| 413 | |||
| 414 | $id = Database::insert( |
||
| 415 | $this->tbl_global_agenda, |
||
| 416 | $attributes |
||
| 417 | ); |
||
| 418 | } |
||
| 419 | break; |
||
| 420 | } |
||
| 421 | |||
| 422 | return $id; |
||
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @param int $eventId |
||
| 427 | * @param int $courseId |
||
| 428 | * |
||
| 429 | * @return array |
||
| 430 | */ |
||
| 431 | public function getRepeatedInfoByEvent($eventId, $courseId) |
||
| 432 | { |
||
| 433 | $repeatTable = Database::get_course_table(TABLE_AGENDA_REPEAT); |
||
| 434 | $eventId = intval($eventId); |
||
| 435 | $courseId = intval($courseId); |
||
| 436 | $sql = "SELECT * FROM $repeatTable |
||
| 437 | WHERE c_id = $courseId AND cal_id = $eventId"; |
||
| 438 | $res = Database::query($sql); |
||
| 439 | $repeatInfo = array(); |
||
| 440 | if (Database::num_rows($res) > 0) { |
||
| 441 | $repeatInfo = Database::fetch_array($res, 'ASSOC'); |
||
| 442 | } |
||
| 443 | |||
| 444 | return $repeatInfo; |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @param int $eventId |
||
| 449 | * @param string $type |
||
| 450 | * @param string $end in local time |
||
| 451 | * @param array $sentTo |
||
| 452 | * |
||
| 453 | * @return bool |
||
| 454 | */ |
||
| 455 | public function addRepeatedItem($eventId, $type, $end, $sentTo = array()) |
||
| 456 | { |
||
| 457 | $t_agenda = Database::get_course_table(TABLE_AGENDA); |
||
| 458 | $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT); |
||
| 459 | |||
| 460 | if (empty($this->course)) { |
||
| 461 | return false; |
||
| 462 | } |
||
| 463 | |||
| 464 | $course_id = $this->course['real_id']; |
||
| 465 | $eventId = intval($eventId); |
||
| 466 | |||
| 467 | $sql = "SELECT title, content, start_date, end_date, all_day |
||
| 468 | FROM $t_agenda |
||
| 469 | WHERE c_id = $course_id AND id = $eventId"; |
||
| 470 | $res = Database::query($sql); |
||
| 471 | |||
| 472 | if (Database::num_rows($res) !== 1) { |
||
| 473 | return false; |
||
| 474 | } |
||
| 475 | |||
| 476 | $row = Database::fetch_array($res); |
||
| 477 | $origStartDate = api_strtotime($row['start_date'], 'UTC'); |
||
| 478 | $origEndDate = api_strtotime($row['end_date'], 'UTC'); |
||
| 479 | $diff = $origEndDate - $origStartDate; |
||
| 480 | |||
| 481 | $title = $row['title']; |
||
| 482 | $content = $row['content']; |
||
| 483 | $allDay = $row['all_day']; |
||
| 484 | |||
| 485 | $now = time(); |
||
| 486 | $type = Database::escape_string($type); |
||
| 487 | $end = api_strtotime($end); |
||
| 488 | |||
| 489 | if (1 <= $end && $end <= 500) { |
||
| 490 | // We assume that, with this type of value, the user actually gives a count of repetitions |
||
| 491 | //and that he wants us to calculate the end date with that (particularly in case of imports from ical) |
||
| 492 | switch ($type) { |
||
| 493 | case 'daily': |
||
| 494 | $end = $origStartDate + (86400 * $end); |
||
| 495 | break; |
||
| 496 | case 'weekly': |
||
| 497 | $end = $this->addWeek($origStartDate, $end); |
||
| 498 | break; |
||
| 499 | case 'monthlyByDate': |
||
| 500 | $end = $this->addMonth($origStartDate, $end); |
||
| 501 | break; |
||
| 502 | case 'monthlyByDay': |
||
| 503 | //TODO |
||
| 504 | break; |
||
| 505 | case 'monthlyByDayR': |
||
| 506 | //TODO |
||
| 507 | break; |
||
| 508 | case 'yearly': |
||
| 509 | $end = $this->addYear($origStartDate, $end); |
||
| 510 | break; |
||
| 511 | } |
||
| 512 | } |
||
| 513 | |||
| 514 | $typeList = array( |
||
| 515 | 'daily', |
||
| 516 | 'weekly', |
||
| 517 | 'monthlyByDate', |
||
| 518 | 'monthlyByDay', |
||
| 519 | 'monthlyByDayR', |
||
| 520 | 'yearly' |
||
| 521 | ); |
||
| 522 | |||
| 523 | // The event has to repeat *in the future*. We don't allow repeated |
||
| 524 | // events in the past |
||
| 525 | if ($end > $now && in_array($type, $typeList)) { |
||
| 526 | $sql = "INSERT INTO $t_agenda_r (c_id, cal_id, cal_type, cal_end) |
||
| 527 | VALUES ($course_id, '$eventId', '$type', '$end')"; |
||
| 528 | Database::query($sql); |
||
| 529 | |||
| 530 | switch ($type) { |
||
| 531 | // @todo improve loop. |
||
| 532 | View Code Duplication | case 'daily': |
|
| 533 | for ($i = $origStartDate + 86400; $i <= $end; $i += 86400) { |
||
| 534 | $start = date('Y-m-d H:i:s', $i); |
||
| 535 | $repeatEnd = date('Y-m-d H:i:s', $i + $diff); |
||
| 536 | $this->addEvent( |
||
| 537 | $start, |
||
| 538 | $repeatEnd, |
||
| 539 | $allDay, |
||
| 540 | $title, |
||
| 541 | $content, |
||
| 542 | $sentTo, |
||
| 543 | false, |
||
| 544 | $eventId |
||
| 545 | ); |
||
| 546 | } |
||
| 547 | break; |
||
| 548 | View Code Duplication | case 'weekly': |
|
| 549 | for ($i = $origStartDate + 604800; $i <= $end; $i += 604800) { |
||
| 550 | $start = date('Y-m-d H:i:s', $i); |
||
| 551 | $repeatEnd = date('Y-m-d H:i:s', $i + $diff); |
||
| 552 | $this->addEvent( |
||
| 553 | $start, |
||
| 554 | $repeatEnd, |
||
| 555 | $allDay, |
||
| 556 | $title, |
||
| 557 | $content, |
||
| 558 | $sentTo, |
||
| 559 | false, |
||
| 560 | $eventId |
||
| 561 | ); |
||
| 562 | } |
||
| 563 | break; |
||
| 564 | View Code Duplication | case 'monthlyByDate': |
|
| 565 | $next_start = $this->addMonth($origStartDate); |
||
| 566 | while ($next_start <= $end) { |
||
| 567 | $start = date('Y-m-d H:i:s', $next_start); |
||
| 568 | $repeatEnd = date('Y-m-d H:i:s', $next_start + $diff); |
||
| 569 | $this->addEvent( |
||
| 570 | $start, |
||
| 571 | $repeatEnd, |
||
| 572 | $allDay, |
||
| 573 | $title, |
||
| 574 | $content, |
||
| 575 | $sentTo, |
||
| 576 | false, |
||
| 577 | $eventId |
||
| 578 | ); |
||
| 579 | $next_start = $this->addMonth($next_start); |
||
| 580 | } |
||
| 581 | break; |
||
| 582 | case 'monthlyByDay': |
||
| 583 | //not yet implemented |
||
| 584 | break; |
||
| 585 | case 'monthlyByDayR': |
||
| 586 | //not yet implemented |
||
| 587 | break; |
||
| 588 | View Code Duplication | case 'yearly': |
|
| 589 | $next_start = $this->addYear($origStartDate); |
||
| 590 | while ($next_start <= $end) { |
||
| 591 | $start = date('Y-m-d H:i:s', $next_start); |
||
| 592 | $repeatEnd = date('Y-m-d H:i:s', $next_start + $diff); |
||
| 593 | $this->addEvent( |
||
| 594 | $start, |
||
| 595 | $repeatEnd, |
||
| 596 | $allDay, |
||
| 597 | $title, |
||
| 598 | $content, |
||
| 599 | $sentTo, |
||
| 600 | false, |
||
| 601 | $eventId |
||
| 602 | ); |
||
| 603 | $next_start = $this->addYear($next_start); |
||
| 604 | } |
||
| 605 | break; |
||
| 606 | } |
||
| 607 | } |
||
| 608 | |||
| 609 | return true; |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @param int $item_id |
||
| 614 | * @param array $sentTo |
||
| 615 | * @return int |
||
| 616 | */ |
||
| 617 | public function storeAgendaEventAsAnnouncement($item_id, $sentTo = array()) |
||
| 618 | { |
||
| 619 | $table_agenda = Database::get_course_table(TABLE_AGENDA); |
||
| 620 | $course_id = api_get_course_int_id(); |
||
| 621 | |||
| 622 | // Check params |
||
| 623 | if (empty($item_id) || $item_id != strval(intval($item_id))) { |
||
| 624 | return -1; |
||
| 625 | } |
||
| 626 | |||
| 627 | // Get the agenda item. |
||
| 628 | $item_id = intval($item_id); |
||
| 629 | $sql = "SELECT * FROM $table_agenda |
||
| 630 | WHERE c_id = $course_id AND id = ".$item_id; |
||
| 631 | $res = Database::query($sql); |
||
| 632 | |||
| 633 | if (Database::num_rows($res) > 0) { |
||
| 634 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 635 | |||
| 636 | // Sending announcement |
||
| 637 | if (!empty($sentTo)) { |
||
| 638 | $id = AnnouncementManager::add_announcement( |
||
| 639 | api_get_course_info(), |
||
| 640 | api_get_session_id(), |
||
| 641 | $row['title'], |
||
| 642 | $row['content'], |
||
| 643 | $sentTo, |
||
| 644 | null, |
||
| 645 | null, |
||
| 646 | $row['end_date'] |
||
| 647 | ); |
||
| 648 | |||
| 649 | AnnouncementManager::sendEmail( |
||
| 650 | api_get_course_info(), |
||
| 651 | api_get_session_id(), |
||
| 652 | $id |
||
| 653 | ); |
||
| 654 | |||
| 655 | return $id; |
||
| 656 | } |
||
| 657 | } |
||
| 658 | |||
| 659 | return -1; |
||
| 660 | } |
||
| 661 | |||
| 662 | /** |
||
| 663 | * Edits an event |
||
| 664 | * |
||
| 665 | * @param int $id |
||
| 666 | * @param string $start datetime format: 2012-06-14 09:00:00 |
||
| 667 | * @param string $end datetime format: 2012-06-14 09:00:00 |
||
| 668 | * @param int $allDay is all day 'true' or 'false' |
||
| 669 | * @param string $title |
||
| 670 | * @param string $content |
||
| 671 | * @param array $usersToSend |
||
| 672 | * @param array $attachmentArray |
||
| 673 | * @param array $attachmentCommentList |
||
| 674 | * @param string $comment |
||
| 675 | * @param string $color |
||
| 676 | * @param bool $addAnnouncement |
||
| 677 | * @param bool $updateContent |
||
| 678 | * @param int $authorId |
||
| 679 | * |
||
| 680 | * @return bool |
||
| 681 | */ |
||
| 682 | public function editEvent( |
||
| 683 | $id, |
||
| 684 | $start, |
||
| 685 | $end, |
||
| 686 | $allDay, |
||
| 687 | $title, |
||
| 688 | $content, |
||
| 689 | $usersToSend = array(), |
||
| 690 | $attachmentArray = array(), |
||
| 691 | $attachmentCommentList = array(), |
||
| 692 | $comment = null, |
||
| 693 | $color = '', |
||
| 694 | $addAnnouncement = false, |
||
| 695 | $updateContent = true, |
||
| 696 | $authorId = 0 |
||
| 697 | ) { |
||
| 698 | $start = api_get_utc_datetime($start); |
||
| 699 | $end = api_get_utc_datetime($end); |
||
| 700 | $allDay = isset($allDay) && $allDay == 'true' ? 1 : 0; |
||
| 701 | $authorId = empty($authorId) ? api_get_user_id() : (int) $authorId; |
||
| 702 | |||
| 703 | switch ($this->type) { |
||
| 704 | case 'personal': |
||
| 705 | $eventInfo = $this->get_event($id); |
||
| 706 | if ($eventInfo['user'] != api_get_user_id()) { |
||
| 707 | break; |
||
| 708 | } |
||
| 709 | $attributes = array( |
||
| 710 | 'title' => $title, |
||
| 711 | 'date' => $start, |
||
| 712 | 'enddate' => $end, |
||
| 713 | 'all_day' => $allDay, |
||
| 714 | |||
| 715 | ); |
||
| 716 | |||
| 717 | if ($updateContent) { |
||
| 718 | $attributes['text'] = $content; |
||
| 719 | } |
||
| 720 | |||
| 721 | if (!empty($color)) { |
||
| 722 | $attributes['color'] = $color; |
||
| 723 | } |
||
| 724 | |||
| 725 | Database::update( |
||
| 726 | $this->tbl_personal_agenda, |
||
| 727 | $attributes, |
||
| 728 | array('id = ?' => $id) |
||
| 729 | ); |
||
| 730 | break; |
||
| 731 | case 'course': |
||
| 732 | $eventInfo = $this->get_event($id); |
||
| 733 | |||
| 734 | if (empty($eventInfo)) { |
||
| 735 | return false; |
||
| 736 | } |
||
| 737 | |||
| 738 | $groupId = api_get_group_id(); |
||
| 739 | $groupIid = 0; |
||
| 740 | if ($groupId) { |
||
| 741 | $groupInfo = GroupManager::get_group_properties($groupId); |
||
| 742 | if ($groupInfo) { |
||
| 743 | $groupIid = $groupInfo['iid']; |
||
| 744 | } |
||
| 745 | } |
||
| 746 | |||
| 747 | $course_id = $this->course['real_id']; |
||
| 748 | |||
| 749 | if (empty($course_id)) { |
||
| 750 | return false; |
||
| 751 | } |
||
| 752 | |||
| 753 | if ($this->getIsAllowedToEdit()) { |
||
| 754 | $attributes = array( |
||
| 755 | 'title' => $title, |
||
| 756 | 'start_date' => $start, |
||
| 757 | 'end_date' => $end, |
||
| 758 | 'all_day' => $allDay, |
||
| 759 | 'comment' => $comment |
||
| 760 | ); |
||
| 761 | |||
| 762 | if ($updateContent) { |
||
| 763 | $attributes['content'] = $content; |
||
| 764 | } |
||
| 765 | |||
| 766 | if (!empty($color)) { |
||
| 767 | $attributes['color'] = $color; |
||
| 768 | } |
||
| 769 | |||
| 770 | Database::update( |
||
| 771 | $this->tbl_course_agenda, |
||
| 772 | $attributes, |
||
| 773 | array( |
||
| 774 | 'id = ? AND c_id = ? AND session_id = ? ' => array( |
||
| 775 | $id, |
||
| 776 | $course_id, |
||
| 777 | $this->sessionId |
||
| 778 | ) |
||
| 779 | ) |
||
| 780 | ); |
||
| 781 | |||
| 782 | if (!empty($usersToSend)) { |
||
| 783 | $sendTo = $this->parseSendToArray($usersToSend); |
||
| 784 | |||
| 785 | $usersToDelete = array_diff( |
||
| 786 | $eventInfo['send_to']['users'], |
||
| 787 | $sendTo['users'] |
||
| 788 | ); |
||
| 789 | $usersToAdd = array_diff( |
||
| 790 | $sendTo['users'], |
||
| 791 | $eventInfo['send_to']['users'] |
||
| 792 | ); |
||
| 793 | |||
| 794 | $groupsToDelete = array_diff( |
||
| 795 | $eventInfo['send_to']['groups'], |
||
| 796 | $sendTo['groups'] |
||
| 797 | ); |
||
| 798 | $groupToAdd = array_diff( |
||
| 799 | $sendTo['groups'], |
||
| 800 | $eventInfo['send_to']['groups'] |
||
| 801 | ); |
||
| 802 | |||
| 803 | if ($sendTo['everyone']) { |
||
| 804 | // Delete all from group |
||
| 805 | if (isset($eventInfo['send_to']['groups']) && |
||
| 806 | !empty($eventInfo['send_to']['groups']) |
||
| 807 | ) { |
||
| 808 | foreach ($eventInfo['send_to']['groups'] as $group) { |
||
| 809 | $groupIidItem = 0; |
||
| 810 | if ($group) { |
||
| 811 | $groupInfo = GroupManager::get_group_properties( |
||
| 812 | $group |
||
| 813 | ); |
||
| 814 | if ($groupInfo) { |
||
| 815 | $groupIidItem = $groupInfo['iid']; |
||
| 816 | } |
||
| 817 | } |
||
| 818 | |||
| 819 | api_item_property_delete( |
||
| 820 | $this->course, |
||
| 821 | TOOL_CALENDAR_EVENT, |
||
| 822 | $id, |
||
| 823 | 0, |
||
| 824 | $groupIidItem, |
||
| 825 | $this->sessionId |
||
| 826 | ); |
||
| 827 | } |
||
| 828 | } |
||
| 829 | |||
| 830 | // Storing the selected users. |
||
| 831 | if (isset($eventInfo['send_to']['users']) && |
||
| 832 | !empty($eventInfo['send_to']['users']) |
||
| 833 | ) { |
||
| 834 | foreach ($eventInfo['send_to']['users'] as $userId) { |
||
| 835 | api_item_property_delete( |
||
| 836 | $this->course, |
||
| 837 | TOOL_CALENDAR_EVENT, |
||
| 838 | $id, |
||
| 839 | $userId, |
||
| 840 | $groupIid, |
||
| 841 | $this->sessionId |
||
| 842 | ); |
||
| 843 | } |
||
| 844 | } |
||
| 845 | |||
| 846 | // Add to everyone only. |
||
| 847 | api_item_property_update( |
||
| 848 | $this->course, |
||
| 849 | TOOL_CALENDAR_EVENT, |
||
| 850 | $id, |
||
| 851 | 'visible', |
||
| 852 | $authorId, |
||
| 853 | $groupIid, |
||
| 854 | null, |
||
| 855 | $start, |
||
| 856 | $end, |
||
| 857 | $this->sessionId |
||
| 858 | ); |
||
| 859 | } else { |
||
| 860 | // Delete "everyone". |
||
| 861 | api_item_property_delete( |
||
| 862 | $this->course, |
||
| 863 | TOOL_CALENDAR_EVENT, |
||
| 864 | $id, |
||
| 865 | 0, |
||
| 866 | 0, |
||
| 867 | $this->sessionId |
||
| 868 | ); |
||
| 869 | |||
| 870 | // Add groups |
||
| 871 | if (!empty($groupToAdd)) { |
||
| 872 | foreach ($groupToAdd as $group) { |
||
| 873 | $groupIidItem = 0; |
||
| 874 | if ($group) { |
||
| 875 | $groupInfo = GroupManager::get_group_properties( |
||
| 876 | $group |
||
| 877 | ); |
||
| 878 | if ($groupInfo) { |
||
| 879 | $groupIidItem = $groupInfo['iid']; |
||
| 880 | } |
||
| 881 | } |
||
| 882 | |||
| 883 | api_item_property_update( |
||
| 884 | $this->course, |
||
| 885 | TOOL_CALENDAR_EVENT, |
||
| 886 | $id, |
||
| 887 | 'visible', |
||
| 888 | $authorId, |
||
| 889 | $groupIidItem, |
||
| 890 | 0, |
||
| 891 | $start, |
||
| 892 | $end, |
||
| 893 | $this->sessionId |
||
| 894 | ); |
||
| 895 | } |
||
| 896 | } |
||
| 897 | |||
| 898 | // Delete groups. |
||
| 899 | if (!empty($groupsToDelete)) { |
||
| 900 | foreach ($groupsToDelete as $group) { |
||
| 901 | $groupIidItem = 0; |
||
| 902 | if ($group) { |
||
| 903 | $groupInfo = GroupManager::get_group_properties( |
||
| 904 | $group |
||
| 905 | ); |
||
| 906 | if ($groupInfo) { |
||
| 907 | $groupIidItem = $groupInfo['iid']; |
||
| 908 | } |
||
| 909 | } |
||
| 910 | |||
| 911 | api_item_property_delete( |
||
| 912 | $this->course, |
||
| 913 | TOOL_CALENDAR_EVENT, |
||
| 914 | $id, |
||
| 915 | 0, |
||
| 916 | $groupIidItem, |
||
| 917 | $this->sessionId |
||
| 918 | ); |
||
| 919 | } |
||
| 920 | } |
||
| 921 | |||
| 922 | // Add users. |
||
| 923 | if (!empty($usersToAdd)) { |
||
| 924 | foreach ($usersToAdd as $userId) { |
||
| 925 | api_item_property_update( |
||
| 926 | $this->course, |
||
| 927 | TOOL_CALENDAR_EVENT, |
||
| 928 | $id, |
||
| 929 | 'visible', |
||
| 930 | $authorId, |
||
| 931 | $groupIid, |
||
| 932 | $userId, |
||
| 933 | $start, |
||
| 934 | $end, |
||
| 935 | $this->sessionId |
||
| 936 | ); |
||
| 937 | } |
||
| 938 | } |
||
| 939 | |||
| 940 | // Delete users. |
||
| 941 | if (!empty($usersToDelete)) { |
||
| 942 | foreach ($usersToDelete as $userId) { |
||
| 943 | api_item_property_delete( |
||
| 944 | $this->course, |
||
| 945 | TOOL_CALENDAR_EVENT, |
||
| 946 | $id, |
||
| 947 | $userId, |
||
| 948 | $groupIid, |
||
| 949 | $this->sessionId |
||
| 950 | ); |
||
| 951 | } |
||
| 952 | } |
||
| 953 | } |
||
| 954 | } |
||
| 955 | |||
| 956 | // Add announcement. |
||
| 957 | if (isset($addAnnouncement) && !empty($addAnnouncement)) { |
||
| 958 | $this->storeAgendaEventAsAnnouncement( |
||
| 959 | $id, |
||
| 960 | $usersToSend |
||
| 961 | ); |
||
| 962 | } |
||
| 963 | |||
| 964 | // Add attachment. |
||
| 965 | View Code Duplication | if (isset($attachmentArray) && !empty($attachmentArray)) { |
|
| 966 | $counter = 0; |
||
| 967 | foreach ($attachmentArray as $attachmentItem) { |
||
| 968 | $this->updateAttachment( |
||
| 969 | $attachmentItem['id'], |
||
| 970 | $id, |
||
| 971 | $attachmentItem, |
||
| 972 | $attachmentCommentList[$counter], |
||
| 973 | $this->course |
||
| 974 | ); |
||
| 975 | $counter++; |
||
| 976 | } |
||
| 977 | } |
||
| 978 | |||
| 979 | return true; |
||
| 980 | } else { |
||
| 981 | return false; |
||
| 982 | } |
||
| 983 | break; |
||
| 984 | case 'admin': |
||
| 985 | case 'platform': |
||
| 986 | if (api_is_platform_admin()) { |
||
| 987 | $attributes = array( |
||
| 988 | 'title' => $title, |
||
| 989 | 'start_date' => $start, |
||
| 990 | 'end_date' => $end, |
||
| 991 | 'all_day' => $allDay |
||
| 992 | ); |
||
| 993 | |||
| 994 | if ($updateContent) { |
||
| 995 | $attributes['content'] = $content; |
||
| 996 | } |
||
| 997 | Database::update( |
||
| 998 | $this->tbl_global_agenda, |
||
| 999 | $attributes, |
||
| 1000 | array('id = ?' => $id) |
||
| 1001 | ); |
||
| 1002 | } |
||
| 1003 | break; |
||
| 1004 | } |
||
| 1005 | } |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * @param int $id |
||
| 1009 | * @param bool $deleteAllItemsFromSerie |
||
| 1010 | */ |
||
| 1011 | public function deleteEvent($id, $deleteAllItemsFromSerie = false) |
||
| 1012 | { |
||
| 1013 | switch ($this->type) { |
||
| 1014 | case 'personal': |
||
| 1015 | $eventInfo = $this->get_event($id); |
||
| 1016 | if ($eventInfo['user'] == api_get_user_id()) { |
||
| 1017 | Database::delete( |
||
| 1018 | $this->tbl_personal_agenda, |
||
| 1019 | array('id = ?' => $id) |
||
| 1020 | ); |
||
| 1021 | } |
||
| 1022 | break; |
||
| 1023 | case 'course': |
||
| 1024 | $course_id = api_get_course_int_id(); |
||
| 1025 | |||
| 1026 | if (!empty($course_id) && api_is_allowed_to_edit(null, true)) { |
||
| 1027 | // Delete |
||
| 1028 | $eventInfo = $this->get_event($id); |
||
| 1029 | if ($deleteAllItemsFromSerie) { |
||
| 1030 | /* This is one of the children. |
||
| 1031 | Getting siblings and delete 'Em all + the father! */ |
||
| 1032 | if (isset($eventInfo['parent_event_id']) && !empty($eventInfo['parent_event_id'])) { |
||
| 1033 | // Removing items. |
||
| 1034 | $events = $this->getAllRepeatEvents( |
||
| 1035 | $eventInfo['parent_event_id'] |
||
| 1036 | ); |
||
| 1037 | if (!empty($events)) { |
||
| 1038 | foreach ($events as $event) { |
||
| 1039 | $this->deleteEvent($event['id']); |
||
| 1040 | } |
||
| 1041 | } |
||
| 1042 | // Removing parent. |
||
| 1043 | $this->deleteEvent($eventInfo['parent_event_id']); |
||
| 1044 | } else { |
||
| 1045 | // This is the father looking for the children. |
||
| 1046 | $events = $this->getAllRepeatEvents($id); |
||
| 1047 | if (!empty($events)) { |
||
| 1048 | foreach ($events as $event) { |
||
| 1049 | $this->deleteEvent($event['id']); |
||
| 1050 | } |
||
| 1051 | } |
||
| 1052 | } |
||
| 1053 | } |
||
| 1054 | |||
| 1055 | // Removing from events. |
||
| 1056 | Database::delete( |
||
| 1057 | $this->tbl_course_agenda, |
||
| 1058 | array('id = ? AND c_id = ?' => array($id, $course_id)) |
||
| 1059 | ); |
||
| 1060 | |||
| 1061 | api_item_property_update( |
||
| 1062 | $this->course, |
||
| 1063 | TOOL_CALENDAR_EVENT, |
||
| 1064 | $id, |
||
| 1065 | 'delete', |
||
| 1066 | api_get_user_id() |
||
| 1067 | ); |
||
| 1068 | |||
| 1069 | // Removing from series. |
||
| 1070 | Database::delete( |
||
| 1071 | $this->table_repeat, |
||
| 1072 | array( |
||
| 1073 | 'cal_id = ? AND c_id = ?' => array( |
||
| 1074 | $id, |
||
| 1075 | $course_id |
||
| 1076 | ) |
||
| 1077 | ) |
||
| 1078 | ); |
||
| 1079 | |||
| 1080 | if (isset($eventInfo['attachment']) && !empty($eventInfo['attachment'])) { |
||
| 1081 | foreach ($eventInfo['attachment'] as $attachment) { |
||
| 1082 | self::deleteAttachmentFile( |
||
| 1083 | $attachment['id'], |
||
| 1084 | $this->course |
||
| 1085 | ); |
||
| 1086 | } |
||
| 1087 | } |
||
| 1088 | } |
||
| 1089 | break; |
||
| 1090 | case 'admin': |
||
| 1091 | if (api_is_platform_admin()) { |
||
| 1092 | Database::delete( |
||
| 1093 | $this->tbl_global_agenda, |
||
| 1094 | array('id = ?' => $id) |
||
| 1095 | ); |
||
| 1096 | } |
||
| 1097 | break; |
||
| 1098 | } |
||
| 1099 | } |
||
| 1100 | |||
| 1101 | /** |
||
| 1102 | * Get agenda events |
||
| 1103 | * @param int $start |
||
| 1104 | * @param int $end |
||
| 1105 | * @param int $course_id |
||
| 1106 | * @param int $groupId |
||
| 1107 | * @param int $user_id |
||
| 1108 | * @param string $format |
||
| 1109 | * |
||
| 1110 | * @return array|string |
||
| 1111 | */ |
||
| 1112 | public function getEvents( |
||
| 1113 | $start, |
||
| 1114 | $end, |
||
| 1115 | $course_id = null, |
||
| 1116 | $groupId = null, |
||
| 1117 | $user_id = 0, |
||
| 1118 | $format = 'json' |
||
| 1119 | ) { |
||
| 1120 | switch ($this->type) { |
||
| 1121 | case 'admin': |
||
| 1122 | $this->getPlatformEvents($start, $end); |
||
| 1123 | break; |
||
| 1124 | case 'course': |
||
| 1125 | $courseInfo = api_get_course_info_by_id($course_id); |
||
| 1126 | |||
| 1127 | // Session coach can see all events inside a session. |
||
| 1128 | if (api_is_coach()) { |
||
| 1129 | // Own course |
||
| 1130 | $this->getCourseEvents( |
||
| 1131 | $start, |
||
| 1132 | $end, |
||
| 1133 | $courseInfo, |
||
| 1134 | $groupId, |
||
| 1135 | $this->sessionId, |
||
| 1136 | $user_id |
||
| 1137 | ); |
||
| 1138 | |||
| 1139 | // Others |
||
| 1140 | $this->getSessionEvents( |
||
| 1141 | $start, |
||
| 1142 | $end, |
||
| 1143 | $this->sessionId, |
||
| 1144 | $user_id, |
||
| 1145 | $this->eventOtherSessionColor |
||
| 1146 | ); |
||
| 1147 | } else { |
||
| 1148 | $this->getCourseEvents( |
||
| 1149 | $start, |
||
| 1150 | $end, |
||
| 1151 | $courseInfo, |
||
| 1152 | $groupId, |
||
| 1153 | $this->sessionId, |
||
| 1154 | $user_id |
||
| 1155 | ); |
||
| 1156 | } |
||
| 1157 | break; |
||
| 1158 | case 'personal': |
||
| 1159 | default: |
||
| 1160 | $sessionFilterActive = false; |
||
| 1161 | if (!empty($this->sessionId)) { |
||
| 1162 | $sessionFilterActive = true; |
||
| 1163 | } |
||
| 1164 | |||
| 1165 | if ($sessionFilterActive == false) { |
||
| 1166 | // Getting personal events |
||
| 1167 | $this->getPersonalEvents($start, $end); |
||
| 1168 | |||
| 1169 | // Getting platform/admin events |
||
| 1170 | $this->getPlatformEvents($start, $end); |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | $ignoreVisibility = api_get_configuration_value('personal_agenda_show_all_session_events'); |
||
| 1174 | |||
| 1175 | // Getting course events |
||
| 1176 | $my_course_list = array(); |
||
| 1177 | if (!api_is_anonymous()) { |
||
| 1178 | $session_list = SessionManager::get_sessions_by_user( |
||
| 1179 | api_get_user_id(), |
||
| 1180 | $ignoreVisibility |
||
| 1181 | |||
| 1182 | ); |
||
| 1183 | $my_course_list = CourseManager::get_courses_list_by_user_id( |
||
| 1184 | api_get_user_id(), |
||
| 1185 | false |
||
| 1186 | ); |
||
| 1187 | } |
||
| 1188 | |||
| 1189 | if (api_is_drh()) { |
||
| 1190 | if (api_drh_can_access_all_session_content()) { |
||
| 1191 | $session_list = array(); |
||
| 1192 | $sessionList = SessionManager::get_sessions_followed_by_drh( |
||
| 1193 | api_get_user_id(), |
||
| 1194 | null, |
||
| 1195 | null, |
||
| 1196 | null, |
||
| 1197 | true, |
||
| 1198 | false |
||
| 1199 | ); |
||
| 1200 | |||
| 1201 | if (!empty($sessionList)) { |
||
| 1202 | foreach ($sessionList as $sessionItem) { |
||
| 1203 | $sessionId = $sessionItem['id']; |
||
| 1204 | $courses = SessionManager::get_course_list_by_session_id( |
||
| 1205 | $sessionId |
||
| 1206 | ); |
||
| 1207 | $sessionInfo = array( |
||
| 1208 | 'session_id' => $sessionId, |
||
| 1209 | 'courses' => $courses |
||
| 1210 | ); |
||
| 1211 | $session_list[] = $sessionInfo; |
||
| 1212 | } |
||
| 1213 | } |
||
| 1214 | } |
||
| 1215 | } |
||
| 1216 | |||
| 1217 | if (!empty($session_list)) { |
||
| 1218 | foreach ($session_list as $session_item) { |
||
| 1219 | if ($sessionFilterActive) { |
||
| 1220 | if ($this->sessionId != $session_item['session_id']) { |
||
| 1221 | continue; |
||
| 1222 | } |
||
| 1223 | } |
||
| 1224 | |||
| 1225 | $my_courses = $session_item['courses']; |
||
| 1226 | $my_session_id = $session_item['session_id']; |
||
| 1227 | |||
| 1228 | if (!empty($my_courses)) { |
||
| 1229 | foreach ($my_courses as $course_item) { |
||
| 1230 | $courseInfo = api_get_course_info_by_id( |
||
| 1231 | $course_item['real_id'] |
||
| 1232 | ); |
||
| 1233 | $this->getCourseEvents( |
||
| 1234 | $start, |
||
| 1235 | $end, |
||
| 1236 | $courseInfo, |
||
| 1237 | 0, |
||
| 1238 | $my_session_id |
||
| 1239 | ); |
||
| 1240 | } |
||
| 1241 | } |
||
| 1242 | } |
||
| 1243 | } |
||
| 1244 | |||
| 1245 | if (!empty($my_course_list) && $sessionFilterActive == false) { |
||
| 1246 | foreach ($my_course_list as $courseInfoItem) { |
||
| 1247 | $courseInfo = api_get_course_info_by_id( |
||
| 1248 | $courseInfoItem['real_id'] |
||
| 1249 | ); |
||
| 1250 | if (isset($course_id) && !empty($course_id)) { |
||
| 1251 | if ($courseInfo['real_id'] == $course_id) { |
||
| 1252 | $this->getCourseEvents( |
||
| 1253 | $start, |
||
| 1254 | $end, |
||
| 1255 | $courseInfo |
||
| 1256 | ); |
||
| 1257 | } |
||
| 1258 | } else { |
||
| 1259 | $this->getCourseEvents( |
||
| 1260 | $start, |
||
| 1261 | $end, |
||
| 1262 | $courseInfo |
||
| 1263 | ); |
||
| 1264 | } |
||
| 1265 | } |
||
| 1266 | } |
||
| 1267 | |||
| 1268 | break; |
||
| 1269 | } |
||
| 1270 | |||
| 1271 | switch ($format) { |
||
| 1272 | case 'json': |
||
| 1273 | if (empty($this->events)) { |
||
| 1274 | return ''; |
||
| 1275 | } |
||
| 1276 | |||
| 1277 | return json_encode($this->events); |
||
| 1278 | break; |
||
| 1279 | case 'array': |
||
| 1280 | if (empty($this->events)) { |
||
| 1281 | return []; |
||
| 1282 | } |
||
| 1283 | |||
| 1284 | return $this->events; |
||
| 1285 | break; |
||
| 1286 | } |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * @param int $id |
||
| 1291 | * @param int $minute_delta |
||
| 1292 | * @return int |
||
| 1293 | */ |
||
| 1294 | public function resizeEvent($id, $minute_delta) |
||
| 1295 | { |
||
| 1296 | $id = (int) $id; |
||
| 1297 | $delta = intval($minute_delta); |
||
| 1298 | $event = $this->get_event($id); |
||
| 1299 | if (!empty($event)) { |
||
| 1300 | switch ($this->type) { |
||
| 1301 | case 'personal': |
||
| 1302 | $sql = "UPDATE $this->tbl_personal_agenda SET |
||
| 1303 | enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE) |
||
| 1304 | WHERE id = ".$id; |
||
| 1305 | Database::query($sql); |
||
| 1306 | break; |
||
| 1307 | View Code Duplication | case 'course': |
|
| 1308 | $sql = "UPDATE $this->tbl_course_agenda SET |
||
| 1309 | end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) |
||
| 1310 | WHERE |
||
| 1311 | c_id = ".$this->course['real_id']." AND |
||
| 1312 | id = ".$id; |
||
| 1313 | Database::query($sql); |
||
| 1314 | break; |
||
| 1315 | case 'admin': |
||
| 1316 | $sql = "UPDATE $this->tbl_global_agenda SET |
||
| 1317 | end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) |
||
| 1318 | WHERE id = ".$id; |
||
| 1319 | Database::query($sql); |
||
| 1320 | break; |
||
| 1321 | } |
||
| 1322 | } |
||
| 1323 | |||
| 1324 | return 1; |
||
| 1325 | } |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * @param int $id |
||
| 1329 | * @param int $minute_delta minutes |
||
| 1330 | * @param int $allDay |
||
| 1331 | * @return int |
||
| 1332 | */ |
||
| 1333 | public function move_event($id, $minute_delta, $allDay) |
||
| 1334 | { |
||
| 1335 | $id = (int) $id; |
||
| 1336 | $event = $this->get_event($id); |
||
| 1337 | |||
| 1338 | if (empty($event)) { |
||
| 1339 | return false; |
||
| 1340 | } |
||
| 1341 | |||
| 1342 | // we convert the hour delta into minutes and add the minute delta |
||
| 1343 | $delta = intval($minute_delta); |
||
| 1344 | $allDay = intval($allDay); |
||
| 1345 | |||
| 1346 | if (!empty($event)) { |
||
| 1347 | switch ($this->type) { |
||
| 1348 | case 'personal': |
||
| 1349 | $sql = "UPDATE $this->tbl_personal_agenda SET |
||
| 1350 | all_day = $allDay, date = DATE_ADD(date, INTERVAL $delta MINUTE), |
||
| 1351 | enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE) |
||
| 1352 | WHERE id=".$id; |
||
| 1353 | Database::query($sql); |
||
| 1354 | break; |
||
| 1355 | View Code Duplication | case 'course': |
|
| 1356 | $sql = "UPDATE $this->tbl_course_agenda SET |
||
| 1357 | all_day = $allDay, |
||
| 1358 | start_date = DATE_ADD(start_date, INTERVAL $delta MINUTE), |
||
| 1359 | end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) |
||
| 1360 | WHERE |
||
| 1361 | c_id = ".$this->course['real_id']." AND |
||
| 1362 | id=".$id; |
||
| 1363 | Database::query($sql); |
||
| 1364 | break; |
||
| 1365 | case 'admin': |
||
| 1366 | $sql = "UPDATE $this->tbl_global_agenda SET |
||
| 1367 | all_day = $allDay, |
||
| 1368 | start_date = DATE_ADD(start_date,INTERVAL $delta MINUTE), |
||
| 1369 | end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) |
||
| 1370 | WHERE id=".$id; |
||
| 1371 | Database::query($sql); |
||
| 1372 | break; |
||
| 1373 | } |
||
| 1374 | } |
||
| 1375 | |||
| 1376 | return 1; |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | /** |
||
| 1380 | * Gets a single event |
||
| 1381 | * |
||
| 1382 | * @param int $id event id |
||
| 1383 | * @return array |
||
| 1384 | */ |
||
| 1385 | public function get_event($id) |
||
| 1386 | { |
||
| 1387 | // make sure events of the personal agenda can only be seen by the user himself |
||
| 1388 | $id = intval($id); |
||
| 1389 | $event = null; |
||
| 1390 | switch ($this->type) { |
||
| 1391 | case 'personal': |
||
| 1392 | $sql = "SELECT * FROM ".$this->tbl_personal_agenda." |
||
| 1393 | WHERE id = $id AND user = ".api_get_user_id(); |
||
| 1394 | $result = Database::query($sql); |
||
| 1395 | View Code Duplication | if (Database::num_rows($result)) { |
|
| 1396 | $event = Database::fetch_array($result, 'ASSOC'); |
||
| 1397 | $event['description'] = $event['text']; |
||
| 1398 | $event['content'] = $event['text']; |
||
| 1399 | $event['start_date'] = $event['date']; |
||
| 1400 | $event['end_date'] = $event['enddate']; |
||
| 1401 | } |
||
| 1402 | break; |
||
| 1403 | case 'course': |
||
| 1404 | if (!empty($this->course['real_id'])) { |
||
| 1405 | $sql = "SELECT * FROM ".$this->tbl_course_agenda." |
||
| 1406 | WHERE c_id = ".$this->course['real_id']." AND id = ".$id; |
||
| 1407 | $result = Database::query($sql); |
||
| 1408 | if (Database::num_rows($result)) { |
||
| 1409 | $event = Database::fetch_array($result, 'ASSOC'); |
||
| 1410 | $event['description'] = $event['content']; |
||
| 1411 | |||
| 1412 | // Getting send to array |
||
| 1413 | $event['send_to'] = $this->getUsersAndGroupSubscribedToEvent( |
||
| 1414 | $id, |
||
| 1415 | $this->course['real_id'], |
||
| 1416 | $this->sessionId |
||
| 1417 | ); |
||
| 1418 | |||
| 1419 | // Getting repeat info |
||
| 1420 | $event['repeat_info'] = $this->getRepeatedInfoByEvent( |
||
| 1421 | $id, |
||
| 1422 | $this->course['real_id'] |
||
| 1423 | ); |
||
| 1424 | |||
| 1425 | if (!empty($event['parent_event_id'])) { |
||
| 1426 | $event['parent_info'] = $this->get_event( |
||
| 1427 | $event['parent_event_id'] |
||
| 1428 | ); |
||
| 1429 | } |
||
| 1430 | |||
| 1431 | $event['attachment'] = $this->getAttachmentList( |
||
| 1432 | $id, |
||
| 1433 | $this->course |
||
| 1434 | ); |
||
| 1435 | } |
||
| 1436 | } |
||
| 1437 | break; |
||
| 1438 | case 'admin': |
||
| 1439 | case 'platform': |
||
| 1440 | $sql = "SELECT * FROM ".$this->tbl_global_agenda." |
||
| 1441 | WHERE id = $id"; |
||
| 1442 | $result = Database::query($sql); |
||
| 1443 | if (Database::num_rows($result)) { |
||
| 1444 | $event = Database::fetch_array($result, 'ASSOC'); |
||
| 1445 | $event['description'] = $event['content']; |
||
| 1446 | } |
||
| 1447 | break; |
||
| 1448 | } |
||
| 1449 | |||
| 1450 | return $event; |
||
| 1451 | } |
||
| 1452 | |||
| 1453 | /** |
||
| 1454 | * Gets personal events |
||
| 1455 | * @param int $start |
||
| 1456 | * @param int $end |
||
| 1457 | * @return array |
||
| 1458 | */ |
||
| 1459 | public function getPersonalEvents($start, $end) |
||
| 1518 | |||
| 1519 | /** |
||
| 1520 | * Get user/group list per event. |
||
| 1521 | * |
||
| 1522 | * @param int $eventId |
||
| 1523 | * @param int $courseId |
||
| 1524 | * @param integer $sessionId |
||
| 1525 | * @paraù int $sessionId |
||
| 1526 | * |
||
| 1527 | * @return array |
||
| 1528 | */ |
||
| 1529 | public function getUsersAndGroupSubscribedToEvent( |
||
| 1588 | |||
| 1589 | /** |
||
| 1590 | * @param int $start |
||
| 1591 | * @param int $end |
||
| 1592 | * @param int $sessionId |
||
| 1593 | * @param int $userId |
||
| 1594 | * @param string $color |
||
| 1595 | * |
||
| 1596 | * @return array |
||
| 1597 | */ |
||
| 1598 | public function getSessionEvents( |
||
| 1599 | $start, |
||
| 1600 | $end, |
||
| 1601 | $sessionId = 0, |
||
| 1602 | $userId = 0, |
||
| 1603 | $color = '' |
||
| 1604 | ) { |
||
| 1605 | $courses = SessionManager::get_course_list_by_session_id($sessionId); |
||
| 1606 | |||
| 1607 | if (!empty($courses)) { |
||
| 1621 | |||
| 1622 | /** |
||
| 1623 | * @param int $start |
||
| 1624 | * @param int $end |
||
| 1625 | * @param array $courseInfo |
||
| 1626 | * @param int $groupId |
||
| 1627 | * @param int $session_id |
||
| 1628 | * @param int $user_id |
||
| 1629 | * @param string $color |
||
| 1630 | * |
||
| 1631 | * @return array |
||
| 1632 | */ |
||
| 1633 | public function getCourseEvents( |
||
| 2006 | |||
| 2007 | /** |
||
| 2008 | * @param int $start tms |
||
| 2009 | * @param int $end tms |
||
| 2010 | * @return array |
||
| 2011 | */ |
||
| 2012 | public function getPlatformEvents($start, $end) |
||
| 2085 | |||
| 2086 | /** |
||
| 2087 | * Format needed for the Fullcalendar js lib |
||
| 2088 | * |
||
| 2089 | * @param string $utcTime |
||
| 2090 | * @return bool|string |
||
| 2091 | */ |
||
| 2092 | private function formatEventDate($utcTime) |
||
| 2102 | |||
| 2103 | /** |
||
| 2104 | * @param FormValidator $form |
||
| 2105 | * @param array $groupList |
||
| 2106 | * @param array $userList |
||
| 2107 | * @param array $sendTo array('users' => [1, 2], 'groups' => [3, 4]) |
||
| 2108 | * @param array $attributes |
||
| 2109 | * @param bool $addOnlyItemsInSendTo |
||
| 2110 | * @param bool $required |
||
| 2111 | */ |
||
| 2112 | public function setSendToSelect( |
||
| 2226 | |||
| 2227 | /** |
||
| 2228 | * Separates the users and groups array |
||
| 2229 | * users have a value USER:XXX (with XXX the user id |
||
| 2230 | * groups have a value GROUP:YYY (with YYY the group id) |
||
| 2231 | * use the 'everyone' key |
||
| 2232 | * @author Julio Montoya based in separate_users_groups in agenda.inc.php |
||
| 2233 | * @param array $to |
||
| 2234 | * @return array |
||
| 2235 | */ |
||
| 2236 | public function parseSendToArray($to) |
||
| 2265 | |||
| 2266 | /** |
||
| 2267 | * @param array $params |
||
| 2268 | * @return FormValidator |
||
| 2269 | */ |
||
| 2270 | public function getForm($params = []) |
||
| 2506 | |||
| 2507 | /** |
||
| 2508 | * @param FormValidator $form |
||
| 2509 | * @param array $sendTo array('everyone' => false, 'users' => [1, 2], 'groups' => [3, 4]) |
||
| 2510 | * @param array $attributes |
||
| 2511 | * @param bool $addOnlyItemsInSendTo |
||
| 2512 | * @param bool $required |
||
| 2513 | * @return bool |
||
| 2514 | */ |
||
| 2515 | public function showToForm( |
||
| 2555 | |||
| 2556 | /** |
||
| 2557 | * @param int $id |
||
| 2558 | * @param int $visibility 0= invisible, 1 visible |
||
| 2559 | * @param array $courseInfo |
||
| 2560 | * @param int $userId |
||
| 2561 | */ |
||
| 2562 | public static function changeVisibility( |
||
| 2593 | |||
| 2594 | /** |
||
| 2595 | * Get repeat types |
||
| 2596 | * @return array |
||
| 2597 | */ |
||
| 2598 | public static function getRepeatTypes() |
||
| 2609 | |||
| 2610 | /** |
||
| 2611 | * Show a list with all the attachments according to the post's id |
||
| 2612 | * @param int $eventId |
||
| 2613 | * @param array $courseInfo |
||
| 2614 | * @return array with the post info |
||
| 2615 | */ |
||
| 2616 | View Code Duplication | public function getAttachmentList($eventId, $courseInfo) |
|
| 2617 | { |
||
| 2618 | $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); |
||
| 2619 | $courseId = intval($courseInfo['real_id']); |
||
| 2620 | $eventId = intval($eventId); |
||
| 2621 | |||
| 2622 | $sql = "SELECT id, path, filename, comment |
||
| 2623 | FROM $tableAttachment |
||
| 2624 | WHERE |
||
| 2625 | c_id = $courseId AND |
||
| 2626 | agenda_id = $eventId"; |
||
| 2627 | $result = Database::query($sql); |
||
| 2628 | $list = array(); |
||
| 2629 | if (Database::num_rows($result) != 0) { |
||
| 2630 | $list = Database::store_result($result, 'ASSOC'); |
||
| 2631 | } |
||
| 2632 | |||
| 2633 | return $list; |
||
| 2634 | } |
||
| 2635 | |||
| 2636 | /** |
||
| 2637 | * Show a list with all the attachments according to the post's id |
||
| 2638 | * @param int $attachmentId |
||
| 2639 | * @param int $eventId |
||
| 2640 | * @param array $courseInfo |
||
| 2641 | * @return array with the post info |
||
| 2642 | */ |
||
| 2643 | View Code Duplication | public function getAttachment($attachmentId, $eventId, $courseInfo) |
|
| 2665 | |||
| 2666 | /** |
||
| 2667 | * Add an attachment file into agenda |
||
| 2668 | * @param int $eventId |
||
| 2669 | * @param array $fileUserUpload ($_FILES['user_upload']) |
||
| 2670 | * @param string $comment about file |
||
| 2671 | * @param array $courseInfo |
||
| 2672 | * @return string |
||
| 2673 | */ |
||
| 2674 | public function addAttachment( |
||
| 2747 | |||
| 2748 | /** |
||
| 2749 | * @param int $attachmentId |
||
| 2750 | * @param int $eventId |
||
| 2751 | * @param array $fileUserUpload |
||
| 2752 | * @param string $comment |
||
| 2753 | * @param array $courseInfo |
||
| 2754 | */ |
||
| 2755 | public function updateAttachment( |
||
| 2772 | |||
| 2773 | /** |
||
| 2774 | * This function delete a attachment file by id |
||
| 2775 | * @param int $attachmentId |
||
| 2776 | * @param array $courseInfo |
||
| 2777 | * @return string |
||
| 2778 | */ |
||
| 2779 | public function deleteAttachmentFile($attachmentId, $courseInfo) |
||
| 2811 | |||
| 2812 | /** |
||
| 2813 | * Adds x weeks to a UNIX timestamp |
||
| 2814 | * @param int The timestamp |
||
| 2815 | * @param int The number of weeks to add |
||
| 2816 | * @param integer $timestamp |
||
| 2817 | * @return int The new timestamp |
||
| 2818 | */ |
||
| 2819 | public function addWeek($timestamp, $num = 1) |
||
| 2823 | |||
| 2824 | /** |
||
| 2825 | * Adds x months to a UNIX timestamp |
||
| 2826 | * @param int The timestamp |
||
| 2827 | * @param int The number of years to add |
||
| 2828 | * @param integer $timestamp |
||
| 2829 | * @return int The new timestamp |
||
| 2830 | */ |
||
| 2831 | public function addMonth($timestamp, $num = 1) |
||
| 2846 | |||
| 2847 | /** |
||
| 2848 | * Adds x years to a UNIX timestamp |
||
| 2849 | * @param int The timestamp |
||
| 2850 | * @param int The number of years to add |
||
| 2851 | * @param integer $timestamp |
||
| 2852 | * @return int The new timestamp |
||
| 2853 | */ |
||
| 2854 | public function addYear($timestamp, $num = 1) |
||
| 2863 | |||
| 2864 | /** |
||
| 2865 | * @param int $eventId |
||
| 2866 | * @return array |
||
| 2867 | */ |
||
| 2868 | public function getAllRepeatEvents($eventId) |
||
| 2892 | |||
| 2893 | /** |
||
| 2894 | * @param int $eventId |
||
| 2895 | * @param int $courseId |
||
| 2896 | * |
||
| 2897 | * @return bool |
||
| 2898 | */ |
||
| 2899 | View Code Duplication | public function hasChildren($eventId, $courseId) |
|
| 2918 | |||
| 2919 | /** |
||
| 2920 | * @param int $filter |
||
| 2921 | * @param string $view |
||
| 2922 | * @return string |
||
| 2923 | */ |
||
| 2924 | public function displayActions($view, $filter = 0) |
||
| 3069 | |||
| 3070 | /** |
||
| 3071 | * @return FormValidator |
||
| 3072 | */ |
||
| 3073 | public function getImportCalendarForm() |
||
| 3092 | |||
| 3093 | /** |
||
| 3094 | * @param array $courseInfo |
||
| 3095 | * @param $file |
||
| 3096 | * @return false|string |
||
| 3097 | */ |
||
| 3098 | public function importEventFile($courseInfo, $file) |
||
| 3227 | |||
| 3228 | /** |
||
| 3229 | * Parse filter turns USER:12 to ['users' => [12])] or G:1 ['groups' => [1]] |
||
| 3230 | * @param integer $filter |
||
| 3231 | * @return array |
||
| 3232 | */ |
||
| 3233 | public function parseAgendaFilter($filter) |
||
| 3258 | |||
| 3259 | /** |
||
| 3260 | * This function retrieves all the agenda items of all the courses the user is subscribed to |
||
| 3261 | */ |
||
| 3262 | public static function get_myagendaitems( |
||
| 3380 | |||
| 3381 | /** |
||
| 3382 | * This function retrieves one personal agenda item returns it. |
||
| 3383 | * @param array The array containing existing events. We add to this array. |
||
| 3384 | * @param int Day |
||
| 3385 | * @param int Month |
||
| 3386 | * @param int Year (4 digits) |
||
| 3387 | * @param int Week number |
||
| 3388 | * @param string Type of view (month_view, week_view, day_view) |
||
| 3389 | * @return array The results of the database query, or null if not found |
||
| 3390 | */ |
||
| 3391 | public static function get_global_agenda_items( |
||
| 3526 | |||
| 3527 | /** |
||
| 3528 | * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions. |
||
| 3529 | */ |
||
| 3530 | public static function get_personal_agenda_items( |
||
| 3646 | |||
| 3647 | |||
| 3648 | /** |
||
| 3649 | * Show the monthcalender of the given month |
||
| 3650 | * @param array Agendaitems |
||
| 3651 | * @param int Month number |
||
| 3652 | * @param int Year number |
||
| 3653 | * @param array Array of strings containing long week day names (deprecated, you can send an empty array instead) |
||
| 3654 | * @param string The month name |
||
| 3655 | * @return void Direct output |
||
| 3656 | */ |
||
| 3657 | public static function display_mymonthcalendar( |
||
| 3909 | |||
| 3910 | /** |
||
| 3911 | * Get personal agenda items between two dates (=all events from all registered courses) |
||
| 3912 | * @param int user ID of the user |
||
| 3913 | * @param string Optional start date in datetime format (if no start date is given, uses today) |
||
| 3914 | * @param string Optional end date in datetime format (if no date is given, uses one year from now) |
||
| 3915 | * @param integer $user_id |
||
| 3916 | * @return array Array of events ordered by start date, in |
||
| 3917 | * [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, |
||
| 3918 | * where datestart and dateend are in yyyyMMddhhmmss format. |
||
| 3919 | * @deprecated use agenda events |
||
| 3920 | */ |
||
| 3921 | public static function get_personal_agenda_items_between_dates( |
||
| 4044 | |||
| 4045 | /** |
||
| 4046 | * This function retrieves one personal agenda item returns it. |
||
| 4047 | * @param int $id The agenda item ID |
||
| 4048 | * @return array The results of the database query, or null if not found |
||
| 4049 | */ |
||
| 4050 | View Code Duplication | public static function get_personal_agenda_item($id) |
|
| 4066 | |||
| 4067 | /** |
||
| 4068 | * This function calculates the startdate of the week (monday) |
||
| 4069 | * and the enddate of the week (sunday) |
||
| 4070 | * and returns it as an array |
||
| 4071 | */ |
||
| 4072 | public static function calculate_start_end_of_week($week_number, $year) |
||
| 4106 | |||
| 4107 | /** |
||
| 4108 | * @return bool |
||
| 4109 | */ |
||
| 4110 | public function getIsAllowedToEdit() |
||
| 4114 | |||
| 4115 | /** |
||
| 4116 | * @param bool $isAllowedToEdit |
||
| 4117 | */ |
||
| 4118 | public function setIsAllowedToEdit($isAllowedToEdit) |
||
| 4122 | |||
| 4123 | /** |
||
| 4124 | * @param int $userId |
||
| 4125 | * @param array $event |
||
| 4126 | * |
||
| 4127 | * @return bool |
||
| 4128 | */ |
||
| 4129 | public function sendEmail($userId, $event) |
||
| 4150 | } |
||
| 4151 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.