コード例 #1
0
ファイル: hrdemog.php プロジェクト: JoeMurray/civihr
/**
 * Implementation of hook_civicrm_uninstall
 */
function hrdemog_civicrm_uninstall()
{
    $customGroup = civicrm_api3('CustomGroup', 'getsingle', array('return' => "id", 'name' => "Extended_Demographics"));
    civicrm_api3('CustomGroup', 'delete', array('id' => $customGroup['id']));
    //delete optionGroup
    if ($visaGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'is_visa_required_20130702051150', 'id', 'name')) {
        CRM_Core_BAO_OptionGroup::del($visaGroupID);
    }
    return _hrdemog_civix_civicrm_uninstall();
}
 static function getOptionGroupId($option_group_name)
 {
     require_once 'CRM/Core/BAO/OptionGroup.php';
     $params = array("name" => $option_group_name);
     $default = array();
     $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($params, $default);
     if ($optionGroup) {
         return $optionGroup->id;
     } else {
         return;
     }
 }
コード例 #3
0
/**
 * create/update survey
 *
 * This API is used to create new survey or update any of the existing
 * In case of updating existing survey, id of that particular survey must
 * be in $params array.
 *
 * @param array $params  (referance) Associative array of property
 *                       name/value pairs to insert in new 'survey'
 *
 * @return array   survey array
 *
 * @access public
 */
function civicrm_api3_option_group_create($params)
{
    $ids = array();
    $bao = CRM_Core_BAO_OptionGroup::add($params, $ids);
    if (is_null($bao)) {
        return civicrm_api3_create_error('Entity not created');
    } else {
        $values = array();
        _civicrm_api3_object_to_array($bao, $values[$bao->id]);
        return civicrm_api3_create_success($values, $params, 'option_group', 'create', $bao);
    }
}
コード例 #4
0
ファイル: OptionGroup.php プロジェクト: ksecor/civicrm
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     require_once 'CRM/Core/BAO/OptionGroup.php';
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_OptionGroup::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'));
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['optionGroup'] = $this->_id;
         }
         $optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name)));
     }
 }
コード例 #5
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     $params = $this->exportValues();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_OptionGroup::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['optionGroup'] = $this->_id;
         }
         $optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name)), ts('Saved'), 'success');
     }
 }
