Example #1
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     // process url params
     if ($this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive')) {
         $this->assign('contactID', $this->_contactID);
     }
     if ($this->_caseID = CRM_Utils_Request::retrieve('case_id', 'Positive')) {
         $this->assign('case_id', $this->_caseID);
         // get Vacancy ID
         $vacancyID = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($this->_caseID);
         //Get application and evaluaiton profile IDs
         foreach (array('application_profile', 'evaluation_profile') as $profileName) {
             $dao = new CRM_Core_DAO_UFJoin();
             $dao->module = 'Vacancy';
             $dao->entity_id = $vacancyID;
             $dao->module_data = $profileName;
             $dao->find(TRUE);
             $profile[$profileName] = $dao->uf_group_id;
         }
         //Check for existing Evaluation activity type and assign variables to tpl
         $this->assign('actions', 'add');
         $params = array('activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation'));
         $caseActivity = CRM_Case_BAO_Case::getCaseActivity($this->_caseID, $params, $this->_contactID);
         foreach ($caseActivity as $caseActivity) {
             $evalID = $caseActivity['id'];
             $this->assign('id', $evalID);
             $this->assign('actions', 'update');
         }
         $this->_profileID = $profile['application_profile'];
         $this->_evalProfileID = $profile['evaluation_profile'];
     }
 }
Example #2
0
 /**
  * Function used to build form element for soft credit block.
  *
  * @param CRM_Core_Form $form
  *
  * @return \CRM_Core_Form
  */
 public static function buildQuickForm(&$form)
 {
     if (!empty($form->_honor_block_is_active)) {
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $form->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, 'soft_credit');
             if ($jsonData) {
                 foreach (array('honor_block_title', 'honor_block_text') as $name) {
                     $form->assign($name, $jsonData[$name]);
                 }
                 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
                 // radio button for Honor Type
                 foreach ($jsonData['soft_credit_types'] as $value) {
                     $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
                 }
                 $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             }
         }
         return $form;
     }
     // by default generate 10 blocks
     $item_count = 11;
     $showSoftCreditRow = 2;
     if ($form->getAction() & CRM_Core_Action::UPDATE) {
         $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     } elseif (!empty($form->_pledgeID)) {
         //Check and select most recent completed contrubtion and use it to retrieve
         //soft-credit information to use as default for current pledge payment, CRM-13981
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
         foreach ($pledgePayments as $id => $record) {
             if ($record['contribution_id']) {
                 $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
                 if ($record['status'] == 'Completed' && count($softCredits) > 0) {
                     $form->_softCreditInfo = $softCredits;
                 }
             }
         }
     }
     if (property_exists($form, "_softCreditInfo")) {
         if (!empty($form->_softCreditInfo['soft_credit'])) {
             $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
             $showSoftCreditRow++;
         }
     }
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
         $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
         if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
             $form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
         }
     }
     self::addPCPFields($form);
     $form->assign('showSoftCreditRow', $showSoftCreditRow);
     $form->assign('rowCount', $item_count);
     $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
 }
Example #3
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         CRM_Utils_System::setTitle(ts('Title and Settings') . " ({$title})");
         foreach (array('on_behalf', 'soft_credit') as $module) {
             $ufJoinDAO = new CRM_Core_DAO_UFJoin();
             $ufJoinDAO->module = $module;
             $ufJoinDAO->entity_id = $this->_id;
             $ufJoinDAO->entity_table = 'civicrm_contribution_page';
             if ($ufJoinDAO->find(TRUE)) {
                 $jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, $module);
                 if ($module == 'soft_credit') {
                     $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id;
                     $defaults = array_merge($defaults, $jsonData);
                     $defaults['honor_block_is_active'] = $ufJoinDAO->is_active;
                 } else {
                     $defaults['onbehalf_profile_id'] = $ufJoinDAO->uf_group_id;
                     $defaults = array_merge($defaults, $jsonData);
                     $defaults['is_organization'] = $ufJoinDAO->is_active;
                 }
             } else {
                 if ($module == 'soft_credit') {
                     $ufGroupDAO = new CRM_Core_DAO_UFGroup();
                     $ufGroupDAO->name = 'honoree_individual';
                     if ($ufGroupDAO->find(TRUE)) {
                         $defaults['honoree_profile'] = $ufGroupDAO->id;
                     }
                     $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
                 } else {
                     $ufGroupDAO = new CRM_Core_DAO_UFGroup();
                     $ufGroupDAO->name = 'on_behalf_organization';
                     if ($ufGroupDAO->find(TRUE)) {
                         $defaults['onbehalf_profile_id'] = $ufGroupDAO->id;
                     }
                     $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
                     $defaults['is_for_organization'] = 1;
                 }
             }
         }
     } else {
         $ufGroupDAO = new CRM_Core_DAO_UFGroup();
         $ufGroupDAO->name = 'honoree_individual';
         if ($ufGroupDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufGroupDAO->id;
         }
         $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
     }
     return $defaults;
 }
