当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_String::strtoboolstr方法代码示例

本文整理汇总了PHP中CRM_Utils_String::strtoboolstr方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_String::strtoboolstr方法的具体用法?PHP CRM_Utils_String::strtoboolstr怎么用?PHP CRM_Utils_String::strtoboolstr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_String的用法示例。


在下文中一共展示了CRM_Utils_String::strtoboolstr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: formatCommonData

 /**
  * format common params data to proper format to store.
  *
  * @param array  $params        contain record values.
  * @param array  $formatted     array of formatted data.
  * @param array  $contactFields contact DAO fields.
  * @static
  */
 function formatCommonData($params, &$formatted, &$contactFields)
 {
     $csType = array(CRM_Utils_Array::value('contact_type', $formatted));
     //CRM-5125
     //add custom fields for contact sub type
     if (!empty($this->_contactSubType)) {
         $csType = $this->_contactSubType;
     }
     if ($relCsType = CRM_Utils_Array::value('contact_sub_type', $formatted)) {
         $csType = $relCsType;
     }
     $customFields = CRM_Core_BAO_CustomField::getFields($formatted['contact_type'], false, false, $csType);
     //if a Custom Email Greeting, Custom Postal Greeting or Custom Addressee is mapped, and no "Greeting / Addressee Type ID" is provided, then automatically set the type = Customized, CRM-4575
     $elements = array('email_greeting_custom' => 'email_greeting', 'postal_greeting_custom' => 'postal_greeting', 'addressee_custom' => 'addressee');
     foreach ($elements as $k => $v) {
         if (array_key_exists($k, $params) && !array_key_exists($v, $params)) {
             $label = key(CRM_Core_OptionGroup::values($v, true, null, null, 'AND v.name = "Customized"'));
             $params[$v] = $label;
         }
     }
     //format date first
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     foreach ($params as $key => $val) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             //we should not update Date to null, CRM-4062
             if ($val && $customFields[$customFieldID]['data_type'] == 'Date') {
                 self::formatCustomDate($params, $formatted, $dateType, $key);
                 unset($params[$key]);
             } else {
                 if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 }
             }
         }
         if ($key == 'birth_date' && $val) {
             CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
         } else {
             if ($key == 'deceased_date' && $val) {
                 CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
             } else {
                 if ($key == 'is_deceased' && $val) {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 } else {
                     if ($key == 'gender') {
                         //CRM-4360
                         $params[$key] = $this->checkGender($val);
                     }
                 }
             }
         }
     }
     //now format custom data.
     foreach ($params as $key => $field) {
         if ($field == null || $field === '') {
             continue;
         }
         if (is_array($field)) {
             foreach ($field as $value) {
                 $break = false;
                 if (is_array($value)) {
                     foreach ($value as $name => $testForEmpty) {
                         // check if $value does not contain IM provider or phoneType
                         if (($name !== 'phone_type_id' || $name !== 'provider_id') && ($testForEmpty === '' || $testForEmpty == null)) {
                             $break = true;
                             break;
                         }
                     }
                 } else {
                     $break = true;
                 }
                 if (!$break) {
                     _civicrm_add_formatted_param($value, $formatted);
                 }
             }
             continue;
         }
         $formatValues = array($key => $field);
         if ($key !== 'preferred_communication_method' && array_key_exists($key, $contactFields)) {
             // due to merging of individual table and
             // contact table, we need to avoid
             // preferred_communication_method forcefully
             $formatValues['contact_type'] = $formatted['contact_type'];
         }
         if ($key == 'id' && isset($field)) {
             $formatted[$key] = $field;
         }
         _civicrm_add_formatted_param($formatValues, $formatted);
         //Handling Custom Data
         if (($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) && array_key_exists($customFieldID, $customFields)) {
             //get the html type.
             $type = $customFields[$customFieldID]['html_type'];
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:Contact.php

示例2: import

 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     try {
         // first make sure this is a valid line
         $response = $this->summary($values);
         if ($response != CRM_Import_Parser::VALID) {
             return $response;
         }
         $params =& $this->getActiveFieldParams();
         //assign join date equal to start date if join date is not provided
         if (!CRM_Utils_Array::value('join_date', $params) && CRM_Utils_Array::value('membership_start_date', $params)) {
             $params['join_date'] = $params['membership_start_date'];
         }
         $session = CRM_Core_Session::singleton();
         $dateType = $session->get('dateTypes');
         $formatted = array();
         $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
         // don't add to recent items, CRM-4399
         $formatted['skipRecentView'] = TRUE;
         $dateLabels = array('join_date' => ts('Member Since'), 'membership_start_date' => ts('Start Date'), 'membership_end_date' => ts('End Date'));
         foreach ($params as $key => $val) {
             if ($val) {
                 switch ($key) {
                     case 'join_date':
                     case 'membership_start_date':
                     case 'membership_end_date':
                         if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                             if (!CRM_Utils_Rule::date($params[$key])) {
                                 CRM_Contact_Import_Parser_Contact::addToErrorMsg($dateLabels[$key], $errorMessage);
                             }
                         } else {
                             CRM_Contact_Import_Parser_Contact::addToErrorMsg($dateLabels[$key], $errorMessage);
                         }
                         break;
                     case 'membership_type_id':
                         if (!is_numeric($val)) {
                             unset($params['membership_type_id']);
                             $params['membership_type'] = $val;
                         }
                         break;
                     case 'status_id':
                         if (!is_numeric($val)) {
                             unset($params['status_id']);
                             $params['membership_status'] = $val;
                         }
                         break;
                     case 'is_override':
                         $params[$key] = CRM_Utils_String::strtobool($val);
                         break;
                 }
                 if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                     if ($customFields[$customFieldID]['data_type'] == 'Date') {
                         CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                         unset($params[$key]);
                     } else {
                         if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                             $params[$key] = CRM_Utils_String::strtoboolstr($val);
                         }
                     }
                 }
             }
         }
         //date-Format part ends
         static $indieFields = NULL;
         if ($indieFields == NULL) {
             $tempIndieFields = CRM_Member_DAO_Membership::import();
             $indieFields = $tempIndieFields;
         }
         $formatValues = array();
         foreach ($params as $key => $field) {
             if ($field == NULL || $field === '') {
                 continue;
             }
             $formatValues[$key] = $field;
         }
         //format params to meet api v2 requirements.
         //@todo find a way to test removing this formatting
         $formatError = $this->membership_format_params($formatValues, $formatted, TRUE);
         if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
             $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, NULL, 'Membership');
         } else {
             //fix for CRM-2219 Update Membership
             // onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
             if (CRM_Utils_Array::value('is_override', $formatted) && !CRM_Utils_Array::value('status_id', $formatted)) {
                 array_unshift($values, 'Required parameter missing: Status');
                 return CRM_Import_Parser::ERROR;
             }
             if (!empty($formatValues['membership_id'])) {
                 $dao = new CRM_Member_BAO_Membership();
                 $dao->id = $formatValues['membership_id'];
                 $dates = array('join_date', 'start_date', 'end_date');
//.........这里部分代码省略.........
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:101,代码来源:Membership.php

示例3: import

 /**
  * Handle the values in import mode.
  *
  * @param int $onDuplicate
  *   The code for what action to take on duplicates.
  * @param array $values
  *   The array of values belonging to this line.
  *
  * @return bool
  *   the result of this processing
  */
 public function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get('dateTypes');
     $formatted = array('version' => 3);
     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
     // don't add to recent items, CRM-4399
     $formatted['skipRecentView'] = TRUE;
     foreach ($params as $key => $val) {
         if ($val) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                     unset($params[$key]);
                 } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 }
             }
             if ($key == 'participant_register_date') {
                 CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'participant_register_date');
                 $formatted['participant_register_date'] = CRM_Utils_Date::processDate($params['participant_register_date']);
             }
         }
     }
     if (!(!empty($params['participant_role_id']) || !empty($params['participant_role']))) {
         if (!empty($params['event_id'])) {
             $params['participant_role_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'default_role_id');
         } else {
             $eventTitle = $params['event_title'];
             $qParams = array();
             $dao = new CRM_Core_DAO();
             $params['participant_role_id'] = $dao->singleValueQuery("SELECT default_role_id FROM civicrm_event WHERE title = '{$eventTitle}' ", $qParams);
         }
     }
     //date-Format part ends
     static $indieFields = NULL;
     if ($indieFields == NULL) {
         $indieFields = CRM_Event_BAO_Participant::import();
     }
     $formatValues = array();
     foreach ($params as $key => $field) {
         if ($field == NULL || $field === '') {
             continue;
         }
         $formatValues[$key] = $field;
     }
     $formatError = _civicrm_api3_deprecated_participant_formatted_param($formatValues, $formatted, TRUE);
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         return CRM_Import_Parser::ERROR;
     }
     if (!CRM_Utils_Rule::integer($formatted['event_id'])) {
         array_unshift($values, ts('Invalid value for Event ID'));
         return CRM_Import_Parser::ERROR;
     }
     if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
         $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Participant');
     } else {
         if ($formatValues['participant_id']) {
             $dao = new CRM_Event_BAO_Participant();
             $dao->id = $formatValues['participant_id'];
             $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, $formatValues['participant_id'], 'Participant');
             if ($dao->find(TRUE)) {
                 $ids = array('participant' => $formatValues['participant_id'], 'userId' => $session->get('userID'));
                 $participantValues = array();
                 //@todo calling api functions directly is not supported
                 $newParticipant = _civicrm_api3_deprecated_participant_check_params($formatted, $participantValues, FALSE);
                 if ($newParticipant['error_message']) {
                     array_unshift($values, $newParticipant['error_message']);
                     return CRM_Import_Parser::ERROR;
                 }
                 $newParticipant = CRM_Event_BAO_Participant::create($formatted, $ids);
                 if (!empty($formatted['fee_level'])) {
                     $otherParams = array('fee_label' => $formatted['fee_level'], 'event_id' => $newParticipant->event_id);
                     CRM_Price_BAO_LineItem::syncLineItems($newParticipant->id, 'civicrm_participant', $newParticipant->fee_amount, $otherParams);
                 }
                 $this->_newParticipant[] = $newParticipant->id;
                 return CRM_Import_Parser::VALID;
             } else {
                 array_unshift($values, 'Matching Participant record not found for Participant ID ' . $formatValues['participant_id'] . '. Row was skipped.');
                 return CRM_Import_Parser::ERROR;
             }
         }