コード例 #6
0
 /**
  * Process the form submission.
  *
  * @param array $params
  * @param string $type
  * @param array $linkedEntities
  *
  * @throws \CiviCRM_API3_Exception
  */
 public static function postProcess($params = array(), $type, $linkedEntities = array())
 {
     //Check entity_id not present in params take it from class variable
     if (empty($params['entity_id'])) {
         $params['entity_id'] = self::$_entityId;
     }
     //Process this function only when you get this variable
     if ($params['allowRepeatConfigToSubmit'] == 1) {
         if (!empty($params['entity_table']) && !empty($params['entity_id']) && $type) {
             $params['used_for'] = $type;
             if (empty($params['parent_entity_id'])) {
                 $params['parent_entity_id'] = self::$_parentEntityId;
             }
             if (!empty($params['schedule_reminder_id'])) {
                 $params['id'] = $params['schedule_reminder_id'];
             } else {
                 $params['id'] = self::$_scheduleReminderID;
             }
             //Save post params to the schedule reminder table
             $recurobj = new CRM_Core_BAO_RecurringEntity();
             $dbParams = $recurobj->mapFormValuesToDB($params);
             //Delete repeat configuration and rebuild
             if (!empty($params['id'])) {
                 CRM_Core_BAO_ActionSchedule::del($params['id']);
                 unset($params['id']);
             }
             $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
             //exclude dates
             $excludeDateList = array();
             if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
                 //Since we get comma separated values lets get them in array
                 $excludeDates = explode(",", $params['exclude_date_list']);
                 //Check if there exists any values for this option group
                 $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], 'id', 'name');
                 if ($optionGroupIdExists) {
                     CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
                 }
                 $optionGroupParams = array('name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, 'title' => $type . ' recursion', 'is_reserved' => 0, 'is_active' => 1);
                 $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
                 if ($opGroup->id) {
                     $oldWeight = 0;
                     $fieldValues = array('option_group_id' => $opGroup->id);
                     foreach ($excludeDates as $val) {
                         $optionGroupValue = array('option_group_id' => $opGroup->id, 'label' => CRM_Utils_Date::processDate($val), 'value' => CRM_Utils_Date::processDate($val), 'name' => $opGroup->name, 'description' => 'Used for recurring ' . $type, 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), 'is_active' => 1);
                         $excludeDateList[] = $optionGroupValue['value'];
                         CRM_Core_BAO_OptionValue::create($optionGroupValue);
                     }
                 }
             }
             //Set type for API
             $apiEntityType = explode("_", $type);
             if (!empty($apiEntityType[1])) {
                 $apiType = $apiEntityType[1];
             }
             //Delete relations if any from recurring entity tables before inserting new relations for this entity id
             if ($params['entity_id']) {
                 //If entity has any pre delete function, consider that first
                 if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id']));
                     if (!empty($preDeleteResult)) {
                         call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult));
                     }
                 }
                 //Ready to execute delete on entities if it has delete function set
                 if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     //Check if pre delete function has some ids to be deleted
                     if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) {
                         foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $eid));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     } else {
                         $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE);
                         foreach ($getRelatedEntities as $key => $value) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $value['id']));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     }
                 }
                 // find all entities from the recurring set. At this point we 'll get entities which were not deleted
                 // for e.g due to participants being present. We need to delete them from recurring tables anyway.
                 $pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']);
                 foreach ($pRepeatingEntities as $val) {
                     CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE);
                 }
             }
             $recursion = new CRM_Core_BAO_RecurringEntity();
             $recursion->dateColumns = $params['dateColumns'];
             $recursion->scheduleId = $actionScheduleObj->id;
             if (!empty($excludeDateList)) {
                 $recursion->excludeDates = $excludeDateList;
                 $recursion->excludeDateRangeColumns = $params['excludeDateRangeColumns'];
             }
             if (!empty($params['intervalDateColumns'])) {
                 $recursion->intervalDateColumns = $params['intervalDateColumns'];
             }
             $recursion->entity_id = $params['entity_id'];
             $recursion->entity_table = $params['entity_table'];
             if (!empty($linkedEntities)) {
                 $recursion->linkedEntities = $linkedEntities;
             }
             $recursion->generate();
             $status = ts('Repeat Configuration has been saved');
             CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
         }
     }
 }
コード例 #7
0
ファイル: Main.php プロジェクト: archcidburnziso/civicrm-core
 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     $params['last_modified_id'] = $session->get('userID');
     $params['last_modified_date'] = date('YmdHis');
     if ($this->_surveyId) {
         $params['id'] = $this->_surveyId;
     } else {
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_surveyId, 'Survey');
     $survey = CRM_Campaign_BAO_Survey::create($params);
     $this->_surveyId = $survey->id;
     if (!empty($this->_values['result_id'])) {
         $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1";
         $countSurvey = (int) CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Positive')));
         // delete option group if no any survey is using it.
         if (!$countSurvey) {
             CRM_Core_BAO_OptionGroup::del($this->_values['result_id']);
         }
     }
     parent::endPostProcess();
 }