Example #4
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this);
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this);
     if (!isset($this->_contactID)) {
         $this->_contactID = 0;
     }
     if (!$this->_id) {
         CRM_Core_Error::fatal(ts('There is no related Vacancy to apply'));
     }
     $ufJoinParams = array('module' => 'Vacancy', 'entity_id' => $this->_id, 'module_data' => 'application_profile');
     $ufJoin = new CRM_Core_DAO_UFJoin();
     $ufJoin->copyValues($ufJoinParams);
     $ufJoin->find(TRUE);
     $this->_profileID = $ufJoin->uf_group_id;
 }
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         CRM_Utils_System::setTitle(ts('Title and Settings (%1)', array(1 => $title)));
         $ufJoinParams = array('module' => 'OnBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $onBehalfIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         if ($onBehalfIDs) {
             // get the first one only
             $defaults['onbehalf_profile_id'] = $onBehalfIDs[0];
         }
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $this->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id;
             $jsonData = json_decode($ufJoinDAO->module_data);
             if ($jsonData) {
                 foreach ($jsonData->soft_credit as $index => $value) {
                     $defaults[$index] = $value;
                 }
             }
         } else {
             $ufGroupDAO = new CRM_Core_DAO_UFGroup();
             $ufGroupDAO->name = 'honoree_individual';
             if ($ufGroupDAO->find(TRUE)) {
                 $defaults['honoree_profile'] = $ufGroupDAO->id;
             }
             $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
         }
     } else {
         CRM_Utils_System::setTitle(ts('Title and Settings'));
         $ufGroupDAO = new CRM_Core_DAO_UFGroup();
         $ufGroupDAO->name = 'honoree_individual';
         if ($ufGroupDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufGroupDAO->id;
         }
         $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
     }
     return $defaults;
 }
 /**
  * This function sets the default values for the form. 
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $eventId = $this->_id;
     $defaults = parent::setDefaultValues();
     $this->setShowHide($defaults);
     if (isset($eventId)) {
         $params = array('id' => $eventId);
         CRM_Event_BAO_Event::retrieve($params, $defaults);
         require_once 'CRM/Core/BAO/UFJoin.php';
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $eventId);
         list($defaults['custom_pre_id'], $defaults['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         if ($defaults['is_multiple_registrations']) {
             // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
             $ufJoin = new CRM_Core_DAO_UFJoin();
             $ufJoin->module = 'CiviEvent_Additional';
             $ufJoin->entity_table = 'civicrm_event';
             $ufJoin->entity_id = $eventId;
             $ufJoin->orderBy('weight');
             $ufJoin->find();
             $custom = array(1 => 'additional_custom_pre_id', 2 => 'additional_custom_post_id');
             while ($ufJoin->fetch()) {
                 $defaults[$custom[$ufJoin->weight]] = $ufJoin->is_active ? $ufJoin->uf_group_id : 'none';
             }
         }
     } else {
         $defaults['is_email_confirm'] = 0;
     }
     // provide defaults for required fields if empty (and as a 'hint' for approval message field)
     $defaults['registration_link_text'] = CRM_Utils_Array::value('registration_link_text', $defaults, ts('Register Now'));
     $defaults['confirm_title'] = CRM_Utils_Array::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
     $defaults['thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults, ts('Thank You for Registering'));
     $defaults['approval_req_text'] = CRM_Utils_Array::value('approval_req_text', $defaults, ts('Participation in this event requires approval. Submit your registration request here. Once approved, you will receive an email with a link to a web page where you can complete the registration process.'));
     if (CRM_Utils_Array::value('registration_start_date', $defaults)) {
         list($defaults['registration_start_date'], $defaults['registration_start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['registration_start_date'], 'activityDateTime');
     }
     if (CRM_Utils_Array::value('registration_end_date', $defaults)) {
         list($defaults['registration_end_date'], $defaults['registration_end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['registration_end_date'], 'activityDateTime');
     }
     return $defaults;
 }
Example #7
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
     if ($this->_id) {
         $ufJoinParams = array('module' => 'OnBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $onBehalfIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         if ($onBehalfIDs) {
             // get the first one only
             $defaults['onbehalf_profile_id'] = $onBehalfIDs[0];
         }
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $this->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id;
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE);
             $defaults = array_merge($defaults, $jsonData);
             $defaults['honor_block_is_active'] = $ufJoinDAO->is_active;
         } else {
             $ufGroupDAO = new CRM_Core_DAO_UFGroup();
             $ufGroupDAO->name = 'honoree_individual';
             if ($ufGroupDAO->find(TRUE)) {
                 $defaults['honoree_profile'] = $ufGroupDAO->id;
             }
             $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
         }
     } else {
         $ufGroupDAO = new CRM_Core_DAO_UFGroup();
         $ufGroupDAO->name = 'honoree_individual';
         if ($ufGroupDAO->find(TRUE)) {
             $defaults['honoree_profile'] = $ufGroupDAO->id;
         }
         $defaults['soft_credit_types'] = array(CRM_Utils_Array::value('in_honor_of', $soft_credit_types), CRM_Utils_Array::value('in_memory_of', $soft_credit_types));
     }
     return $defaults;
 }
 /**
  * Get or Set multilingually affected honor params for processing module_data or setting default values.
  *
  * @param string $params :
  * @param bool $setDefault : If yes then returns array to used for setting default value afterward
  *
  * @return array|string
  */
 public static function formatMultilingualHonorParams($params, $setDefault = FALSE)
 {
     $config = CRM_Core_Config::singleton();
     $sctJson = $sctJsonDecode = NULL;
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     //When we are fetching the honor params respecting both multi and mono lingual state
     //and setting it to default param of Contribution Page's Main and Setting form
     if ($setDefault) {
         $sctJsonDecode = json_decode($params);
         $sctJsonDecode = (array) $sctJsonDecode->soft_credit;
         if (!$domain->locales && !empty($sctJsonDecode['default'])) {
             //monolingual state
             $sctJsonDecode += (array) $sctJsonDecode['default'];
         } elseif (!empty($sctJsonDecode[$config->lcMessages])) {
             //multilingual state
             foreach ($sctJsonDecode[$config->lcMessages] as $column => $value) {
                 $sctJsonDecode[$column] = $value;
             }
             unset($sctJsonDecode[$config->lcMessages]);
         }
         return $sctJsonDecode;
     }
     //check and handle multilingual honoree params
     if (!$domain->locales) {
         //if in singlelingual state simply return the array format
         $sctJson = json_encode(array('soft_credit' => array('soft_credit_types' => $params['soft_credit_types'], 'default' => array('honor_block_title' => $params['honor_block_title'], 'honor_block_text' => $params['honor_block_text']))));
     } else {
         //if in multilingual state then retrieve the module_data against this contribution and
         //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
         $sctJson = array('soft_credit' => array('soft_credit_types' => $params['soft_credit_types'], $config->lcMessages => array('honor_block_title' => $params['honor_block_title'], 'honor_block_text' => $params['honor_block_text'])));
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $params['id'];
         $ufJoinDAO->find(TRUE);
         $jsonData = json_decode($ufJoinDAO->module_data);
         if ($jsonData) {
             $sctJson['soft_credit'] = array_merge((array) $jsonData->soft_credit, $sctJson['soft_credit']);
         }
         $sctJson = json_encode($sctJson);
     }
     return $sctJson;
 }
