Beispiel #1
0
/**
 * Get CiviCRM domain details
 * {@getfields domain_create}
 * @example DomainGet.php
 */
function civicrm_api3_domain_get($params)
{
    $params['version'] = CRM_Utils_Array::value('domain_version', $params);
    unset($params['version']);
    $bao = new CRM_Core_BAO_Domain();
    if (CRM_Utils_Array::value('current_domain', $params)) {
        $domainBAO = CRM_Core_Config::domainID();
        $params['id'] = $domainBAO;
    }
    _civicrm_api3_dao_set_filter($bao, $params, true, 'domain');
    $domains = _civicrm_api3_dao_to_array($bao, $params, true, 'domain');
    foreach ($domains as $domain) {
        if (!empty($domain['contact_id'])) {
            $values = array();
            $locparams = array('contact_id' => $domain['contact_id']);
            $values['location'] = CRM_Core_BAO_Location::getValues($locparams, TRUE);
            $address_array = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'state_province_id', 'postal_code', 'country_id', 'geo_code_1', 'geo_code_2');
            if (!empty($values['location']['email'])) {
                $domain['domain_email'] = CRM_Utils_Array::value('email', $values['location']['email'][1]);
            }
            if (!empty($values['location']['phone'])) {
                $domain['domain_phone'] = array('phone_type' => CRM_Core_OptionGroup::getLabel('phone_type', CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])), 'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1]));
            }
            if (!empty($values['location']['address'])) {
                foreach ($address_array as $value) {
                    $domain['domain_address'][$value] = CRM_Utils_Array::value($value, $values['location']['address'][1]);
                }
            }
            list($domain['from_name'], $domain['from_email']) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
            $domains[$domain['id']] = array_merge($domains[$domain['id']], $domain);
        }
    }
    return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao);
}
Beispiel #2
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $this->_contactID = $this->get('cid');
     $this->_caseID = $this->get('id');
     $this->assign('caseID', $this->_caseID);
     $this->assign('contactID', $this->_contactID);
     //retrieve details about case
     $params = array('id' => $this->_caseID);
     $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date');
     CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties);
     $values['case_type_id'] = explode(CRM_Case_BAO_Case::VALUE_SEPERATOR, CRM_Utils_Array::value('case_type_id', $values));
     $statuses = CRM_Case_PseudoConstant::caseStatus();
     $caseTypeName = CRM_Case_PseudoConstant::caseTypeName($this->_caseID);
     $caseType = CRM_Core_OptionGroup::getLabel('case_type', $caseTypeName['id']);
     $this->_caseDetails = array('case_type' => $caseType, 'case_status' => $statuses[$values['case_status_id']], 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date']);
     $this->_caseType = $caseTypeName['name'];
     $this->assign('caseDetails', $this->_caseDetails);
     $newActivityUrl = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=", false, null, false);
     $this->assign('newActivityUrl', $newActivityUrl);
     $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", false, null, false);
     $this->assign('reportUrl', $reportUrl);
     // add to recently viewed
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home");
     $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - ' . $caseType;
     // add the recently created case
     CRM_Utils_Recent::add($title, $url, $this->_caseID, 'Case', $this->_contactID, null);
 }
Beispiel #3
0
 static function details($csID, $ssID = null, $gID = null)
 {
     $error = array(null, null, null);
     if (!$csID && !$ssID && !$gID) {
         return $error;
     }
     $customSearchID = $csID;
     $formValues = array();
     if ($ssID || $gID) {
         if ($gID) {
             $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id');
         }
         $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($ssID);
         $customSearchID = CRM_Utils_Array::value('customSearchID', $formValues);
     }
     if (!$customSearchID) {
         return $error;
     }
     // check that the csid exists in the db along with the right file
     // and implements the right interface
     require_once 'CRM/Core/OptionGroup.php';
     $customSearchClass = CRM_Core_OptionGroup::getLabel('custom_search', $customSearchID);
     if (!$customSearchClass) {
         return $error;
     }
     $customSearchFile = str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php';
     $error = (include_once $customSearchFile);
     if ($error == false) {
         CRM_Core_Error::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.');
     }
     return array($customSearchID, $customSearchClass, $formValues);
 }
/**
 * Get expenses
 *
 * function passed on to CRM_Financial_BAO_FinancialItem
 */
function civicrm_api3_campaign_expense_get($params)
{
    $params['entity_table'] = 'civicrm_campaign';
    $params['entity_id'] = $params['campaign_id'];
    $reply = _civicrm_api3_basic_get(CRM_Financial_BAO_FinancialItem, $params);
    // extract the encoded expense_type_id from description
    if (isset($reply['values'])) {
        $values = $reply['values'];
        // copy array so we can modify while iterating
        foreach ($values as $expense_id => $expense) {
            if (!empty($expense['description'])) {
                $parts = explode(":", $expense['description'], 2);
                if (count($parts) > 1) {
                    $reply['values'][$expense_id]['expense_type_id'] = $parts[0];
                    $reply['values'][$expense_id]['description'] = $parts[1];
                } else {
                    $reply['values'][$expense_id]['expense_type_id'] = 1;
                    // TODO: use default?
                    $reply['values'][$expense_id]['description'] = $expense['description'];
                }
            } else {
                $reply['values'][$expense_id]['expense_type_id'] = 1;
                // TODO: use default?
                $reply['values'][$expense_id]['description'] = '';
            }
            $reply['values'][$expense_id]['expense_type'] = CRM_Core_OptionGroup::getLabel('campaign_expense_types', $reply['values'][$expense_id]['expense_type_id']);
        }
    }
    return $reply;
}
 /**
  * View details of a recurring contribution.
  */
 public function view()
 {
     $recur = new CRM_Contribute_DAO_ContributionRecur();
     $recur->id = $this->_id;
     if ($recur->find(TRUE)) {
         $values = array();
         CRM_Core_DAO::storeValues($recur, $values);
         // if there is a payment processor ID, get the name of the payment processor
         if (!empty($values['payment_processor_id'])) {
             $values['payment_processor'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
         }
         $idFields = array('contribution_status_id', 'campaign_id');
         if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($values['id'])) {
             $idFields[] = 'financial_type_id';
         }
         foreach ($idFields as $idField) {
             if (!empty($values[$idField])) {
                 $values[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $values[$idField]);
             }
         }
         // Get financial type name
         if (!empty($values['financial_type_id'])) {
             $values['financial_type_name'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'financial_type_id', $values['financial_type_id']);
         }
         // Get Paid By label
         if (!empty($values['payment_instrument_id'])) {
             $values['payment_instrument'] = CRM_Core_OptionGroup::getLabel('payment_instrument', $values['payment_instrument_id']);
         }
         $this->assign('recur', $values);
         $this->assign('customDataType', 'ContributionRecur');
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', $this, $this->_id);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     }
 }
 static function buildQuickForm(&$form)
 {
     require_once 'CRM/Case/PseudoConstant.php';
     $form->_caseStatus = CRM_Case_PseudoConstant::caseStatus();
     $form->_defaultCaseStatus = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $form->_caseId, 'status_id');
     if (!array_key_exists($form->_defaultCaseStatus, $form->_caseStatus)) {
         $form->_caseStatus[$form->_defaultCaseStatus] = CRM_Core_OptionGroup::getLabel('case_status', $form->_defaultCaseStatus, false);
     }
     $form->add('select', 'case_status_id', ts('Case Status'), $form->_caseStatus, true);
 }