コード例 #8
0
ファイル: EventInfo.php プロジェクト: bhirsch/voipdev
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     //format params
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true);
     $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false);
     $params['is_map'] = CRM_Utils_Array::value('is_map', $params, false);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     $params['is_public'] = CRM_Utils_Array::value('is_public', $params, false);
     $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false);
     $params['id'] = $this->_id;
     //new event, so lets set the created_id
     if ($this->_action & CRM_Core_Action::ADD) {
         $session =& CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event');
     require_once 'CRM/Event/BAO/Event.php';
     // copy all not explicitely set $params keys from the template (if it should be sourced)
     if (CRM_Utils_Array::value('template_id', $params)) {
         $defaults = array();
         $templateParams = array('id' => $params['template_id']);
         CRM_Event_BAO_Event::retrieve($templateParams, $defaults);
         unset($defaults['id']);
         unset($defaults['default_fee_id']);
         unset($defaults['default_discount_fee_id']);
         foreach ($defaults as $key => $value) {
             if (!isset($params[$key])) {
                 $params[$key] = $value;
             }
         }
     }
     $event = CRM_Event_BAO_Event::create($params);
     // now that we have the event’s id, do some more template-based stuff
     if (CRM_Utils_Array::value('template_id', $params)) {
         // copy event fees
         $ogParams = array('name' => "civicrm_event.amount.{$event->id}");
         $defaults = array();
         require_once 'CRM/Core/BAO/OptionGroup.php';
         if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) {
             // Copy the Main Event Fees
             CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id);
             // Copy the Discount option Group and Values
             require_once 'CRM/Core/BAO/Discount.php';
             $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event");
             foreach ($optionGroupIds as $id) {
                 $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label');
                 CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix);
             }
         }
         // copy price sets if any
         require_once 'CRM/Price/BAO/Set.php';
         $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
         if ($priceSetId) {
             CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId);
         }
         // link profiles if none linked
         $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         require_once 'CRM/Core/BAO/UFJoin.php';
         if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) {
             CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id));
         }
         // if no Tell-a-Friend defined, check whether there’s one for template and copy if so
         $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         require_once 'CRM/Friend/BAO/Friend.php';
         if (!CRM_Friend_BAO_Friend::getValues($tafParams)) {
             $tafParams['entity_id'] = $params['template_id'];
             if (CRM_Friend_BAO_Friend::getValues($tafParams)) {
                 $tafParams['entity_id'] = $event->id;
                 CRM_Friend_BAO_Friend::addTellAFriend($tafParams);
             }
         }
     }
     $this->set('id', $event->id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}";
         // special case for 'Save and Done' consistency.
         if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") {
             $urlParam = "action=update&reset=1&id={$event->id}";
             CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())));
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam));
     }
     parent::endPostProcess();
 }
コード例 #9
0
ファイル: OptionValue.php プロジェクト: ksecor/civicrm
 /**
  * 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
  * @access public
  *
  */
 function run()
 {
     $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, false, 0);
     $this->assign('gid', $this->_gid);
     if ($this->_gid) {
         require_once 'CRM/Core/BAO/OptionGroup.php';
         $groupTitle = CRM_Core_BAO_OptionGroup::getTitle($this->_gid);
         CRM_Utils_System::setTitle(ts('%1 - Option Values', array(1 => $groupTitle)));
         //get optionGroup name in case of email/postal greeting or addressee, CRM-4575
         $this->_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'name');
     }
     parent::run();
 }
コード例 #10
0
ファイル: CustomField.php プロジェクト: bhirsch/voipdev
 /**
  * Function to check if option group is related to more than one
  * custom field
  *
  * @params int $optionGroupId option group id
  *
  * @return
  * @static
  */
 static function checkOptionGroup($optionGroupId)
 {
     $query = "\nSELECT count(*)\nFROM   civicrm_custom_field\nWHERE  option_group_id = {$optionGroupId}";
     $count = CRM_Core_DAO::singleValueQuery($query);
     if ($count < 2) {
         //delete the option group
         require_once "CRM/Core/BAO/OptionGroup.php";
         CRM_Core_BAO_OptionGroup::del($optionGroupId);
     }
 }