Example #9
0
 public static function getUFGroupIds(&$params)
 {
     $dao = new CRM_Core_DAO_UFJoin();
     // CRM-4377 (ab)uses the module column
     if (isset($params['module'])) {
         $dao->module = CRM_Utils_Array::value('module', $params);
     }
     $dao->entity_table = CRM_Utils_Array::value('entity_table', $params);
     $dao->entity_id = CRM_Utils_Array::value('entity_id', $params);
     $dao->orderBy('weight asc');
     $first = $second = $firstActive = $secondActive = null;
     $firstWeight = null;
     $dao->find();
     if ($dao->fetch()) {
         $first = $dao->uf_group_id;
         $firstWeight = $dao->weight;
         $firstActive = $dao->is_active;
     }
     while ($dao->fetch()) {
         if ($first != $dao->uf_group_id) {
             $second = $dao->uf_group_id;
             $secondActive = $dao->is_active;
             break;
         }
     }
     // if there is only one profile check to see the weight, if > 1 then let it be second
     // this is an approx rule, but should work in most cases.
     if ($second == null && $firstWeight > 1) {
         $second = $first;
         $first = null;
     }
     return array($first, $second, $firstActive, $secondActive);
 }
Example #10
0
 /**
  * Function used to build form element for soft credit block.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     if (!empty($form->_honor_block_is_active)) {
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $form->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE);
             if ($jsonData) {
                 foreach (array('honor_block_title', 'honor_block_text') as $name) {
                     $form->assign($name, $jsonData[$name]);
                 }
                 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
                 // radio button for Honor Type
                 foreach ($jsonData['soft_credit_types'] as $value) {
                     $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
                 }
                 $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             }
         }
         return $form;
     }
     // by default generate 10 blocks
     $item_count = 11;
     $showSoftCreditRow = 2;
     if ($form->getAction() & CRM_Core_Action::UPDATE) {
         $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     } elseif (!empty($form->_pledgeID)) {
         //Check and select most recent completed contrubtion and use it to retrieve
         //soft-credit information to use as default for current pledge payment, CRM-13981
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
         foreach ($pledgePayments as $id => $record) {
             if ($record['contribution_id']) {
                 $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
                 if ($record['status'] == 'Completed' && count($softCredits) > 0) {
                     $form->_softCreditInfo = $softCredits;
                 }
             }
         }
     }
     if (property_exists($form, "_softCreditInfo")) {
         if (!empty($form->_softCreditInfo['soft_credit'])) {
             $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
             $showSoftCreditRow++;
         }
     }
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
         $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
         if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
             $form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
         }
     }
     // CRM-7368 allow user to set or edit PCP link for contributions
     $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
     if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
         $form->assign('siteHasPCPs', 1);
         // Fixme: Not a true entityRef field. Relies on PCP.js.tpl
         $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -')));
         // stores the label
         $form->add('hidden', 'pcp_made_through');
         $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
         $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
         $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
     }
     $form->assign('showSoftCreditRow', $showSoftCreditRow);
     $form->assign('rowCount', $item_count);
     $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
 }
Example #11
0
/**
 * Implementation of hook_civicrm_buildForm
 *
 * @params string $formName - the name of the form
 *         object $form - reference to the form object
 * @return void
 */