//.........这里部分代码省略.........
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:101,代码来源:Participant.php

示例4: formatData

 function formatData(&$params)
 {
     $fields = $this->_allFields;
     foreach ($params as $key => $value) {
         if ($value) {
             if (array_key_exists($key, $fields)) {
                 if (array_key_exists('enumValues', $fields[$key])) {
                     $enumValue = $fields[$key]['enumValues'];
                     $enumArray = explode(',', $enumValue);
                     if ($val = array_search(strtolower(trim($value)), array_map('strtolower', $enumArray))) {
                         $params[$key] = $enumArray[$val];
                     }
                 }
                 if (array_key_exists('pseudoconstant', $fields[$key])) {
                     if (array_key_exists('optionGroupName', $fields[$key]['pseudoconstant'])) {
                         $options = CRM_Core_OptionGroup::values($fields[$key]['pseudoconstant']['optionGroupName'], FALSE, FALSE, FALSE, NULL, 'name');
                         if (array_key_exists(strtolower(trim($value)), array_change_key_case($options))) {
                             $flipOpt = array_change_key_case($options);
                             $params[$key] = $flipOpt[strtolower(trim($value))];
                         }
                     }
                 }
                 if ($fields[$key]['type'] == CRM_Utils_Type::T_BOOLEAN) {
                     $params[$key] = CRM_Utils_String::strtoboolstr($value);
                 }
             }
         }
     }
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:29,代码来源:Api.php

示例5: import

 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Member_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     //assign join date equal to start date if join date is not provided
     if (!$params['join_date'] && $params['membership_start_date']) {
         $params['join_date'] = $params['membership_start_date'];
     }
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     $formatted = array();
     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
     // don't add to recent items, CRM-4399
     $formatted['skipRecentView'] = true;
     foreach ($params as $key => $val) {
         if ($val) {
             switch ($key) {
                 case 'join_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Join Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Join Date', $errorMessage);
                     }
                     break;
                 case 'membership_start_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Start Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Start Date', $errorMessage);
                     }
                     break;
                 case 'membership_end_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('End Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('End Date', $errorMessage);
                     }
                     break;
                 case 'is_override':
                     $params[$key] = CRM_Utils_String::strtobool($val);
                     break;
             }
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                 if ($customFields[$customFieldID][2] == 'Date') {
                     CRM_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                     unset($params[$key]);
                 } else {
                     if ($customFields[$customFieldID][2] == 'Boolean') {
                         $params[$key] = CRM_Utils_String::strtoboolstr($val);
                     }
                 }
             }
         }
     }
     //date-Format part ends
     static $indieFields = null;
     if ($indieFields == null) {
         require_once 'CRM/Member/DAO/Membership.php';
         $tempIndieFields =& CRM_Member_DAO_Membership::import();
         $indieFields = $tempIndieFields;
     }
     $formatValues = array();
     foreach ($params as $key => $field) {
         if ($field == null || $field === '') {
             continue;
         }
         $formatValues[$key] = $field;
     }
     $formatError = _civicrm_membership_formatted_param($formatValues, $formatted, true);
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         return CRM_Member_Import_Parser::ERROR;
     }
     if ($onDuplicate != CRM_Member_Import_Parser::DUPLICATE_UPDATE) {
         $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, null, 'Membership');
     } else {
         //fix for CRM-2219 Update Membership
         // onDuplicate == CRM_Member_Import_Parser::DUPLICATE_UPDATE
         if (CRM_Utils_Array::value('is_override', $formatted) && !CRM_Utils_Array::value('status_id', $formatted)) {
             array_unshift($values, "Required parameter missing: Status");
             return CRM_Member_Import_Parser::ERROR;
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:Membership.php

示例6: import

 /**
  * Handle the values in import mode.
  *
  * @param int $onDuplicate
  *   The code for what action to take on duplicates.
  * @param array $values
  *   The array of values belonging to this line.
  *
  * @return bool
  *   the result of this processing
  */
 public function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $formatted = array('version' => 3);
     // don't add to recent items, CRM-4399
     $formatted['skipRecentView'] = TRUE;
     //for date-Formats
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get('dateTypes');
     $customDataType = !empty($params['contact_type']) ? $params['contact_type'] : 'Contribution';
     $customFields = CRM_Core_BAO_CustomField::getFields($customDataType);
     //CRM-10994
     if (isset($params['total_amount']) && $params['total_amount'] == 0) {
         $params['total_amount'] = '0.00';
     }
     foreach ($params as $key => $val) {
         if ($val) {
             switch ($key) {
                 case 'receive_date':
                 case 'cancel_date':
                 case 'receipt_date':
                 case 'thankyou_date':
                     $params[$key] = CRM_Utils_Date::formatDate($params[$key], $dateType);
                     break;
                 case 'pledge_payment':
                     $params[$key] = CRM_Utils_String::strtobool($val);
                     break;
             }
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                     unset($params[$key]);
                 } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 }
             }
         }
     }
     //date-Format part ends
     static $indieFields = NULL;
     if ($indieFields == NULL) {
         $tempIndieFields = CRM_Contribute_DAO_Contribution::import();
         $indieFields = $tempIndieFields;
     }
     $paramValues = array();
     foreach ($params as $key => $field) {
         if ($field == NULL || $field === '') {
             continue;
         }
         $paramValues[$key] = $field;
     }
     //import contribution record according to select contact type
     if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP && (!empty($paramValues['contribution_contact_id']) || !empty($paramValues['external_identifier']))) {
         $paramValues['contact_type'] = $this->_contactType;
     } elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE && (!empty($paramValues['contribution_id']) || !empty($values['trxn_id']) || !empty($paramValues['invoice_id']))) {
         $paramValues['contact_type'] = $this->_contactType;
     } elseif (!empty($params['soft_credit'])) {
         $paramValues['contact_type'] = $this->_contactType;
     } elseif (!empty($paramValues['pledge_payment'])) {
         $paramValues['contact_type'] = $this->_contactType;
     }
     //need to pass $onDuplicate to check import mode.
     if (!empty($paramValues['pledge_payment'])) {
         $paramValues['onDuplicate'] = $onDuplicate;
     }
     require_once 'CRM/Utils/DeprecatedUtils.php';
     $formatError = _civicrm_api3_deprecated_formatted_param($paramValues, $formatted, TRUE, $onDuplicate);
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         if (CRM_Utils_Array::value('error_data', $formatError) == 'soft_credit') {
             return CRM_Contribute_Import_Parser::SOFT_CREDIT_ERROR;
         } elseif (CRM_Utils_Array::value('error_data', $formatError) == 'pledge_payment') {
             return CRM_Contribute_Import_Parser::PLEDGE_PAYMENT_ERROR;
         }
         return CRM_Import_Parser::ERROR;
     }
     if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
         $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Contribution');
     } else {
         //fix for CRM-2219 - Update Contribution
         // onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
         if (!empty($paramValues['invoice_id']) || !empty($paramValues['trxn_id']) || !empty($paramValues['contribution_id'])) {
             $dupeIds = array('id' => CRM_Utils_Array::value('contribution_id', $paramValues), 'trxn_id' => CRM_Utils_Array::value('trxn_id', $paramValues), 'invoice_id' => CRM_Utils_Array::value('invoice_id', $paramValues));
             $ids['contribution'] = CRM_Contribute_BAO_Contribution::checkDuplicateIds($dupeIds);
//.........这里部分代码省略.........
开发者ID:nielosz,项目名称:civicrm-core,代码行数:101,代码来源:Contribution.php

示例7: processVoterData

 public function processVoterData()
 {
     $status = NULL;
     $operation = CRM_Utils_Type::escape($_POST['operation'], 'String');
     if ($operation == 'release') {
         $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
         $isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String'));
         if ($activityId && CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', $isDelete)) {
             $status = 'success';
         }
     } elseif ($operation == 'reserve') {
         $activityId = NULL;
         $createActivity = TRUE;
         if (!empty($_POST['activity_id'])) {
             $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
             if ($activityId) {
                 $createActivity = FALSE;
                 $activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', 0);
                 if ($activityUpdated) {
                     $status = 'success';
                 }
             }
         }
         if ($createActivity) {
             $ids = array('source_record_id', 'source_contact_id', 'target_contact_id', 'assignee_contact_id');
             $activityParams = array();
             foreach ($ids as $id) {
                 $val = CRM_Utils_Array::value($id, $_POST);
                 if (!$val) {
                     $createActivity = FALSE;
                     break;
                 }
                 $activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer');
             }
         }
         if ($createActivity) {
             $isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String'));
             $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
             $scheduledStatusId = array_search('Scheduled', $activityStatus);
             if ($isReserved) {
                 $surveyValues = array();
                 $surveyParams = array('id' => $activityParams['source_record_id']);
                 CRM_Core_DAO::commonRetrieve('CRM_Campaign_DAO_Survey', $surveyParams, $surveyValues, array('title', 'activity_type_id', 'campaign_id'));
                 $activityTypeId = $surveyValues['activity_type_id'];
                 $surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST);
                 if (!$surveytitle) {
                     $surveytitle = $surveyValues['title'];
                 }
                 $subject = $surveytitle . ' - ' . ts('Respondent Reservation');
                 $activityParams['subject'] = $subject;
                 $activityParams['status_id'] = $scheduledStatusId;
                 $activityParams['skipRecentView'] = 1;
                 $activityParams['activity_date_time'] = date('YmdHis');
                 $activityParams['activity_type_id'] = $activityTypeId;
                 $activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL;
                 $activity = CRM_Activity_BAO_Activity::create($activityParams);
                 if ($activity->id) {
                     $status = 'success';
                 }
             } else {
                 //delete reserved activity for given voter.
                 $voterIds = array($activityParams['target_contact_id']);
                 $activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'], $voterIds, $activityParams['source_contact_id'], array($scheduledStatusId));
                 foreach ($activities as $voterId => $values) {
                     $activityId = CRM_Utils_Array::value('activity_id', $values);
                     if ($activityId && $values['status_id'] == $scheduledStatusId) {
                         CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', TRUE);
                         $status = 'success';
                         break;
                     }
                 }
             }
         }
     } elseif ($operation == 'gotv') {
         $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
         $hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String'));
         if ($activityId) {
             if ($hasVoted) {
                 $statusValue = 2;
             } else {
                 $statusValue = 1;
             }
             CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'status_id', $statusValue);
             $status = 'success';
         }
     }
     CRM_Utils_JSON::output(array('status' => $status));
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:88,代码来源:AJAX.php

示例8: create


//.........这里部分代码省略.........
                                 if (empty($countries['country_id'])) {
                                     CRM_Utils_Array::lookupValue($countries, 'country', CRM_Core_PseudoConstant::countryIsoCode(), TRUE);
                                 }
                                 $validCountries[] = CRM_Utils_Array::value('country_id', $countries);
                             }
                             $value = implode(CRM_Core_DAO::VALUE_SEPARATOR, $validCountries);
                             $type = 'String';
                         } elseif (!$value) {
                             // CRM-3415
                             // using type of timestamp allows us to sneak in a null into db
                             // gross but effective hack
                             $value = NULL;
                             $type = 'Timestamp';
                         } else {
                             $type = 'String';
                         }
                         break;
                     case 'File':
                         if (!$field['file_id']) {
                             CRM_Core_Error::fatal();
                         }
                         // need to add/update civicrm_entity_file
                         $entityFileDAO = new CRM_Core_DAO_EntityFile();
                         $entityFileDAO->file_id = $field['file_id'];
                         $entityFileDAO->find(TRUE);
                         $entityFileDAO->entity_table = $field['table_name'];
                         $entityFileDAO->entity_id = $field['entity_id'];
                         $entityFileDAO->file_id = $field['file_id'];
                         $entityFileDAO->save();
                         $entityFileDAO->free();
                         $value = $field['file_id'];
                         $type = 'String';
                         break;
                     case 'Date':
                         $value = CRM_Utils_Date::isoToMysql($value);
                         break;
                     case 'Int':
                         if (is_numeric($value)) {
                             $type = 'Integer';
                         } else {
                             $type = 'Timestamp';
                         }
                         break;
                     case 'ContactReference':
                         if ($value == NULL) {
                             $type = 'Timestamp';
                         } else {
                             $type = 'Integer';
                         }
                         break;
                     case 'RichTextEditor':
                         $type = 'String';
                         break;
                     case 'Boolean':
                         //fix for CRM-3290
                         $value = CRM_Utils_String::strtoboolstr($value);
                         if ($value === FALSE) {
                             $type = 'Timestamp';
                         }
                         break;
                     default:
                         break;
                 }
                 if (strtolower($value) === "null") {
                     // when unsetting a value to null, we don't need to validate the type
                     // https://projectllr.atlassian.net/browse/VGQBMP-20
                     $set[$field['column_name']] = $value;
                 } else {
                     $set[$field['column_name']] = "%{$count}";
                     $params[$count] = array($value, $type);
                     $count++;
                 }
             }
             if (!empty($set)) {
                 $setClause = array();
                 foreach ($set as $n => $v) {
                     $setClause[] = "{$n} = {$v}";
                 }
                 $setClause = implode(',', $setClause);
                 if (!$where) {
                     // do this only for insert
                     $set['entity_id'] = "%{$count}";
                     $params[$count] = array($entityID, 'Integer');
                     $count++;
                     $fieldNames = implode(',', array_keys($set));
                     $fieldValues = implode(',', array_values($set));
                     $query = "{$sqlOP} ( {$fieldNames} ) VALUES ( {$fieldValues} )";
                     // for multiple values we dont do on duplicate key update
                     if (!$isMultiple) {
                         $query .= " ON DUPLICATE KEY UPDATE {$setClause}";
                     }
                 } else {
                     $query = "{$sqlOP} SET {$setClause} {$where}";
                 }
                 $dao = CRM_Core_DAO::executeQuery($query, $params);
                 CRM_Utils_Hook::custom($hookOP, $hookID, $entityID, $fields);
             }
         }
     }
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:101,代码来源:CustomValueTable.php