コード例 #11
0
 /**
  * This function is to make a copy of a contribution page, including
  * all the blocks in the page
  *
  * @param int $id the contribution page id to copy
  *
  * @return the copy object
  * @access public
  * @static
  */
 static function copy($id)
 {
     $fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' '));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_ContributionPage', array('id' => $id), NULL, $fieldsFix);
     //copying all the blocks pertaining to the contribution page
     $copyPledgeBlock =& CRM_Core_DAO::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyMembershipBlock =& CRM_Core_DAO::copyGeneric('CRM_Member_DAO_MembershipBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyUFJoin =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyWidget =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Widget', array('contribution_page_id' => $id), array('contribution_page_id' => $copy->id));
     //copy option group and values
     $copy->default_amount_id = CRM_Core_BAO_OptionGroup::copyValue('contribution', $id, $copy->id, CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'default_amount_id'));
     $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyPersonalCampaignPages =& CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyPremium =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Premium', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $premiumQuery = "\nSELECT id\nFROM civicrm_premiums\nWHERE entity_table = 'civicrm_contribution_page'\n      AND entity_id ={$id}";
     $premiumDao = CRM_Core_DAO::executeQuery($premiumQuery, CRM_Core_DAO::$_nullArray);
     while ($premiumDao->fetch()) {
         if ($premiumDao->id) {
             $copyPremiumProduct =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array('premiums_id' => $premiumDao->id), array('premiums_id' => $copyPremium->id));
         }
     }
     $copy->save();
     CRM_Utils_Hook::copy('ContributionPage', $copy);
     return $copy;
 }
コード例 #12
0
ファイル: Set.php プロジェクト: bhirsch/voipdev
 /**
  * This function is to make a copy of a price set, including
  * all the fields
  *
  * @param int $id the price set id to copy
  *
  * @return the copy object 
  * @access public
  * @static
  */
 static function copy($id)
 {
     $maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set");
     $title = ts('[Copy id %1]', array(1 => $maxId + 1));
     $fieldsFix = array('suffix' => array('title' => ' ' . $title, 'name' => '__Copy_id_' . ($maxId + 1) . '_'));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_Set', array('id' => $id), null, $fieldsFix);
     //copying all the blocks pertaining to the price set
     $copyPriceField =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_Field', array('price_set_id' => $id), array('price_set_id' => $copy->id));
     if (!empty($copyPriceField)) {
         $price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id));
         //copy option group and values
         require_once "CRM/Core/BAO/OptionGroup.php";
         foreach ($price as $originalId => $copyId) {
             CRM_Core_BAO_OptionGroup::copyValue('price', $originalId, $copyId);
         }
     }
     $copy->save();
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('Set', $copy);
     return $copy;
 }
コード例 #13
0
ファイル: Grant.php プロジェクト: ksecor/civicrm
 /**
  * Function to get events Summary
  *
  * @static
  * @return array Array of event summary values
  */
 static function getGrantStatusOptGroup()
 {
     require_once 'CRM/Core/BAO/OptionGroup.php';
     $params = array();
     $params['name'] = CRM_Grant_BAO_Grant::$statusGroupName;
     $defaults = array();
     $bao = new CRM_Core_BAO_OptionGroup();
     $og = $bao->retrieve($params, $defaults);
     if (!$og) {
         CRM_Core_Error::fatal('No option group for grant statuses - database discrepancy! Make sure you loaded civicrm_data.mysql');
     }
     return $og;
 }
コード例 #14
0
ファイル: Options.php プロジェクト: nielosz/civicrm-core
 /**
  * Get the DataType for a specified Option Group.
  *
  * @param string $optionGroupName name of the option group
  *
  * @return string|null
  */
 public static function getOptionGroupDataType($optionGroupName)
 {
     $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupName, 'id', 'name');
     $dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroupId);
     return $dataType;
 }
コード例 #15
0
ファイル: Grant.php プロジェクト: saurabhbatra96/civicrm-core
 /**
  * Get events Summary.
  *
  *
  * @return array
  *   Array of event summary values
  */
 public static function getGrantStatusOptGroup()
 {
     $params = array();
     $params['name'] = CRM_Grant_BAO_Grant::$statusGroupName;
     $defaults = array();
     $og = CRM_Core_BAO_OptionGroup::retrieve($params, $defaults);
     if (!$og) {
         CRM_Core_Error::fatal('No option group for grant statuses - database discrepancy! Make sure you loaded civicrm_data.mysql');
     }
     return $og;
 }