Beispiel #7
0
 static function buildQuickForm(&$form)
 {
     $form->removeElement('status_id');
     $form->removeElement('priority_id');
     $form->_caseStatus = CRM_Case_PseudoConstant::caseStatus();
     $form->_defaultCaseStatus = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $form->_caseId, 'status_id');
     if (!array_key_exists($form->_defaultCaseStatus, $form->_caseStatus)) {
         $form->_caseStatus[$form->_defaultCaseStatus] = CRM_Core_OptionGroup::getLabel('case_status', $form->_defaultCaseStatus, FALSE);
     }
     $form->add('select', 'case_status_id', ts('Case Status'), $form->_caseStatus, TRUE);
 }
 /**
  * Test simple get via API
  */
 function testGetProjectContactById()
 {
     $relTypeId = CRM_Core_OptionGroup::getValue(CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP, 'volunteer_owner', 'name');
     $relTypeLabel = CRM_Core_OptionGroup::getLabel(CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP, $relTypeId);
     $dao = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_ProjectContact', array('relationship_type_id' => $relTypeId));
     $this->assertObjectHasAttribute('id', $dao, 'Failed to prepopulate Volunteer Project Contact');
     $api = $this->callAPIAndDocument('VolunteerProjectContact', 'get', array('id' => $dao->id), __FUNCTION__, __FILE__);
     // make sure the label and machine name are returned
     $vpc = $api['values'][1];
     $this->assertEquals('volunteer_owner', $vpc['relationship_type_name']);
     $this->assertEquals($relTypeLabel, $vpc['relationship_type_label']);
 }
 static function buildQuickForm(&$form)
 {
     require_once 'CRM/Case/PseudoConstant.php';
     $form->_caseType = CRM_Case_PseudoConstant::caseType();
     $caseTypeId = explode(CRM_Case_BAO_Case::VALUE_SEPARATOR, CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $form->_caseId, 'case_type_id'));
     $form->_caseTypeId = $caseTypeId[1];
     if (!in_array($form->_caseTypeId, $form->_caseType)) {
         $form->_caseType[$form->_caseTypeId] = CRM_Core_OptionGroup::getLabel('case_type', $form->_caseTypeId, false);
     }
     $form->add('select', 'case_type_id', ts('New Case Type'), $form->_caseType, true);
     // timeline
     $form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), null, true, array('onclick' => "return showHideByValue('is_reset_timeline','','resetTimeline','table-row','radio',false);"));
     $form->addDateTime('reset_date_time', ts('Reset Start Date'), false, array('formatType' => 'activityDateTime'));
 }
Beispiel #10
0
/**
 * Generic file to retrieve all the constants and
 * pseudo constants used in CiviCRM
 *
 */
function civicrm_domain_get()
{
    require_once 'CRM/Core/BAO/Domain.php';
    $dao = CRM_Core_BAO_Domain::getDomain();
    $values = array();
    $params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_domain');
    require_once 'CRM/Core/BAO/Location.php';
    $values['location'] = CRM_Core_BAO_Location::getValues($params, true);
    $address_array = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'state_province_id', 'postal_code', 'country_id', 'geo_code_1', 'geo_code_2');
    require_once 'CRM/Core/OptionGroup.php';
    $domain[$dao->id] = array('id' => $dao->id, 'domain_name' => $dao->name, 'description' => $dao->description, 'domain_email' => CRM_Utils_Array::value('email', $values['location']['email'][1]), 'domain_phone' => array('phone_type' => CRM_Core_OptionGroup::getLabel('phone_type', CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])), 'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1])));
    foreach ($address_array as $value) {
        $domain[$dao->id]['domain_address'][$value] = CRM_Utils_Array::value($value, $values['location']['address'][1]);
    }
    list($domain[$dao->id]['from_name'], $domain[$dao->id]['from_email']) = CRM_Core_BAO_Domain::getNameAndEmail();
    return $domain;
}
 /**
  * View details of a recurring contribution
  *
  * @return void
  * @access public
  */
 function view()
 {
     $recur = new CRM_Contribute_DAO_ContributionRecur();
     $recur->id = $this->_id;
     if ($recur->find(TRUE)) {
         $values = array();
         CRM_Core_DAO::storeValues($recur, $values);
         // if there is a payment processor ID, get the name of the payment processor
         if (!empty($values['payment_processor_id'])) {
             $values['payment_processor'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
         }
         // get contribution status label
         if (!empty($values['contribution_status_id'])) {
             $values['contribution_status'] = CRM_Core_OptionGroup::getLabel('contribution_status', $values['contribution_status_id']);
         }
         $this->assign('recur', $values);
     }
 }
/**
 * Returns array of needs  matching a set of one or more group properties
 *
 * @param array $params  Array of one or more valid
 *                       property_name=>value pairs. If $params is set
 *                       as null, all needs will be returned
 *
 * @return array  (referance) Array of matching needs
 * {@getfields need_get}
 * @access public
 */
function civicrm_api3_volunteer_need_get($params)
{
    $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
    if (!empty($result['values'])) {
        foreach ($result['values'] as &$need) {
            if (!empty($need['start_time'])) {
                $need['display_time'] = CRM_Volunteer_BAO_Need::getTimes($need['start_time'], CRM_Utils_Array::value('duration', $need));
            } else {
                $need['display_time'] = ts('Flexible', array('domain' => 'org.civicrm.volunteer'));
            }
            if (isset($need['role_id'])) {
                $need['role_label'] = CRM_Core_OptionGroup::getLabel(CRM_Volunteer_Upgrader::customOptionGroupName, $need['role_id']);
            } elseif (CRM_Utils_Array::value('is_flexible', $need)) {
                $need['role_label'] = CRM_Volunteer_BAO_Need::getFlexibleRoleLabel();
            }
        }
    }
    return $result;
}
 /**
  * Returns a user friendly text explaining the condition params
  * e.g. 'Older than 65'
  *
  * @return string
  * @access public
  */
 public function userFriendlyConditionParams()
 {
     $return = '';
     $params = $this->getActionParameters();
     $type = CRM_Core_OptionGroup::getLabel('activity_type', $params['activity_type_id']);
     $return .= ts("Type: %1", array(1 => $type));
     $status = CRM_Core_OptionGroup::getLabel('activity_status', $params['status_id']);
     $return .= "<br>";
     $return .= ts("Status: %1", array(1 => $status));
     $subject = $params['subject'];
     if (!empty($subject)) {
         $return .= "<br>";
         $return .= ts("Subject: %1", array(1 => $subject));
     }
     if (!empty($params['assignee_contact_id'])) {
         $assignee = civicrm_api3('Contact', 'getvalue', array('return' => 'display_name', 'id' => $params['assignee_contact_id']));
         $return .= '<br>';
         $return .= ts("Assignee: %1", array(1 => $assignee));
     }
     return $return;
 }
 /**
  * @param CRM_Core_Form $form
  */
 public static function buildQuickForm(&$form)
 {
     $form->removeElement('status_id');
     $form->removeElement('priority_id');
     $form->_caseStatus = CRM_Case_PseudoConstant::caseStatus();
     foreach ($form->_caseId as $key => $val) {
         $form->_oldCaseStatus[] = $form->_defaultCaseStatus[] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $val, 'status_id');
     }
     foreach ($form->_defaultCaseStatus as $keydefault => $valdefault) {
         if (!array_key_exists($valdefault, $form->_caseStatus)) {
             $form->_caseStatus[$valdefault] = CRM_Core_OptionGroup::getLabel('case_status', $valdefault, FALSE);
         }
     }
     $element = $form->add('select', 'case_status_id', ts('Case Status'), $form->_caseStatus, TRUE);
     // check if the case status id passed in url is a valid one, set as default and freeze
     if (CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form)) {
         $caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form);
         $caseStatus = CRM_Case_PseudoConstant::caseStatus();
         $form->_defaultCaseStatus = array_key_exists($caseStatusId, $caseStatus) ? $caseStatusId : NULL;
         $element->freeze();
     }
 }