function hrrecruitment_civicrm_buildForm($formName, &$form)
{
    $caseTypes = CRM_Case_PseudoConstant::caseType('name');
    $appValue = array_search('Application', $caseTypes);
    //To hide application case type from add assignment form
    if ($formName == 'CRM_Case_Form_Case') {
        if ($form->_action & CRM_Core_Action::DELETE || $form->_action & CRM_Core_Action::RENEW) {
            return;
        }
        $form->_caseType = CRM_Case_PseudoConstant::caseType();
        unset($form->_caseType[$appValue]);
        $form->add('select', 'case_type_id', ts('Assignment Type'), $form->_caseType, TRUE);
    }
    //report change
    if ($formName == 'CRM_Report_Form_Case_Summary' || $formName == 'CRM_Report_Form_Case_Detail') {
        $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE, 'AND filter = 1', TRUE);
        $form->case_statuses = $form->case_statuses + $statuses;
    }
    if ($formName == 'CRM_Activity_Form_Search') {
        $actId = CRM_Utils_Request::retrieve('type', 'Positive', $form);
        $form->_formValues['activity_type_id'][$actId] = $defaults['activity_type_id'][$actId] = 1;
        $form->setDefaults($defaults);
        $form->set('formValues', $form->_formValues);
        $form->preProcess();
    }
    if ($formName == 'CRM_Case_Form_CaseView') {
        $params = array('id' => $form->_caseID);
        CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, array('status_id'));
        $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE, 'AND (filter IN (0,1) OR filter IS NULL)', TRUE);
        $form->_caseDetails['case_status'] = $statuses[$values['case_status_id']];
        $form->assign('caseDetails', $form->_caseDetails);
    }
    if ($formName == 'CRM_Case_Form_Activity' || $formName == 'CRM_Contact_Form_Task_Email') {
        $caseId = CRM_Utils_Request::retrieve('caseid', 'String', $form);
        $vacancyID = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($caseId);
        $caseId = explode(',', $caseId);
        $aType = CRM_Utils_Request::retrieve('atype', 'Positive') ? CRM_Utils_Request::retrieve('atype', 'Positive') : CRM_Utils_Array::value('activity_type_id', $form->_defaultValues);
        $evalID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation');
        /* Check for proper permissions */
        if ($vacancyID && $aType) {
            $administerper = CRM_HRRecruitment_BAO_HRVacancyPermission::checkVacancyPermission($vacancyID, array("administer Vacancy", "administer CiviCRM", "manage Applicants"));
            $evaluateper = CRM_HRRecruitment_BAO_HRVacancyPermission::checkVacancyPermission($vacancyID, array("administer Vacancy", "administer CiviCRM", "evaluate Applicants"));
            if ($aType != $evalID && !$administerper || $aType == $evalID && !$evaluateper) {
                CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm'));
                CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to perform this action.'));
                return;
            }
        }
        /* TO set vacancy stages as case status for 'Change Case Status' activity */
        if ($aType == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Case Status')) {
            $allcase = TRUE;
            foreach ($caseId as $key => $val) {
                $caseType = CRM_Case_BAO_Case::getCaseType($val, 'id');
                if ($caseType != $appValue) {
                    $allcase = FALSE;
                }
            }
            if ($allcase) {
                $form->removeElement('case_status_id');
                $form->_caseStatus = CRM_Case_PseudoConstant::caseStatus('label', TRUE, 'AND filter = 1', TRUE);
                $form->add('select', 'case_status_id', ts('Case Status'), $form->_caseStatus, TRUE);
                if ($caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form)) {
                    $form->freeze('case_status_id');
                    $form->setDefaults(array('case_status_id' => $caseStatusId));
                }
            }
        }
        /* build the evaluation profile on the evaluation activity */
        //check for evaluation activity type
        if ($aType == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation')) {
            //rename label and status name for Activity Status
            $activityStatus = $form->getElement('status_id');
            $activityStatus->_options = array();
            $scheduleStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled');
            $completeStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Completed');
            $activityStatus->addOption('Scheduled', $scheduleStatus);
            $activityStatus->addOption('Complete Evaluation', $completeStatus);
            $activityStatus->_label = 'Evaluation Status';
            //retriev Case ID, Activity ID, Contact ID
            $caseID = CRM_Utils_Request::retrieve('caseid', 'Positive', $form);
            $activityID = CRM_Utils_Request::retrieve('id', 'Positive', $form);
            $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
            //get Evaluation profile ID
            $dao = new CRM_Core_DAO_UFJoin();
            $dao->module = 'Vacancy';
            $dao->entity_id = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($caseID);
            $dao->module_data = 'evaluation_profile';
            $dao->find(TRUE);
            $profileID = $dao->uf_group_id;
            $profileFields = CRM_Core_BAO_UFGroup::getFields($profileID);
            $form->assign('fields', $profileFields);
            CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $profileFields, $def);
            $form->setDefaults($def);
            //auto populate assignee contact name with vacancy related permission
            if ($form->_action & CRM_Core_Action::ADD) {
                $evaluateContactID = CRM_HRRecruitment_BAO_HRVacancyPermission::getPermissionContact($vacancyID, 'evaluate Applicants');
                $defaults['assignee_contact_id'] = $evaluateContactID;
                $form->setDefaults($defaults);
            }
            //build evaluaiton profile fields
            foreach ($profileFields as $profileFieldKey => $profileFieldVal) {
                CRM_Core_BAO_UFGroup::buildProfile($form, $profileFieldVal, CRM_Profile_Form::MODE_EDIT, $contactID, TRUE, FALSE, NULL);
                $form->_fields[$profileFieldKey] = $profileFields[$profileFieldKey];
                $params[$profileFieldKey] = $profileFieldVal;
            }
            if (!empty($activityID)) {
                $params['entityID'] = $activityID;
                $form->addElement('hidden', 'evaluationProfile', $profileID);
                $defVal = CRM_Core_BAO_CustomValueTable::getValues($params);
                $form->setDefaults($defVal);
            }
            CRM_Core_Region::instance('case-activity-form')->add(array('template' => 'CRM/UF/Form/Block.tpl'));
        }
        //HR-373 -- set Completed status for Comment activity by default
        if ($aType == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Comment')) {
            $defaults['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed');
            $form->setDefaults($defaults);
        }
    }
    /* HR-401 Changes to Edit Evaluation and Application popups */
    if ($formName == 'CRM_Custom_Form_Field' || $formName == 'CRM_HRRecruitment_Form_HRVacancy') {
        $uncolapseAppl = $uncolapseEval = array();
        $applicationCG = civicrm_api3('CustomGroup', 'get', array('extends' => "Case", 'extends_entity_column_value' => $appValue, 'name' => 'Application'));
        foreach ($applicationCG['values'] as $k => $v) {
            $uncolapseAppl[] = $v['id'];
        }
        $evalCG = civicrm_api3('CustomGroup', 'get', array('extends' => "Activity", 'extends_entity_column_value' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation')));
        foreach ($evalCG['values'] as $k => $v) {
            $uncolapseEval[$k] = $v['id'];
        }
        CRM_Core_Resources::singleton()->addSetting(array('profileSelectorSet' => array('application' => $uncolapseAppl, 'evaluation' => $uncolapseEval)));
        $gID = CRM_Utils_Array::value('gid', $_GET);
        /* HR-401 set default for 'Is field searchable' */
        if (!empty($gID) && (in_array($gID, $uncolapseEval) || in_array($gID, $uncolapseAppl)) && $formName == 'CRM_Custom_Form_Field') {
            $default['is_searchable'] = 1;
            $form->setDefaults($default);
        }
    }
}
Example #12
0
 /**
  * Given the list of params in the params array, fetch the object
  * and store the values in the values array
  *
  * @param array $params input parameters to find object
  * @param array $values output values of the object
  *
  * @return CRM_HRRecruitment_DAO_HRVacancy|null the found object or null
  * @access public
  * @static
  */
 static function retrieve(&$params, &$defaults)
 {
     $vacancy = new self();
     $vacancy->copyValues($params);
     if ($vacancy->find(TRUE)) {
         CRM_Core_DAO::storeValues($vacancy, $defaults);
         $stage = new CRM_HRRecruitment_DAO_HRVacancyStage();
         $stage->vacancy_id = $vacancy->id;
         $stage->find();
         while ($stage->fetch()) {
             $defaults['stages'][$stage->weight] = $stage->case_status_id;
         }
         $permission = new CRM_HRRecruitment_DAO_HRVacancyPermission();
         $permission->vacancy_id = $vacancy->id;
         $permission->find();
         $count = 1;
         while ($permission->fetch()) {
             $defaults['permission'][$count] = $permission->permission;
             $defaults['permission_contact_id'][$count] = $permission->contact_id;
             $count++;
         }
         foreach (array('application_profile', 'evaluation_profile') as $profileName) {
             $ufJoin = new CRM_Core_DAO_UFJoin();
             $ufJoin->module = 'Vacancy';
             $ufJoin->entity_id = $vacancy->id;
             $ufJoin->module_data = $profileName;
             $ufJoin->find(TRUE);
             $defaults[$profileName] = $ufJoin->uf_group_id;
         }
     }
 }
 /**
  * Get or Set honor/on_behalf params for processing module_data or setting default values.
  *
  * @param array $params :
  * @param bool $setDefault : If yes then returns array to used for setting default value afterward
  * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf
  *
  * @return array|string
  */
 public static function formatModuleData($params, $setDefault = FALSE, $module)
 {
     $tsLocale = CRM_Core_I18n::getLocale();
     $config = CRM_Core_Config::singleton();
     $json = $jsonDecode = NULL;
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $moduleDataFormat = array('soft_credit' => array(1 => 'soft_credit_types', 'multilingual' => array('honor_block_title', 'honor_block_text')), 'on_behalf' => array(1 => 'is_for_organization', 'multilingual' => array('for_organization')));
     //When we are fetching the honor params respecting both multi and mono lingual state
     //and setting it to default param of Contribution Page's Main and Setting form
     if ($setDefault) {
         $jsonDecode = json_decode($params);
         $jsonDecode = (array) $jsonDecode->{$module};
         if (!$domain->locales && !empty($jsonDecode['default'])) {
             //monolingual state
             $jsonDecode += (array) $jsonDecode['default'];
             unset($jsonDecode['default']);
         } elseif (!empty($jsonDecode[$tsLocale])) {
             //multilingual state
             foreach ($jsonDecode[$tsLocale] as $column => $value) {
                 $jsonDecode[$column] = $value;
             }
             unset($jsonDecode[$tsLocale]);
         }
         return $jsonDecode;
     }
     //check and handle multilingual honoree params
     if (!$domain->locales) {
         //if in singlelingual state simply return the array format
         $json = array($module => NULL);
         foreach ($moduleDataFormat[$module] as $key => $attribute) {
             if ($key === 'multilingual') {
                 $json[$module]['default'] = array();
                 foreach ($attribute as $attr) {
                     $json[$module]['default'][$attr] = $params[$attr];
                 }
             } else {
                 $json[$module][$attribute] = $params[$attribute];
             }
         }
         $json = json_encode($json);
     } else {
         //if in multilingual state then retrieve the module_data against this contribution and
         //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
         $json = array($module => NULL);
         foreach ($moduleDataFormat[$module] as $key => $attribute) {
             if ($key === 'multilingual') {
                 $json[$module][$config->lcMessages] = array();
                 foreach ($attribute as $attr) {
                     $json[$module][$config->lcMessages][$attr] = $params[$attr];
                 }
             } else {
                 $json[$module][$attribute] = $params[$attribute];
             }
         }
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = $module;
         $ufJoinDAO->entity_id = $params['id'];
         $ufJoinDAO->find(TRUE);
         $jsonData = json_decode($ufJoinDAO->module_data);
         if ($jsonData) {
             $json[$module] = array_merge((array) $jsonData->{$module}, $json[$module]);
         }
         $json = json_encode($json);
     }
     return $json;
 }
Example #14
0
 /**
  * @param array $params
  *
  * @return array
  */
 public static function getUFGroupIds(&$params)
 {
     $dao = new CRM_Core_DAO_UFJoin();
     // CRM-4377 (ab)uses the module column
     if (isset($params['module'])) {
         $dao->module = CRM_Utils_Array::value('module', $params);
     }
     $dao->entity_table = CRM_Utils_Array::value('entity_table', $params);
     $dao->entity_id = CRM_Utils_Array::value('entity_id', $params);
     $dao->orderBy('weight asc');
     $dao->find();
     $first = $firstActive = NULL;
     $second = $secondActive = array();
     while ($dao->fetch()) {
         if ($dao->weight == 1) {
             $first = $dao->uf_group_id;
             $firstActive = $dao->is_active;
         } else {
             $second[] = $dao->uf_group_id;
             $secondActive[] = $dao->is_active;
         }
     }
     return array($first, $second, $firstActive, $secondActive);
 }
Example #15
0
 /**
  * Function to delete the uf join record for an uf group 
  *
  * @param array  $params    (reference) an assoc array of name/value pairs
  *
  * @return void
  * @access public
  * @static
  */
 static function delUFJoin(&$params)
 {
     require_once 'CRM/Core/DAO/UFJoin.php';
     $ufJoin = new CRM_Core_DAO_UFJoin();
     $ufJoin->copyValues($params);
     $ufJoin->delete();
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     // current contribution page id
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if (!$this->_id) {
         // seems like the session is corrupted and/or we lost the id trail
         // lets just bump this to a regular session error and redirect user to main page
         $this->controller->invalidKeyRedirect();
     }
     // this was used prior to the cleverer this_>getContactID - unsure now
     $this->_userID = $session->get('userID');
     //Check if honor block is enabled for current contribution
     $ufJoinParams = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     $ufJoin = new CRM_Core_DAO_UFJoin();
     $ufJoin->copyValues($ufJoinParams);
     $ufJoin->find(TRUE);
     $this->_honor_block_is_active = $ufJoin->is_active;
     $this->_contactID = $this->_membershipContactID = $this->getContactID();
     $this->_mid = NULL;
     if ($this->_contactID) {
         $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
         if ($this->_mid) {
             $membership = new CRM_Member_DAO_Membership();
             $membership->id = $this->_mid;
             if ($membership->find(TRUE)) {
                 $this->_defaultMemTypeId = $membership->membership_type_id;
                 if ($membership->contact_id != $this->_contactID) {
                     $validMembership = FALSE;
                     $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID);
                     if (!empty($employers) && array_key_exists($membership->contact_id, $employers)) {
                         $this->_membershipContactID = $membership->contact_id;
                         $this->assign('membershipContactID', $this->_membershipContactID);
                         $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']);
                         $validMembership = TRUE;
                     } else {
                         $membershipType = new CRM_Member_BAO_MembershipType();
                         $membershipType->id = $membership->membership_type_id;
                         if ($membershipType->find(TRUE)) {
                             // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
                             // Convert to commma separated list.
                             $inheritedRelTypes = implode(CRM_Utils_Array::explodePadded($membershipType->relationship_type_id), ',');
                             $permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->_userID, $membershipType->relationship_type_id);
                             if (array_key_exists($membership->contact_id, $permContacts)) {
                                 $this->_membershipContactID = $membership->contact_id;
                                 $validMembership = TRUE;
                             }
                         }
                     }
                     if (!$validMembership) {
                         CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
                     }
                 }
             } else {
                 CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
             }
             unset($membership);
         }
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // Contribution page values are cleared from session, so can't use normal Printer Friendly view.
     // Use Browser Print instead.
     $this->assign('browserPrint', TRUE);
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->assign('action', $this->_action);
     // current mode
     $this->_mode = $this->_action == 1024 ? 'test' : 'live';
     $this->_values = $this->get('values');
     $this->_fields = $this->get('fields');
     $this->_bltID = $this->get('bltID');
     $this->_paymentProcessor = $this->get('paymentProcessor');
     $this->_priceSetId = $this->get('priceSetId');
     $this->_priceSet = $this->get('priceSet');
     if (!$this->_values) {
         // get all the values from the dao object
         $this->_values = array();
         $this->_fields = array();
         CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
         // check if form is active
         if (empty($this->_values['is_active'])) {
             // form is inactive, die a fatal death
             CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
         }
         // also check for billing informatin
         // get the billing location type
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
         // CRM-8108 remove ts around Billing location type
         //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
         $this->_bltID = array_search('Billing', $locationTypes);
         if (!$this->_bltID) {
             CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
         }
         $this->set('bltID', $this->_bltID);
         // check for is_monetary status
         $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values);
         $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values);
         //FIXME: to support multiple payment processors
         if ($isMonetary && (!$isPayLater || !empty($this->_values['payment_processor']))) {
             $ppID = CRM_Utils_Array::value('payment_processor', $this->_values);
             if (!$ppID) {
                 CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).'));
             }
             $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
             $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds, $this->_mode);
             $this->set('paymentProcessors', $this->_paymentProcessors);
             //set default payment processor
             if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) {
                 foreach ($this->_paymentProcessors as $ppId => $values) {
                     if ($values['is_default'] == 1 || count($this->_paymentProcessors) == 1) {
                         $defaultProcessorId = $ppId;
                         break;
                     }
                 }
             }
             if (isset($defaultProcessorId)) {
                 $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode);
                 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
             }
             if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
                 foreach ($this->_paymentProcessors as $eachPaymentProcessor) {
                     // check selected payment processor is active
                     if (empty($eachPaymentProcessor)) {
                         CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
                     }
                     // ensure that processor has a valid config
                     $this->_paymentObject =& CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this);
                     $error = $this->_paymentObject->checkConfig();
                     if (!empty($error)) {
                         CRM_Core_Error::fatal($error);
                     }
                 }
             }
         }
         // get price info
         // CRM-5095
         CRM_Price_BAO_PriceSet::initSet($this, $this->_id, 'civicrm_contribution_page');
         // this avoids getting E_NOTICE errors in php
         $setNullFields = array('amount_block_is_active', 'is_allow_other_amount', 'footer_text');
         foreach ($setNullFields as $f) {
             if (!isset($this->_values[$f])) {
                 $this->_values[$f] = NULL;
             }
         }
         //check if Membership Block is enabled, if Membership Fields are included in profile
         //get membership section for this contribution page
         $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
         $this->set('membershipBlock', $this->_membershipBlock);
         if ($this->_values['custom_pre_id']) {
             $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']);
         }
         if ($this->_values['custom_post_id']) {
             $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']);
         }
         if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) {
             CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.'));
         }
         $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id);
         if ($pledgeBlock) {
             $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock);
             $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock);
             $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock);
             $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock);
             //set pledge id in values
             $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this);
             //authenticate pledge user for pledge payment.
             if ($pledgeId) {
                 $this->_values['pledge_id'] = $pledgeId;
                 //lets override w/ pledge campaign.
                 $this->_values['campaign_id'] = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeId, 'campaign_id');
                 self::authenticatePledgeUser();
             }
         }
         $this->set('values', $this->_values);
         $this->set('fields', $this->_fields);
     }
     // Handle PCP
     $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
     if ($pcpId) {
         $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'contribute', $this->_values);
         $this->_pcpId = $pcp['pcpId'];
         $this->_pcpBlock = $pcp['pcpBlock'];
         $this->_pcpInfo = $pcp['pcpInfo'];
     }
     // Link (button) for users to create their own Personal Campaign page
     if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute')) {
         $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}&component=contribute", FALSE, NULL, TRUE);
         $this->assign('linkTextUrl', $linkTextUrl);
         $this->assign('linkText', $linkText);
     }
     //set pledge block if block id is set
     if (!empty($this->_values['pledge_block_id'])) {
         $this->assign('pledgeBlock', TRUE);
     }
     // check if one of the (amount , membership)  bloks is active or not
     $this->_membershipBlock = $this->get('membershipBlock');
     if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) {
         CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.'));
     }
     if ($this->_values['amount_block_is_active']) {
         $this->set('amount_block_is_active', $this->_values['amount_block_is_active']);
     }
     $this->_contributeMode = $this->get('contributeMode');
     $this->assign('contributeMode', $this->_contributeMode);
     //assigning is_monetary and is_email_receipt to template
     $this->assign('is_monetary', $this->_values['is_monetary']);
     $this->assign('is_email_receipt', $this->_values['is_email_receipt']);
     $this->assign('bltID', $this->_bltID);
     //assign cancelSubscription URL to templates
     $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values));
     // assigning title to template in case someone wants to use it, also setting CMS page title
     if ($this->_pcpId) {
         $this->assign('title', $this->_pcpInfo['title']);
         CRM_Utils_System::setTitle($this->_pcpInfo['title']);
     } else {
         $this->assign('title', $this->_values['title']);
         CRM_Utils_System::setTitle($this->_values['title']);
     }
     $this->_defaults = array();
     $this->_amount = $this->get('amount');
     //CRM-6907
     $config = CRM_Core_Config::singleton();
     $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency);
     //lets allow user to override campaign.
     $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this);
     if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
         $this->_values['campaign_id'] = $campID;
     }
     //do check for cancel recurring and clean db, CRM-7696
     if (CRM_Utils_Request::retrieve('cancel', 'Boolean', CRM_Core_DAO::$_nullObject)) {
         self::cancelRecurring();
     }
 }
