Exemple #1
0
 function __construct()
 {
     require_once 'CRM/Core/OptionGroup.php';
     require_once 'SFS/Utils/ExtendedCare.php';
     $sql = "SELECT column_name,option_group_id FROM civicrm_custom_field WHERE column_name IN('term', 'day_of_week')";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $options = array();
     while ($dao->fetch()) {
         $options[$dao->column_name] = CRM_Core_OptionGroup::valuesByID($dao->option_group_id);
     }
     $sql = " SELECT DISTINCT( name ) as class\nFROM   sfschool_extended_care_source\nWHERE  is_active = 1";
     $dao = CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
         $options['class'][$dao->class] = $dao->class;
     }
     $this->_columns = array($this->_extentedCareTable => array('dao' => 'CRM_Contact_DAO_Contact', 'filters' => array('term' => array('title' => ts('Term'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'type' => CRM_Utils_Type::T_STRING, 'options' => $options['term'], 'default' => SFS_Utils_ExtendedCare::getTerm()), 'day_of_week' => array('title' => ts('Day Of Week'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'type' => CRM_Utils_Type::T_STRING, 'options' => $options['day_of_week']), 'name' => array('title' => ts('Class'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'type' => CRM_Utils_Type::T_STRING, 'options' => $options['class']))), 'civicrm_student' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('no_display' => true, 'required' => true, 'title' => ts('Student')), 'id' => array('no_display' => true, 'no_repeat' => true, 'required' => true))), 'civicrm_parent' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('no_display' => true, 'required' => true, 'title' => ts('Parent')), 'id' => array('no_display' => true, 'required' => true))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_display' => true, 'required' => true))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_display' => true, 'required' => true))));
     parent::__construct();
 }
 static function &valuesByID($customFieldID, $optionGroupID = NULL)
 {
     if (!$optionGroupID) {
         $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldID, 'option_group_id');
     }
     $options = CRM_Core_OptionGroup::valuesByID($optionGroupID);
     CRM_Utils_Hook::customFieldOptions($customFieldID, $options, FALSE);
     return $options;
 }
/**
 * Helper function to validate custom field value
 *
 * @params String $fieldName    Custom field name (eg: custom_8 )
 * @params Mixed  $value        Field value to be validate
 * @params Array  $fieldDetails Field Details
 * @params Array  $errors       Collect validation  errors
 *
 * @param $fieldName
 * @param $value
 * @param $fieldDetails
 * @param array $errors
 *
 * @return Array  Validation errors
 * @todo remove this function - not in use but need to review functionality before
 * removing as it might be useful in wrapper layer
 */
