Merge pull request #18764 from civicrm/5.31
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 14 Oct 2020 08:59:09 +0000 (19:59 +1100)
committerGitHub <noreply@github.com>
Wed, 14 Oct 2020 08:59:09 +0000 (19:59 +1100)
5.31

CRM/Event/Page/UserDashboard.php

index 39097caa463dcb73d461a60027fa6cb21c6b52d1..e1c0aa73c2c089217de4a78efd2b0d020e3a11aa 100644 (file)
@@ -25,19 +25,29 @@ class CRM_Event_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBoard {
    *
    */
   public function listParticipations() {
-    $controller = new CRM_Core_Controller_Simple(
-      'CRM_Event_Form_Search',
-      ts('Events'),
-      NULL,
-      FALSE, FALSE, TRUE, FALSE
-    );
-    $controller->setEmbedded(TRUE);
-    $controller->reset();
-    $controller->set('context', 'user');
-    $controller->set('cid', $this->_contactId);
-    $controller->set('force', 1);
-    $controller->process();
-    $controller->run();
+    $event_rows = [];
+
+    $participants = \Civi\Api4\Participant::get(FALSE)
+      ->addSelect('id', 'contact_id', 'status_id:name', 'status_id:label', 'event.id', 'event.title', 'event.start_date', 'event.end_date')
+      ->addWhere('contact_id', '=', $this->_contactId)
+      ->addOrderBy('event.start_date', 'DESC')
+      ->execute()
+      ->indexBy('id');
+
+    // Flatten the results in the format expected by the template
+    foreach ($participants as $p) {
+      $p['participant_id'] = $p['id'];
+      $p['status'] = $p['status_id:name'];
+      $p['participant_status'] = $p['status_id:label'];
+      $p['event_id'] = $p['event.id'];
+      $p['event_title'] = $p['event.title'];
+      $p['event_start_date'] = $p['event.start_date'];
+      $p['event_end_date'] = $p['event.end_date'];
+
+      $event_rows[] = $p;
+    }
+
+    $this->assign('event_rows', $event_rows);
   }
 
   /**