Example #17
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 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['uf_join'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 /**
  * Does a UFJoin lookup and caches it for future use.
  *
  * @return array of UFGroup (profile) IDs
  */
 private function getProfileIDs()
 {
     if (empty($this->_profile_ids) && $this->getProject() !== FALSE) {
         $dao = new CRM_Core_DAO_UFJoin();
         $dao->entity_table = CRM_Volunteer_BAO_Project::$_tableName;
         $dao->entity_id = $this->getProject()->id;
         $dao->orderBy('weight asc');
         $dao->find();
         while ($dao->fetch()) {
             $this->_profile_ids[] = $dao->uf_group_id;
         }
     }
     if (empty($this->_profile_ids)) {
         $this->_profile_ids[] = civicrm_api3('UFGroup', 'getvalue', array('name' => 'volunteer_sign_up', 'return' => 'id'));
     }
     return $this->_profile_ids;
 }
 /**
  * Search for profiles
  *
  * @return array
  *   UFGroup (Profile) Ids
  */
 function getProfileIDs()
 {
     if (empty($this->_profile_ids)) {
         $profileIds = array();
         foreach ($this->projectIds as $projectId) {
             $dao = new CRM_Core_DAO_UFJoin();
             $dao->entity_table = CRM_Volunteer_BAO_Project::$_tableName;
             $dao->entity_id = $projectId;
             $dao->orderBy('weight asc');
             $dao->find();
             while ($dao->fetch()) {
                 $profileIds[] = $dao->uf_group_id;
             }
         }
         $this->_profile_ids = array_unique($profileIds);
     }
     return $this->_profile_ids;
 }
Example #20
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_CORE_DAO_UFJOIN']['_export']) {
         $GLOBALS['_CRM_CORE_DAO_UFJOIN']['_export'] = array();
         $fields =& CRM_Core_DAO_UFJoin::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_CORE_DAO_UFJOIN']['_export']['uf_join'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_CORE_DAO_UFJOIN']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CORE_DAO_UFJOIN']['_export'];
 }