Beispiel #15
0
 /**
  * @param int $csID
  * @param int $ssID
  * @param int $gID
  *
  * @return array
  * @throws Exception
  */
 public static function details($csID, $ssID = NULL, $gID = NULL)
 {
     $error = array(NULL, NULL, NULL);
     if (!$csID && !$ssID && !$gID) {
         return $error;
     }
     $customSearchID = $csID;
     $formValues = array();
     if ($ssID || $gID) {
         if ($gID) {
             $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id');
         }
         $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($ssID);
         $customSearchID = CRM_Utils_Array::value('customSearchID', $formValues);
     }
     if (!$customSearchID) {
         return $error;
     }
     // check that the csid exists in the db along with the right file
     // and implements the right interface
     $customSearchClass = CRM_Core_OptionGroup::getLabel('custom_search', $customSearchID);
     if (!$customSearchClass) {
         return $error;
     }
     $ext = CRM_Extension_System::singleton()->getMapper();
     if (!$ext->isExtensionKey($customSearchClass)) {
         $customSearchFile = str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php';
     } else {
         $customSearchFile = $ext->keyToPath($customSearchClass);
         $customSearchClass = $ext->keyToClass($customSearchClass);
     }
     $error = (include_once $customSearchFile);
     if ($error == FALSE) {
         CRM_Core_Error::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.');
     }
     return array($customSearchID, $customSearchClass, $formValues);
 }
Beispiel #16
0
 /**
  * Returns a user friendly text explaining the condition params
  * e.g. 'Older than 65'
  *
  * @return string
  * @access public
  */
 public function userFriendlyConditionParams()
 {
     $return = '';
     $params = $this->getActionParameters();
     $type = CRM_Core_OptionGroup::getLabel('activity_type', $params['activity_type_id']);
     $return .= ts("Type: %1", array(1 => $type));
     $status = CRM_Core_OptionGroup::getLabel('activity_status', $params['status_id']);
     $return .= "<br>";
     $return .= ts("Status: %1", array(1 => $status));
     $subject = $params['subject'];
     if (!empty($subject)) {
         $return .= "<br>";
         $return .= ts("Subject: %1", array(1 => $subject));
     }
     if (!empty($params['assignee_contact_id'])) {
         if (!is_array($params['assignee_contact_id'])) {
             $params['assignee_contact_id'] = array($params['assignee_contact_id']);
         }
         $assignees = '';
         foreach ($params['assignee_contact_id'] as $cid) {
             try {
                 $assignee = civicrm_api3('Contact', 'getvalue', array('return' => 'display_name', 'id' => $cid));
                 if ($assignee) {
                     if (strlen($assignees)) {
                         $assignees .= ', ';
                     }
                     $assignees .= $assignee;
                 }
             } catch (Exception $e) {
                 //do nothing
             }
         }
         $return .= '<br>';
         $return .= ts("Assignee(s): %1", array(1 => $assignees));
     }
     return $return;
 }
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = FALSE;
     $dispname_flag = $phone_flag = $email_flag = 0;
     $prev_email = $prev_dispname = $prev_phone = NULL;
     foreach ($rows as $rowNum => $row) {
         // Link constituent (contributor) to contribution detail
         if (array_key_exists('civicrm_contact_display_name_constituent', $row) && array_key_exists('civicrm_contact_id_constituent', $row)) {
             $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id_constituent'], $this->_absoluteUrl, $this->_id, $this->_drilldownReport);
             $rows[$rowNum]['civicrm_contact_display_name_constituent_link'] = $url;
             $rows[$rowNum]['civicrm_contact_display_name_constituent_hover'] = ts('List all direct contribution(s) from this contact.');
             $entryFound = TRUE;
         }
         // convert soft credit contact name to link
         if (array_key_exists('civicrm_contact_display_name_creditor', $row) && !empty($rows[$rowNum]['civicrm_contact_display_name_creditor']) && array_key_exists('civicrm_contact_id_creditor', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id_creditor'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_display_name_creditor_link'] = $url;
             $rows[$rowNum]['civicrm_contact_display_name_creditor_hover'] = ts("view contact summary");
         }
         // make subtotals look nicer
         if (array_key_exists('civicrm_contact_id_constituent', $row) && !$row['civicrm_contact_id_constituent']) {
             $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields);
             $entryFound = TRUE;
         }
         // convert campaign_id to campaign title
         if (array_key_exists('civicrm_contribution_campaign_id', $row)) {
             if ($value = $row['civicrm_contribution_campaign_id']) {
                 $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value];
                 $entryFound = TRUE;
             }
         }
         //convert soft_credit_type_id into label
         if (array_key_exists('civicrm_contribution_soft_soft_credit_type_id', $rows[$rowNum])) {
             $rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id'] = CRM_Core_OptionGroup::getLabel('soft_credit_type', $row['civicrm_contribution_soft_soft_credit_type_id']);
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
     }
     $this->removeDuplicates($rows);
 }
Beispiel #18
0
/**
 * Returns all files assigned to a single entity instance.
 *
 * @param object $entityID         id of the supported entity.
 * @param string $entity_table   
 *
 * @return array   nested array of entity-file property values.
 * @access public
 */