示例9: formatCommonData

 /**
  * Format common params data to proper format to store.
  *
  * @param array $params
  *   Contain record values.
  * @param array $formatted
  *   Array of formatted data.
  * @param array $contactFields
  *   Contact DAO fields.
  */
 public function formatCommonData($params, &$formatted, &$contactFields)
 {
     $csType = array(CRM_Utils_Array::value('contact_type', $formatted));
     //CRM-5125
     //add custom fields for contact sub type
     if (!empty($this->_contactSubType)) {
         $csType = $this->_contactSubType;
     }
     if ($relCsType = CRM_Utils_Array::value('contact_sub_type', $formatted)) {
         $csType = $relCsType;
     }
     $customFields = CRM_Core_BAO_CustomField::getFields($formatted['contact_type'], FALSE, FALSE, $csType);
     $addressCustomFields = CRM_Core_BAO_CustomField::getFields('Address');
     $customFields = $customFields + $addressCustomFields;
     //if a Custom Email Greeting, Custom Postal Greeting or Custom Addressee is mapped, and no "Greeting / Addressee Type ID" is provided, then automatically set the type = Customized, CRM-4575
     $elements = array('email_greeting_custom' => 'email_greeting', 'postal_greeting_custom' => 'postal_greeting', 'addressee_custom' => 'addressee');
     foreach ($elements as $k => $v) {
         if (array_key_exists($k, $params) && !array_key_exists($v, $params)) {
             $label = key(CRM_Core_OptionGroup::values($v, TRUE, NULL, NULL, 'AND v.name = "Customized"'));
             $params[$v] = $label;
         }
     }
     //format date first
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     foreach ($params as $key => $val) {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($key);
         if ($customFieldID && !array_key_exists($customFieldID, $addressCustomFields)) {
             //we should not update Date to null, CRM-4062
             if ($val && $customFields[$customFieldID]['data_type'] == 'Date') {
                 self::formatCustomDate($params, $formatted, $dateType, $key);
             } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                 if (empty($val) && !is_numeric($val) && $this->_onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) {
                     //retain earlier value when Import mode is `Fill`
                     unset($params[$key]);
                 } else {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 }
             }
             if ($key == 'birth_date' && $val) {
                 CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
             } elseif ($key == 'deceased_date' && $val) {
                 CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
             } elseif ($key == 'is_deceased' && $val) {
                 $params[$key] = CRM_Utils_String::strtoboolstr($val);
             } elseif ($key == 'gender') {
                 //CRM-4360
                 $params[$key] = $this->checkGender($val);
             }
         }
     }
     //now format custom data.
     foreach ($params as $key => $field) {
         if (is_array($field)) {
             $isAddressCustomField = FALSE;
             foreach ($field as $value) {
                 $break = FALSE;
                 if (is_array($value)) {
                     foreach ($value as $name => $testForEmpty) {
                         if ($addressCustomFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                             $isAddressCustomField = TRUE;
                             break;
                         }
                         // check if $value does not contain IM provider or phoneType
                         if (($name !== 'phone_type_id' || $name !== 'provider_id') && ($testForEmpty === '' || $testForEmpty == NULL)) {
                             $break = TRUE;
                             break;
                         }
                     }
                 } else {
                     $break = TRUE;
                 }
                 if (!$break) {
                     require_once 'CRM/Utils/DeprecatedUtils.php';
                     _civicrm_api3_deprecated_add_formatted_param($value, $formatted);
                 }
             }
             if (!$isAddressCustomField) {
                 continue;
             }
         }
         $formatValues = array($key => $field);
         if ($key !== 'preferred_communication_method' && array_key_exists($key, $contactFields)) {
             // due to merging of individual table and
             // contact table, we need to avoid
             // preferred_communication_method forcefully
             $formatValues['contact_type'] = $formatted['contact_type'];
         }
         if ($key == 'id' && isset($field)) {
             $formatted[$key] = $field;
//.........这里部分代码省略.........
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:101,代码来源:Contact.php

示例10: import

 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $activityLabel = array_search('activity_label', $this->_mapperKeys);
     if ($activityLabel) {
         $params = array_merge($params, array('activity_label' => $values[$activityLabel]));
     }
     //for date-Formats
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get('dateTypes');
     if (!isset($params['source_contact_id'])) {
         $params['source_contact_id'] = $session->get('userID');
     }
     $formatted = array();
     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
     foreach ($params as $key => $val) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             if ($key == 'activity_date_time' && $val) {
                 $params[$key] = CRM_Utils_Date::formatDate($val, $dateType);
             } elseif ($customFields[$customFieldID]['data_type'] == 'Date') {
                 CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $params, $dateType, $key);
             } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                 $params[$key] = CRM_Utils_String::strtoboolstr($val);
             }
         } elseif ($key == 'activity_subject') {
             $params['subject'] = $val;
         }
     }
     //date-Format part ends
     require_once 'CRM/Utils/DeprecatedUtils.php';
     $formatError = _civicrm_api3_deprecated_activity_formatted_param($params, $params, TRUE);
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         return CRM_Import_Parser::ERROR;
     }
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, CRM_Core_DAO::$_nullObject, NULL, 'Activity');
     if ($this->_contactIdIndex < 0) {
         //retrieve contact id using contact dedupe rule.
         //since we are support only individual's activity import.
         $params['contact_type'] = 'Individual';
         $params['version'] = 3;
         $error = _civicrm_api3_deprecated_duplicate_formatted_contact($params);
         if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
             $matchedIDs = explode(',', $error['error_message']['params'][0]);
             if (count($matchedIDs) > 1) {
                 array_unshift($values, 'Multiple matching contact records detected for this row. The activity was not imported');
                 return CRM_Import_Parser::ERROR;
             } else {
                 $cid = $matchedIDs[0];
                 $params['target_contact_id'] = $cid;
                 $params['version'] = 3;
                 $newActivity = civicrm_api('activity', 'create', $params);
                 if (CRM_Utils_Array::value('is_error', $newActivity)) {
                     array_unshift($values, $newActivity['error_message']);
                     return CRM_Import_Parser::ERROR;
                 }
                 $this->_newActivity[] = $newActivity['id'];
                 return CRM_Import_Parser::VALID;
             }
         } else {
             // Using new Dedupe rule.
             $ruleParams = array('contact_type' => 'Individual', 'used' => 'Unsupervised');
             $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
             $disp = NULL;
             foreach ($fieldsArray as $value) {
                 if (array_key_exists(trim($value), $params)) {
                     $paramValue = $params[trim($value)];
                     if (is_array($paramValue)) {
                         $disp .= $params[trim($value)][0][trim($value)] . " ";
                     } else {
                         $disp .= $params[trim($value)] . " ";
                     }
                 }
             }
             if (CRM_Utils_Array::value('external_identifier', $params)) {
                 if ($disp) {
                     $disp .= "AND {$params['external_identifier']}";
                 } else {
                     $disp = $params['external_identifier'];
                 }
             }
             array_unshift($values, 'No matching Contact found for (' . $disp . ')');
             return CRM_Import_Parser::ERROR;
         }
     } else {
         if (CRM_Utils_Array::value('external_identifier', $params)) {
//.........这里部分代码省略.........
开发者ID:hguru,项目名称:224Civi,代码行数:101,代码来源:Activity.php

示例11: import

 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Event_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get('dateTypes');
     $formatted = array();
     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
     // don't add to recent items, CRM-4399
     $formatted['skipRecentView'] = true;
     foreach ($params as $key => $val) {
         if ($val) {
             if ($key == 'participant_register_date') {
                 if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                     if (!CRM_Utils_Rule::date($params[$key])) {
                         CRM_Import_Parser_Contact::addToErrorMsg('Register Date', $errorMessage);
                     }
                 } else {
                     CRM_Import_Parser_Contact::addToErrorMsg('Register Date', $errorMessage);
                 }
             }
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     CRM_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                     unset($params[$key]);
                 } else {
                     if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                         $params[$key] = CRM_Utils_String::strtoboolstr($val);
                     }
                 }
             }
         }
     }
     if (!($params['participant_role_id'] || $params['participant_role'])) {
         if ($params['event_id']) {
             $params['participant_role_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $params['event_id'], 'default_role_id');
         } else {
             $eventTitle = $params['event_title'];
             $qParams = array();
             $dao = new CRM_Core_DAO();
             $params['participant_role_id'] = $dao->singleValueQuery("SELECT default_role_id FROM civicrm_event WHERE title = '{$eventTitle}' ", $qParams);
         }
     }
     //date-Format part ends
     static $indieFields = null;
     if ($indieFields == null) {
         require_once 'CRM/Event/BAO/Participant.php';
         $indieFields =& CRM_Event_BAO_Participant::import();
     }
     $formatValues = array();
     foreach ($params as $key => $field) {
         if ($field == null || $field === '') {
             continue;
         }
         $formatValues[$key] = $field;
     }
     $formatError = _civicrm_participant_formatted_param($formatValues, $formatted, true);
     require_once "api/v2/Participant.php";
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         return CRM_Event_Import_Parser::ERROR;
     }
     if (!CRM_Utils_Rule::integer($formatted['event_id'])) {
         array_unshift($values, ts('Invalid value for Event ID'));
         return CRM_Event_Import_Parser::ERROR;
     }
     if ($onDuplicate != CRM_Event_Import_Parser::DUPLICATE_UPDATE) {
         $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, null, 'Participant');
     } else {
         if ($formatValues['participant_id']) {
             require_once 'CRM/Event/BAO/Participant.php';
             $dao = new CRM_Event_BAO_Participant();
             $dao->id = $formatValues['participant_id'];
             $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, $formatValues['participant_id'], 'Participant');
             if ($dao->find(true)) {
                 $ids = array('participant' => $formatValues['participant_id'], 'userId' => $session->get('userID'));
                 $newParticipant = civicrm_participant_check_params($formatted, false);
                 if ($newParticipant['error_message']) {
                     array_unshift($values, $newParticipant['error_message']);
                     return CRM_Event_Import_Parser::ERROR;
                 }
                 $newParticipant =& CRM_Event_BAO_Participant::create($formatted, $ids);
                 $this->_newParticipant[] = $newParticipant->id;
                 return CRM_Event_Import_Parser::VALID;
             } else {
                 array_unshift($values, "Matching Participant record not found for Participant ID " . $formatValues['participant_id'] . ". Row was skipped.");
                 return CRM_Event_Import_Parser::ERROR;
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Participant.php

示例12: import

 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Activity_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $activityName = array_search('activity_name', $this->_mapperKeys);
     if ($activityName) {
         $params = array_merge($params, array('activity_name' => $values[$activityName]));
     }
     //for date-Formats
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     $params['source_contact_id'] = $session->get('userID');
     $formatted = array();
     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
     foreach ($params as $key => $val) {
         if ($key == 'activity_date_time') {
             if ($val) {
                 if ($dateType == 1) {
                     $params[$key] = CRM_Utils_Date::customFormat($val, '%Y%m%d%H%i');
                     //hack to add seconds
                     $params[$key] = $params[$key] . '00';
                 } else {
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                 }
             }
         } elseif ($key == 'duration') {
             $params['duration_minutes'] = $params['duration'];
             unset($params['duration']);
         }
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             if ($customFields[$customFieldID]['data_type'] == 'Date') {
                 CRM_Import_Parser_Contact::formatCustomDate($params, $params, $dateType, $key);
             } else {
                 if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 }
             }
         }
     }
     //date-Format part ends
     $formatError = _civicrm_activity_formatted_param($params, $params, true);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, CRM_Core_DAO::$_nullObject, null, 'Activity');
     if ($this->_contactIdIndex < 0) {
         //retrieve contact id using contact dedupe rule.
         //since we are support only individual's activity import.
         $params['contact_type'] = 'Individual';
         $error = civicrm_check_contact_dedupe($params);
         if (civicrm_duplicate($error)) {
             $matchedIDs = explode(',', $error['error_message']['params'][0]);
             if (count($matchedIDs) > 1) {
                 array_unshift($values, "Multiple matching contact records detected for this row. The activity was not imported");
                 return CRM_Activity_Import_Parser::ERROR;
             } else {
                 $cid = $matchedIDs[0];
                 $params['target_contact_id'] = $cid;
                 $newActivity = civicrm_activity_create($params);
                 if (CRM_Utils_Array::value('is_error', $newActivity)) {
                     array_unshift($values, $newActivity['error_message']);
                     return CRM_Activity_Import_Parser::ERROR;
                 }
                 $this->_newActivity[] = $newActivity['id'];
                 return CRM_Activity_Import_Parser::VALID;
             }
         } else {
             // Using new Dedupe rule.
             $ruleParams = array('contact_type' => 'Individual', 'level' => 'Strict');
             require_once 'CRM/Dedupe/BAO/Rule.php';
             $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
             foreach ($fieldsArray as $value) {
                 if (array_key_exists(trim($value), $params)) {
                     $paramValue = $params[trim($value)];
                     if (is_array($paramValue)) {
                         $disp .= $params[trim($value)][0][trim($value)] . " ";
                     } else {
                         $disp .= $params[trim($value)] . " ";
                     }
                 }
             }
             if (CRM_Utils_Array::value('external_identifier', $params)) {
                 if ($disp) {
                     $disp .= "AND {$params['external_identifier']}";
                 } else {
                     $disp = $params['external_identifier'];
                 }
             }
             array_unshift($values, "No matching Contact found for (" . $disp . ")");
             return CRM_Activity_Import_Parser::ERROR;
//.........这里部分代码省略.........
开发者ID:ksecor,项目名称:civicrm,代码行数:101,代码来源:Activity.php

示例13: isErrorInCoreData

 function isErrorInCoreData($params, &$errorMessage)
 {
     $fields = $this->_allFields;
     foreach ($params as $key => $value) {
         if ($key == 'contact_id' && (empty($value) || !is_numeric($value))) {
             self::addToErrorMsg(ts('Please enter valid Contact ID'), $errorMessage);
         }
         if ($value) {
             if (array_key_exists($key, $fields)) {
                 if (array_key_exists('enumValues', $fields[$key])) {
                     $enumValue = $fields[$key]['enumValues'];
                     $enumArray = explode(', ', $enumValue);
                     if (!self::in_value(trim($value), $enumArray)) {
                         self::addToErrorMsg($fields[$key]['title'], $errorMessage);
                     }
                 }
                 if (array_key_exists('pseudoconstant', $fields[$key])) {
                     if (array_key_exists('optionGroupName', $fields[$key]['pseudoconstant'])) {
                         $options = CRM_Core_OptionGroup::values($fields[$key]['pseudoconstant']['optionGroupName'], FALSE, FALSE, FALSE, NULL, 'name');
                         if (!array_key_exists(strtolower(trim($value)), array_change_key_case($options))) {
                             self::addToErrorMsg($fields[$key]['title'], $errorMessage);
                         }
                     }
                 }
                 switch ($fields[$key]['type']) {
                     case CRM_Utils_Type::T_BOOLEAN:
                         if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
                             self::addToErrorMsg($fields[$key]['title'], $errorMessage);
                         }
                         break;
                     case CRM_Utils_Type::T_INT:
                     case CRM_Utils_Type::T_MONEY:
                     case CRM_Utils_Type::T_FLOAT:
                         if ($key == "leave_amount" && is_array($value)) {
                             foreach ($value as $values) {
                                 if (!empty($values['leave_amount']) && !is_numeric($values['leave_amount'])) {
                                     self::addToErrorMsg(ts("%1 is not numeric", $fields[$key]['title']), $errorMessage);
                                 }
                             }
                         } else {
                             if (!is_numeric($value)) {
                                 self::addToErrorMsg(ts("%1 is not numeric", $fields[$key]['title']), $errorMessage);
                             }
                         }
                         break;
                 }
                 switch ($key) {
                     case 'contact_id':
                         //Contact ID
                         if ($key == 'contact_id' && (empty($value) || !is_numeric($value))) {
                             self::addToErrorMsg(ts('Please enter Contact ID'), $errorMessage);
                         }
                     case 'manager_id':
                         //Manager ID
                         $params = array('contact_id' => $value);
                         $result = civicrm_api3('contact', 'get', $params);
                         if ($result['count'] <= 0 || $result['values'][$result['id']]['contact_type'] != "Individual") {
                             self::addToErrorMsg($fields[$key]['title'], $errorMessage);
                         }
                         break;
                 }
             }
         }
     }
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:65,代码来源:Parser.php

示例14: import

 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Contribute_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $formatted = array();
     // don't add to recent items, CRM-4399
     $formatted['skipRecentView'] = true;
     //for date-Formats
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
     foreach ($params as $key => $val) {
         if ($val) {
             switch ($key) {
                 case 'receive_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     break;
                 case 'cancel_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     break;
                 case 'receipt_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     break;
                 case 'thankyou_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     break;
                 case 'pledge_payment':
                     $params[$key] = CRM_Utils_String::strtobool($val);
                     break;
             }
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     CRM_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                     unset($params[$key]);
                 } else {
                     if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                         $params[$key] = CRM_Utils_String::strtoboolstr($val);
                     }
                 }
             }
         }
     }
     //date-Format part ends
     static $indieFields = null;
     if ($indieFields == null) {
         require_once 'CRM/Contribute/DAO/Contribution.php';
         $tempIndieFields =& CRM_Contribute_DAO_Contribution::import();
         $indieFields = $tempIndieFields;
     }
     $paramValues = array();
     foreach ($params as $key => $field) {
         if ($field == null || $field === '') {
             continue;
         }
         $paramValues[$key] = $field;
     }
     //import contribution record according to select contact type
     if ($onDuplicate == CRM_Contribute_Import_Parser::DUPLICATE_SKIP && ($paramValues['contribution_contact_id'] || $paramValues['external_identifier'])) {
         $paramValues['contact_type'] = $this->_contactType;
     } else {
         if ($onDuplicate == CRM_Contribute_Import_Parser::DUPLICATE_UPDATE && ($paramValues['contribution_id'] || $values['trxn_id'] || $paramValues['invoice_id'])) {
             $paramValues['contact_type'] = $this->_contactType;
         } else {
             if (!empty($params['soft_credit'])) {
                 $paramValues['contact_type'] = $this->_contactType;
             } else {
                 if (CRM_Utils_Array::value('pledge_payment', $paramValues)) {
                     $paramValues['contact_type'] = $this->_contactType;
                 }
             }
         }
     }
     //need to pass $onDuplicate to check import mode.
     if (CRM_Utils_Array::value('pledge_payment', $paramValues)) {
         $paramValues['onDuplicate'] = $onDuplicate;
     }
     $formatError = _civicrm_contribute_formatted_param($paramValues, $formatted, true);
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         if (CRM_Utils_Array::value('error_data', $formatError) == 'soft_credit') {
             return CRM_Contribute_Import_Parser::SOFT_CREDIT_ERROR;
         } else {
             if (CRM_Utils_Array::value('error_data', $formatError) == 'pledge_payment') {
                 return CRM_Contribute_Import_Parser::PLEDGE_PAYMENT_ERROR;
             }
         }
         return CRM_Contribute_Import_Parser::ERROR;
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:Contribution.php