Example #21
0
 /**
  * Delete the uf join record for an uf group.
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  */
 public static function delUFJoin(&$params)
 {
     $ufJoin = new CRM_Core_DAO_UFJoin();
     $ufJoin->copyValues($params);
     $ufJoin->delete();
 }
 /**
  * Search for profiles by Volunteer Project ID
  * @param type $projectId
  * @return array of UFGroup (Profile) Ids
  */
 function getProfileIDs()
 {
     if (empty($this->_profile_ids)) {
         $dao = new CRM_Core_DAO_UFJoin();
         $dao->entity_table = CRM_Volunteer_BAO_Project::$_tableName;
         $dao->entity_id = $this->_project->id;
         $dao->orderBy('weight asc');
         $dao->find();
         while ($dao->fetch()) {
             $this->_profile_ids[] = $dao->uf_group_id;
         }
     }
     return $this->_profile_ids;
 }
Example #23
0
 /**
  * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped
  * on DB upgrade
  *
  * @param CRM_Queue_TaskContext $ctx
  *
  * @return bool
  *   TRUE for success
  */
 public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx)
 {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     // fetch onBehalf entry in UFJoin table
     $ufGroupDAO = new CRM_Core_DAO_UFJoin();
     $ufGroupDAO->module = 'OnBehalf';
     $ufGroupDAO->find(TRUE);
     $forOrgColums = array();
     if ($domain->locales) {
         $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
         foreach ($locales as $locale) {
             $forOrgColums[] = "for_organization_{$locale}";
         }
     } else {
         $forOrgColums[] = "for_organization";
     }
     $query = "\n      SELECT " . implode(", ", $forOrgColums) . ", uj.id as join_id, uj.uf_group_id as uf_group_id\n      FROM civicrm_contribution_page cp\n       INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'";
     $dao = CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE);
     if ($dao->N) {
         while ($dao->fetch()) {
             $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization);
             if ($domain->locales) {
                 foreach ($locales as $locale) {
                     $for_organization = "for_organization_{$locale}";
                     $onBehalfParams['on_behalf'] += array($locale => array('for_organization' => $dao->{$for_organization}));
                 }
             } else {
                 $onBehalfParams['on_behalf'] += array('default' => array('for_organization' => $dao->for_organization));
             }
             $ufJoinParam = array('id' => $dao->join_id, 'module' => 'on_behalf', 'uf_group_id' => $dao->uf_group_id, 'module_data' => json_encode($onBehalfParams));
             CRM_Core_BAO_UFJoin::create($ufJoinParam);
         }
     }
     return TRUE;
 }
 /**
  * Function used to build form element for soft credit block
  *
  * @param object   $form form object
  * @access public
  *
  * @return void
  */
 static function buildQuickForm(&$form)
 {
     if ($form->_mode == 'live' && !empty($form->_values['honor_block_is_active'])) {
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $form->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $jsonData = json_decode($ufJoinDAO->module_data);
             if ($jsonData) {
                 $form->assign('honor_block_title', $jsonData->soft_credit->honor_block_title);
                 $form->assign('honor_block_text', $jsonData->soft_credit->honor_block_text);
                 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
                 $extraOption = array('onclick' => "enableHonorType();");
                 // radio button for Honor Type
                 foreach ($jsonData->soft_credit->soft_credit_types as $value) {
                     $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value, $extraOption);
                 }
                 $form->addGroup($honorTypes, 'soft_credit_type_id', NULL);
             }
         }
         return $form;
     }
     $prefix = 'soft_credit_';
     // by default generate 5 blocks
     $item_count = 6;
     $showSoftCreditRow = 2;
     $showCreateNew = TRUE;
     if ($form->_action & CRM_Core_Action::UPDATE) {
         $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     } elseif ($form->_pledgeID) {
         //Check and select most recent completed contrubtion and use it to retrieve
         //soft-credit information to use as default for current pledge payment, CRM-13981
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
         foreach ($pledgePayments as $id => $record) {
             if ($record['contribution_id']) {
                 $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
                 if ($record['status'] == 'Completed' && count($softCredits) > 0) {
                     $form->_softCreditInfo = $softCredits;
                 }
             }
         }
     }
     if (property_exists($form, "_softCreditInfo")) {
         if (!empty($form->_softCreditInfo['soft_credit'])) {
             $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
             $showSoftCreditRow++;
             $showCreateNew = FALSE;
         }
     }
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
         CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix);
         $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
         $form->add('select', "{$prefix}type[{$rowNumber}]", ts('Soft Credit Type'), array('' => ts('- select -')) + CRM_Core_OptionGroup::values("{$prefix}type", FALSE));
         if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
             $form->add('hidden', "{$prefix}id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
         }
     }
     // CRM-7368 allow user to set or edit PCP link for contributions
     $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
     if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
         $form->assign('siteHasPCPs', 1);
         $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1', FALSE, NULL, FALSE);
         $form->assign('pcpDataUrl', $pcpDataUrl);
         $form->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page'));
         $form->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id'));
         $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
         $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
         $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
     }
     $form->assign('showSoftCreditRow', $showSoftCreditRow);
     $form->assign('rowCount', $item_count);
     $form->assign('showCreateNew', $showCreateNew);
     $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("{$prefix}type"), array('id' => 'sct_default_id'));
     // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page
     if (!empty($form->_values['pcp_made_through_id'])) {
         $form->assign('pcpLinked', 1);
     }
 }