function crm_get_files_by_entity($entityID, $entityTable = 'civicrm_contact', $fileID = null)
{
    if (!$entityID) {
        return _crm_error('Required parameters missing');
    }
    require_once 'CRM/Core/DAO/EntityFile.php';
    require_once 'CRM/Core/DAO/File.php';
    $entityFileDAO =& new CRM_Core_DAO_EntityFile();
    $entityFileDAO->entity_table = $entityTable;
    $entityFileDAO->entity_id = $entityID;
    if ($fileID) {
        $entityFileDAO->file_id = $fileID;
    }
    if ($entityFileDAO->find()) {
        $entityFile = array();
        while ($entityFileDAO->fetch()) {
            _crm_object_to_array($entityFileDAO, $entityFile);
            $files[$entityFileDAO->file_id] = $entityFile;
            if (array_key_exists('file_id', $files[$entityFileDAO->file_id])) {
                $fileDAO =& new CRM_Core_DAO_File();
                $fileDAO->id = $entityFile['file_id'];
                $fileDAO->find(true);
                _crm_object_to_array($fileDAO, $files[$entityFileDAO->file_id]);
            }
            if (CRM_Utils_Array::value('file_type_id', $files[$entityFileDAO->file_id])) {
                $files[$entityFileDAO->file_id]['file_type'] = CRM_Core_OptionGroup::getLabel('file_type', $files[$entityFileDAO->file_id]['file_type_id']);
            }
        }
    } else {
        return _crm_error('Exact match not found');
    }
    return $files;
}
 /**
  *  Function to retrieve the list of soft contributions for given contact.
  *
  * @param int $contact_id
  *   Contact id.
  * @param string $filter
  * @param int $isTest
  *   Additional filter criteria, later used in where clause.
  *
  * @return array
  */
 public static function getSoftContributionList($contact_id, $filter = NULL, $isTest = 0)
 {
     $query = '
 SELECT ccs.id, ccs.amount as amount,
        ccs.contribution_id,
        ccs.pcp_id,
        ccs.pcp_display_in_roll,
        ccs.pcp_roll_nickname,
        ccs.pcp_personal_note,
        ccs.soft_credit_type_id,
        cc.receive_date,
        cc.contact_id as contributor_id,
        cc.contribution_status_id as contribution_status_id,
        cp.title as pcp_title,
        cc.currency,
        contact.display_name,
        cct.name as contributionType
 FROM civicrm_contribution_soft ccs
   LEFT JOIN civicrm_contribution cc
         ON ccs.contribution_id = cc.id
   LEFT JOIN civicrm_pcp cp
         ON ccs.pcp_id = cp.id
   LEFT JOIN civicrm_contact contact ON
   ccs.contribution_id = cc.id AND cc.contact_id = contact.id
   LEFT JOIN civicrm_financial_type cct ON cc.financial_type_id = cct.id
 ';
     $where = "\n      WHERE cc.is_test = %2 AND ccs.contact_id = %1";
     if ($filter) {
         $where .= $filter;
     }
     $query .= "{$where} ORDER BY cc.receive_date DESC";
     $params = array(1 => array($contact_id, 'Integer'), 2 => array($isTest, 'Integer'));
     $cs = CRM_Core_DAO::executeQuery($query, $params);
     $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     $result = array();
     while ($cs->fetch()) {
         $result[$cs->id]['amount'] = $cs->amount;
         $result[$cs->id]['currency'] = $cs->currency;
         $result[$cs->id]['contributor_id'] = $cs->contributor_id;
         $result[$cs->id]['contribution_id'] = $cs->contribution_id;
         $result[$cs->id]['contributor_name'] = $cs->display_name;
         $result[$cs->id]['financial_type'] = $cs->contributionType;
         $result[$cs->id]['receive_date'] = $cs->receive_date;
         $result[$cs->id]['pcp_id'] = $cs->pcp_id;
         $result[$cs->id]['pcp_title'] = $cs->pcp_title;
         $result[$cs->id]['pcp_display_in_roll'] = $cs->pcp_display_in_roll;
         $result[$cs->id]['pcp_roll_nickname'] = $cs->pcp_roll_nickname;
         $result[$cs->id]['pcp_personal_note'] = $cs->pcp_personal_note;
         $result[$cs->id]['contribution_status'] = CRM_Utils_Array::value($cs->contribution_status_id, $contributionStatus);
         $result[$cs->id]['sct_label'] = CRM_Core_OptionGroup::getLabel('soft_credit_type', $cs->soft_credit_type_id);
         if ($isTest) {
             $result[$cs->id]['contribution_status'] = $result[$cs->id]['contribution_status'] . '<br /> (test)';
         }
     }
     return $result;
 }
 /**
  * Where clause for a single field.
  *
  * @param $values
  * @param $query
  *
  * @return void
  */
 public static function whereClauseSingle(&$values, &$query)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     $val = $names = array();
     switch ($name) {
         case 'case_type_id':
         case 'case_type':
         case 'case_status':
         case 'case_status_id':
         case 'case_id':
             if (strpos($name, 'type')) {
                 $name = 'case_type_id';
                 $label = 'Case Type(s)';
             } elseif (strpos($name, 'status')) {
                 $name = 'status_id';
                 $label = 'Case Status(s)';
             } else {
                 $name = 'id';
                 $label = 'Case ID';
             }
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.{$name}", $op, $value, "Integer");
             list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Case_DAO_Case', $name, $value, $op);
             $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $label, 2 => $op, 3 => $value));
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_owner':
         case 'case_mycases':
             if (!empty($value)) {
                 if ($value == 2) {
                     $session = CRM_Core_Session::singleton();
                     $userID = $session->get('userID');
                     $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_relationship.contact_id_b", $op, $userID, 'Int');
                     $query->_qill[$grouping][] = ts('Case %1 My Cases', array(1 => $op));
                     $query->_tables['case_relationship'] = $query->_whereTables['case_relationship'] = 1;
                 } elseif ($value == 1) {
                     $query->_qill[$grouping][] = ts('Case %1 All Cases', array(1 => $op));
                     $query->_where[$grouping][] = "civicrm_case_contact.contact_id = contact_a.id";
                 }
                 $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
                 $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             }
             return;
         case 'case_deleted':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.is_deleted", $op, $value, 'Boolean');
             if ($value) {
                 $query->_qill[$grouping][] = ts("Find Deleted Cases");
             }
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_activity_subject':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.subject", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Activity Subject %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_subject':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.subject", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Case Subject %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_source_contact_id':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case_reporter.sort_name", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Activity Reporter %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case_reporter'] = $query->_whereTables['civicrm_case_reporter'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_recent_activity_date':
             $date = CRM_Utils_Date::format($value);
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_date_time", $op, $date, 'Date');
             if ($date) {
                 $date = CRM_Utils_Date::customFormat($date);
                 $query->_qill[$grouping][] = ts("Activity Actual Date %1 %2", array(1 => $op, 2 => $date));
             }
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_scheduled_activity_date':
             $date = CRM_Utils_Date::format($value);
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_date_time", $op, $date, 'Date');
             if ($date) {
                 $date = CRM_Utils_Date::customFormat($date);
                 $query->_qill[$grouping][] = ts("Activity Schedule Date %1 %2", array(1 => $op, 2 => $date));
             }
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_recent_activity_type':
             $names = $value;
             if ($activityType = CRM_Core_OptionGroup::getLabel('activity_type', $value, 'value')) {
                 $names = $activityType;
             }
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_type_id", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Type %1 %2", array(1 => $op, 2 => $names));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['case_activity_type'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_status_id':
             $names = $value;
             if ($activityStatus = CRM_Core_OptionGroup::getLabel('activity_status', $value, 'value')) {
                 $names = $activityStatus;
             }
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.status_id", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Type %1 %2", array(1 => $op, 2 => $names));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['case_activity_status'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_duration':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.duration", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Duration %1 %2", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_medium_id':
             $names = $value;
             if ($activityMedium = CRM_Core_OptionGroup::getLabel('encounter_medium', $value, 'value')) {
                 $names = $activityMedium;
             }
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.medium_id", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Medium %1 %2", array(1 => $op, 2 => $names));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['case_activity_medium'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_details':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.details", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Activity Details %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_is_auto':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.is_auto", $op, $value, 'Boolean');
             $query->_qill[$grouping][] = ts("Activity Auto Genrated %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
             // adding where clause for case_role
         // adding where clause for case_role
         case 'case_role':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_relation_type.name_b_a", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Role in Case  %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_relation_type'] = $query->_whereTables['case_relationship_type'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_from_start_date_low':
         case 'case_from_start_date_high':
             $query->dateQueryBuilder($values, 'civicrm_case', 'case_from_start_date', 'start_date', 'Start Date');
             return;
         case 'case_to_end_date_low':
         case 'case_to_end_date_high':
             $query->dateQueryBuilder($values, 'civicrm_case', 'case_to_end_date', 'end_date', 'End Date');
             return;
         case 'case_start_date':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.start_date", $op, $value, 'Int');
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_end_date':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.end_date", $op, $value, 'Int');
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_taglist':
             $taglist = $value;
             $value = array();
             foreach ($taglist as $val) {
                 if ($val) {
                     $val = explode(',', $val);
                     foreach ($val as $tId) {
                         if (is_numeric($tId)) {
                             $value[$tId] = 1;
                         }
                     }
                 }
             }
         case 'case_tags':
             $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     if ($v) {
                         $val[$k] = $k;
                         $names[] = $tags[$k];
                     }
                 }
             }
             $query->_where[$grouping][] = " civicrm_case_tag.tag_id IN (" . implode(',', $val) . " )";
             $query->_qill[$grouping][] = ts('Case Tags %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             $query->_tables['civicrm_case_tag'] = $query->_whereTables['civicrm_case_tag'] = 1;
             return;
     }
 }
