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 | public $comment; |
||
| 20 | private $isAllowedToEdit; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Constructor |
||
| 24 | */ |
||
| 25 | public function __construct() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param int $senderId |
||
| 55 | */ |
||
| 56 | public function setSenderId($senderId) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return int |
||
| 63 | */ |
||
| 64 | public function getSenderId() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $type can be 'personal', 'admin' or 'course' |
||
| 71 | */ |
||
| 72 | public function setType($type) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param int $id |
||
| 83 | */ |
||
| 84 | public function setSessionId($id) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return int $id |
||
| 91 | */ |
||
| 92 | public function getSessionId() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param array $courseInfo |
||
| 99 | */ |
||
| 100 | public function set_course($courseInfo) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return array |
||
| 107 | */ |
||
| 108 | public function getTypes() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Adds an event to the calendar |
||
| 115 | * @param string $start datetime format: 2012-06-14 09:00:00 |
||
| 116 | * @param string $end datetime format: 2012-06-14 09:00:00 |
||
| 117 | * @param string $allDay (true, false) |
||
| 118 | * @param string $title |
||
| 119 | * @param string $content |
||
| 120 | * @param array $usersToSend array('everyone') or a list of user/group ids |
||
| 121 | * @param bool $addAsAnnouncement event as a *course* announcement |
||
| 122 | * @param int $parentEventId |
||
| 123 | * @param array $attachmentArray array of $_FILES[''] |
||
| 124 | * @param array $attachmentCommentList |
||
| 125 | * @param string $eventComment |
||
| 126 | * @param string $color |
||
| 127 | * |
||
| 128 | * @return int |
||
| 129 | */ |
||
| 130 | public function addEvent( |
||
| 131 | $start, |
||
| 132 | $end, |
||
| 133 | $allDay, |
||
| 134 | $title, |
||
| 135 | $content, |
||
| 136 | $usersToSend = array(), |
||
| 137 | $addAsAnnouncement = false, |
||
| 138 | $parentEventId = null, |
||
| 139 | $attachmentArray = array(), |
||
| 140 | $attachmentCommentList = array(), |
||
| 141 | $eventComment = null, |
||
| 142 | $color = '' |
||
| 143 | ) { |
||
| 144 | $start = api_get_utc_datetime($start); |
||
| 145 | $end = api_get_utc_datetime($end); |
||
| 146 | $allDay = isset($allDay) && $allDay == 'true' ? 1 : 0; |
||
| 147 | $id = null; |
||
| 148 | $content = Security::remove_XSS($content); |
||
| 149 | $eventComment = nl2br($eventComment); |
||
| 150 | |||
| 151 | switch ($this->type) { |
||
| 152 | case 'personal': |
||
| 153 | $attributes = array( |
||
| 154 | 'user' => api_get_user_id(), |
||
| 155 | 'title' => $title, |
||
| 156 | 'text' => $content, |
||
| 157 | 'date' => $start, |
||
| 158 | 'enddate' => $end, |
||
| 159 | 'all_day' => $allDay, |
||
| 160 | 'color' => $color |
||
| 161 | ); |
||
| 162 | |||
| 163 | $id = Database::insert( |
||
| 164 | $this->tbl_personal_agenda, |
||
| 165 | $attributes |
||
| 166 | ); |
||
| 167 | break; |
||
| 168 | case 'course': |
||
| 169 | $attributes = array( |
||
| 170 | 'title' => $title, |
||
| 171 | 'content' => $content, |
||
| 172 | 'start_date' => $start, |
||
| 173 | 'end_date' => $end, |
||
| 174 | 'all_day' => $allDay, |
||
| 175 | 'session_id' => $this->getSessionId(), |
||
| 176 | 'c_id' => $this->course['real_id'], |
||
| 177 | 'comment' => $eventComment, |
||
| 178 | 'color' => $color |
||
| 179 | ); |
||
| 180 | |||
| 181 | if (!empty($parentEventId)) { |
||
| 182 | $attributes['parent_event_id'] = $parentEventId; |
||
| 183 | } |
||
| 184 | |||
| 185 | $senderId = $this->getSenderId(); |
||
| 186 | $sessionId = $this->getSessionId(); |
||
| 187 | |||
| 188 | // Simple course event. |
||
| 189 | $id = Database::insert($this->tbl_course_agenda, $attributes); |
||
| 190 | |||
| 191 | if ($id) { |
||
| 192 | $sql = "UPDATE ".$this->tbl_course_agenda." SET id = iid WHERE iid = $id"; |
||
| 193 | Database::query($sql); |
||
| 194 | |||
| 195 | $groupId = api_get_group_id(); |
||
| 196 | |||
| 197 | if (!empty($usersToSend)) { |
||
| 198 | $sendTo = $this->parseSendToArray($usersToSend); |
||
| 199 | |||
| 200 | if ($sendTo['everyone']) { |
||
| 201 | api_item_property_update( |
||
| 202 | $this->course, |
||
| 203 | TOOL_CALENDAR_EVENT, |
||
| 204 | $id, |
||
| 205 | "AgendaAdded", |
||
| 206 | $senderId, |
||
| 207 | $groupId, |
||
| 208 | '', |
||
| 209 | $start, |
||
| 210 | $end, |
||
| 211 | $sessionId |
||
| 212 | ); |
||
| 213 | api_item_property_update( |
||
| 214 | $this->course, |
||
| 215 | TOOL_CALENDAR_EVENT, |
||
| 216 | $id, |
||
| 217 | "visible", |
||
| 218 | $senderId, |
||
| 219 | $groupId, |
||
| 220 | '', |
||
| 221 | $start, |
||
| 222 | $end, |
||
| 223 | $sessionId |
||
| 224 | ); |
||
| 225 | } else { |
||
| 226 | // Storing the selected groups |
||
| 227 | View Code Duplication | if (!empty($sendTo['groups'])) { |
|
| 228 | foreach ($sendTo['groups'] as $group) { |
||
| 229 | api_item_property_update( |
||
| 230 | $this->course, |
||
| 231 | TOOL_CALENDAR_EVENT, |
||
| 232 | $id, |
||
| 233 | "AgendaAdded", |
||
| 234 | $senderId, |
||
| 235 | $group, |
||
| 236 | 0, |
||
| 237 | $start, |
||
| 238 | $end, |
||
| 239 | $sessionId |
||
| 240 | ); |
||
| 241 | |||
| 242 | api_item_property_update( |
||
| 243 | $this->course, |
||
| 244 | TOOL_CALENDAR_EVENT, |
||
| 245 | $id, |
||
| 246 | "visible", |
||
| 247 | $senderId, |
||
| 248 | $group, |
||
| 249 | 0, |
||
| 250 | $start, |
||
| 251 | $end, |
||
| 252 | $sessionId |
||
| 253 | ); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | // storing the selected users |
||
| 258 | View Code Duplication | if (!empty($sendTo['users'])) { |
|
| 259 | foreach ($sendTo['users'] as $userId) { |
||
| 260 | api_item_property_update( |
||
| 261 | $this->course, |
||
| 262 | TOOL_CALENDAR_EVENT, |
||
| 263 | $id, |
||
| 264 | "AgendaAdded", |
||
| 265 | $senderId, |
||
| 266 | $groupId, |
||
| 267 | $userId, |
||
| 268 | $start, |
||
| 269 | $end, |
||
| 270 | $sessionId |
||
| 271 | ); |
||
| 272 | |||
| 273 | api_item_property_update( |
||
| 274 | $this->course, |
||
| 275 | TOOL_CALENDAR_EVENT, |
||
| 276 | $id, |
||
| 277 | "visible", |
||
| 278 | $senderId, |
||
| 279 | $groupId, |
||
| 280 | $userId, |
||
| 281 | $start, |
||
| 282 | $end, |
||
| 283 | $sessionId |
||
| 284 | ); |
||
| 285 | } |
||
| 286 | } |
||
| 287 | } |
||
| 288 | } |
||
| 289 | |||
| 290 | // Add announcement. |
||
| 291 | if ($addAsAnnouncement) { |
||
| 292 | $this->storeAgendaEventAsAnnouncement($id, $usersToSend); |
||
| 293 | } |
||
| 294 | |||
| 295 | // Add attachment. |
||
| 296 | View Code Duplication | if (isset($attachmentArray) && !empty($attachmentArray)) { |
|
| 297 | $counter = 0; |
||
| 298 | foreach ($attachmentArray as $attachmentItem) { |
||
| 299 | $this->addAttachment( |
||
| 300 | $id, |
||
| 301 | $attachmentItem, |
||
| 302 | $attachmentCommentList[$counter], |
||
| 303 | $this->course |
||
| 304 | ); |
||
| 305 | $counter++; |
||
| 306 | } |
||
| 307 | } |
||
| 308 | } |
||
| 309 | break; |
||
| 310 | View Code Duplication | case 'admin': |
|
| 311 | if (api_is_platform_admin()) { |
||
| 312 | $attributes = array( |
||
| 313 | 'title' => $title, |
||
| 314 | 'content' => $content, |
||
| 315 | 'start_date' => $start, |
||
| 316 | 'end_date' => $end, |
||
| 317 | 'all_day' => $allDay, |
||
| 318 | 'access_url_id' => api_get_current_access_url_id() |
||
| 319 | ); |
||
| 320 | |||
| 321 | $id = Database::insert($this->tbl_global_agenda, $attributes); |
||
| 322 | } |
||
| 323 | break; |
||
| 324 | } |
||
| 325 | |||
| 326 | return $id; |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @param int $eventId |
||
| 331 | * @param int $courseId |
||
| 332 | * |
||
| 333 | * @return array |
||
| 334 | */ |
||
| 335 | public function getRepeatedInfoByEvent($eventId, $courseId) |
||
| 336 | { |
||
| 337 | $repeatTable = Database::get_course_table(TABLE_AGENDA_REPEAT); |
||
| 338 | $eventId = intval($eventId); |
||
| 339 | $courseId = intval($courseId); |
||
| 340 | $sql = "SELECT * FROM $repeatTable |
||
| 341 | WHERE c_id = $courseId AND cal_id = $eventId"; |
||
| 342 | $res = Database::query($sql); |
||
| 343 | $repeatInfo = array(); |
||
| 344 | if (Database::num_rows($res) > 0) { |
||
| 345 | $repeatInfo = Database::fetch_array($res, 'ASSOC'); |
||
| 346 | } |
||
| 347 | |||
| 348 | return $repeatInfo; |
||
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @param int $eventId |
||
| 353 | * @param string $type |
||
| 354 | * @param string $end in local time |
||
| 355 | * @param array $sentTo |
||
| 356 | * |
||
| 357 | * @return bool |
||
| 358 | */ |
||
| 359 | public function addRepeatedItem($eventId, $type, $end, $sentTo = array()) |
||
| 360 | { |
||
| 361 | $t_agenda = Database::get_course_table(TABLE_AGENDA); |
||
| 362 | $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT); |
||
| 363 | |||
| 364 | if (empty($this->course)) { |
||
| 365 | return false; |
||
| 366 | } |
||
| 367 | |||
| 368 | $course_id = $this->course['real_id']; |
||
| 369 | $eventId = intval($eventId); |
||
| 370 | |||
| 371 | $sql = "SELECT title, content, start_date, end_date, all_day |
||
| 372 | FROM $t_agenda |
||
| 373 | WHERE c_id = $course_id AND id = $eventId"; |
||
| 374 | $res = Database::query($sql); |
||
| 375 | |||
| 376 | if (Database::num_rows($res) !== 1) { |
||
| 377 | return false; |
||
| 378 | } |
||
| 379 | |||
| 380 | $row = Database::fetch_array($res); |
||
| 381 | $origStartDate = api_strtotime($row['start_date'], 'UTC'); |
||
| 382 | $origEndDate = api_strtotime($row['end_date'], 'UTC'); |
||
| 383 | $diff = $origEndDate - $origStartDate; |
||
| 384 | |||
| 385 | $title = $row['title']; |
||
| 386 | $content = $row['content']; |
||
| 387 | $allDay = $row['all_day']; |
||
| 388 | |||
| 389 | $now = time(); |
||
| 390 | $type = Database::escape_string($type); |
||
| 391 | $end = api_strtotime($end); |
||
| 392 | |||
| 393 | if (1 <= $end && $end <= 500) { |
||
| 394 | // We assume that, with this type of value, the user actually gives a count of repetitions |
||
| 395 | //and that he wants us to calculate the end date with that (particularly in case of imports from ical) |
||
| 396 | switch ($type) { |
||
| 397 | case 'daily': |
||
| 398 | $end = $origStartDate + (86400 * $end); |
||
| 399 | break; |
||
| 400 | case 'weekly': |
||
| 401 | $end = $this->addWeek($origStartDate, $end); |
||
| 402 | break; |
||
| 403 | case 'monthlyByDate': |
||
| 404 | $end = $this->addMonth($origStartDate, $end); |
||
| 405 | break; |
||
| 406 | case 'monthlyByDay': |
||
| 407 | //TODO |
||
| 408 | break; |
||
| 409 | case 'monthlyByDayR': |
||
| 410 | //TODO |
||
| 411 | break; |
||
| 412 | case 'yearly': |
||
| 413 | $end = $this->addYear($origStartDate, $end); |
||
| 414 | break; |
||
| 415 | } |
||
| 416 | } |
||
| 417 | |||
| 418 | $typeList = array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'); |
||
| 419 | |||
| 420 | // The event has to repeat *in the future*. We don't allow repeated |
||
| 421 | // events in the past |
||
| 422 | if ($end > $now && in_array($type, $typeList)) { |
||
| 423 | $sql = "INSERT INTO $t_agenda_r (c_id, cal_id, cal_type, cal_end) |
||
| 424 | VALUES ($course_id, '$eventId', '$type', '$end')"; |
||
| 425 | Database::query($sql); |
||
| 426 | |||
| 427 | switch ($type) { |
||
| 428 | // @todo improve loop. |
||
| 429 | View Code Duplication | case 'daily': |
|
| 430 | for ($i = $origStartDate + 86400; $i <= $end; $i += 86400) { |
||
| 431 | $start = date('Y-m-d H:i:s', $i); |
||
| 432 | $repeatEnd = date('Y-m-d H:i:s', $i + $diff); |
||
| 433 | $this->addEvent( |
||
| 434 | $start, |
||
| 435 | $repeatEnd, |
||
| 436 | $allDay, |
||
| 437 | $title, |
||
| 438 | $content, |
||
| 439 | $sentTo, |
||
| 440 | false, |
||
| 441 | $eventId |
||
| 442 | ); |
||
| 443 | } |
||
| 444 | break; |
||
| 445 | View Code Duplication | case 'weekly': |
|
| 446 | for ($i = $origStartDate + 604800; $i <= $end; $i += 604800) { |
||
| 447 | $start = date('Y-m-d H:i:s', $i); |
||
| 448 | $repeatEnd = date('Y-m-d H:i:s', $i + $diff); |
||
| 449 | $this->addEvent( |
||
| 450 | $start, |
||
| 451 | $repeatEnd, |
||
| 452 | $allDay, |
||
| 453 | $title, |
||
| 454 | $content, |
||
| 455 | $sentTo, |
||
| 456 | false, |
||
| 457 | $eventId |
||
| 458 | ); |
||
| 459 | } |
||
| 460 | break; |
||
| 461 | View Code Duplication | case 'monthlyByDate': |
|
| 462 | $next_start = $this->addMonth($origStartDate); |
||
| 463 | while ($next_start <= $end) { |
||
| 464 | $start = date('Y-m-d H:i:s', $next_start); |
||
| 465 | $repeatEnd = date('Y-m-d H:i:s', $next_start + $diff); |
||
| 466 | $this->addEvent( |
||
| 467 | $start, |
||
| 468 | $repeatEnd, |
||
| 469 | $allDay, |
||
| 470 | $title, |
||
| 471 | $content, |
||
| 472 | $sentTo, |
||
| 473 | false, |
||
| 474 | $eventId |
||
| 475 | ); |
||
| 476 | $next_start = $this->addMonth($next_start); |
||
| 477 | } |
||
| 478 | break; |
||
| 479 | case 'monthlyByDay': |
||
| 480 | //not yet implemented |
||
| 481 | break; |
||
| 482 | case 'monthlyByDayR': |
||
| 483 | //not yet implemented |
||
| 484 | break; |
||
| 485 | View Code Duplication | case 'yearly': |
|
| 486 | $next_start = $this->addYear($origStartDate); |
||
| 487 | while ($next_start <= $end) { |
||
| 488 | $start = date('Y-m-d H:i:s', $next_start); |
||
| 489 | $repeatEnd = date('Y-m-d H:i:s', $next_start + $diff); |
||
| 490 | $this->addEvent( |
||
| 491 | $start, |
||
| 492 | $repeatEnd, |
||
| 493 | $allDay, |
||
| 494 | $title, |
||
| 495 | $content, |
||
| 496 | $sentTo, |
||
| 497 | false, |
||
| 498 | $eventId |
||
| 499 | ); |
||
| 500 | $next_start = $this->addYear($next_start); |
||
| 501 | } |
||
| 502 | break; |
||
| 503 | } |
||
| 504 | } |
||
| 505 | |||
| 506 | return true; |
||
| 507 | } |
||
| 508 | |||
| 509 | /** |
||
| 510 | * @param int $itemId |
||
| 511 | * @param array $sentTo |
||
| 512 | * @return int |
||
| 513 | */ |
||
| 514 | public function storeAgendaEventAsAnnouncement($itemId, $sentTo = array()) |
||
| 515 | { |
||
| 516 | $table_agenda = Database::get_course_table(TABLE_AGENDA); |
||
| 517 | $course_id = api_get_course_int_id(); |
||
| 518 | |||
| 519 | // Check params |
||
| 520 | if (empty($itemId) || $itemId != strval(intval($itemId))) { |
||
| 521 | return -1; |
||
| 522 | } |
||
| 523 | |||
| 524 | // Get the agenda item. |
||
| 525 | $itemId = intval($itemId); |
||
| 526 | $sql = "SELECT * FROM $table_agenda |
||
| 527 | WHERE c_id = $course_id AND id = ".$itemId; |
||
| 528 | $res = Database::query($sql); |
||
| 529 | |||
| 530 | if (Database::num_rows($res) > 0) { |
||
| 531 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 532 | // Sending announcement |
||
| 533 | if (!empty($sentTo)) { |
||
| 534 | $id = AnnouncementManager::add_announcement( |
||
| 535 | $row['title'], |
||
| 536 | $row['content'], |
||
| 537 | $sentTo, |
||
| 538 | null, |
||
| 539 | null, |
||
| 540 | $row['end_date'] |
||
| 541 | ); |
||
| 542 | AnnouncementManager::send_email($id); |
||
| 543 | |||
| 544 | return $id; |
||
| 545 | } |
||
| 546 | } |
||
| 547 | |||
| 548 | return -1; |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Edits an event |
||
| 553 | * |
||
| 554 | * @param int $id |
||
| 555 | * @param string $start datetime format: 2012-06-14 09:00:00 |
||
| 556 | * @param string $end datetime format: 2012-06-14 09:00:00 |
||
| 557 | * @param int $allDay is all day 'true' or 'false' |
||
| 558 | * @param string $title |
||
| 559 | * @param string $content |
||
| 560 | * @param array $usersToSend |
||
| 561 | * @param array $attachmentArray |
||
| 562 | * @param array $attachmentCommentList |
||
| 563 | * @param string $comment |
||
| 564 | * @param string $color |
||
| 565 | * @param bool $addAnnouncement |
||
| 566 | * |
||
| 567 | * @return null|false |
||
| 568 | */ |
||
| 569 | public function editEvent( |
||
| 570 | $id, |
||
| 571 | $start, |
||
| 572 | $end, |
||
| 573 | $allDay, |
||
| 574 | $title, |
||
| 575 | $content, |
||
| 576 | $usersToSend = array(), |
||
| 577 | $attachmentArray = array(), |
||
| 578 | $attachmentCommentList = array(), |
||
| 579 | $comment = null, |
||
| 580 | $color = '', |
||
| 581 | $addAnnouncement = false |
||
| 582 | ) { |
||
| 583 | $start = api_get_utc_datetime($start); |
||
| 584 | $end = api_get_utc_datetime($end); |
||
| 585 | $allDay = isset($allDay) && $allDay == 'true' ? 1 : 0; |
||
| 586 | $content = nl2br($content); |
||
| 587 | $comment = nl2br($comment); |
||
| 588 | |||
| 589 | switch ($this->type) { |
||
| 590 | case 'personal': |
||
| 591 | $eventInfo = $this->get_event($id); |
||
| 592 | if ($eventInfo['user'] != api_get_user_id()) { |
||
| 593 | break; |
||
| 594 | } |
||
| 595 | $attributes = array( |
||
| 596 | 'title' => $title, |
||
| 597 | 'text' => $content, |
||
| 598 | 'date' => $start, |
||
| 599 | 'enddate' => $end, |
||
| 600 | 'all_day' => $allDay, |
||
| 601 | 'color' => $color |
||
| 602 | ); |
||
| 603 | Database::update( |
||
| 604 | $this->tbl_personal_agenda, |
||
| 605 | $attributes, |
||
| 606 | array('id = ?' => $id) |
||
| 607 | ); |
||
| 608 | break; |
||
| 609 | case 'course': |
||
| 610 | $eventInfo = $this->get_event($id); |
||
| 611 | |||
| 612 | if (empty($eventInfo)) { |
||
| 613 | return false; |
||
| 614 | } |
||
| 615 | |||
| 616 | $groupId = api_get_group_id(); |
||
| 617 | $course_id = $this->course['real_id']; |
||
| 618 | |||
| 619 | if (empty($course_id)) { |
||
| 620 | return false; |
||
| 621 | } |
||
| 622 | |||
| 623 | if ($this->getIsAllowedToEdit()) { |
||
| 624 | $attributes = array( |
||
| 625 | 'title' => $title, |
||
| 626 | 'content' => $content, |
||
| 627 | 'start_date' => $start, |
||
| 628 | 'end_date' => $end, |
||
| 629 | 'all_day' => $allDay, |
||
| 630 | 'comment' => $comment, |
||
| 631 | 'color' => $color |
||
| 632 | ); |
||
| 633 | |||
| 634 | Database::update( |
||
| 635 | $this->tbl_course_agenda, |
||
| 636 | $attributes, |
||
| 637 | array( |
||
| 638 | 'id = ? AND c_id = ? AND session_id = ? ' => array( |
||
| 639 | $id, |
||
| 640 | $course_id, |
||
| 641 | $this->sessionId |
||
| 642 | ) |
||
| 643 | ) |
||
| 644 | ); |
||
| 645 | |||
| 646 | if (!empty($usersToSend)) { |
||
| 647 | $sendTo = $this->parseSendToArray($usersToSend); |
||
| 648 | |||
| 649 | $usersToDelete = array_diff($eventInfo['send_to']['users'], $sendTo['users']); |
||
| 650 | $usersToAdd = array_diff($sendTo['users'], $eventInfo['send_to']['users']); |
||
| 651 | $groupsToDelete = array_diff($eventInfo['send_to']['groups'], $sendTo['groups']); |
||
| 652 | $groupToAdd = array_diff($sendTo['groups'], $eventInfo['send_to']['groups']); |
||
| 653 | |||
| 654 | if ($sendTo['everyone']) { |
||
| 655 | // Delete all from group |
||
| 656 | View Code Duplication | if (isset($eventInfo['send_to']['groups']) && |
|
| 657 | !empty($eventInfo['send_to']['groups']) |
||
| 658 | ) { |
||
| 659 | foreach ($eventInfo['send_to']['groups'] as $group) { |
||
| 660 | api_item_property_delete( |
||
| 661 | $this->course, |
||
| 662 | TOOL_CALENDAR_EVENT, |
||
| 663 | $id, |
||
| 664 | 0, |
||
| 665 | $group, |
||
| 666 | $this->sessionId |
||
| 667 | ); |
||
| 668 | } |
||
| 669 | } |
||
| 670 | |||
| 671 | // Storing the selected users. |
||
| 672 | View Code Duplication | if (isset($eventInfo['send_to']['users']) && |
|
| 673 | !empty($eventInfo['send_to']['users']) |
||
| 674 | ) { |
||
| 675 | foreach ($eventInfo['send_to']['users'] as $userId) { |
||
| 676 | api_item_property_delete( |
||
| 677 | $this->course, |
||
| 678 | TOOL_CALENDAR_EVENT, |
||
| 679 | $id, |
||
| 680 | $userId, |
||
| 681 | $groupId, |
||
| 682 | $this->sessionId |
||
| 683 | ); |
||
| 684 | } |
||
| 685 | } |
||
| 686 | |||
| 687 | // Add to everyone only. |
||
| 688 | api_item_property_update( |
||
| 689 | $this->course, |
||
| 690 | TOOL_CALENDAR_EVENT, |
||
| 691 | $id, |
||
| 692 | "visible", |
||
| 693 | api_get_user_id(), |
||
| 694 | $groupId, |
||
| 695 | null, |
||
| 696 | $start, |
||
| 697 | $end, |
||
| 698 | $this->sessionId |
||
| 699 | ); |
||
| 700 | } else { |
||
| 701 | // Delete "everyone". |
||
| 702 | api_item_property_delete( |
||
| 703 | $this->course, |
||
| 704 | TOOL_CALENDAR_EVENT, |
||
| 705 | $id, |
||
| 706 | 0, |
||
| 707 | 0, |
||
| 708 | $this->sessionId |
||
| 709 | ); |
||
| 710 | |||
| 711 | // Add groups |
||
| 712 | View Code Duplication | if (!empty($groupToAdd)) { |
|
| 713 | foreach ($groupToAdd as $group) { |
||
| 714 | api_item_property_update( |
||
| 715 | $this->course, |
||
| 716 | TOOL_CALENDAR_EVENT, |
||
| 717 | $id, |
||
| 718 | "visible", |
||
| 719 | api_get_user_id(), |
||
| 720 | $group, |
||
| 721 | 0, |
||
| 722 | $start, |
||
| 723 | $end, |
||
| 724 | $this->sessionId |
||
| 725 | ); |
||
| 726 | } |
||
| 727 | } |
||
| 728 | |||
| 729 | // Delete groups. |
||
| 730 | View Code Duplication | if (!empty($groupsToDelete)) { |
|
| 731 | foreach ($groupsToDelete as $group) { |
||
| 732 | api_item_property_delete( |
||
| 733 | $this->course, |
||
| 734 | TOOL_CALENDAR_EVENT, |
||
| 735 | $id, |
||
| 736 | 0, |
||
| 737 | $group, |
||
| 738 | $this->sessionId |
||
| 739 | ); |
||
| 740 | } |
||
| 741 | } |
||
| 742 | |||
| 743 | // Add users. |
||
| 744 | View Code Duplication | if (!empty($usersToAdd)) { |
|
| 745 | foreach ($usersToAdd as $userId) { |
||
| 746 | api_item_property_update( |
||
| 747 | $this->course, |
||
| 748 | TOOL_CALENDAR_EVENT, |
||
| 749 | $id, |
||
| 750 | "visible", |
||
| 751 | api_get_user_id(), |
||
| 752 | $groupId, |
||
| 753 | $userId, |
||
| 754 | $start, |
||
| 755 | $end, |
||
| 756 | $this->sessionId |
||
| 757 | ); |
||
| 758 | } |
||
| 759 | } |
||
| 760 | |||
| 761 | // Delete users. |
||
| 762 | View Code Duplication | if (!empty($usersToDelete)) { |
|
| 763 | foreach ($usersToDelete as $userId) { |
||
| 764 | api_item_property_delete( |
||
| 765 | $this->course, |
||
| 766 | TOOL_CALENDAR_EVENT, |
||
| 767 | $id, |
||
| 768 | $userId, |
||
| 769 | $groupId, |
||
| 770 | $this->sessionId |
||
| 771 | ); |
||
| 772 | } |
||
| 773 | } |
||
| 774 | } |
||
| 775 | } |
||
| 776 | |||
| 777 | // Add announcement. |
||
| 778 | if (isset($addAnnouncement) && !empty($addAnnouncement)) { |
||
| 779 | $this->storeAgendaEventAsAnnouncement($id, $usersToSend); |
||
| 780 | } |
||
| 781 | |||
| 782 | // Add attachment. |
||
| 783 | View Code Duplication | if (isset($attachmentArray) && !empty($attachmentArray)) { |
|
| 784 | $counter = 0; |
||
| 785 | foreach ($attachmentArray as $attachmentItem) { |
||
| 786 | $this->updateAttachment( |
||
| 787 | $attachmentItem['id'], |
||
| 788 | $id, |
||
| 789 | $attachmentItem, |
||
| 790 | $attachmentCommentList[$counter], |
||
| 791 | $this->course |
||
| 792 | ); |
||
| 793 | $counter++; |
||
| 794 | } |
||
| 795 | } |
||
| 796 | } |
||
| 797 | break; |
||
| 798 | case 'admin': |
||
| 799 | View Code Duplication | case 'platform': |
|
| 800 | if (api_is_platform_admin()) { |
||
| 801 | $attributes = array( |
||
| 802 | 'title' => $title, |
||
| 803 | 'content' => $content, |
||
| 804 | 'start_date' => $start, |
||
| 805 | 'end_date' => $end, |
||
| 806 | 'all_day' => $allDay |
||
| 807 | ); |
||
| 808 | Database::update( |
||
| 809 | $this->tbl_global_agenda, |
||
| 810 | $attributes, |
||
| 811 | array('id = ?' => $id) |
||
| 812 | ); |
||
| 813 | } |
||
| 814 | break; |
||
| 815 | } |
||
| 816 | } |
||
| 817 | |||
| 818 | /** |
||
| 819 | * @param int $id |
||
| 820 | * @param bool $deleteAllItemsFromSerie |
||
| 821 | */ |
||
| 822 | public function deleteEvent($id, $deleteAllItemsFromSerie = false) |
||
| 823 | { |
||
| 824 | switch ($this->type) { |
||
| 825 | case 'personal': |
||
| 826 | $eventInfo = $this->get_event($id); |
||
| 827 | if ($eventInfo['user'] == api_get_user_id()) { |
||
| 828 | Database::delete( |
||
| 829 | $this->tbl_personal_agenda, |
||
| 830 | array('id = ?' => $id) |
||
| 831 | ); |
||
| 832 | } |
||
| 833 | break; |
||
| 834 | case 'course': |
||
| 835 | $course_id = api_get_course_int_id(); |
||
| 836 | |||
| 837 | if (!empty($course_id) && api_is_allowed_to_edit(null, true)) { |
||
| 838 | // Delete |
||
| 839 | $eventInfo = $this->get_event($id); |
||
| 840 | if ($deleteAllItemsFromSerie) { |
||
| 841 | /* This is one of the children. |
||
| 842 | Getting siblings and delete 'Em all + the father! */ |
||
| 843 | if (isset($eventInfo['parent_event_id']) && !empty($eventInfo['parent_event_id'])) { |
||
| 844 | // Removing items. |
||
| 845 | $events = $this->getAllRepeatEvents($eventInfo['parent_event_id']); |
||
| 846 | if (!empty($events)) { |
||
| 847 | foreach ($events as $event) { |
||
| 848 | $this->deleteEvent($event['id']); |
||
| 849 | } |
||
| 850 | } |
||
| 851 | // Removing parent. |
||
| 852 | $this->deleteEvent($eventInfo['parent_event_id']); |
||
| 853 | } else { |
||
| 854 | // This is the father looking for the children. |
||
| 855 | $events = $this->getAllRepeatEvents($id); |
||
| 856 | if (!empty($events)) { |
||
| 857 | foreach ($events as $event) { |
||
| 858 | $this->deleteEvent($event['id']); |
||
| 859 | } |
||
| 860 | } |
||
| 861 | } |
||
| 862 | } |
||
| 863 | |||
| 864 | // Removing from events. |
||
| 865 | Database::delete( |
||
| 866 | $this->tbl_course_agenda, |
||
| 867 | array('id = ? AND c_id = ?' => array($id, $course_id)) |
||
| 868 | ); |
||
| 869 | |||
| 870 | api_item_property_update( |
||
| 871 | $this->course, |
||
| 872 | TOOL_CALENDAR_EVENT, |
||
| 873 | $id, |
||
| 874 | 'delete', |
||
| 875 | api_get_user_id() |
||
| 876 | ); |
||
| 877 | |||
| 878 | // Removing from series. |
||
| 879 | Database::delete( |
||
| 880 | $this->table_repeat, |
||
| 881 | array('cal_id = ? AND c_id = ?' => array($id, $course_id)) |
||
| 882 | ); |
||
| 883 | |||
| 884 | if (isset($eventInfo['attachment']) && !empty($eventInfo['attachment'])) { |
||
| 885 | foreach ($eventInfo['attachment'] as $attachment) { |
||
| 886 | self::deleteAttachmentFile($attachment['id'], $this->course); |
||
| 887 | } |
||
| 888 | } |
||
| 889 | } |
||
| 890 | break; |
||
| 891 | case 'admin': |
||
| 892 | if (api_is_platform_admin()) { |
||
| 893 | Database::delete( |
||
| 894 | $this->tbl_global_agenda, |
||
| 895 | array('id = ?' => $id) |
||
| 896 | ); |
||
| 897 | } |
||
| 898 | break; |
||
| 899 | } |
||
| 900 | } |
||
| 901 | |||
| 902 | /** |
||
| 903 | * Get agenda events |
||
| 904 | * @param int $start |
||
| 905 | * @param int $end |
||
| 906 | * @param int $course_id |
||
| 907 | * @param int $groupId |
||
| 908 | * @param int $user_id |
||
| 909 | * @param string $format |
||
| 910 | * |
||
| 911 | * @return array|string |
||
| 912 | */ |
||
| 913 | public function getEvents( |
||
| 914 | $start, |
||
| 915 | $end, |
||
| 916 | $course_id = null, |
||
| 917 | $groupId = null, |
||
| 918 | $user_id = 0, |
||
| 919 | $format = 'json' |
||
| 920 | ) { |
||
| 921 | switch ($this->type) { |
||
| 922 | case 'admin': |
||
| 923 | $this->getPlatformEvents($start, $end); |
||
| 924 | break; |
||
| 925 | case 'course': |
||
| 926 | $session_id = $this->sessionId; |
||
| 927 | $courseInfo = api_get_course_info_by_id($course_id); |
||
| 928 | |||
| 929 | // Session coach can see all events inside a session. |
||
| 930 | if (api_is_coach()) { |
||
| 931 | // Own course |
||
| 932 | $this->getCourseEvents( |
||
| 933 | $start, |
||
| 934 | $end, |
||
| 935 | $courseInfo, |
||
| 936 | $groupId, |
||
| 937 | $session_id, |
||
| 938 | $user_id |
||
| 939 | ); |
||
| 940 | |||
| 941 | // Others |
||
| 942 | $this->getSessionEvents( |
||
| 943 | $start, |
||
| 944 | $end, |
||
| 945 | api_get_session_id(), |
||
| 946 | $user_id, |
||
| 947 | $this->eventOtherSessionColor |
||
| 948 | ); |
||
| 949 | } else { |
||
| 950 | $this->getCourseEvents( |
||
| 951 | $start, |
||
| 952 | $end, |
||
| 953 | $courseInfo, |
||
| 954 | $groupId, |
||
| 955 | $session_id, |
||
| 956 | $user_id |
||
| 957 | ); |
||
| 958 | } |
||
| 959 | break; |
||
| 960 | case 'personal': |
||
| 961 | default: |
||
| 962 | $sessionFilterActive = false; |
||
| 963 | |||
| 964 | if (!empty($this->sessionId)) { |
||
| 965 | $sessionFilterActive = true; |
||
| 966 | } |
||
| 967 | |||
| 968 | if ($sessionFilterActive == false) { |
||
| 969 | // Getting personal events |
||
| 970 | $this->getPersonalEvents($start, $end); |
||
| 971 | |||
| 972 | // Getting platform/admin events |
||
| 973 | $this->getPlatformEvents($start, $end); |
||
| 974 | } |
||
| 975 | |||
| 976 | // Getting course events |
||
| 977 | $my_course_list = array(); |
||
| 978 | |||
| 979 | if (!api_is_anonymous()) { |
||
| 980 | $session_list = SessionManager::get_sessions_by_user( |
||
| 981 | api_get_user_id() |
||
| 982 | ); |
||
| 983 | $my_course_list = CourseManager::get_courses_list_by_user_id( |
||
| 984 | api_get_user_id(), |
||
| 985 | false |
||
| 986 | ); |
||
| 987 | } |
||
| 988 | |||
| 989 | if (api_is_drh()) { |
||
| 990 | if (api_drh_can_access_all_session_content()) { |
||
| 991 | $session_list = array(); |
||
| 992 | $sessionList = SessionManager::get_sessions_followed_by_drh( |
||
| 993 | api_get_user_id(), |
||
| 994 | null, |
||
| 995 | null, |
||
| 996 | null, |
||
| 997 | true, |
||
| 998 | false |
||
| 999 | ); |
||
| 1000 | |||
| 1001 | if (!empty($sessionList)) { |
||
| 1002 | foreach ($sessionList as $sessionItem) { |
||
| 1003 | $sessionId = $sessionItem['id']; |
||
| 1004 | $courses = SessionManager::get_course_list_by_session_id( |
||
| 1005 | $sessionId |
||
| 1006 | ); |
||
| 1007 | $sessionInfo = array( |
||
| 1008 | 'session_id' => $sessionId, |
||
| 1009 | 'courses' => $courses |
||
| 1010 | ); |
||
| 1011 | $session_list[] = $sessionInfo; |
||
| 1012 | } |
||
| 1013 | } |
||
| 1014 | } |
||
| 1015 | } |
||
| 1016 | |||
| 1017 | if (!empty($session_list)) { |
||
| 1018 | foreach ($session_list as $session_item) { |
||
| 1019 | if ($sessionFilterActive) { |
||
| 1020 | if ($this->sessionId != $session_item['session_id']) { |
||
| 1021 | continue; |
||
| 1022 | } |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | $my_courses = $session_item['courses']; |
||
| 1026 | $my_session_id = $session_item['session_id']; |
||
| 1027 | |||
| 1028 | if (!empty($my_courses)) { |
||
| 1029 | foreach ($my_courses as $course_item) { |
||
| 1030 | $courseInfo = api_get_course_info_by_id($course_item['real_id']); |
||
| 1031 | $this->getCourseEvents( |
||
| 1032 | $start, |
||
| 1033 | $end, |
||
| 1034 | $courseInfo, |
||
| 1035 | 0, |
||
| 1036 | $my_session_id |
||
| 1037 | ); |
||
| 1038 | } |
||
| 1039 | } |
||
| 1040 | } |
||
| 1041 | } |
||
| 1042 | |||
| 1043 | if (!empty($my_course_list) && $sessionFilterActive == false) { |
||
| 1044 | foreach ($my_course_list as $courseInfoItem) { |
||
| 1045 | $courseInfo = api_get_course_info_by_id($courseInfoItem['real_id']); |
||
| 1046 | if (isset($course_id) && !empty($course_id)) { |
||
| 1047 | if ($courseInfo['real_id'] == $course_id) { |
||
| 1048 | $this->getCourseEvents($start, $end, $courseInfo); |
||
| 1049 | } |
||
| 1050 | } else { |
||
| 1051 | $this->getCourseEvents( |
||
| 1052 | $start, |
||
| 1053 | $end, |
||
| 1054 | $courseInfo |
||
| 1055 | ); |
||
| 1056 | } |
||
| 1057 | } |
||
| 1058 | } |
||
| 1059 | |||
| 1060 | break; |
||
| 1061 | } |
||
| 1062 | |||
| 1063 | if (!empty($this->events)) { |
||
| 1064 | switch ($format) { |
||
| 1065 | case 'json': |
||
| 1066 | return json_encode($this->events); |
||
| 1067 | break; |
||
| 1068 | case 'array': |
||
| 1069 | return $this->events; |
||
| 1070 | break; |
||
| 1071 | } |
||
| 1072 | |||
| 1073 | } |
||
| 1074 | return ''; |
||
| 1075 | } |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * @param int $id |
||
| 1079 | * @param int $day_delta |
||
| 1080 | * @param int $minute_delta |
||
| 1081 | * @return int |
||
| 1082 | */ |
||
| 1083 | public function resizeEvent($id, $day_delta, $minute_delta) |
||
| 1114 | |||
| 1115 | /** |
||
| 1116 | * @param $id |
||
| 1117 | * @param $day_delta |
||
| 1118 | * @param $minute_delta |
||
| 1119 | * @return int |
||
| 1120 | */ |
||
| 1121 | public function move_event($id, $day_delta, $minute_delta) |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Gets a single event |
||
| 1165 | * |
||
| 1166 | * @param int event id |
||
| 1167 | * @return array |
||
| 1168 | */ |
||
| 1169 | public function get_event($id) |
||
| 1230 | |||
| 1231 | /** |
||
| 1232 | * Gets personal events |
||
| 1233 | * @param int $start |
||
| 1234 | * @param int $end |
||
| 1235 | * @return array |
||
| 1236 | */ |
||
| 1237 | public function getPersonalEvents($start, $end) |
||
| 1238 | { |
||
| 1239 | $start = intval($start); |
||
| 1240 | $end = intval($end); |
||
| 1241 | $startCondition = ''; |
||
| 1242 | $endCondition = ''; |
||
| 1243 | |||
| 1244 | if ($start !== 0) { |
||
| 1245 | $start = api_get_utc_datetime($start); |
||
| 1246 | $startCondition = "AND date >= '".$start."'"; |
||
| 1247 | } |
||
| 1248 | if ($start !== 0) { |
||
| 1249 | $end = api_get_utc_datetime($end); |
||
| 1250 | $endCondition = "AND (enddate <= '".$end."' OR enddate IS NULL)"; |
||
| 1251 | } |
||
| 1252 | $user_id = api_get_user_id(); |
||
| 1253 | |||
| 1254 | $sql = "SELECT * FROM ".$this->tbl_personal_agenda." |
||
| 1255 | WHERE user = $user_id $startCondition $endCondition"; |
||
| 1256 | |||
| 1257 | $result = Database::query($sql); |
||
| 1258 | $my_events = array(); |
||
| 1259 | if (Database::num_rows($result)) { |
||
| 1260 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 1261 | $event = array(); |
||
| 1262 | $event['id'] = 'personal_'.$row['id']; |
||
| 1263 | $event['title'] = $row['title']; |
||
| 1264 | $event['className'] = 'personal'; |
||
| 1265 | $event['borderColor'] = $event['backgroundColor'] = $this->event_personal_color; |
||
| 1266 | $event['editable'] = true; |
||
| 1267 | $event['sent_to'] = get_lang('Me'); |
||
| 1268 | $event['type'] = 'personal'; |
||
| 1269 | |||
| 1270 | View Code Duplication | if (!empty($row['date']) && $row['date'] != '0000-00-00 00:00:00') { |
|
| 1271 | $event['start'] = $this->formatEventDate($row['date']); |
||
| 1272 | $event['start_date_localtime'] = api_get_local_time($row['date']); |
||
| 1273 | } |
||
| 1274 | |||
| 1275 | View Code Duplication | if (!empty($row['enddate']) && $row['enddate'] != '0000-00-00 00:00:00') { |
|
| 1276 | $event['end'] = $this->formatEventDate($row['enddate']); |
||
| 1277 | $event['end_date_localtime'] = api_get_local_time($row['enddate']); |
||
| 1278 | } |
||
| 1279 | $event['description'] = $row['text']; |
||
| 1280 | $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; |
||
| 1281 | |||
| 1282 | $event['parent_event_id'] = 0; |
||
| 1283 | $event['has_children'] = 0; |
||
| 1284 | |||
| 1285 | $my_events[] = $event; |
||
| 1286 | $this->events[] = $event; |
||
| 1287 | } |
||
| 1288 | } |
||
| 1289 | return $my_events; |
||
| 1290 | } |
||
| 1291 | |||
| 1292 | /** |
||
| 1293 | * Get user/group list per event. |
||
| 1294 | * |
||
| 1295 | * @param int $eventId |
||
| 1296 | * @param int $courseId |
||
| 1297 | * @param integer $sessionId |
||
| 1298 | * @paraù int $sessionId |
||
| 1299 | * |
||
| 1300 | * @return array |
||
| 1301 | */ |
||
| 1302 | public function getUsersAndGroupSubscribedToEvent($eventId, $courseId, $sessionId) |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * @param int $start |
||
| 1361 | * @param int $end |
||
| 1362 | * @param int $sessionId |
||
| 1363 | * @param int $userId |
||
| 1364 | * @param string $color |
||
| 1365 | * |
||
| 1366 | * @return array |
||
| 1367 | */ |
||
| 1368 | public function getSessionEvents($start, $end, $sessionId = 0, $userId = 0, $color = '') |
||
| 1387 | |||
| 1388 | /** |
||
| 1389 | * @param int $start |
||
| 1390 | * @param int $end |
||
| 1391 | * @param array $courseInfo |
||
| 1392 | * @param int $groupId |
||
| 1393 | * @param int $session_id |
||
| 1394 | * @param int $user_id |
||
| 1395 | * @param string $color |
||
| 1396 | * |
||
| 1397 | * @return array |
||
| 1398 | */ |
||
| 1399 | public function getCourseEvents( |
||
| 1400 | $start, |
||
| 1401 | $end, |
||
| 1402 | $courseInfo, |
||
| 1403 | $groupId = 0, |
||
| 1404 | $session_id = 0, |
||
| 1405 | $user_id = 0, |
||
| 1406 | $color = '' |
||
| 1407 | ) { |
||
| 1408 | $start = isset($start) && !empty($start) ? api_get_utc_datetime(intval($start)) : null; |
||
| 1409 | $end = isset($end) && !empty($end) ? api_get_utc_datetime(intval($end)) : null; |
||
| 1410 | |||
| 1411 | if (empty($courseInfo)) { |
||
| 1412 | return array(); |
||
| 1413 | } |
||
| 1414 | $course_id = $courseInfo['real_id']; |
||
| 1415 | |||
| 1416 | if (empty($course_id)) { |
||
| 1417 | return array(); |
||
| 1418 | } |
||
| 1419 | |||
| 1420 | $session_id = intval($session_id); |
||
| 1421 | $user_id = intval($user_id); |
||
| 1422 | $groupList = GroupManager::get_group_list(null, $courseInfo['code']); |
||
| 1423 | |||
| 1424 | $group_name_list = array(); |
||
| 1425 | if (!empty($groupList)) { |
||
| 1426 | foreach ($groupList as $group) { |
||
| 1427 | $group_name_list[$group['id']] = $group['name']; |
||
| 1428 | } |
||
| 1429 | } |
||
| 1430 | |||
| 1431 | if (!empty($groupId)) { |
||
| 1432 | View Code Duplication | if (!api_is_allowed_to_edit()) { |
|
| 1433 | $user_id = api_get_user_id(); |
||
| 1434 | $group_memberships = GroupManager::get_group_ids( |
||
| 1435 | $course_id, |
||
| 1436 | $user_id |
||
| 1437 | ); |
||
| 1438 | } else { |
||
| 1439 | $group_memberships = GroupManager::get_group_ids( |
||
| 1440 | $course_id, |
||
| 1441 | $user_id |
||
| 1442 | ); |
||
| 1443 | } |
||
| 1444 | View Code Duplication | } else { |
|
| 1445 | // if no group was defined but I am a student reviewing his agenda, |
||
| 1446 | // group events should show, so we should fetch those groups to which |
||
| 1447 | // I belong |
||
| 1448 | if (!api_is_allowed_to_edit()) { |
||
| 1449 | $user_id = api_get_user_id(); |
||
| 1450 | $group_memberships = GroupManager::get_group_ids( |
||
| 1451 | $course_id, |
||
| 1452 | $user_id |
||
| 1453 | ); |
||
| 1454 | } else { |
||
| 1455 | // If no group was defined and I am a teacher/admin reviewing |
||
| 1456 | // someone else's agenda, we should fetch this person's groups |
||
| 1457 | $group_memberships = GroupManager::get_group_ids( |
||
| 1458 | $course_id, |
||
| 1459 | $user_id |
||
| 1460 | ); |
||
| 1461 | } |
||
| 1462 | } |
||
| 1463 | |||
| 1464 | $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA); |
||
| 1465 | $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||
| 1466 | |||
| 1467 | if (!empty($groupId)) { |
||
| 1468 | $group_memberships = array($groupId); |
||
| 1469 | } |
||
| 1470 | |||
| 1471 | if (is_array($group_memberships) && count($group_memberships) > 0) { |
||
| 1472 | if (api_is_allowed_to_edit()) { |
||
| 1473 | if (!empty($groupId)) { |
||
| 1474 | $where_condition = "( ip.to_group_id IN (".implode(", ", $group_memberships).") ) "; |
||
| 1475 | View Code Duplication | } else { |
|
| 1476 | if (!empty($user_id)) { |
||
| 1477 | $where_condition = "( ip.to_user_id = $user_id OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ) "; |
||
| 1478 | } else { |
||
| 1479 | $where_condition = "( ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; |
||
| 1480 | } |
||
| 1481 | } |
||
| 1482 | } else { |
||
| 1483 | $where_condition = "( ip.to_user_id = $user_id OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ) "; |
||
| 1484 | } |
||
| 1485 | |||
| 1486 | if (empty($session_id)) { |
||
| 1487 | $sessionCondition = " |
||
| 1488 | ( |
||
| 1489 | agenda.session_id = 0 AND (ip.session_id IS NULL OR ip.session_id = 0) |
||
| 1490 | ) "; |
||
| 1491 | } else { |
||
| 1492 | $sessionCondition = " |
||
| 1493 | ( |
||
| 1494 | agenda.session_id = $session_id AND |
||
| 1495 | ip.session_id = $session_id |
||
| 1496 | ) "; |
||
| 1497 | } |
||
| 1498 | |||
| 1499 | $sql = "SELECT DISTINCT |
||
| 1500 | agenda.*, |
||
| 1501 | ip.visibility, |
||
| 1502 | ip.to_group_id, |
||
| 1503 | ip.insert_user_id, |
||
| 1504 | ip.ref, |
||
| 1505 | to_user_id |
||
| 1506 | FROM $tlb_course_agenda agenda |
||
| 1507 | INNER JOIN $tbl_property ip |
||
| 1508 | ON (agenda.id = ip.ref AND agenda.c_id = ip.c_id AND ip.tool = '".TOOL_CALENDAR_EVENT."') |
||
| 1509 | WHERE |
||
| 1510 | $where_condition AND |
||
| 1511 | ip.visibility = '1' AND |
||
| 1512 | agenda.c_id = $course_id AND |
||
| 1513 | ip.c_id = agenda.c_id AND |
||
| 1514 | $sessionCondition |
||
| 1515 | "; |
||
| 1516 | } else { |
||
| 1517 | $visibilityCondition = " ip.visibility='1' AND "; |
||
| 1518 | |||
| 1519 | if (api_is_allowed_to_edit()) { |
||
| 1520 | if ($user_id == 0) { |
||
| 1521 | $where_condition = ""; |
||
| 1522 | } else { |
||
| 1523 | $where_condition = " (ip.to_user_id = ".$user_id." OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL AND "; |
||
| 1524 | } |
||
| 1525 | $visibilityCondition = " (ip.visibility IN ('1', '0')) AND "; |
||
| 1526 | } else { |
||
| 1527 | $where_condition = " ( (ip.to_user_id = ".api_get_user_id()." OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL) AND "; |
||
| 1528 | } |
||
| 1529 | |||
| 1530 | if (empty($session_id)) { |
||
| 1531 | $sessionCondition = " |
||
| 1532 | ( |
||
| 1533 | agenda.session_id = 0 AND |
||
| 1534 | (ip.session_id IS NULL OR ip.session_id = 0) |
||
| 1535 | ) "; |
||
| 1536 | } else { |
||
| 1537 | $sessionCondition = " |
||
| 1538 | ( |
||
| 1539 | agenda.session_id = $session_id AND |
||
| 1540 | ip.session_id = $session_id |
||
| 1541 | ) "; |
||
| 1542 | } |
||
| 1543 | |||
| 1544 | $sql = "SELECT DISTINCT |
||
| 1545 | agenda.*, |
||
| 1546 | ip.visibility, |
||
| 1547 | ip.to_group_id, |
||
| 1548 | ip.insert_user_id, |
||
| 1549 | ip.ref, |
||
| 1550 | to_user_id |
||
| 1551 | FROM $tlb_course_agenda agenda |
||
| 1552 | INNER JOIN $tbl_property ip |
||
| 1553 | ON (agenda.id = ip.ref AND agenda.c_id = ip.c_id AND ip.tool='".TOOL_CALENDAR_EVENT."' ) |
||
| 1554 | WHERE |
||
| 1555 | $where_condition |
||
| 1556 | $visibilityCondition |
||
| 1557 | agenda.c_id = $course_id AND |
||
| 1558 | $sessionCondition |
||
| 1559 | "; |
||
| 1560 | } |
||
| 1561 | |||
| 1562 | $dateCondition = null; |
||
| 1563 | |||
| 1564 | View Code Duplication | if (!empty($start) && !empty($end)) { |
|
| 1565 | $dateCondition .= "AND ( |
||
| 1566 | agenda.start_date BETWEEN '".$start."' AND '".$end."' OR |
||
| 1567 | agenda.end_date BETWEEN '".$start."' AND '".$end."' OR |
||
| 1568 | ( |
||
| 1569 | agenda.start_date IS NOT NULL AND agenda.end_date IS NOT NULL AND |
||
| 1570 | YEAR(agenda.start_date) = YEAR(agenda.end_date) AND |
||
| 1571 | MONTH('$start') BETWEEN MONTH(agenda.start_date) AND MONTH(agenda.end_date) |
||
| 1572 | ) |
||
| 1573 | )"; |
||
| 1574 | } |
||
| 1575 | |||
| 1576 | $sql .= $dateCondition; |
||
| 1577 | $result = Database::query($sql); |
||
| 1578 | |||
| 1579 | $coachCanEdit = false; |
||
| 1580 | if (!empty($session_id)) { |
||
| 1581 | $coachCanEdit = api_is_coach($session_id, $course_id) || api_is_platform_admin(); |
||
| 1582 | } |
||
| 1583 | |||
| 1584 | if (Database::num_rows($result)) { |
||
| 1585 | $eventsAdded = array_column($this->events, 'unique_id'); |
||
| 1586 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 1587 | $event = array(); |
||
| 1588 | $event['id'] = 'course_'.$row['id']; |
||
| 1589 | $event['unique_id'] = $row['iid']; |
||
| 1590 | // To avoid doubles |
||
| 1591 | if (in_array($event['unique_id'], $eventsAdded)) { |
||
| 1592 | continue; |
||
| 1593 | } |
||
| 1594 | |||
| 1595 | $eventsAdded[] = $event['unique_id']; |
||
| 1596 | |||
| 1597 | $eventId = $row['ref']; |
||
| 1598 | $items = $this->getUsersAndGroupSubscribedToEvent( |
||
| 1599 | $eventId, |
||
| 1600 | $course_id, |
||
| 1601 | $this->sessionId |
||
| 1602 | ); |
||
| 1603 | $group_to_array = $items['groups']; |
||
| 1604 | $user_to_array = $items['users']; |
||
| 1605 | $attachmentList = $this->getAttachmentList($row['id'], $courseInfo); |
||
| 1606 | $event['attachment'] = ''; |
||
| 1607 | |||
| 1608 | if (!empty($attachmentList)) { |
||
| 1609 | foreach ($attachmentList as $attachment) { |
||
| 1610 | $has_attachment = Display::return_icon('attachment.gif', get_lang('Attachment')); |
||
| 1611 | $user_filename = $attachment['filename']; |
||
| 1612 | $url = api_get_path(WEB_CODE_PATH).'calendar/download.php?file='.$attachment['path'].'&course_id='.$course_id.'&'.api_get_cidreq(); |
||
| 1613 | $event['attachment'] .= $has_attachment.Display::url($user_filename, $url).'<br />'; |
||
| 1614 | } |
||
| 1615 | } |
||
| 1616 | |||
| 1617 | $event['title'] = $row['title']; |
||
| 1618 | $event['className'] = 'course'; |
||
| 1619 | $event['allDay'] = 'false'; |
||
| 1620 | $event['course_id'] = $course_id; |
||
| 1621 | $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color; |
||
| 1622 | |||
| 1623 | $sessionInfo = []; |
||
| 1624 | View Code Duplication | if (isset($row['session_id']) && !empty($row['session_id'])) { |
|
| 1625 | $sessionInfo = api_get_session_info($session_id); |
||
| 1626 | $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color; |
||
| 1627 | } |
||
| 1628 | |||
| 1629 | $event['session_name'] = isset($sessionInfo['name']) ? $sessionInfo['name'] : ''; |
||
| 1630 | $event['course_name'] = isset($courseInfo['title']) ? $courseInfo['title'] : ''; |
||
| 1631 | |||
| 1632 | View Code Duplication | if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { |
|
| 1633 | $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color; |
||
| 1634 | } |
||
| 1635 | |||
| 1636 | if (!empty($color)) { |
||
| 1637 | $event['borderColor'] = $event['backgroundColor'] = $color; |
||
| 1638 | } |
||
| 1639 | |||
| 1640 | View Code Duplication | if (isset($row['color']) && !empty($row['color'])) { |
|
| 1641 | $event['borderColor'] = $event['backgroundColor'] = $row['color']; |
||
| 1642 | } |
||
| 1643 | |||
| 1644 | $event['editable'] = false; |
||
| 1645 | |||
| 1646 | if (api_is_allowed_to_edit() && $this->type == 'course') { |
||
| 1647 | $event['editable'] = true; |
||
| 1648 | if (!empty($session_id)) { |
||
| 1649 | if ($coachCanEdit == false) { |
||
| 1650 | $event['editable'] = false; |
||
| 1651 | } |
||
| 1652 | } |
||
| 1653 | } |
||
| 1654 | |||
| 1655 | View Code Duplication | if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') { |
|
| 1656 | $event['start'] = $this->formatEventDate($row['start_date']); |
||
| 1657 | $event['start_date_localtime'] = api_get_local_time($row['start_date']); |
||
| 1658 | } |
||
| 1659 | View Code Duplication | if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') { |
|
| 1660 | $event['end'] = $this->formatEventDate($row['end_date']); |
||
| 1661 | $event['end_date_localtime'] = api_get_local_time($row['end_date']); |
||
| 1662 | } |
||
| 1663 | |||
| 1664 | $event['sent_to'] = ''; |
||
| 1665 | $event['type'] = 'course'; |
||
| 1666 | if ($row['session_id'] != 0) { |
||
| 1667 | $event['type'] = 'session'; |
||
| 1668 | } |
||
| 1669 | |||
| 1670 | // Event Sent to a group? |
||
| 1671 | if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { |
||
| 1672 | $sent_to = array(); |
||
| 1673 | if (!empty($group_to_array)) { |
||
| 1674 | foreach ($group_to_array as $group_item) { |
||
| 1675 | $sent_to[] = $group_name_list[$group_item]; |
||
| 1676 | } |
||
| 1677 | } |
||
| 1678 | $sent_to = implode('@@', $sent_to); |
||
| 1679 | $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to); |
||
| 1680 | $event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>'; |
||
| 1681 | $event['type'] = 'group'; |
||
| 1682 | } |
||
| 1683 | |||
| 1684 | // Event sent to a user? |
||
| 1685 | if (isset($row['to_user_id'])) { |
||
| 1686 | $sent_to = array(); |
||
| 1687 | if (!empty($user_to_array)) { |
||
| 1688 | foreach ($user_to_array as $item) { |
||
| 1689 | $user_info = api_get_user_info($item); |
||
| 1690 | // Add username as tooltip for $event['sent_to'] - ref #4226 |
||
| 1691 | $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES); |
||
| 1692 | $sent_to[] = "<span title='".$username."'>".$user_info['complete_name']."</span>"; |
||
| 1693 | } |
||
| 1694 | } |
||
| 1695 | $sent_to = implode('@@', $sent_to); |
||
| 1696 | $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to); |
||
| 1697 | $event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>'; |
||
| 1698 | } |
||
| 1699 | |||
| 1700 | //Event sent to everyone! |
||
| 1701 | if (empty($event['sent_to'])) { |
||
| 1702 | $event['sent_to'] = '<div class="label_tag notice">'.get_lang('Everyone').'</div>'; |
||
| 1703 | } |
||
| 1704 | |||
| 1705 | $event['description'] = $row['content']; |
||
| 1706 | $event['visibility'] = $row['visibility']; |
||
| 1707 | $event['real_id'] = $row['id']; |
||
| 1708 | $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; |
||
| 1709 | $event['parent_event_id'] = $row['parent_event_id']; |
||
| 1710 | $event['has_children'] = $this->hasChildren($row['id'], $course_id) ? 1 : 0; |
||
| 1711 | $event['comment'] = $row['comment']; |
||
| 1712 | |||
| 1713 | $this->events[] = $event; |
||
| 1714 | } |
||
| 1715 | } |
||
| 1716 | |||
| 1717 | return $this->events; |
||
| 1718 | } |
||
| 1719 | |||
| 1720 | /** |
||
| 1721 | * @param int $start tms |
||
| 1722 | * @param int $end tms |
||
| 1723 | * @return array |
||
| 1724 | */ |
||
| 1725 | public function getPlatformEvents($start, $end) |
||
| 1726 | { |
||
| 1727 | $start = isset($start) && !empty($start) ? api_get_utc_datetime(intval($start)) : null; |
||
| 1728 | $end = isset($end) && !empty($end) ? api_get_utc_datetime(intval($end)) : null; |
||
| 1729 | |||
| 1730 | $dateCondition = ''; |
||
| 1731 | |||
| 1732 | View Code Duplication | if (!empty($start) && !empty($end)) { |
|
| 1733 | $dateCondition .= "AND ( |
||
| 1734 | start_date BETWEEN '".$start."' AND '".$end."' OR |
||
| 1735 | end_date BETWEEN '".$start."' AND '".$end."' OR |
||
| 1736 | ( |
||
| 1737 | start_date IS NOT NULL AND end_date IS NOT NULL AND |
||
| 1738 | YEAR(start_date) = YEAR(end_date) AND |
||
| 1739 | MONTH('$start') BETWEEN MONTH(start_date) AND MONTH(end_date) |
||
| 1740 | ) |
||
| 1741 | )"; |
||
| 1742 | } |
||
| 1743 | |||
| 1744 | $access_url_id = api_get_current_access_url_id(); |
||
| 1745 | |||
| 1746 | $sql = "SELECT * |
||
| 1747 | FROM ".$this->tbl_global_agenda." |
||
| 1748 | WHERE access_url_id = $access_url_id |
||
| 1749 | $dateCondition"; |
||
| 1750 | $result = Database::query($sql); |
||
| 1751 | $my_events = array(); |
||
| 1752 | if (Database::num_rows($result)) { |
||
| 1753 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 1754 | $event = array(); |
||
| 1755 | $event['id'] = 'platform_'.$row['id']; |
||
| 1756 | $event['title'] = $row['title']; |
||
| 1757 | $event['className'] = 'platform'; |
||
| 1758 | $event['allDay'] = 'false'; |
||
| 1759 | $event['borderColor'] = $event['backgroundColor'] = $this->event_platform_color; |
||
| 1760 | $event['editable'] = false; |
||
| 1761 | $event['type'] = 'admin'; |
||
| 1762 | |||
| 1763 | if (api_is_platform_admin() && $this->type == 'admin') { |
||
| 1764 | $event['editable'] = true; |
||
| 1765 | } |
||
| 1766 | |||
| 1767 | View Code Duplication | if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') { |
|
| 1768 | $event['start'] = $this->formatEventDate($row['start_date']); |
||
| 1769 | $event['start_date_localtime'] = api_get_local_time($row['start_date']); |
||
| 1770 | } |
||
| 1771 | View Code Duplication | if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') { |
|
| 1772 | $event['end'] = $this->formatEventDate($row['end_date']); |
||
| 1773 | $event['end_date_localtime'] = api_get_local_time($row['end_date']); |
||
| 1774 | } |
||
| 1775 | |||
| 1776 | $event['description'] = $row['content']; |
||
| 1777 | $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; |
||
| 1778 | |||
| 1779 | $event['parent_event_id'] = 0; |
||
| 1780 | $event['has_children'] = 0; |
||
| 1781 | |||
| 1782 | $my_events[] = $event; |
||
| 1783 | $this->events[] = $event; |
||
| 1784 | } |
||
| 1785 | } |
||
| 1786 | |||
| 1787 | return $my_events; |
||
| 1788 | } |
||
| 1789 | |||
| 1790 | /** |
||
| 1791 | * Format needed for the Fullcalendar js lib |
||
| 1792 | * |
||
| 1793 | * @param string $utcTime |
||
| 1794 | * @return bool|string |
||
| 1795 | */ |
||
| 1796 | private function formatEventDate($utcTime) |
||
| 1806 | |||
| 1807 | /** |
||
| 1808 | * @param FormValidator $form |
||
| 1809 | * @param array $groupList |
||
| 1810 | * @param array $userList |
||
| 1811 | * @param array $sendTo array('users' => [1, 2], 'groups' => [3, 4]) |
||
| 1812 | * @param array $attributes |
||
| 1813 | * @param bool $addOnlyItemsInSendTo |
||
| 1814 | * @param bool $required |
||
| 1815 | */ |
||
| 1816 | public function setSendToSelect( |
||
| 1912 | |||
| 1913 | /** |
||
| 1914 | * Separates the users and groups array |
||
| 1915 | * users have a value USER:XXX (with XXX the user id |
||
| 1916 | * groups have a value GROUP:YYY (with YYY the group id) |
||
| 1917 | * use the 'everyone' key |
||
| 1918 | * @author Julio Montoya based in separate_users_groups in agenda.inc.php |
||
| 1919 | * @param array $to |
||
| 1920 | * @return array |
||
| 1921 | */ |
||
| 1922 | public function parseSendToArray($to) |
||
| 1951 | |||
| 1952 | /** |
||
| 1953 | * @param array $params |
||
| 1954 | * @return FormValidator |
||
| 1955 | */ |
||
| 1956 | public function getForm($params = array()) |
||
| 2138 | |||
| 2139 | /** |
||
| 2140 | * @param FormValidator $form |
||
| 2141 | * @param array $sendTo array('everyone' => false, 'users' => [1, 2], 'groups' => [3, 4]) |
||
| 2142 | * @param array $attributes |
||
| 2143 | * @param bool $addOnlyItemsInSendTo |
||
| 2144 | * @param bool $required |
||
| 2145 | * @return bool |
||
| 2146 | */ |
||
| 2147 | public function showToForm( |
||
| 2186 | |||
| 2187 | /** |
||
| 2188 | * @param int $id |
||
| 2189 | * @param int $visibility 0= invisible, 1 visible |
||
| 2190 | * @param array $courseInfo |
||
| 2191 | * @param int $userId |
||
| 2192 | */ |
||
| 2193 | public static function changeVisibility($id, $visibility, $courseInfo, $userId = null) |
||
| 2208 | |||
| 2209 | /** |
||
| 2210 | * Get repeat types |
||
| 2211 | * @return array |
||
| 2212 | */ |
||
| 2213 | public static function getRepeatTypes() |
||
| 2224 | |||
| 2225 | /** |
||
| 2226 | * Show a list with all the attachments according to the post's id |
||
| 2227 | * @param int $eventId |
||
| 2228 | * @param array $courseInfo |
||
| 2229 | * @return array with the post info |
||
| 2230 | */ |
||
| 2231 | View Code Duplication | public function getAttachmentList($eventId, $courseInfo) |
|
| 2250 | |||
| 2251 | |||
| 2252 | /** |
||
| 2253 | * Show a list with all the attachments according to the post's id |
||
| 2254 | * @param int $attachmentId |
||
| 2255 | * @param int $eventId |
||
| 2256 | * @param array $courseInfo |
||
| 2257 | * @return array with the post info |
||
| 2258 | */ |
||
| 2259 | View Code Duplication | public function getAttachment($attachmentId, $eventId, $courseInfo) |
|
| 2281 | |||
| 2282 | /** |
||
| 2283 | * Add an attachment file into agenda |
||
| 2284 | * @param int $eventId |
||
| 2285 | * @param array $fileUserUpload ($_FILES['user_upload']) |
||
| 2286 | * @param string $comment about file |
||
| 2287 | * @param array $courseInfo |
||
| 2288 | * @return string |
||
| 2289 | */ |
||
| 2290 | public function addAttachment($eventId, $fileUserUpload, $comment, $courseInfo) |
||
| 2353 | |||
| 2354 | /** |
||
| 2355 | * @param int $attachmentId |
||
| 2356 | * @param int $eventId |
||
| 2357 | * @param array $fileUserUpload |
||
| 2358 | * @param string $comment |
||
| 2359 | * @param array $courseInfo |
||
| 2360 | */ |
||
| 2361 | public function updateAttachment($attachmentId, $eventId, $fileUserUpload, $comment, $courseInfo) |
||
| 2369 | |||
| 2370 | /** |
||
| 2371 | * This function delete a attachment file by id |
||
| 2372 | * @param int $attachmentId |
||
| 2373 | * @param array $courseInfo |
||
| 2374 | * @return string |
||
| 2375 | */ |
||
| 2376 | public function deleteAttachmentFile($attachmentId, $courseInfo) |
||
| 2403 | |||
| 2404 | /** |
||
| 2405 | * Adds x weeks to a UNIX timestamp |
||
| 2406 | * @param int The timestamp |
||
| 2407 | * @param int The number of weeks to add |
||
| 2408 | * @param integer $timestamp |
||
| 2409 | * @return int The new timestamp |
||
| 2410 | */ |
||
| 2411 | function addWeek($timestamp, $num = 1) |
||
| 2415 | |||
| 2416 | /** |
||
| 2417 | * Adds x months to a UNIX timestamp |
||
| 2418 | * @param int The timestamp |
||
| 2419 | * @param int The number of years to add |
||
| 2420 | * @param integer $timestamp |
||
| 2421 | * @return int The new timestamp |
||
| 2422 | */ |
||
| 2423 | function addMonth($timestamp, $num = 1) |
||
| 2434 | |||
| 2435 | /** |
||
| 2436 | * Adds x years to a UNIX timestamp |
||
| 2437 | * @param int The timestamp |
||
| 2438 | * @param int The number of years to add |
||
| 2439 | * @param integer $timestamp |
||
| 2440 | * @return int The new timestamp |
||
| 2441 | */ |
||
| 2442 | function addYear($timestamp, $num = 1) |
||
| 2447 | |||
| 2448 | /** |
||
| 2449 | * @param int $eventId |
||
| 2450 | * @return array |
||
| 2451 | */ |
||
| 2452 | public function getAllRepeatEvents($eventId) |
||
| 2476 | |||
| 2477 | /** |
||
| 2478 | * @param int $eventId |
||
| 2479 | * @param int $courseId |
||
| 2480 | * |
||
| 2481 | * @return bool |
||
| 2482 | */ |
||
| 2483 | public function hasChildren($eventId, $courseId) |
||
| 2500 | |||
| 2501 | /** |
||
| 2502 | * @param int $filter |
||
| 2503 | * @param string $view |
||
| 2504 | * @return string |
||
| 2505 | */ |
||
| 2506 | public function displayActions($view, $filter = 0) |
||
| 2613 | |||
| 2614 | /** |
||
| 2615 | * @return FormValidator |
||
| 2616 | */ |
||
| 2617 | public function getImportCalendarForm() |
||
| 2632 | |||
| 2633 | /** |
||
| 2634 | * @param array $courseInfo |
||
| 2635 | * @param $file |
||
| 2636 | * @return false|string |
||
| 2637 | */ |
||
| 2638 | public function importEventFile($courseInfo, $file) |
||
| 2745 | |||
| 2746 | /** |
||
| 2747 | * Parse filter turns USER:12 to ['users' => [12])] or G:1 ['groups' => [1]] |
||
| 2748 | * @param integer $filter |
||
| 2749 | * @return array |
||
| 2750 | */ |
||
| 2751 | public function parseAgendaFilter($filter) |
||
| 2777 | |||
| 2778 | /** |
||
| 2779 | * This function retrieves all the agenda items of all the courses the user is subscribed to |
||
| 2780 | */ |
||
| 2781 | public static function get_myagendaitems($user_id, $courses_dbs, $month, $year) |
||
| 2872 | |||
| 2873 | /** |
||
| 2874 | * This function retrieves one personal agenda item returns it. |
||
| 2875 | * @param array The array containing existing events. We add to this array. |
||
| 2876 | * @param int Day |
||
| 2877 | * @param int Month |
||
| 2878 | * @param int Year (4 digits) |
||
| 2879 | * @param int Week number |
||
| 2880 | * @param string Type of view (month_view, week_view, day_view) |
||
| 2881 | * @return array The results of the database query, or null if not found |
||
| 2882 | */ |
||
| 2883 | public static function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type) |
||
| 3009 | |||
| 3010 | /** |
||
| 3011 | * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions. |
||
| 3012 | */ |
||
| 3013 | public static function get_personal_agenda_items($user_id, $agendaitems, $day = "", $month = "", $year = "", $week = "", $type) |
||
| 3111 | |||
| 3112 | |||
| 3113 | /** |
||
| 3114 | * Show the monthcalender of the given month |
||
| 3115 | * @param array Agendaitems |
||
| 3116 | * @param int Month number |
||
| 3117 | * @param int Year number |
||
| 3118 | * @param array Array of strings containing long week day names (deprecated, you can send an empty array instead) |
||
| 3119 | * @param string The month name |
||
| 3120 | * @return void Direct output |
||
| 3121 | */ |
||
| 3122 | public static function display_mymonthcalendar($user_id, $agendaitems, $month, $year, $weekdaynames = array(), $monthName, $show_content = true) |
||
| 3257 | |||
| 3258 | /** |
||
| 3259 | * Get personal agenda items between two dates (=all events from all registered courses) |
||
| 3260 | * @param int user ID of the user |
||
| 3261 | * @param string Optional start date in datetime format (if no start date is given, uses today) |
||
| 3262 | * @param string Optional end date in datetime format (if no date is given, uses one year from now) |
||
| 3263 | * @param integer $user_id |
||
| 3264 | * @return array Array of events ordered by start date, in |
||
| 3265 | * [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, |
||
| 3266 | * where datestart and dateend are in yyyyMMddhhmmss format. |
||
| 3267 | * @TODO Implement really personal events (from user DB) and global events (from main DB) |
||
| 3268 | */ |
||
| 3269 | public static function get_personal_agenda_items_between_dates($user_id, $date_start='', $date_end='') |
||
| 3354 | |||
| 3355 | |||
| 3356 | /** |
||
| 3357 | * This function retrieves one personal agenda item returns it. |
||
| 3358 | * @param int The agenda item ID |
||
| 3359 | * @return array The results of the database query, or null if not found |
||
| 3360 | */ |
||
| 3361 | public static function get_personal_agenda_item($id) |
||
| 3376 | |||
| 3377 | |||
| 3378 | /** |
||
| 3379 | * This function calculates the startdate of the week (monday) |
||
| 3380 | * and the enddate of the week (sunday) |
||
| 3381 | * and returns it as an array |
||
| 3382 | */ |
||
| 3383 | public static function calculate_start_end_of_week($week_number, $year) |
||
| 3409 | |||
| 3410 | /** |
||
| 3411 | * @return bool |
||
| 3412 | */ |
||
| 3413 | public function getIsAllowedToEdit() |
||
| 3417 | |||
| 3418 | /** |
||
| 3419 | * @param bool $isAllowedToEdit |
||
| 3420 | */ |
||
| 3421 | public function setIsAllowedToEdit($isAllowedToEdit) |
||
| 3425 | } |
||
| 3426 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..