function _civicrm_api3_custom_field_validate_field($fieldName, $value, $fieldDetails, &$errors = array())
{
    return;
    //see comment block
    if (!$value) {
        return $errors;
    }
    $dataType = $fieldDetails['data_type'];
    $htmlType = $fieldDetails['html_type'];
    switch ($dataType) {
        case 'Int':
            if (!CRM_Utils_Rule::integer($value)) {
                $errors[$fieldName] = 'Invalid integer value for ' . $fieldName;
            }
            break;
        case 'Float':
            if (!CRM_Utils_Rule::numeric($value)) {
                $errors[$fieldName] = 'Invalid numeric value for ' . $fieldName;
            }
            break;
        case 'Money':
            if (!CRM_Utils_Rule::money($value)) {
                $errors[$fieldName] = 'Invalid numeric value for ' . $fieldName;
            }
            break;
        case 'Link':
            if (!CRM_Utils_Rule::url($value)) {
                $errors[$fieldName] = 'Invalid link for ' . $fieldName;
            }
            break;
        case 'Boolean':
            if ($value != '1' && $value != '0') {
                $errors[$fieldName] = 'Invalid boolean (use 1 or 0) value for ' . $fieldName;
            }
            break;
        case 'Country':
            if (empty($value)) {
                break;
            }
            if ($htmlType != 'Multi-Select Country' && is_array($value)) {
                $errors[$fieldName] = 'Invalid country for ' . $fieldName;
                break;
            }
            if (!is_array($value)) {
                $value = array($value);
            }
            $query = "SELECT count(*) FROM civicrm_country WHERE id IN (" . implode(',', $value) . ")";
            if (CRM_Core_DAO::singleValueQuery($query) < count($value)) {
                $errors[$fieldName] = 'Invalid country(s) for ' . $fieldName;
            }
            break;
        case 'StateProvince':
            if (empty($value)) {
                break;
            }
            if ($htmlType != 'Multi-Select State/Province' && is_array($value)) {
                $errors[$fieldName] = 'Invalid State/Province for ' . $fieldName;
                break;
            }
            if (!is_array($value)) {
                $value = array($value);
            }
            $query = "\nSELECT count(*)\n  FROM civicrm_state_province\n WHERE id IN ('" . implode("','", $value) . "')";
            if (CRM_Core_DAO::singleValueQuery($query) < count($value)) {
                $errors[$fieldName] = 'Invalid State/Province for ' . $fieldName;
            }
            break;
        case 'ContactReference':
            //FIX ME
            break;
    }
    if (in_array($htmlType, array('Select', 'Multi-Select', 'CheckBox', 'Radio', 'AdvMulti-Select')) && !isset($errors[$fieldName])) {
        $options = CRM_Core_OptionGroup::valuesByID($fieldDetails['option_group_id']);
        if (!is_array($value)) {
            $value = array($value);
        }
        $invalidOptions = array_diff($value, array_keys($options));
        if (!empty($invalidOptions)) {
            $errors[$fieldName] = "Invalid option(s) for field '{$fieldName}': " . implode(',', $invalidOptions);
        }
    }
    return $errors;
}
 /**
  * This function retrive all response options of survey.
  *
  * @param int $surveyId
  *   Survey id.
  * @return array
  *   an array of option values
  */
 public static function getResponsesOptions($surveyId)
 {
     $responseOptions = array();
     if (!$surveyId) {
         return $responseOptions;
     }
     $resultId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'result_id');
     if ($resultId) {
         $responseOptions = CRM_Core_OptionGroup::valuesByID($resultId);
     }
     return $responseOptions;
 }
 /**
  * Low-level option getter, rarely accessed directly.
  * NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
  *
  * @param String $daoName
  * @param String $fieldName
  * @param Array $params
  * - name       string  name of the option group
  * - flip       boolean results are return in id => label format if false
  *                            if true, the results are reversed
  * - grouping   boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
  * - localize   boolean if true, localize the results before returning
  * - condition  string|array add condition(s) to the sql query - will be concatenated using 'AND'
  * - keyColumn  string the column to use for 'id'
  * - labelColumn string the column to use for 'label'
  * - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn
  * - onlyActive boolean return only the action option values
  * - fresh      boolean ignore cache entries and go back to DB
  * @param String $context: Context string
  *
  * @return Array on success, FALSE on error.
  *
  * @static
  */
 public static function get($daoName, $fieldName, $params = array(), $context = NULL)
 {
     CRM_Core_DAO::buildOptionsContext($context);
     $flip = !empty($params['flip']);
     // Merge params with defaults
     $params += array('grouping' => FALSE, 'localize' => FALSE, 'onlyActive' => $context == 'validate' || $context == 'get' ? FALSE : TRUE, 'fresh' => FALSE);
     // Custom fields are not in the schema
     if (strpos($fieldName, 'custom_') === 0 && is_numeric($fieldName[7])) {
         $customField = new CRM_Core_DAO_CustomField();
         $customField->id = (int) substr($fieldName, 7);
         $customField->find(TRUE);
         $options = FALSE;
         if (!empty($customField->option_group_id)) {
             $options = CRM_Core_OptionGroup::valuesByID($customField->option_group_id, $flip, $params['grouping'], $params['localize'], CRM_Utils_Array::value('labelColumn', $params, 'label'), $params['onlyActive'], $params['fresh']);
         } else {
             if ($customField->data_type === 'StateProvince') {
                 $options = self::stateProvince();
             } elseif ($customField->data_type === 'Country') {
                 $options = $context == 'validate' ? self::countryIsoCode() : self::country();
             } elseif ($customField->data_type === 'Boolean') {
                 $options = $context == 'validate' ? array(0, 1) : array(1 => ts('Yes'), 0 => ts('No'));
             }
             $options = $options && $flip ? array_flip($options) : $options;
         }
         if ($options !== FALSE) {
             CRM_Utils_Hook::customFieldOptions($customField->id, $options, FALSE);
         }
         $customField->free();
         return $options;
     }
     // Core field: load schema
     $dao = new $daoName();
     $fields = $dao->fields();
     $fieldKeys = $dao->fieldKeys();
     $dao->free();
     // Support "unique names" as well as sql names
     $fieldKey = $fieldName;
     if (empty($fields[$fieldKey])) {
         $fieldKey = CRM_Utils_Array::value($fieldName, $fieldKeys);
     }
     // If neither worked then this field doesn't exist. Return false.
     if (empty($fields[$fieldKey])) {
         return FALSE;
     }
     $fieldSpec = $fields[$fieldKey];
     // If the field is an enum, explode the enum definition and return the array.
     if (isset($fieldSpec['enumValues'])) {
         // use of a space after the comma is inconsistent in xml
         $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
         $output = explode(',', $enumStr);
         return array_combine($output, $output);
     } elseif (!empty($fieldSpec['pseudoconstant'])) {
         $pseudoconstant = $fieldSpec['pseudoconstant'];
         // Merge params with schema defaults
         $params += array('condition' => CRM_Utils_Array::value('condition', $pseudoconstant, array()), 'keyColumn' => CRM_Utils_Array::value('keyColumn', $pseudoconstant), 'labelColumn' => CRM_Utils_Array::value('labelColumn', $pseudoconstant));
         // Fetch option group from option_value table
         if (!empty($pseudoconstant['optionGroupName'])) {
             if ($context == 'validate') {
                 $params['labelColumn'] = 'name';
             }
             // Call our generic fn for retrieving from the option_value table
             return CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], $flip, $params['grouping'], $params['localize'], $params['condition'] ? ' AND ' . implode(' AND ', (array) $params['condition']) : NULL, $params['labelColumn'] ? $params['labelColumn'] : 'label', $params['onlyActive'], $params['fresh'], $params['keyColumn'] ? $params['keyColumn'] : 'value');
         }
         // Fetch options from other tables
         if (!empty($pseudoconstant['table'])) {
             // Normalize params so the serialized cache string will be consistent.
             CRM_Utils_Array::remove($params, 'flip', 'fresh');
             ksort($params);
             $cacheKey = $daoName . $fieldName . serialize($params);
             // Retrieve cached options
             if (isset(self::$cache[$cacheKey]) && empty($params['fresh'])) {
                 $output = self::$cache[$cacheKey];
             } else {
                 $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($pseudoconstant['table']);
                 if (!class_exists($daoName)) {
                     return FALSE;
                 }
                 // Get list of fields for the option table
                 $dao = new $daoName();
                 $availableFields = array_keys($dao->fieldKeys());
                 $dao->free();
                 $select = "SELECT %1 AS id, %2 AS label";
                 $from = "FROM %3";
                 $wheres = array();
                 $order = "ORDER BY %2";
                 // Use machine name instead of label in validate context
                 if ($context == 'validate') {
                     if (!empty($pseudoconstant['nameColumn'])) {
                         $params['labelColumn'] = $pseudoconstant['nameColumn'];
                     } elseif (in_array('name', $availableFields)) {
                         $params['labelColumn'] = 'name';
                     }
                 }
                 // Condition param can be passed as an sql clause string or an array of clauses
                 if (!empty($params['condition'])) {
                     $wheres[] = implode(' AND ', (array) $params['condition']);
                 }
                 // onlyActive param will automatically filter on common flags
                 if (!empty($params['onlyActive'])) {
                     foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
                         if (in_array($flag, $availableFields)) {
                             $wheres[] = "{$flag} = {$val}";
                         }
                     }
                 }
                 // Filter domain specific options
                 if (in_array('domain_id', $availableFields)) {
                     $wheres[] = 'domain_id = ' . CRM_Core_Config::domainID();
                 }
                 $queryParams = array(1 => array($params['keyColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES), 2 => array($params['labelColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES), 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES));
                 // Add orderColumn param
                 if (!empty($params['orderColumn'])) {
                     $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES);
                     $order = "ORDER BY %4";
                 } elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
                     $order = '';
                 } elseif (in_array('weight', $availableFields)) {
                     $order = "ORDER BY weight";
                 }
                 $output = array();
                 $query = "{$select} {$from}";
                 if ($wheres) {
                     $query .= " WHERE " . implode($wheres, ' AND ');
                 }
                 $query .= ' ' . $order;
                 $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
                 while ($dao->fetch()) {
                     $output[$dao->id] = $dao->label;
                 }
                 $dao->free();
                 // Localize results
                 if (!empty($params['localize']) || $pseudoconstant['table'] == 'civicrm_country' || $pseudoconstant['table'] == 'civicrm_state_province') {
                     $I18nParams = array();
                     if ($pseudoconstant['table'] == 'civicrm_country') {
                         $I18nParams['context'] = 'country';
                     }
                     if ($pseudoconstant['table'] == 'civicrm_state_province') {
                         $I18nParams['context'] = 'province';
                     }
                     $i18n = CRM_Core_I18n::singleton();
                     $i18n->localizeArray($output, $I18nParams);
                     // Maintain sort by label
                     if ($order == "ORDER BY %2") {
                         CRM_Utils_Array::asort($output);
                     }
                 }
                 self::$cache[$cacheKey] = $output;
             }
             return $flip ? array_flip($output) : $output;
         }
     } elseif (CRM_Utils_Array::value('type', $fieldSpec) === CRM_Utils_Type::T_BOOLEAN) {
         $output = $context == 'validate' ? array(0, 1) : array(1 => ts('Yes'), 0 => ts('No'));
         return $flip ? array_flip($output) : $output;
     }
     // If we're still here, it's an error. Return FALSE.
     return FALSE;
 }