Beispiel #21
0
 function &getActivity($clientID, $activityDAO, &$activityTypeInfo)
 {
     if (empty($this->_redactionStringRules)) {
         $this->_redactionStringRules = array();
     }
     $activity = array();
     $activity['fields'] = array();
     if ($clientID) {
         $clientID = CRM_Utils_Type::escape($clientID, 'Integer');
         if (!in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
             $activity['editURL'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}");
         } else {
             $activity['editURL'] = '';
         }
         $client = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
         // add Client SortName as well as Display to the strings to be redacted across the case session
         // suffixed with a randomly generated 4-digit number
         if (!array_key_exists($client, $this->_redactionStringRules)) {
             $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($client => 'name_' . rand(10000, 100000)));
             $clientSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
             if (!array_key_exists($clientSortName, $this->_redactionStringRules)) {
                 $this->_redactionStringRules[$clientSortName] = $this->_redactionStringRules[$client];
             }
         }
         $activity['fields'][] = array('label' => 'Client', 'value' => $this->redact($client), 'type' => 'String');
     }
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     if (!empty($activityDAO->targetID)) {
         // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
         // Maybe not the best solution.
         $targetNames = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $targetID);
         $processTarget = FALSE;
         $label = ts('With Contact(s)');
         if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
             $processTarget = TRUE;
             $label = ts('Recipient');
         }
         if (!$processTarget) {
             foreach ($targetNames as $targetID => $targetName) {
                 if ($targetID != $clientID) {
                     $processTarget = TRUE;
                     break;
                 }
             }
         }
         if ($processTarget) {
             $targetRedacted = array();
             foreach ($targetNames as $targetID => $target) {
                 // add Recipient SortName as well as Display to the strings to be redacted across the case session
                 // suffixed with a randomly generated 4-digit number
                 if (!array_key_exists($target, $this->_redactionStringRules)) {
                     $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($target => 'name_' . rand(10000, 100000)));
                     $targetSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
                     if (!array_key_exists($targetSortName, $this->_redactionStringRules)) {
                         $this->_redactionStringRules[$targetSortName] = $this->_redactionStringRules[$target];
                     }
                 }
                 $targetRedacted[] = $this->redact($target);
             }
             $activity['fields'][] = array('label' => $label, 'value' => implode('; ', $targetRedacted), 'type' => 'String');
         }
     }
     // Activity Type info is a special field
     $activity['fields'][] = array('label' => ts('Activity Type'), 'value' => $activityTypeInfo['label'], 'type' => 'String');
     $activity['fields'][] = array('label' => ts('Subject'), 'value' => htmlspecialchars($this->redact($activityDAO->subject)), 'type' => 'Memo');
     $creator = $this->getCreatedBy($activityDAO->id);
     // add Creator to the strings to be redacted across the case session
     if (!array_key_exists($creator, $this->_redactionStringRules)) {
         $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($creator => 'name_' . rand(10000, 100000)));
     }
     $activity['fields'][] = array('label' => ts('Created By'), 'value' => $this->redact($creator), 'type' => 'String');
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $source_contact_id = CRM_Activity_BAO_Activity::getActivityContact($activityDAO->id, $sourceID);
     $reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'display_name');
     // add Reporter SortName as well as Display to the strings to be redacted across the case session
     // suffixed with a randomly generated 4-digit number
     if (!array_key_exists($reporter, $this->_redactionStringRules)) {
         $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($reporter => 'name_' . rand(10000, 100000)));
         $reporterSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'sort_name');
         if (!array_key_exists($reporterSortName, $this->_redactionStringRules)) {
             $this->_redactionStringRules[$reporterSortName] = $this->_redactionStringRules[$reporter];
         }
     }
     $activity['fields'][] = array('label' => ts('Reported By'), 'value' => $this->redact($reporter), 'type' => 'String');
     if (!empty($activityDAO->assigneeID)) {
         //allow multiple assignee contacts.CRM-4503.
         $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activityDAO->id), TRUE);
         foreach ($assignee_contact_names as &$assignee) {
             // add Assignee to the strings to be redacted across the case session
             $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($assignee => 'name_' . rand(10000, 100000)));
             $assignee = $this->redact($assignee);
         }
         $assigneeContacts = implode(', ', $assignee_contact_names);
         $activity['fields'][] = array('label' => ts('Assigned To'), 'value' => $assigneeContacts, 'type' => 'String');
     }
     if ($activityDAO->medium_id) {
         $activity['fields'][] = array('label' => ts('Medium'), 'value' => CRM_Core_OptionGroup::getLabel('encounter_medium', $activityDAO->medium_id, FALSE), 'type' => 'String');
     }
     $activity['fields'][] = array('label' => ts('Location'), 'value' => $activityDAO->location, 'type' => 'String');
     $activity['fields'][] = array('label' => ts('Date and Time'), 'value' => $activityDAO->activity_date_time, 'type' => 'Date');
     $activity['fields'][] = array('label' => ts('Details'), 'value' => $this->redact(CRM_Utils_String::stripAlternatives($activityDAO->details)), 'type' => 'Memo');
     // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
     if ($activityDAO->duration) {
         $activity['fields'][] = array('label' => ts('Duration'), 'value' => $activityDAO->duration . ' ' . ts('minutes'), 'type' => 'Int');
     }
     $activity['fields'][] = array('label' => ts('Status'), 'value' => CRM_Core_OptionGroup::getLabel('activity_status', $activityDAO->status_id), 'type' => 'String');
     $activity['fields'][] = array('label' => ts('Priority'), 'value' => CRM_Core_OptionGroup::getLabel('priority', $activityDAO->priority_id), 'type' => 'String');
     //for now empty custom groups
     $activity['customGroups'] = $this->getCustomData($clientID, $activityDAO, $activityTypeInfo);
     return $activity;
 }