示例15: processVoterData

 function processVoterData()
 {
     $status = null;
     $operation = CRM_Utils_Type::escape($_POST['operation'], 'String');
     if ($operation == 'release') {
         require_once 'CRM/Utils/String.php';
         $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
         $isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String'));
         if ($activityId && CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', $isDelete)) {
             $status = 'success';
         }
     } else {
         if ($operation == 'reserve') {
             $activityId = null;
             $createActivity = true;
             if (CRM_Utils_Array::value('activity_id', $_POST)) {
                 $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
                 if ($activityId) {
                     $createActivity = false;
                     $activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', 0);
                     if ($activityUpdated) {
                         $status = 'success';
                     }
                 }
             }
             if ($createActivity) {
                 $ids = array('source_record_id', 'source_contact_id', 'target_contact_id', 'assignee_contact_id');
                 $activityParams = array();
                 foreach ($ids as $id) {
                     $val = CRM_Utils_Array::value($id, $_POST);
                     if (!$val) {
                         $createActivity = false;
                         break;
                     }
                     $activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer');
                 }
             }
             if ($createActivity) {
                 $isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String'));
                 require_once 'CRM/Core/PseudoConstant.php';
                 $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
                 $scheduledStatusId = array_search('Scheduled', $activityStatus);
                 if ($isReserved) {
                     $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $activityParams['source_record_id'], 'activity_type_id');
                     $surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST);
                     if (!$surveytitle) {
                         $surveytitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $activityParams['source_record_id'], 'title');
                     }
                     $subject = ts('%1', array(1 => $surveytitle)) . ' - ' . ts('Respondent Reservation');
                     $activityParams['subject'] = $subject;
                     $activityParams['status_id'] = $scheduledStatusId;
                     $activityParams['skipRecentView'] = 1;
                     $activityParams['activity_date_time'] = date('YmdHis');
                     $activityParams['activity_type_id'] = $activityTypeId;
                     require_once 'CRM/Activity/BAO/Activity.php';
                     $activity = CRM_Activity_BAO_Activity::create($activityParams);
                     if ($activity->id) {
                         $status = 'success';
                     }
                 } else {
                     //delete reserved activity for given voter.
                     require_once 'CRM/Campaign/BAO/Survey.php';
                     $voterIds = array($activityParams['target_contact_id']);
                     $activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'], $voterIds, $activityParams['source_contact_id'], array($scheduledStatusId));
                     foreach ($activities as $voterId => $values) {
                         $activityId = CRM_Utils_Array::value('activity_id', $values);
                         if ($activityId && $values['status_id'] == $scheduledStatusId) {
                             CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', true);
                             $status = 'success';
                             break;
                         }
                     }
                 }
             }
         } else {
             if ($operation == 'gotv') {
                 require_once 'CRM/Utils/String.php';
                 $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
                 $hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String'));
                 if ($activityId) {
                     if ($hasVoted) {
                         $statusValue = 2;
                     } else {
                         $statusValue = 1;
                     }
                     CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'status_id', $statusValue);
                     $status = 'success';
                 }
             }
         }
     }
     echo json_encode(array('status' => $status));
     CRM_Utils_System::civiExit();
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:94,代码来源:AJAX.php


注:本文中的CRM_Utils_String::strtoboolstr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。