Merge pull request #18758 from mlutfy/event43rc
[civicrm-core.git] / CRM / Event / Page / UserDashboard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class is for building event(participation) block on user dashboard
20 */
21 class CRM_Event_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBoard {
22
23 /**
24 * List participations for the UF user.
25 *
26 */
27 public function listParticipations() {
28 $event_rows = [];
29
30 $participants = \Civi\Api4\Participant::get(FALSE)
31 ->addSelect('id', 'contact_id', 'status_id:name', 'status_id:label', 'event.id', 'event.title', 'event.start_date', 'event.end_date')
32 ->addWhere('contact_id', '=', $this->_contactId)
33 ->addOrderBy('event.start_date', 'DESC')
34 ->execute()
35 ->indexBy('id');
36
37 // Flatten the results in the format expected by the template
38 foreach ($participants as $p) {
39 $p['participant_id'] = $p['id'];
40 $p['status'] = $p['status_id:name'];
41 $p['participant_status'] = $p['status_id:label'];
42 $p['event_id'] = $p['event.id'];
43 $p['event_title'] = $p['event.title'];
44 $p['event_start_date'] = $p['event.start_date'];
45 $p['event_end_date'] = $p['event.end_date'];
46
47 $event_rows[] = $p;
48 }
49
50 $this->assign('event_rows', $event_rows);
51 }
52
53 /**
54 * the main function that is called when the page
55 * loads, it decides the which action has to be taken for the page.
56 *
57 */
58 public function run() {
59 parent::preProcess();
60 $this->listParticipations();
61 }
62
63 }