Example #25
0
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     // first delete the join entries associated with this contribution page
     require_once 'CRM/Core/DAO/UFJoin.php';
     $dao = new CRM_Core_DAO_UFJoin();
     $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     $dao->copyValues($params);
     $dao->delete();
     require_once 'CRM/Core/OptionGroup.php';
     $groupName = "civicrm_contribution_page.amount.{$this->_id}";
     CRM_Core_OptionGroup::deleteAssoc($groupName);
     //next delete the membership block fields
     require_once 'CRM/Member/DAO/MembershipBlock.php';
     $dao = new CRM_Member_DAO_MembershipBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     //next delete the pcp block fields
     require_once 'CRM/Contribute/DAO/PCPBlock.php';
     $dao = new CRM_Contribute_DAO_PCPBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     // need to delete premiums. CRM-4586
     require_once 'CRM/Contribute/BAO/Premium.php';
     CRM_Contribute_BAO_Premium::deletePremium($this->_id);
     // price set cleanup, CRM-5527
     require_once 'CRM/Price/BAO/Set.php';
     CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $this->_id);
     // finally delete the contribution page
     require_once 'CRM/Contribute/DAO/ContributionPage.php';
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->id = $this->_id;
     $dao->delete();
     $transaction->commit();
     CRM_Core_Session::setStatus(ts('The contribution page \'%1\' has been deleted.', array(1 => $this->_title)));
 }
Example #26
0
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $transaction = new CRM_Core_Transaction();
     // first delete the join entries associated with this contribution page
     $dao = new CRM_Core_DAO_UFJoin();
     $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     $dao->copyValues($params);
     $dao->delete();
     //next delete the membership block fields
     $dao = new CRM_Member_DAO_MembershipBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     //next delete the pcp block fields
     $dao = new CRM_PCP_DAO_PCPBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     // need to delete premiums. CRM-4586
     CRM_Contribute_BAO_Premium::deletePremium($this->_id);
     // price set cleanup, CRM-5527
     CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
     // finally delete the contribution page
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->id = $this->_id;
     $dao->delete();
     $transaction->commit();
     CRM_Core_Session::setStatus(ts("The contribution page '%1' has been deleted.", array(1 => $this->_title)), ts('Deleted'), 'success');
 }