Beispiel #22
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues();
     $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active');
     foreach ($checkBoxes as $key) {
         if (!isset($params[$key])) {
             $params[$key] = 0;
         }
     }
     $session =& CRM_Core_Session::singleton();
     $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID');
     if (!$contactID) {
         $contactID = $this->get('contactID');
     }
     $params['contact_id'] = $contactID;
     $params['contribution_page_id'] = $this->get('contribution_page_id') ? $this->get('contribution_page_id') : $this->_contriPageId;
     $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
     $approval_needed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCPBlock', $params['contribution_page_id'], 'is_approval_needed', 'entity_id');
     $approvalMessage = null;
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $params['status_id'] = $approval_needed ? 1 : 2;
         $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin your fundraising efforts. You will receive an email confirmation shortly which includes a link to return to your fundraising page.') : ts('and is ready to use.');
     }
     $params['id'] = $this->_pageId;
     require_once 'CRM/Contribute/BAO/PCP.php';
     $pcp = CRM_Contribute_BAO_PCP::add($params, false);
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id);
     $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created');
     $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $pcp->id, 'status_id');
     //send notification of PCP create/update.
     $pcpParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $pcp->contribution_page_id);
     $notifyParams = array();
     $notifyStatus = "";
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
     if ($emails = CRM_Utils_Array::value('notify_email', $notifyParams)) {
         $this->assign('pcpTitle', $pcp->title);
         if ($this->_pageId) {
             $this->assign('mode', 'Update');
         } else {
             $this->assign('mode', 'Add');
         }
         require_once 'CRM/Core/OptionGroup.php';
         $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId);
         $this->assign('pcpStatus', $pcpStatus);
         $this->assign('pcpId', $pcp->id);
         $supporterUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid={$pcp->contact_id}", true, null, true, true);
         $this->assign('supporterUrl', $supporterUrl);
         $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
         $this->assign('supporterName', $supporterName);
         $contribPageUrl = CRM_Utils_System::url("civicrm/contribute/transact", "reset=1&id={$pcp->contribution_page_id}", true, null, true, true);
         $this->assign('contribPageUrl', $contribPageUrl);
         $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcp->contribution_page_id, 'title');
         $this->assign('contribPageTitle', $contribPageTitle);
         $managePCPUrl = CRM_Utils_System::url("civicrm/admin/pcp", "reset=1", true, null, true, true);
         $this->assign('managePCPUrl', $managePCPUrl);
         //get the default domain email address.
         require_once 'CRM/Core/BAO/Domain.php';
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
             CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in Administer CiviCRM &raquo; Configure &raquo; Domain Information. The email address used may need to be a valid mail account with your email service provider.'));
         }
         //if more than one email present for PCP notification ,
         //first email take it as To and other as CC and First email
         //address should be sent in users email receipt for
         //support purpose.
         $emailArray = explode(',', $emails);
         $to = $emailArray[0];
         unset($emailArray[0]);
         $cc = implode(',', $emailArray);
         require_once 'CRM/Core/BAO/MessageTemplates.php';
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc));
         if ($sent) {
             $notifyStatus = ts('A notification email has been sent to the site administrator.');
         }
     }
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id);
     // send email notification to supporter, if initial setup / add mode.
     if (!$this->_pageId) {
         CRM_Contribute_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, true);
         if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) {
             $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.');
         }
     }
     //check if pcp created by anonymous user
     $anonymousPCP = 0;
     if (!$session->get('userID')) {
         $anonymousPCP = 1;
     }
     CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3", array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)));
     if (!$this->_pageId) {
         $session->pushUserContext(CRM_Utils_System::url('civicrm/contribute/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
     }
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active', 'is_notify');
     foreach ($checkBoxes as $key) {
         if (!isset($params[$key])) {
             $params[$key] = 0;
         }
     }
     $session = CRM_Core_Session::singleton();
     $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID');
     if (!$contactID) {
         $contactID = $this->get('contactID');
     }
     $params['title'] = $params['pcp_title'];
     $params['intro_text'] = $params['pcp_intro_text'];
     $params['contact_id'] = $contactID;
     $params['page_id'] = $this->get('component_page_id') ? $this->get('component_page_id') : $this->_contriPageId;
     $params['page_type'] = $this->_component;
     // since we are allowing html input from the user
     // we also need to purify it, so lets clean it up
     $htmlFields = array('intro_text', 'page_text', 'title');
     foreach ($htmlFields as $field) {
         if (!empty($params[$field])) {
             $params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
         }
     }
     $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
     $pcpBlock = new CRM_PCP_DAO_PCPBlock();
     $pcpBlock->entity_table = $entity_table;
     $pcpBlock->entity_id = $params['page_id'];
     $pcpBlock->find(TRUE);
     $params['pcp_block_id'] = $pcpBlock->id;
     $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
     $approval_needed = $pcpBlock->is_approval_needed;
     $approvalMessage = NULL;
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $params['status_id'] = $approval_needed ? 1 : 2;
         $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin promoting your campaign. You will receive an email confirmation shortly which includes a link to return to this page.') : ts('and is ready to use.');
     }
     $params['id'] = $this->_pageId;
     $pcp = CRM_PCP_BAO_PCP::add($params, FALSE);
     //create page in wordpress
     create_wp_campaign($pcp->title, $pcp->contact_id, $pcp->id);
     CRM_Core_Error::debug_log_message("Calling create_wp_campaign.... Params title: {$pcp->title}, contact_id: {$pcp->contact_id}, pcp_id: {$pcp->id} ");
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id);
     $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created');
     $statusId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcp->id, 'status_id');
     //send notification of PCP create/update.
     $pcpParams = array('entity_table' => $entity_table, 'entity_id' => $pcp->page_id);
     $notifyParams = array();
     $notifyStatus = "";
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
     if ($emails = $pcpBlock->notify_email) {
         $this->assign('pcpTitle', $pcp->title);
         if ($this->_pageId) {
             $this->assign('mode', 'Update');
         } else {
             $this->assign('mode', 'Add');
         }
         $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId);
         $this->assign('pcpStatus', $pcpStatus);
         $this->assign('pcpId', $pcp->id);
         $supporterUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$pcp->contact_id}", TRUE, NULL, FALSE, FALSE);
         $this->assign('supporterUrl', $supporterUrl);
         $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
         $this->assign('supporterName', $supporterName);
         if ($this->_component == 'contribute') {
             $pageUrl = CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE);
             $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcpBlock->entity_id, 'title');
         } elseif ($this->_component == 'event') {
             $pageUrl = CRM_Utils_System::url('civicrm/event', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE);
             $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $pcpBlock->entity_id, 'title');
         }
         $this->assign('contribPageUrl', $pageUrl);
         $this->assign('contribPageTitle', $contribPageTitle);
         $managePCPUrl = CRM_Utils_System::url('civicrm/admin/pcp', "reset=1", TRUE, NULL, FALSE, FALSE);
         $this->assign('managePCPUrl', $managePCPUrl);
         //get the default domain email address.
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
             $fixUrl = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1');
             CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
         }
         //if more than one email present for PCP notification ,
         //first email take it as To and other as CC and First email
         //address should be sent in users email receipt for
         //support purpose.
         $emailArray = explode(',', $emails);
         $to = $emailArray[0];
         unset($emailArray[0]);
         $cc = implode(',', $emailArray);
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc));
         if ($sent) {
             $notifyStatus = ts('A notification email has been sent to the site administrator.');
         }
     }
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id);
     // send email notification to supporter, if initial setup / add mode.
     if (!$this->_pageId) {
         CRM_PCP_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, TRUE, $this->_component);
         if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) {
             $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.');
         }
     }
     //check if pcp created by anonymous user
     $anonymousPCP = 0;
     if (!$session->get('userID')) {
         $anonymousPCP = 1;
     }
     CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3", array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)), '', 'info');
     if (!$this->_pageId) {
         $session->pushUserContext(CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
     } elseif ($this->_context == 'dashboard') {
         $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
     }
 }
Beispiel #24
0
 public static function getBatchSummary()
 {
     $batchID = CRM_Utils_Type::escape($_REQUEST['batchID'], 'String');
     $params = array('id' => $batchID);
     $batchInfo = CRM_Batch_BAO_Batch::retrieve($params, $value);
     $batchTotals = CRM_Batch_BAO_Batch::batchTotals(array($batchID));
     $batchSummary = array('created_by' => CRM_Contact_BAO_Contact::displayName($batchInfo->created_id), 'status' => CRM_Core_OptionGroup::getLabel('batch_status', $batchInfo->status_id), 'description' => $batchInfo->description, 'payment_instrument' => CRM_Core_OptionGroup::getLabel('payment_instrument', $batchInfo->payment_instrument_id), 'item_count' => $batchInfo->item_count, 'assigned_item_count' => $batchTotals[$batchID]['item_count'], 'total' => CRM_Utils_Money::format($batchInfo->total), 'assigned_total' => CRM_Utils_Money::format($batchTotals[$batchID]['total']), 'opened_date' => CRM_Utils_Date::customFormat($batchInfo->created_date));
     CRM_Utils_JSON::output($batchSummary);
 }
 /**
  * Sets $this->roles and returns the Roles associated with this Project. Delegate of __get().
  * Note: only roles for active, visible needs are returned.
  *
  * @return array Roles, labels keyed by IDs
  */
 private function _get_roles()
 {
     if (empty($this->roles)) {
         $roles = array();
         if (empty($this->needs)) {
             $this->_get_needs();
         }
         foreach ($this->needs as $need) {
             if (CRM_Utils_Array::value('is_flexible', $need) == '1') {
                 $roles[CRM_Volunteer_BAO_Need::FLEXIBLE_ROLE_ID] = CRM_Volunteer_BAO_Need::getFlexibleRoleLabel();
             } else {
                 $role_id = CRM_Utils_Array::value('role_id', $need);
                 $roles[$role_id] = CRM_Core_OptionGroup::getLabel(CRM_Volunteer_BAO_Assignment::ROLE_OPTION_GROUP, $role_id);
             }
         }
         asort($roles);
         $this->roles = $roles;
     }
     return $this->roles;
 }
Beispiel #26
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = false;
     $checkList = array();
     $display_flag = $prev_cid = $cid = 0;
     foreach ($rows as $rowNum => $row) {
         if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
             // don't repeat contact details if its same as the previous row
             if (array_key_exists('civicrm_pledge_contact_id', $row)) {
                 if ($cid = $row['civicrm_pledge_contact_id']) {
                     if ($rowNum == 0) {
                         $prev_cid = $cid;
                     } else {
                         if ($prev_cid == $cid) {
                             $display_flag = 1;
                             $prev_cid = $cid;
                         } else {
                             $display_flag = 0;
                             $prev_cid = $cid;
                         }
                     }
                     if ($display_flag) {
                         foreach ($row as $colName => $colVal) {
                             if (in_array($colName, $this->_noRepeats)) {
                                 unset($rows[$rowNum][$colName]);
                             }
                         }
                     }
                     $entryFound = true;
                 }
             }
         }
         // convert display name to links
         if (array_key_exists('civicrm_contact_display_name', $row) && array_key_exists('civicrm_pledge_contact_id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_pledge_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_display_name_hover'] = ts("View Contact Summary for this Contact.");
             $entryFound = true;
         }
         //handle status id
         if (array_key_exists('civicrm_pledge_status_id', $row)) {
             if ($value = $row['civicrm_pledge_status_id']) {
                 $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Core_OptionGroup::getLabel('contribution_status', $value);
             }
             $entryFound = true;
         }
         // handle state province
         if (array_key_exists('civicrm_address_state_province_id', $row)) {
             if ($value = $row['civicrm_address_state_province_id']) {
                 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($value, false);
             }
             $entryFound = true;
         }
         // handle country
         if (array_key_exists('civicrm_address_country_id', $row)) {
             if ($value = $row['civicrm_address_country_id']) {
                 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, false);
             }
             $entryFound = true;
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
     }
 }
