public function testEllipsify() { $maxLen = 5; $cases = array('1' => '1', '12345' => '12345', '123456' => '12...'); foreach ($cases as $input => $expected) { $this->assertEquals($expected, CRM_Utils_String::ellipsify($input, $maxLen)); } }
public function testEllipsify() { $maxLen = 5; $cases = array('1' => '1', '12345' => '12345', '123456' => '12...'); foreach ($cases as $input => $expected) { $this->assertEquals($expected, CRM_Utils_String::ellipsify($input, $maxLen)); } // test utf-8 string, CRM-18997 $input = 'Registro de eventos on-line: Taller: "Onboarding - Cómo integrar exitosamente a los nuevos talentos dentro de su organización - Formación práctica."'; $maxLen = 128; $this->assertEquals(TRUE, mb_check_encoding(CRM_Utils_String::ellipsify($input, $maxLen), 'UTF-8')); }
/** * Process the participant. * * @param CRM_Core_Form $form * @param int $contactID * * @return \CRM_Event_BAO_Participant */ public static function addParticipant(&$form, $contactID) { if (empty($form->_params)) { return NULL; } $params = $form->_params; $transaction = new CRM_Core_Transaction(); $groupName = 'participant_role'; $query = "\nSELECT v.label as label ,v.value as value\nFROM civicrm_option_value v,\n civicrm_option_group g\nWHERE v.option_group_id = g.id\n AND g.name = %1\n AND v.is_active = 1\n AND g.is_active = 1\n"; $p = array(1 => array($groupName, 'String')); $dao = CRM_Core_DAO::executeQuery($query, $p); if ($dao->fetch()) { $roleID = $dao->value; } // handle register date CRM-4320 $registerDate = NULL; if (!empty($form->_allowConfirmation) && $form->_participantId) { $registerDate = $params['participant_register_date']; } elseif (!empty($params['participant_register_date']) && is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) { $registerDate = CRM_Utils_Date::format($params['participant_register_date']); } $participantFields = CRM_Event_DAO_Participant::fields(); $participantParams = array('id' => CRM_Utils_Array::value('participant_id', $params), 'contact_id' => $contactID, 'event_id' => $form->_eventId ? $form->_eventId : $params['event_id'], 'status_id' => CRM_Utils_Array::value('participant_status', $params, 1), 'role_id' => CRM_Utils_Array::value('participant_role_id', $params, $roleID), 'register_date' => $registerDate ? $registerDate : date('YmdHis'), 'source' => CRM_Utils_String::ellipsify(isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params), $participantFields['participant_source']['maxlength']), 'fee_level' => CRM_Utils_Array::value('amount_level', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), 'registered_by_id' => CRM_Utils_Array::value('registered_by_id', $params), 'discount_id' => CRM_Utils_Array::value('discount_id', $params), 'fee_currency' => CRM_Utils_Array::value('currencyID', $params), 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params)); if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') { $participantParams['is_test'] = 1; } else { $participantParams['is_test'] = 0; } if (!empty($form->_params['note'])) { $participantParams['note'] = $form->_params['note']; } elseif (!empty($form->_params['participant_note'])) { $participantParams['note'] = $form->_params['participant_note']; } // reuse id if one already exists for this one (can happen // with back button being hit etc) if (!$participantParams['id'] && !empty($params['contributionID'])) { $pID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['contributionID'], 'participant_id', 'contribution_id'); $participantParams['id'] = $pID; } $participantParams['discount_id'] = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); if (!$participantParams['discount_id']) { $participantParams['discount_id'] = "null"; } $participant = CRM_Event_BAO_Participant::create($participantParams); $transaction->commit(); return $participant; }
/** * Render a backtrace array as an array. * * @param array $backTrace * Array of stack frames. * @param bool $showArgs * TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument. * @param int $maxArgLen * Maximum number of characters to show from each argument string. * @return array * @see debug_backtrace * @see Exception::getTrace() */ public static function parseBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) { $ret = array(); foreach ($backTrace as $trace) { $args = array(); $fnName = CRM_Utils_Array::value('function', $trace); $className = isset($trace['class']) ? $trace['class'] . $trace['type'] : ''; // Do not show args for a few password related functions $skipArgs = $className == 'DB::' && $fnName == 'connect' ? TRUE : FALSE; if (!empty($trace['args'])) { foreach ($trace['args'] as $arg) { if (!$showArgs || $skipArgs) { $args[] = '(' . gettype($arg) . ')'; continue; } switch ($type = gettype($arg)) { case 'boolean': $args[] = $arg ? 'TRUE' : 'FALSE'; break; case 'integer': case 'double': $args[] = $arg; break; case 'string': $args[] = '"' . CRM_Utils_String::ellipsify(addcslashes((string) $arg, "\r\n\t\""), $maxArgLen) . '"'; break; case 'array': $args[] = '(Array:' . count($arg) . ')'; break; case 'object': $args[] = 'Object(' . get_class($arg) . ')'; break; case 'resource': $args[] = 'Resource'; break; case 'NULL': $args[] = 'NULL'; break; default: $args[] = "({$type})"; break; } } } $ret[] = sprintf("%s(%s): %s%s(%s)", CRM_Utils_Array::value('file', $trace, '[internal function]'), CRM_Utils_Array::value('line', $trace, ''), $className, $fnName, implode(", ", $args)); } return $ret; }
/** * Render a backtrace array as a string * * @param array $backTrace array of stack frames * @param boolean $showArgs TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument * @param int $maxArgLen maximum number of characters to show from each argument string * @return string printable plain-text * @see debug_backtrace * @see Exception::getTrace() */ static function formatBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) { $message = ''; foreach ($backTrace as $idx => $trace) { $args = array(); $fnName = CRM_Utils_Array::value('function', $trace); $className = array_key_exists('class', $trace) ? $trace['class'] . $trace['type'] : ''; // do now show args for a few password related functions $skipArgs = $className == 'DB::' && $fnName == 'connect' ? TRUE : FALSE; foreach ($trace['args'] as $arg) { if (!$showArgs || $skipArgs) { $args[] = '(' . gettype($arg) . ')'; continue; } switch ($type = gettype($arg)) { case 'boolean': $args[] = $arg ? 'TRUE' : 'FALSE'; break; case 'integer': case 'double': $args[] = $arg; break; case 'string': $args[] = '"' . CRM_Utils_String::ellipsify(addcslashes((string) $arg, "\r\n\t\""), $maxArgLen) . '"'; break; case 'array': $args[] = '(Array:' . count($arg) . ')'; break; case 'object': $args[] = 'Object(' . get_class($arg) . ')'; break; case 'resource': $args[] = 'Resource'; break; case 'NULL': $args[] = 'NULL'; break; default: $args[] = "({$type})"; break; } } $message .= sprintf("#%s %s(%s): %s%s(%s)\n", $idx, CRM_Utils_Array::value('file', $trace, '[internal function]'), CRM_Utils_Array::value('line', $trace, ''), $className, $fnName, implode(", ", $args)); } $message .= sprintf("#%s {main}\n", 1 + $idx); return $message; }