コード例 #16
0
ファイル: OptionValue.php プロジェクト: konadave/civicrm-core
 /**
  * Add/edit option-value of a particular group
  *
  * @param array $params
  *   Array containing exported values from the invoking form.
  * @param array $groupParams
  *   Array containing group fields whose option-values is to retrieved/saved.
  * @param $action
  * @param int $optionValueID Has the id of the optionValue being edited, disabled ..etc.
  *   Has the id of the optionValue being edited, disabled ..etc.
  *
  * @return CRM_Core_DAO_OptionValue
  *
  */
 public static function addOptionValue(&$params, &$groupParams, &$action, &$optionValueID)
 {
     $ids = array();
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     // checking if the group name with the given id or name (in $groupParams) exists
     if (!empty($groupParams)) {
         $config = CRM_Core_Config::singleton();
         $groupParams['is_active'] = 1;
         $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $defaults);
     }
     // if the corresponding group doesn't exist, create one, provided $groupParams has 'name' in it.
     if (!$optionGroup->id) {
         if ($groupParams['name']) {
             $newOptionGroup = CRM_Core_BAO_OptionGroup::add($groupParams, $defaults);
             $params['weight'] = 1;
             $optionGroupID = $newOptionGroup->id;
         }
     } else {
         $optionGroupID = $optionGroup->id;
         $oldWeight = NULL;
         if ($optionValueID) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $optionValueID, 'weight', 'id');
         }
         $fieldValues = array('option_group_id' => $optionGroupID);
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues);
     }
     $params['option_group_id'] = $optionGroupID;
     if ($action & CRM_Core_Action::ADD && empty($params['value'])) {
         $fieldValues = array('option_group_id' => $optionGroupID);
         // use the next available value
         /* CONVERT(value, DECIMAL) is used to convert varchar
            field 'value' to decimal->integer                    */
         $params['value'] = (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, 'CONVERT(value, DECIMAL)');
     }
     if (!$params['label'] && $params['name']) {
         $params['label'] = $params['name'];
     }
     // set name to label if it's not set - but *only* for ADD action (CRM-3522)
     if ($action & CRM_Core_Action::ADD && empty($params['name']) && $params['label']) {
         $params['name'] = $params['label'];
     }
     if ($action & CRM_Core_Action::UPDATE) {
         $ids['optionValue'] = $optionValueID;
     }
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
     return $optionValue;
 }
コード例 #17
0
ファイル: Survey.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     $params['last_modified_id'] = $session->get('userID');
     $params['last_modified_date'] = date('YmdHis');
     require_once 'CRM/Core/BAO/OptionValue.php';
     require_once 'CRM/Core/BAO/OptionGroup.php';
     $updateResultSet = false;
     if (CRM_Utils_Array::value('option_type', $params) == 2 && CRM_Utils_Array::value('option_group_id', $params)) {
         if ($params['option_group_id'] == CRM_Utils_Array::value('result_id', $this->_values)) {
             $updateResultSet = true;
         }
     }
     if ($this->_surveyId) {
         if ($this->_action & CRM_Core_Action::DELETE) {
             CRM_Campaign_BAO_Survey::del($this->_surveyId);
             CRM_Core_Session::setStatus(ts(' Survey has been deleted.'));
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
             return;
         }
         $params['id'] = $this->_surveyId;
     } else {
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
     $recontactInterval = array();
     if ($updateResultSet) {
         $optionValue = new CRM_Core_DAO_OptionValue();
         $optionValue->option_group_id = $this->_values['result_id'];
         $optionValue->delete();
         $params['result_id'] = $this->_values['result_id'];
     } else {
         $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis');
         $optionGroup = new CRM_Core_DAO_OptionGroup();
         $optionGroup->name = $opGroupName;
         $optionGroup->label = $params['title'] . ' Response Set';
         $optionGroup->is_active = 1;
         $optionGroup->save();
         $params['result_id'] = $optionGroup->id;
     }
     foreach ($params['option_value'] as $k => $v) {
         if (strlen(trim($v))) {
             $optionValue = new CRM_Core_DAO_OptionValue();
             $optionValue->option_group_id = $params['result_id'];
             $optionValue->label = $params['option_label'][$k];
             $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
             $optionValue->value = trim($v);
             $optionValue->weight = $params['option_weight'][$k];
             $optionValue->is_active = 1;
             if (CRM_Utils_Array::value('default_option', $params) && $params['default_option'] == $k) {
                 $optionValue->is_default = 1;
             }
             $optionValue->save();
             if (CRM_Utils_Array::value($k, $params['option_interval'])) {
                 $recontactInterval[$optionValue->label] = $params['option_interval'][$k];
             }
         }
     }
     $params['recontact_interval'] = serialize($recontactInterval);
     $surveyId = CRM_Campaign_BAO_Survey::create($params);
     if (CRM_Utils_Array::value('result_id', $this->_values) && !$updateResultSet) {
         $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1";
         $countSurvey = CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Integer')));
         // delete option group if no any survey is using it.
         if (!($countSurvey >= 1)) {
             CRM_Core_BAO_OptionGroup::del($this->_values['result_id']);
         }
     }
     require_once 'CRM/Core/BAO/UFJoin.php';
     // also update the ProfileModule tables
     $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id);
     // first delete all past entries
     if ($this->_surveyId) {
         CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
     }
     if (CRM_Utils_Array::value('profile_id', $params)) {
         $ufJoinParams['weight'] = 1;
         $ufJoinParams['uf_group_id'] = $params['profile_id'];
         CRM_Core_BAO_UFJoin::create($ufJoinParams);
     }
     if (!is_a($surveyId, 'CRM_Core_Error')) {
         CRM_Core_Session::setStatus(ts('Survey %1 has been saved.', array(1 => $params['title'])));
     }
     if ($this->_context == 'dialog') {
         $returnArray = array('returnSuccess' => true);
         echo json_encode($returnArray);
         CRM_Utils_System::civiExit();
     }
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another Survey.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add'));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
     }
 }
コード例 #18
0
ファイル: Event.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**
  * This function is to make a copy of a Event, including
  * all the fields in the event Wizard
  *
  * @param int $id the event id to copy
  *
  * @return void
  * @access public
  */
 static function copy($id)
 {
     $defaults = $eventValues = array();
     //get the require event values.
     $eventParams = array('id' => $id);
     $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id');
     CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
     // since the location is sharable, lets use the same loc_block_id.
     $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues);
     $fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' '));
     if (!CRM_Utils_Array::value('is_show_location', $eventValues)) {
         $fieldsFix['prefix']['is_show_location'] = 0;
     }
     $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : null), $fieldsFix);
     $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     require_once "CRM/Core/BAO/OptionGroup.php";
     //copy option Group and values
     $copyEvent->default_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_fee_id', $eventValues));
     //copy discounted fee levels
     require_once 'CRM/Core/BAO/Discount.php';
     $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
     if (!empty($discount)) {
         foreach ($discount as $discountOptionGroup) {
             $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $discountOptionGroup);
             $length = substr_compare($name, "civicrm_event.amount." . $id, 0);
             $discountSuffix = substr($name, $length * -1);
             $copyEvent->default_discount_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_discount_fee_id', $eventValues), $discountSuffix);
         }
     }
     //copy custom data
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $extends = array('event');
     $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(null, null, $extends);
     if ($groupTree) {
         foreach ($groupTree as $groupID => $group) {
             $table[$groupTree[$groupID]['table_name']] = array('entity_id');
             foreach ($group['fields'] as $fieldID => $field) {
                 $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
             }
         }
         foreach ($table as $tableName => $tableColumns) {
             $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
             $tableColumns[0] = $copyEvent->id;
             $select = 'SELECT ' . implode(', ', $tableColumns);
             $from = ' FROM ' . $tableName;
             $where = " WHERE {$tableName}.entity_id = {$id}";
             $query = $insert . $select . $from . $where;
             $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         }
     }
     $copyEvent->save();
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('Event', $copyEvent);
     return $copyEvent;
 }
コード例 #19
0
 /**
  * Ensure only one option value exists adds a new value.
  */
 public function testEnsureOptionGroupExistsNewValue()
 {
     $optionGroupID = CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'Bombed', 'title' => ts('Catastrophy'), 'description' => ts('blah blah'), 'is_reserved' => 1));
     $optionGroup = $this->callAPISuccessGetSingle('OptionGroup', array('name' => 'Bombed'));
     $this->assertEquals($optionGroupID, $optionGroup['id']);
 }