Exemple #6
0
 static function &valuesByID($customFieldID, $optionGroupID = null)
 {
     if (!$optionGroupID) {
         $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldID, 'option_group_id');
     }
     require_once 'CRM/Core/OptionGroup.php';
     $options =& CRM_Core_OptionGroup::valuesByID($optionGroupID);
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::customFieldOptions($customFieldID, $options, false);
     return $options;
 }
 /**
  * @param string $context
  * @return array|bool
  */
 public function getOptions($context = NULL)
 {
     CRM_Core_DAO::buildOptionsContext($context);
     if (!$this->id) {
         return FALSE;
     }
     if (!$this->data_type || !$this->custom_group_id) {
         $this->find(TRUE);
     }
     if (!empty($this->option_group_id)) {
         $options = CRM_Core_OptionGroup::valuesByID($this->option_group_id, FALSE, FALSE, FALSE, 'label', !($context == 'validate' || $context == 'get'));
     } elseif ($this->data_type === 'StateProvince') {
         $options = CRM_Core_Pseudoconstant::stateProvince();
     } elseif ($this->data_type === 'Country') {
         $options = $context == 'validate' ? CRM_Core_Pseudoconstant::countryIsoCode() : CRM_Core_Pseudoconstant::country();
     } elseif ($this->data_type === 'Boolean') {
         $options = $context == 'validate' ? array(0, 1) : CRM_Core_SelectValues::boolean();
     } else {
         return FALSE;
     }
     CRM_Utils_Hook::customFieldOptions($this->id, $options, FALSE);
     CRM_Utils_Hook::fieldOptions($this->getEntity(), "custom_{$this->id}", $options, array('context' => $context));
     return $options;
 }
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_votingTab = $this->get('votingTab');
     $this->_reserveToInterview = $this->get('reserveToInterview');
     if ($this->_reserveToInterview || $this->_votingTab) {
         //user came from voting tab / reserve form.
         foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) {
             $this->{"_{$fld}"} = $this->get($fld);
         }
         //get the target voter ids.
         if ($this->_votingTab) {
             $this->getVoterIds();
         }
     } else {
         parent::preProcess();
         //get the survey id from user submitted values.
         $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues'));
         $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues'));
     }
     //get the contact read only fields to display.
     require_once 'CRM/Core/BAO/Preferences.php';
     $readOnlyFields = array_merge(array('contact_type' => '', 'sort_name' => ts('Name')));
     //get the read only field data.
     $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
     $returnProperties['contact_sub_type'] = true;
     //get the profile id.
     require_once 'CRM/Core/BAO/UFJoin.php';
     $ufJoinParams = array('entity_id' => $this->_surveyId, 'entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign');
     $this->_ufGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
     $this->assign('ufGroupId', $this->_ufGroupId);
     //validate all voters for required activity.
     //get the survey activities for given voters.
     require_once 'CRM/Campaign/BAO/Survey.php';
     $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId);
     require_once 'CRM/Core/PseudoConstant.php';
     $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
     $scheduledStatusId = array_search('Scheduled', $activityStatus);
     $activityIds = array();
     foreach ($this->_contactIds as $key => $voterId) {
         $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds);
         $statusId = CRM_Utils_Array::value('status_id', $actVals);
         $activityId = CRM_Utils_Array::value('activity_id', $actVals);
         if ($activityId && $statusId && $scheduledStatusId == $statusId) {
             $activityIds["activity_id_{$voterId}"] = $activityId;
         } else {
             unset($this->_contactIds[$key]);
         }
     }
     //retrieve the contact details.
     $voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties);
     $this->_allowAjaxReleaseButton = false;
     if ($this->_votingTab && (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign') || CRM_Core_Permission::check('release campaign contacts'))) {
         $this->_allowAjaxReleaseButton = true;
     }
     $this->assign('votingTab', $this->_votingTab);
     $this->assign('componentIds', $this->_contactIds);
     $this->assign('voterDetails', $voterDetails);
     $this->assign('readOnlyFields', $readOnlyFields);
     $this->assign('interviewerId', $this->_interviewerId);
     $this->assign('surveyActivityIds', json_encode($activityIds));
     $this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton);
     //get the survey values.
     $this->_surveyValues = $this->get('surveyValues');
     if (!is_array($this->_surveyValues)) {
         $this->_surveyValues = array();
         if ($this->_surveyId) {
             require_once 'CRM/Campaign/BAO/Survey.php';
             $surveyParams = array('id' => $this->_surveyId);
             CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues);
         }
         $this->set('surveyValues', $this->_surveyValues);
     }
     $this->assign('surveyValues', $this->_surveyValues);
     //get the survey result options.
     $this->_resultOptions = $this->get('resultOptions');
     if (!is_array($this->_resultOptions)) {
         $this->_resultOptions = array();
         if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) {
             require_once 'CRM/Core/OptionGroup.php';
             $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId);
         }
         $this->set('resultOptions', $this->_resultOptions);
     }
     //validate the required ids.
     $this->validateIds();
     //append breadcrumb to survey dashboard.
     require_once 'CRM/Campaign/BAO/Campaign.php';
     if (CRM_Campaign_BAO_Campaign::accessCampaignDashboard()) {
         $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
         CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
     }
     //set the title.
     require_once 'CRM/Core/PseudoConstant.php';
     $activityTypes = CRM_Core_PseudoConstant::activityType(false, true, false, 'label', true);
     $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues);
     CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId])));
 }
 /**
  * Build all the data structures needed to build the form.
  */
 public function preProcess()
 {
     $this->_votingTab = $this->get('votingTab');
     $this->_reserveToInterview = $this->get('reserveToInterview');
     if ($this->_reserveToInterview || $this->_votingTab) {
         //user came from voting tab / reserve form.
         foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) {
             $this->{"_{$fld}"} = $this->get($fld);
         }
         //get the target voter ids.
         if ($this->_votingTab) {
             $this->getVoterIds();
         }
     } else {
         parent::preProcess();
         //get the survey id from user submitted values.
         $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues'));
         $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues'));
     }
     if ($this->_surveyId) {
         $params = array('id' => $this->_surveyId);
         CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails);
     }
     $orderClause = FALSE;
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == '_qf_Interview_submit_orderBy' && !empty($_POST['order_bys'])) {
         $orderByParams = CRM_Utils_Array::value('order_bys', $_POST);
     } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) {
         $orderByParams = array(1 => array('column' => 'civicrm_address.street_name', 'order' => 'ASC'), 2 => array('column' => 'civicrm_address.street_number%2', 'order' => 'ASC'), 3 => array('column' => 'civicrm_address.street_number', 'order' => 'ASC'), 4 => array('column' => 'contact_a.sort_name', 'order' => 'ASC'));
     }
     $orderBy = array();
     if (!empty($orderByParams)) {
         foreach ($orderByParams as $key => $val) {
             if (!empty($val['column'])) {
                 $orderBy[] = "{$val['column']} {$val['order']}";
             }
         }
         if (!empty($orderBy)) {
             $orderClause = "ORDER BY " . implode(', ', $orderBy);
         }
     }
     $this->_contactIds = array_unique($this->_contactIds);
     if (!empty($this->_contactIds) && $orderClause) {
         $clause = 'contact_a.id IN ( ' . implode(',', $this->_contactIds) . ' ) ';
         $sql = "\nSELECT contact_a.id\nFROM civicrm_contact contact_a\nLEFT JOIN civicrm_address ON contact_a.id = civicrm_address.contact_id\nWHERE {$clause}\n{$orderClause}";
         $this->_contactIds = array();
         $dao = CRM_Core_DAO::executeQuery($sql);
         while ($dao->fetch()) {
             $this->_contactIds[] = $dao->id;
         }
     }
     //get the contact read only fields to display.
     $readOnlyFields = array_merge(array('contact_type' => '', 'sort_name' => ts('Name')));
     //get the read only field data.
     $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
     $returnProperties['contact_sub_type'] = TRUE;
     //validate all voters for required activity.
     //get the survey activities for given voters.
     $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId);
     $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
     $scheduledStatusId = array_search('Scheduled', $activityStatus);
     $activityIds = array();
     foreach ($this->_contactIds as $key => $voterId) {
         $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds);
         $statusId = CRM_Utils_Array::value('status_id', $actVals);
         $activityId = CRM_Utils_Array::value('activity_id', $actVals);
         if ($activityId && $statusId && $scheduledStatusId == $statusId) {
             $activityIds["activity_id_{$voterId}"] = $activityId;
         } else {
             unset($this->_contactIds[$key]);
         }
     }
     //retrieve the contact details.
     $voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties);
     $this->_allowAjaxReleaseButton = FALSE;
     if ($this->_votingTab && (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign') || CRM_Core_Permission::check('release campaign contacts'))) {
         $this->_allowAjaxReleaseButton = TRUE;
     }
     //validate voter ids across profile.
     $this->filterVoterIds();
     $this->assign('votingTab', $this->_votingTab);
     $this->assign('componentIds', $this->_contactIds);
     $this->assign('componentIdsJson', json_encode($this->_contactIds));
     $this->assign('voterDetails', $voterDetails);
     $this->assign('readOnlyFields', $readOnlyFields);
     $this->assign('interviewerId', $this->_interviewerId);
     $this->assign('surveyActivityIds', json_encode($activityIds));
     $this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton);
     //get the survey values.
     $this->_surveyValues = $this->get('surveyValues');
     if (!is_array($this->_surveyValues)) {
         $this->_surveyValues = array();
         if ($this->_surveyId) {
             $surveyParams = array('id' => $this->_surveyId);
             CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues);
         }
         $this->set('surveyValues', $this->_surveyValues);
     }
     $this->assign('surveyValues', $this->_surveyValues);
     $result = CRM_Campaign_BAO_Survey::getReportID($this->_surveyId);
     $this->assign("instanceId", $result);
     //get the survey result options.
     $this->_resultOptions = $this->get('resultOptions');
     if (!is_array($this->_resultOptions)) {
         $this->_resultOptions = array();
         if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) {
             $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId);
         }
         $this->set('resultOptions', $this->_resultOptions);
     }
     //validate the required ids.
     $this->validateIds();
     //append breadcrumb to survey dashboard.
     if (CRM_Campaign_BAO_Campaign::accessCampaign()) {
         $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
         CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
     }
     //set the title.
     $activityTypes = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
     $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues);
     CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId])));
 }
 /**
  * Get a id => value matching of all reference types
  */
 protected function getReferenceTypes($context)
 {
     $types = $context->getCachedEntry('analyser_account.reference_types');
     if ($types === NULL) {
         $group_id = banking_helper_optiongroupid_by_name('civicrm_banking.reference_types');
         $types = CRM_Core_OptionGroup::valuesByID($group_id, $flip = TRUE, $grouping = FALSE, $localize = FALSE, $labelColumnName = 'id', $onlyActive = TRUE, $fresh = FALSE);
         $context->setCachedEntry('analyser_account.reference_types', $types);
     }
     return $types;
 }
