/**
  * Function to delete Entity Role records
  *
  * @param  int  $entityRoleId ID of the EntityRole record to be deleted.
  *
  * @access public
  * @static
  */
 static function del($entityRoleId)
 {
     $entityDAO = new CRM_ACL_DAO_EntityRole();
     $entityDAO->id = $entityRoleId;
     $entityDAO->find(TRUE);
     $entityDAO->delete();
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  * @static
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['acl_entity_role'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Esempio n. 3
0
 /**
  * Updates contacts affected by the option value passed.
  *
  * @param int $optionValueId
  *   The option value id.
  * @param int $action
  *   The action describing whether prefix/suffix was UPDATED or DELETED.
  *
  * @return bool
  */
 public static function updateRecords(&$optionValueId, $action)
 {
     //finding group name
     $optionValue = new CRM_Core_DAO_OptionValue();
     $optionValue->id = $optionValueId;
     $optionValue->find(TRUE);
     $optionGroup = new CRM_Core_DAO_OptionGroup();
     $optionGroup->id = $optionValue->option_group_id;
     $optionGroup->find(TRUE);
     // group name
     $gName = $optionGroup->name;
     // value
     $value = $optionValue->value;
     // get the proper group name & affected field name
     // todo: this may no longer be needed for individuals - check inputs
     $individuals = array('gender' => 'gender_id', 'individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id', 'communication_style' => 'communication_style_id');
     $contributions = array('payment_instrument' => 'payment_instrument_id');
     $activities = array('activity_type' => 'activity_type_id');
     $participant = array('participant_role' => 'role_id');
     $eventType = array('event_type' => 'event_type_id');
     $aclRole = array('acl_role' => 'acl_role_id');
     $all = array_merge($individuals, $contributions, $activities, $participant, $eventType, $aclRole);
     $fieldName = '';
     foreach ($all as $name => $id) {
         if ($gName == $name) {
             $fieldName = $id;
         }
     }
     if ($fieldName == '') {
         return TRUE;
     }
     if (array_key_exists($gName, $individuals)) {
         $contactDAO = new CRM_Contact_DAO_Contact();
         $contactDAO->{$fieldName} = $value;
         $contactDAO->find();
         while ($contactDAO->fetch()) {
             if ($action == CRM_Core_Action::DELETE) {
                 $contact = new CRM_Contact_DAO_Contact();
                 $contact->id = $contactDAO->id;
                 $contact->find(TRUE);
                 // make sure dates doesn't get reset
                 $contact->birth_date = CRM_Utils_Date::isoToMysql($contact->birth_date);
                 $contact->deceased_date = CRM_Utils_Date::isoToMysql($contact->deceased_date);
                 $contact->{$fieldName} = 'NULL';
                 $contact->save();
             }
         }
         return TRUE;
     }
     if (array_key_exists($gName, $contributions)) {
         $contribution = new CRM_Contribute_DAO_Contribution();
         $contribution->{$fieldName} = $value;
         $contribution->find();
         while ($contribution->fetch()) {
             if ($action == CRM_Core_Action::DELETE) {
                 $contribution->{$fieldName} = 'NULL';
                 $contribution->save();
             }
         }
         return TRUE;
     }
     if (array_key_exists($gName, $activities)) {
         $activity = new CRM_Activity_DAO_Activity();
         $activity->{$fieldName} = $value;
         $activity->find();
         while ($activity->fetch()) {
             $activity->delete();
         }
         return TRUE;
     }
     //delete participant role, type and event type option value
     if (array_key_exists($gName, $participant)) {
         $participantValue = new CRM_Event_DAO_Participant();
         $participantValue->{$fieldName} = $value;
         if ($participantValue->find(TRUE)) {
             return FALSE;
         }
         return TRUE;
     }
     //delete event type option value
     if (array_key_exists($gName, $eventType)) {
         $event = new CRM_Event_DAO_Event();
         $event->{$fieldName} = $value;
         if ($event->find(TRUE)) {
             return FALSE;
         }
         return TRUE;
     }
     //delete acl_role option value
     if (array_key_exists($gName, $aclRole)) {
         $entityRole = new CRM_ACL_DAO_EntityRole();
         $entityRole->{$fieldName} = $value;
         $aclDAO = new CRM_ACL_DAO_ACL();
         $aclDAO->entity_id = $value;
         if ($entityRole->find(TRUE) || $aclDAO->find(TRUE)) {
             return FALSE;
         }
         return TRUE;
     }
 }
Esempio n. 4
0
 /**
  * Get all of the ACLs for a contact through ACL groups owned by Contact
  * groups.
  *
  * @param int $contact_id   -   ID of a contact to search for
  *
  * @return array            -   Array of assoc. arrays of ACL rules
  * @access public
  * @static
  */
 public static function &getGroupACLRoles($contact_id)
 {
     $contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');
     $rule = new CRM_ACL_BAO_ACL();
     $acl = self::getTableName();
     $aclRole = 'civicrm_acl_role';
     $aclER = CRM_ACL_DAO_EntityRole::getTableName();
     $c2g = CRM_Contact_BAO_GroupContact::getTableName();
     $group = CRM_Contact_BAO_Group::getTableName();
     $query = "   SELECT          {$acl}.*\n                        FROM            {$acl}\n                        INNER JOIN      civicrm_option_group og\n                                ON      og.name = 'acl_role'\n                        INNER JOIN      civicrm_option_value ov\n                                ON      {$acl}.entity_table   = '{$aclRole}'\n                                AND     ov.option_group_id  = og.id\n                                AND     {$acl}.entity_id      = ov.value\n                                AND     ov.is_active        = 1\n                        INNER JOIN      {$aclER}\n                                ON      {$aclER}.acl_role_id = {$acl}.entity_id\n                                AND     {$aclER}.is_active    = 1\n                        INNER JOIN  {$c2g}\n                                ON      {$aclER}.entity_id      = {$c2g}.group_id\n                                AND     {$aclER}.entity_table   = 'civicrm_group'\n                        WHERE       {$acl}.entity_table       = '{$aclRole}'\n                            AND     {$acl}.is_active          = 1\n                            AND     {$c2g}.contact_id         = {$contact_id}\n                            AND     {$c2g}.status             = 'Added'";
     $results = array();
     $rule->query($query);
     while ($rule->fetch()) {
         $results[$rule->id] =& $rule->toArray();
     }
     // also get all acls for "Any Role" case
     // and authenticated User Role if present
     $roles = "0";
     $session = CRM_Core_Session::singleton();
     if ($session->get('ufID') > 0) {
         $roles .= ",2";
     }
     $query = "\nSELECT {$acl}.*\n  FROM {$acl}\n WHERE {$acl}.entity_id      IN ( {$roles} )\n   AND {$acl}.entity_table   = 'civicrm_acl_role'\n";
     $rule->query($query);
     while ($rule->fetch()) {
         $results[$rule->id] =& $rule->toArray();
     }
     return $results;
 }
Esempio n. 5
0
 /**
  * Browse all acls.
  *
  * @return void
  */
 public function browse()
 {
     // 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;
         }
         $entityRoles[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'entityRole.manage.action', 'EntityRole', $dao->id);
     }
     $this->assign('rows', $entityRoles);
 }
 static function updateCiviACLEntityRole(&$params, $op)
 {
     $dao = new CRM_ACL_DAO_EntityRole();
     $dao->entity_table = 'civicrm_group';
     $dao->entity_id = $params['acl_group_id'];
     if ($op == 'delete') {
         $dao->delete();
         return;
     }
     $dao->acl_role_id = $params['acl_role_id'];
     $dao->find(TRUE);
     $dao->is_active = TRUE;
     $dao->save();
     $params['acl_entity_role_id'] = $dao->id;
 }
Esempio n. 7
0
 static function updateCiviACLEntityRole(&$params, $op)
 {
     require_once 'CRM/ACL/DAO/EntityRole.php';
     $dao = new CRM_ACL_DAO_EntityRole();
     $dao->entity_table = 'civicrm_group';
     $dao->entity_id = $params['acl_group_id'];
     if ($op == 'delete') {
         $dao->delete();
         return;
     }
     $dao->acl_role_id = $params['acl_role_id'];
     $dao->find(true);
     $dao->is_active = true;
     $dao->save();
     $params['acl_entity_role_id'] = $dao->id;
 }