/**
  * 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();
 }
Example #2
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;
     }
 }
 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;
 }
Example #4
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);
 }
Example #5
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;
 }