Exemple #11
0
 public function buildQuickForm()
 {
     if ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) {
         $classDetail = array();
         if ($this->_indexID) {
             $params = array(1 => array($this->_indexID, 'Integer'));
             $classDetail = array('name' => array('title' => ts('Class')), 'day_of_week' => array('title' => ts('Day Of week')), 'session' => array('title' => ts('Session')), 'term' => array('title' => ts('Term')));
             $sql = "SELECT * FROM sfschool_extended_care_source where id=%1";
             $dao = CRM_Core_DAO::executeQuery($sql, $params);
             while ($dao->fetch()) {
                 foreach ($classDetail as $field => $value) {
                     $classDetail[$field]['value'] = $dao->{$field};
                 }
                 if (strstr($dao->url, 'http:') || strstr($dao->url, 'https:')) {
                     $url = $dao->url;
                 } else {
                     if ($dao->url) {
                         $urlParts = explode(';;', $dao->url);
                         $url = CRM_Utils_System::url($urlParts[0], $urlParts[1]);
                     } else {
                         $url = null;
                     }
                 }
                 $this->assign('moreInfo', $url);
             }
         }
         $this->assign('classDetail', $classDetail);
         if ($this->_action & CRM_Core_Action::DISABLE) {
             $buttonLabel = ts('Disable');
         } else {
             $buttonLabel = ts('Enable');
         }
         $this->addButtons(array(array('type' => 'submit', 'name' => $buttonLabel, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $options = array();
     $sql = "SELECT column_name,option_group_id FROM civicrm_custom_field WHERE column_name IN('term', 'day_of_week', 'session' , 'grade')";
     $dao = CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
         $options[$dao->column_name] = CRM_Core_OptionGroup::valuesByID($dao->option_group_id);
     }
     $this->add('select', 'term', ts('Term'), array('' => '-select') + $options['term'], true);
     $this->add('select', 'day_of_week', ts('Day Of Week:'), array('' => '-select') + $options['day_of_week'], true);
     $this->add('select', 'session', ts('Session:'), array('' => '-select') + $options['session'], true);
     $this->add('select', 'max_grade', ts('Max Grade:'), array('' => '-select') + $options['grade'], true);
     $this->add('select', 'min_grade', ts('Min Grade:'), array('' => '-select') + $options['grade'], true);
     $this->add('text', 'name', ts('Class Name:'), null, true);
     $this->addDate('start_date', ts('Start Date'), CRM_Core_SelectValues::date('custom', 10, 2));
     $this->addDate('end_date', ts('End Date'), CRM_Core_SelectValues::date('custom', 10, 2));
     $this->add('text', 'instructor', ts('Instructor:'));
     $this->add('text', 'fee_block', ts('Fee Block:'));
     $this->add('text', 'total_fee_block', ts('Session Fees:'));
     $this->add('text', 'max_participants', ts('Max Participant:'));
     $this->add('text', 'location', ts('Location:'));
     $this->add('text', 'url', ts('Url:'));
     $this->add('text', 'additional_rows', ts('Additional Rows:'));
     $this->addRule('additional_rows', ts('Please enter valid Rows'), 'positiveInteger');
     $this->addRule('max_participants', ts('Please enter valid Max Participants'), 'positiveInteger');
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     if ($this->_action & CRM_Core_Action::ADD) {
         $this->add('checkbox', 'is_active', ts('Enabled?'));
     }
     $this->assign('elements', $this->_customFields);
 }
Exemple #12
0
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $buttonLabel = ts('Delete');
     } else {
         require_once 'SFS/Utils/Query.php';
         $buttonLabel = ts('Save');
         $students = SFS_Utils_Query::getStudentsByGrade(true, false, true, '');
         $this->add('select', 'entity_id', ts('Student'), array('' => '--select--') + $students, true);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $this->freeze('entity_id');
         }
         if ($this->_object == 'fee') {
             $sql = "SELECT cf.column_name as column_name, cf.option_group_id as option_group_id\n                         FROM civicrm_custom_field cf\n                         INNER JOIN  civicrm_custom_group cg ON cf.custom_group_id = cg.id\n                         WHERE cg.table_name = %1";
             $params = array(1 => array($this->_tableName, 'String'));
             $dao = CRM_Core_DAO::executeQuery($sql, $params);
             $options = array();
             while ($dao->fetch()) {
                 if ($dao->option_group_id) {
                     $options[$dao->column_name] = CRM_Core_OptionGroup::valuesByID($dao->option_group_id);
                 }
             }
             $this->add('select', 'fee_type', ts('Fee Type'), array('' => '--select--') + $options['fee_type'], true);
             $this->add('select', 'category', ts('Category'), array('' => '--select--') + $options['category'], true);
             $this->add('text', 'description', ts('Description'), null, true);
             $this->addDate('fee_date', ts('Fee Date'), CRM_Core_SelectValues::date('custom', 1, 1));
             $this->add('text', 'total_blocks', ts('Total Blocks'), null, true);
             $this->addRule('total_blocks', ts('Please enter valid Total Blocks'), 'positiveInteger');
         } else {
             $classes = SFS_Utils_Query::getClasses();
             $this->add('text', 'pickup_person_name', ts('Pickup Person:'));
             $this->addDateTime('signin_time', ts('Signin'), CRM_Core_SelectValues::date('custom', 10, 2));
             $this->addDateTime('signout_time', ts('Signout'), CRM_Core_SelectValues::date('custom', 10, 2));
             $this->add('select', 'class', ts('Class'), array('' => '--select--') + $classes, true);
             $this->add('checkbox', 'is_morning', ts('Is morning?'));
             $this->add('checkbox', 'at_school_meeting', ts('At School Meeting?'));
         }
     }
     $this->addButtons(array(array('type' => 'next', 'name' => $buttonLabel, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }