EntityRole.php 6.15 KB
Newer Older
totten's avatar
totten committed
1 2 3
<?php
/*
 +--------------------------------------------------------------------+
yashodha's avatar
yashodha committed
4
 | CiviCRM version 4.6                                                |
totten's avatar
totten committed
5
 +--------------------------------------------------------------------+
kurund's avatar
kurund committed
6
 | Copyright CiviCRM LLC (c) 2004-2014                                |
totten's avatar
totten committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
26
 */
totten's avatar
totten committed
27 28 29 30

/**
 *
 * @package CRM
kurund's avatar
kurund committed
31
 * @copyright CiviCRM LLC (c) 2004-2014
totten's avatar
totten committed
32 33 34 35 36 37 38
 * $Id$
 *
 */

/**
 *
 * @package CRM
kurund's avatar
kurund committed
39
 * @copyright CiviCRM LLC (c) 2004-2014
totten's avatar
totten committed
40 41 42 43 44
 * $Id$
 *
 */
class CRM_ACL_Page_EntityRole extends CRM_Core_Page_Basic {

45 46
  public $useLivePageJS = TRUE;

totten's avatar
totten committed
47 48 49 50 51 52 53 54 55 56
  /**
   * The action links that we need to display for the browse screen
   *
   * @var array
   */
  static $_links = NULL;

  /**
   * Get BAO Name
   *
57 58
   * @return string
   *   Classname of BAO.
totten's avatar
totten committed
59
   */
60
  public function getBAOName() {
totten's avatar
totten committed
61 62 63 64 65 66
    return 'CRM_ACL_BAO_EntityRole';
  }

  /**
   * Get action Links
   *
67 68
   * @return array
   *   (reference) of action links
totten's avatar
totten committed
69
   */
70
  public function &links() {
totten's avatar
totten committed
71 72 73 74 75 76 77 78 79 80
    if (!(self::$_links)) {
      self::$_links = array(
        CRM_Core_Action::UPDATE => array(
          'name' => ts('Edit'),
          'url' => 'civicrm/acl/entityrole',
          'qs' => 'action=update&id=%%id%%',
          'title' => ts('Edit ACL Role Assignment'),
        ),
        CRM_Core_Action::DISABLE => array(
          'name' => ts('Disable'),
81
          'ref' => 'crm-enable-disable',
totten's avatar
totten committed
82 83 84 85
          'title' => ts('Disable ACL Role Assignment'),
        ),
        CRM_Core_Action::ENABLE => array(
          'name' => ts('Enable'),
86
          'ref' => 'crm-enable-disable',
totten's avatar
totten committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
          'title' => ts('Enable ACL Role Assignment'),
        ),
        CRM_Core_Action::DELETE => array(
          'name' => ts('Delete'),
          'url' => 'civicrm/acl/entityrole',
          'qs' => 'action=delete&id=%%id%%',
          'title' => ts('Delete ACL Role Assignment'),
        ),
      );
    }
    return self::$_links;
  }

  /**
   * Run the page.
   *
   * This method is called after the page is created. It checks for the
   * type of action and executes that action.
   * Finally it calls the parent's run method.
   *
   * @return void
   */
109
  public function run() {
totten's avatar
totten committed
110 111 112 113 114 115 116 117 118 119 120 121 122
    // get the requested action
    $action = CRM_Utils_Request::retrieve('action', 'String',
      // default to 'browse'
      $this, FALSE, 'browse'
    );

    // assign vars to templates
    $this->assign('action', $action);
    $id = CRM_Utils_Request::retrieve('id', 'Positive',
      $this, FALSE, 0
    );

    // set breadcrumb to append to admin/access
totten's avatar
totten committed
123 124 125
    $breadCrumb = array(
      array(
        'title' => ts('Access Control'),
totten's avatar
totten committed
126 127 128
        'url' => CRM_Utils_System::url('civicrm/admin/access',
          'reset=1'
        ),
totten's avatar
totten committed
129
      ),
totten's avatar
totten committed
130
    );
totten's avatar
totten committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    CRM_Utils_System::appendBreadCrumb($breadCrumb);
    CRM_Utils_System::setTitle(ts('Assign Users to Roles'));

    // what action to take ?
    if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
      $this->edit($action, $id);
    }

    // reset cache if enabled/disabled
    if ($action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) {
      CRM_ACL_BAO_Cache::resetCache();
    }

    // finally browse the acl's
    if ($action & CRM_Core_Action::BROWSE) {
    }

    // parent run
    return parent::run();
  }

  /**
   * Browse all acls
   *
   * @return void
   */
157
  public function browse() {
totten's avatar
totten committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

    // get all acl's sorted by weight
    $entityRoles = array();
    $dao = new CRM_ACL_DAO_EntityRole();
    $dao->find();

    $aclRoles = CRM_Core_OptionGroup::values('acl_role');
    $groups = CRM_Core_PseudoConstant::staticGroup();

    while ($dao->fetch()) {
      $entityRoles[$dao->id] = array();
      CRM_Core_DAO::storeValues($dao, $entityRoles[$dao->id]);

      $entityRoles[$dao->id]['acl_role'] = $aclRoles[$dao->acl_role_id];
      $entityRoles[$dao->id]['entity'] = $groups[$dao->entity_id];

      // form all action links
      $action = array_sum(array_keys($this->links()));
      if ($dao->is_active) {
        $action -= CRM_Core_Action::ENABLE;
      }
      else {
        $action -= CRM_Core_Action::DISABLE;
      }

183 184 185 186 187 188 189 190 191
      $entityRoles[$dao->id]['action'] = CRM_Core_Action::formLink(
        self::links(),
        $action,
        array('id' => $dao->id),
        ts('more'),
        FALSE,
        'entityRole.manage.action',
        'EntityRole',
        $dao->id
totten's avatar
totten committed
192 193 194 195 196 197 198 199
      );
    }
    $this->assign('rows', $entityRoles);
  }

  /**
   * Get name of edit form
   *
200 201
   * @return string
   *   Classname of edit form.
totten's avatar
totten committed
202
   */
203
  public function editForm() {
totten's avatar
totten committed
204 205 206 207 208 209
    return 'CRM_ACL_Form_EntityRole';
  }

  /**
   * Get edit form name
   *
210 211
   * @return string
   *   name of this page.
totten's avatar
totten committed
212
   */
213
  public function editName() {
totten's avatar
totten committed
214 215 216 217 218 219
    return 'ACL EntityRole';
  }

  /**
   * Get user context.
   *
220 221
   * @param null $mode
   *
222 223
   * @return string
   *   user context.
totten's avatar
totten committed
224
   */
225
  public function userContext($mode = NULL) {
totten's avatar
totten committed
226 227
    return 'civicrm/acl/entityrole';
  }
228

totten's avatar
totten committed
229
}