Edit.php 1.68 KB
Newer Older
mattwire's avatar
mattwire committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

use CRM_Groupadmin_ExtensionUtil as E;

/**
 * Form controller class
 *
 * @see https://docs.civicrm.org/dev/en/latest/framework/quickform/
 */
class CRM_Groupadmin_Form_Edit extends CRM_Core_Form {

  /**
   * @var int
   *   Group ID
   */
  protected $groupID;

  public function buildQuickForm() {
    $this->groupID = CRM_Utils_Request::retrieveValue('gid', 'Positive', NULL, TRUE);
    $this->setTitle('Edit Group Administrators');

    $this->assign('groupTitle', civicrm_api3('Group', 'getvalue', ['id' => $this->groupID, 'return' => 'title']));

mattwire's avatar
mattwire committed
24
    /* Join not supported until 5.27 - https://github.com/civicrm/civicrm-core/commit/16f5a13d62017fa30190a477b9f580b4eabd23a2
mattwire's avatar
mattwire committed
25
26
27
28
29
30
31
32
    $groupAdminContacts = \Civi\Api4\GroupAdminContact::get()
      ->addSelect('contact_id', 'contact.display_name')
      ->setJoin([
        ['Contact AS contact', TRUE, ['contact_id', '=', 'contact_id']],
      ])
      ->addWhere('group_id', '=', $this->groupID)
      ->setCheckPermissions(FALSE)
      ->execute();
mattwire's avatar
mattwire committed
33
34
35
36
37
38
    */

    $groupAdminContacts = civicrm_api3('GroupAdminContact', 'get', [
      'return' => ['contact_id', 'contact.display_name'],
      'group_id' => $this->groupID,
    ])['values'];
mattwire's avatar
mattwire committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

    foreach ($groupAdminContacts as $groupAdminContact) {
      $adminContacts[$groupAdminContact['contact_id']] = $groupAdminContact['contact.display_name'];
    }
    $this->assign('groupAdminContacts', $adminContacts);
    $this->assign('groupID', $this->groupID);

    $this->addEntityRef('contact_id', ts('Add Group Admin Contact'), ['create' => FALSE], FALSE);

    $this->addButtons([
      [
        'type' => 'submit',
        'name' => E::ts('Submit'),
        'isDefault' => TRUE,
      ],
    ]);
  }

}