Beispiel #27
0
 /**
  * Get list of contribution In Honor of contact Ids.
  *
  * @param int $honorId
  *   In Honor of Contact ID.
  *
  * @return array
  *   list of contribution fields
  */
 public static function getHonorContacts($honorId)
 {
     $params = array();
     $honorDAO = new CRM_Contribute_DAO_ContributionSoft();
     $honorDAO->contact_id = $honorId;
     $honorDAO->find();
     $type = CRM_Contribute_PseudoConstant::financialType();
     while ($honorDAO->fetch()) {
         $contributionDAO = new CRM_Contribute_DAO_Contribution();
         $contributionDAO->id = $honorDAO->contribution_id;
         if ($contributionDAO->find(TRUE)) {
             $params[$contributionDAO->id]['honor_type'] = CRM_Core_OptionGroup::getLabel('soft_credit_type', $honorDAO->soft_credit_type_id, 'value');
             $params[$contributionDAO->id]['honorId'] = $contributionDAO->contact_id;
             $params[$contributionDAO->id]['display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contributionDAO->contact_id, 'display_name');
             $params[$contributionDAO->id]['type'] = $type[$contributionDAO->financial_type_id];
             $params[$contributionDAO->id]['type_id'] = $contributionDAO->financial_type_id;
             $params[$contributionDAO->id]['amount'] = CRM_Utils_Money::format($contributionDAO->total_amount, $contributionDAO->currency);
             $params[$contributionDAO->id]['source'] = $contributionDAO->source;
             $params[$contributionDAO->id]['receive_date'] = $contributionDAO->receive_date;
             $params[$contributionDAO->id]['contribution_status'] = CRM_Contribute_PseudoConstant::contributionStatus($contributionDAO->contribution_status_id);
         }
     }
     return $params;
 }
Beispiel #28
0
 public function buildQuickForm()
 {
     $this->_fields['source_contact_id']['label'] = ts('Reported By');
     unset($this->_fields['status_id']['attributes']['required']);
     if ($this->_caseType) {
         $xmlProcessor = new CRM_Case_XMLProcessor_Process();
         $aTypes = array();
         foreach ($this->_caseType as $key => $val) {
             $activityTypes = $xmlProcessor->get($val, 'ActivityTypes', TRUE);
             $aTypes = $aTypes + $activityTypes;
         }
         // remove Open Case activity type since we're inside an existing case
         $openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
         unset($aTypes[$openCaseID]);
         asort($aTypes);
         $this->_fields['followup_activity_type_id']['attributes'] = array('' => '- select activity type -') + $aTypes;
     }
     $result = parent::buildQuickForm();
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH | CRM_Core_Action::RENEW)) {
         return;
     }
     $this->assign('urlPath', 'civicrm/case/activity');
     $encounterMediums = CRM_Case_PseudoConstant::encounterMedium();
     // Fixme: what's the justification for this? It seems like it is just re-adding an option in case it is the default and disabled.
     // Is that really a big problem?
     if ($this->_activityTypeFile == 'OpenCase') {
         $this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'medium_id');
         if (!array_key_exists($this->_encounterMedium, $encounterMediums)) {
             $encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium', $this->_encounterMedium, FALSE);
         }
     }
     $this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE);
     $i = 0;
     foreach ($this->_caseId as $key => $val) {
         $this->_relatedContacts[] = $rgc = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($val);
         $contName = CRM_Case_BAO_Case::getContactNames($val);
         foreach ($contName as $nkey => $nval) {
             array_push($this->_relatedContacts[$i][0], $this->_relatedContacts[$i][0]['managerOf'] = $nval['display_name']);
         }
         $i++;
     }
     //add case client in send a copy selector.CRM-4438.
     foreach ($this->_caseId as $key => $val) {
         $relatedContacts[] = $relCon = CRM_Case_BAO_Case::getContactNames($val);
     }
     if (!empty($relatedContacts)) {
         foreach ($relatedContacts as $relatedContact) {
             $this->_relatedContacts[] = $relatedContact;
         }
     }
     if (!empty($this->_relatedContacts)) {
         $checkBoxes = array();
         foreach ($this->_relatedContacts as $id => $row) {
             $checkBoxes[$id] = $this->addElement('checkbox', $id, NULL, NULL, array('class' => 'select-row'));
         }
         $this->addGroup($checkBoxes, 'contact_check');
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
         $this->assign('searchRows', $this->_relatedContacts);
     }
     $this->_relatedContacts = $rgc + $relCon;
     $this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this);
 }
Beispiel #29
0
 /** 
  * where clause for a single field
  * 
  * @return void 
  * @access public 
  */
 static function whereClauseSingle(&$values, &$query)
 {
     require_once "CRM/Contact/BAO/Query.php";
     list($name, $op, $value, $grouping, $wildcard) = $values;
     switch ($name) {
         case 'case_status_id':
             require_once "CRM/Case/PseudoConstant.php";
             $statuses = CRM_Case_PseudoConstant::caseStatus();
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.status_id", $op, $value, 'Int');
             $value = $statuses[$value];
             $query->_qill[$grouping][] = ts('Case Status %2 %1', array(1 => $value, 2 => $op));
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_type_id':
             require_once 'CRM/Case/PseudoConstant.php';
             $caseTypes = CRM_Case_PseudoConstant::caseType('label', false);
             $names = array();
             $val = array();
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     if ($v) {
                         $val[$k] = $k;
                         $names[] = $caseTypes[$k];
                     }
                 }
             } else {
                 if (is_numeric($value)) {
                     $val[$value] = $value;
                     $names[] = $value;
                 } else {
                     if ($caseTypeId = CRM_Utils_Array::key($value, $caseTypes)) {
                         $val[$caseTypeId] = $caseTypeId;
                         $names[] = $caseTypes[$caseTypeId];
                     }
                 }
             }
             require_once 'CRM/Case/BAO/Case.php';
             $value = CRM_Case_BAO_Case::VALUE_SEPERATOR . implode(CRM_Case_BAO_Case::VALUE_SEPERATOR . "%' OR civicrm_case.case_type_id LIKE '%" . CRM_Case_BAO_Case::VALUE_SEPERATOR, $val) . CRM_Case_BAO_Case::VALUE_SEPERATOR;
             $query->_where[$grouping][] = "(civicrm_case.case_type_id LIKE '%{$value}%')";
             $query->_qill[$grouping][] = ts('Case Type %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_id':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.id", $op, $value, 'Int');
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_owner':
         case 'case_mycases':
             if (!empty($value)) {
                 if ($value == 2) {
                     $session = CRM_Core_Session::singleton();
                     $userID = $session->get('userID');
                     $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_relationship.contact_id_b", $op, $userID, 'Int');
                     $query->_qill[$grouping][] = ts('Case %1 My Cases', array(1 => $op));
                     $query->_tables['case_relationship'] = $query->_whereTables['case_relationship'] = 1;
                 } else {
                     if ($value == 1) {
                         $query->_qill[$grouping][] = ts('Case %1 All Cases', array(1 => $op));
                         $query->_where[$grouping][] = "civicrm_case_contact.contact_id = contact_a.id";
                     }
                 }
                 $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
                 $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             }
             return;
         case 'case_deleted':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.is_deleted", $op, $value, 'Boolean');
             if ($value) {
                 $query->_qill[$grouping][] = ts("Find Deleted Cases");
             }
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             return;
         case 'case_subject':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.subject", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Activity Subject %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_source_contact_id':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case_reporter.sort_name", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Activity Reporter %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case_reporter'] = $query->_whereTables['civicrm_case_reporter'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_recent_activity_date':
             $date = CRM_Utils_Date::format($value);
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_date_time", $op, $date, 'Date');
             if ($date) {
                 $date = CRM_Utils_Date::customFormat($date);
                 $query->_qill[$grouping][] = ts("Activity Actual Date %1 %2", array(1 => $op, 2 => $date));
             }
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_scheduled_activity_date':
             $date = CRM_Utils_Date::format($value);
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_date_time", $op, $date, 'Date');
             if ($date) {
                 $date = CRM_Utils_Date::customFormat($date);
                 $query->_qill[$grouping][] = ts("Activity Schedule Date %1 %2", array(1 => $op, 2 => $date));
             }
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_recent_activity_type':
             $names = $value;
             require_once "CRM/Core/OptionGroup.php";
             if ($activityType = CRM_Core_OptionGroup::getLabel('activity_type', $value, 'value')) {
                 $names = $activityType;
             }
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_type_id", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Type %1 %2", array(1 => $op, 2 => $names));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['case_activity_type'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_status_id':
             $names = $value;
             require_once "CRM/Core/OptionGroup.php";
             if ($activityStatus = CRM_Core_OptionGroup::getLabel('activity_status', $value, 'value')) {
                 $names = $activityStatus;
             }
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.status_id", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Type %1 %2", array(1 => $op, 2 => $names));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['case_activity_status'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_duration':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.duration", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Duration %1 %2", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_medium_id':
             $names = $value;
             require_once "CRM/Core/OptionGroup.php";
             if ($activityMedium = CRM_Core_OptionGroup::getLabel('encounter_medium', $value, 'value')) {
                 $names = $activityMedium;
             }
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.medium_id", $op, $value, 'Int');
             $query->_qill[$grouping][] = ts("Activity Medium %1 %2", array(1 => $op, 2 => $names));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['case_activity_medium'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_details':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.details", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Activity Details %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_activity_is_auto':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.is_auto", $op, $value, 'Boolean');
             $query->_qill[$grouping][] = ts("Activity Auto Genrated %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
             // adding where clause for case_role
         // adding where clause for case_role
         case 'case_role':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_relation_type.name_b_a", $op, $value, 'String');
             $query->_qill[$grouping][] = ts("Role in Case  %1 '%2'", array(1 => $op, 2 => $value));
             $query->_tables['case_relation_type'] = $query->_whereTables['case_relationship_type'] = 1;
             $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
             $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
             return;
         case 'case_tags':
             require_once 'CRM/Core/BAO/Tag.php';
             $tags = CRM_Core_BAO_Tag::getTagsUsedFor(array('civicrm_case'), true);
             $names = array();
             $val = array();
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     if ($v) {
                         $val[$k] = $k;
                         $names[] = $tags[$k];
                     }
                 }
             }
             $query->_where[$grouping][] = " civicrm_case_tag.tag_id IN (" . implode(',', $val) . " )";
             $query->_qill[$grouping][] = ts('Case Tags %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
             $query->_tables['civicrm_case_tag'] = $query->_whereTables['civicrm_case_tag'] = 1;
             return;
     }
 }
Beispiel #30
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $checkList = array();
     $entryFound = FALSE;
     $display_flag = $prev_cid = $cid = 0;
     $contributionTypes = CRM_Contribute_PseudoConstant::financialType();
     $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
     $contributionPages = CRM_Contribute_PseudoConstant::contributionPage();
     foreach ($rows as $rowNum => $row) {
         if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
             // don't repeat contact details if its same as the previous row
             if (array_key_exists('civicrm_contact_id', $row)) {
                 if ($cid = $row['civicrm_contact_id']) {
                     if ($rowNum == 0) {
                         $prev_cid = $cid;
                     } else {
                         if ($prev_cid == $cid) {
                             $display_flag = 1;
                             $prev_cid = $cid;
                         } else {
                             $display_flag = 0;
                             $prev_cid = $cid;
                         }
                     }
                     if ($display_flag) {
                         foreach ($row as $colName => $colVal) {
                             // Hide repeats in no-repeat columns, but not if the field's a section header
                             if (in_array($colName, $this->_noRepeats) && !array_key_exists($colName, $this->_sections)) {
                                 unset($rows[$rowNum][$colName]);
                             }
                         }
                     }
                     $entryFound = TRUE;
                 }
             }
         }
         if (CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) == 'Contribution') {
             unset($rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id']);
         }
         // convert donor sort name to link
         if (array_key_exists('civicrm_contact_sort_name', $row) && !empty($rows[$rowNum]['civicrm_contact_sort_name']) && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_page_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_contribution_page_id'] = $contributionPages[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value];
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_batch_batch_id', $row)) {
             if ($value = $row['civicrm_batch_batch_id']) {
                 $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $value, 'title');
             }
             $entryFound = TRUE;
         }
         // Contribution amount links to viewing contribution
         if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount_sum', $row)) && CRM_Core_Permission::check('access CiviContribute')) {
             $url = CRM_Utils_System::url("civicrm/contact/view/contribution", "reset=1&id=" . $row['civicrm_contribution_contribution_id'] . "&cid=" . $row['civicrm_contact_id'] . "&action=view&context=contribution&selectedChild=contribute", $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contribution_total_amount_sum_link'] = $url;
             $rows[$rowNum]['civicrm_contribution_total_amount_sum_hover'] = ts("View Details of this Contribution.");
             $entryFound = TRUE;
         }
         // convert campaign_id to campaign title
         if (array_key_exists('civicrm_contribution_campaign_id', $row)) {
             if ($value = $row['civicrm_contribution_campaign_id']) {
                 $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value];
                 $entryFound = TRUE;
             }
         }
         // soft credits
         if (array_key_exists('civicrm_contribution_soft_credits', $row) && 'Contribution' == CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) && array_key_exists('civicrm_contribution_contribution_id', $row)) {
             $query = "\nSELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount_sum, civicrm_contribution_currency\nFROM   civireport_contribution_detail_temp2\nWHERE  civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}";
             $dao = CRM_Core_DAO::executeQuery($query);
             $string = '';
             $separator = $this->_outputMode !== 'csv' ? "<br/>" : ' ';
             while ($dao->fetch()) {
                 $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $dao->civicrm_contact_id);
                 $string = $string . ($string ? $separator : '') . "<a href='{$url}'>{$dao->civicrm_contact_sort_name}</a> " . CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->civicrm_contribution_currency);
             }
             $rows[$rowNum]['civicrm_contribution_soft_credits'] = $string;
         }
         if (array_key_exists('civicrm_contribution_soft_credit_for', $row) && 'Soft Credit' == CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) && array_key_exists('civicrm_contribution_contribution_id', $row)) {
             $query = "\nSELECT civicrm_contact_id, civicrm_contact_sort_name\nFROM   civireport_contribution_detail_temp1\nWHERE  civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}";
             $dao = CRM_Core_DAO::executeQuery($query);
             $string = '';
             while ($dao->fetch()) {
                 $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $dao->civicrm_contact_id);
                 $string = $string . "\n<a href='{$url}'>{$dao->civicrm_contact_sort_name}</a>";
             }
             $rows[$rowNum]['civicrm_contribution_soft_credit_for'] = $string;
         }
         //convert soft_credit_type_id into label
         if (array_key_exists('civicrm_contribution_soft_soft_credit_type_id', $rows[$rowNum])) {
             $rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id'] = CRM_Core_OptionGroup::getLabel('soft_credit_type', $row['civicrm_contribution_soft_soft_credit_type_id']);
         }
         $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound;
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
         $lastKey = $rowNum;
     }
 }