/** * @param DC_General $dc */ public function renderPreviewView(EnvironmentInterface $environment) { /** @var EventDispatcher $eventDispatcher */ $eventDispatcher = $GLOBALS['container']['event-dispatcher']; $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('avisota_message_preview')); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('orm_avisota_message')); $input = \Input::getInstance(); $messageRepository = EntityHelper::getRepository('Avisota\\Contao:Message'); $messageId = IdSerializer::fromSerialized($input->get('id') ? $input->get('id') : $input->get('pid')); $message = $messageRepository->find($messageId->getId()); if (!$message) { $environment = \Environment::getInstance(); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent(preg_replace('#&(act=preview|id=[a-f0-9\\-]+)#', '', $environment->request))); } $modules = new \StringBuilder(); /** @var \Avisota\Contao\Message\Core\Send\SendModuleInterface $module */ foreach ($GLOBALS['AVISOTA_SEND_MODULE'] as $className) { $class = new \ReflectionClass($className); $module = $class->newInstance(); $modules->append($module->run($message)); } $context = array('message' => $message, 'modules' => $modules); $template = new \TwigTemplate('avisota/backend/preview', 'html5'); return $template->parse($context); }
public function testAppendReplace() { $sb = new StringBuilder(); $sb->append('a1'); $sb->appendReplace('a2', 'a', 'b'); $this->assertEquals('a1b2', $sb->build()); }
function toString() { $builder = new StringBuilder(); $builder->append($this->getHeader()); $builder->append($this->_parse()); $builder->append($this->getFooter()); return $builder->toString(); }
public function consultaCodigo($_prCodigo) { $sb = new StringBuilder(); $Sql = new Sql(); $sb->append("SELECT *"); $sb->append("FROM " . T_AGENDA); $sb->append(sprintf("WHERE codigo_age = %s", $_prCodigo)); return $Sql->executaSQL($sb->toString()); }
public function listarElogio($_prElogio) { $Sql = new Sql(); $sb = new StringBuilder(); $sb->append("SELECT *"); $sb->append("FROM " . T_ELOGIO); $sb->append(sprintf("WHERE codigo_elo = %s", toNumero($_prElogio))); return $Sql->ExecutaSQL($sb->toString()); }
public static function readString(InputStream $stream) { $length = self::readShort($stream); $builder = new StringBuilder(); for ($i = 0; $i != $length; ++$i) { $builder->append(chr(self::readShort($stream))); } self::readShort($stream); return $builder->toString(); }
function formatReminder() { $builder = new StringBuilder(); if ($this->_reservation->reminder_minutes_prior != 0) { $reminder_time = $this->_reservation->start + $this->_reservation->start * 60 - $this->_reservation->reminder_minutes_prior * 60; $adjusted = Time::getAdjustedTime($reminder_time); $builder->append(sprintf("DALARM:%sT%sZ\r\n", date('Ymd', $adjusted), date('His', $adjusted))); } return $builder->toString(); }
public function existe(Usuarios $_prClasse) { $sb = new StringBuilder(); $Sql = new Sql(); $sb->append("SELECT 1 AS TOTAL"); $sb->append("FROM " . T_USUARIO); $sb->append("WHERE UPPER(login_usr) = " . strtoupper($_prClasse->getLoginUsr())); $retorno = $Sql->ExecutaSQL($sb->toString()); return $retorno[0]['TOTAL'] > 0 ? true : false; }
public function listarSelecao($_prSelecao = 0) { $sb = new StringBuilder(); $Sql = new Sql(); $sb->append("SELECT *"); $sb->append("FROM " . T_EMP); if ($_prSelecao > 0) { $sb->append(sprintf("WHERE codigo_emp IN (%s)", $_prSelecao)); } return $Sql->executaSQL($sb->toString()); }
public function ToString() { $builder = new StringBuilder(); $builder->append("Command: {$this->_query}\n"); $builder->append("Parameters ({$this->Parameters->Count()}): \n"); for ($i = 0; $i < $this->Parameters->Count(); $i++) { $parameter = $this->Parameters->Items($i); $builder->append("{$parameter->Name} = {$parameter->Value}"); } return $builder->toString(); }
/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $resources = Resources::GetInstance(); $errorMessage = new StringBuilder(); $result = $this->attributeService->Validate(CustomAttributeCategory::RESERVATION, $reservationSeries->AttributeValues()); $isValid = $result->IsValid(); foreach ($result->Errors() as $error) { $errorMessage->AppendLine($error); } if (!$isValid) { $errorMessage->PrependLine($resources->GetString('CustomAttributeErrors')); } return new ReservationRuleResult($isValid, $errorMessage->ToString()); }
function testBuilder() { $str = new StringBuilder(); $str->write('Hello World'); $this->assertEquals('e', $str[1]); $this->assertCount(strlen('Hello World'), $str); $this->assertFalse(isset($str[11])); $this->assertTrue(isset($str[10])); $str[5] = '_'; $this->assertEquals('Hello_World', (string) $str); $this->assertEquals(11, $str->getLength()); $this->assertEquals(5, $str->indexOf('_')); $this->assertEmpty((string) $str->clean()); $this->assertEquals('Hello Masoud', (new StringBuilder('Hello %s'))->inject('Masoud')); $this->assertEquals('Hel_lo', (new StringBuilder('Hello'))->insert(3, '_')); $this->assertEquals('Dear, Masoud', (new StringBuilder())->write('Dear, %s', 'Masoud')->toString()); }
/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $layout = $this->repository->GetLayout($reservationSeries->Resource()->GetScheduleId(), new ScheduleLayoutFactory($this->session->Timezone)); $startDate = $reservationSeries->CurrentInstance()->StartDate(); $startPeriod = $layout->GetPeriod($startDate); $endDate = $reservationSeries->CurrentInstance()->EndDate(); $endPeriod = $layout->GetPeriod($endDate); $errors = new StringBuilder(); if ($startPeriod == null || !$startPeriod->IsReservable() || !$startPeriod->BeginDate()->Equals($startDate)) { $errors->AppendLine(Resources::GetInstance()->GetString('InvalidStartSlot')); } if ($endPeriod == null || !$endPeriod->BeginDate()->Equals($endDate)) { $errors->AppendLine(Resources::GetInstance()->GetString('InvalidEndSlot')); } $errorMessage = $errors->ToString(); return new ReservationRuleResult(strlen($errorMessage) == 0, $errorMessage); }
public function logar(Login $login) { $Sql = new Sql(); $sb = new StringBuilder(); $sb->append("SELECT *"); $sb->append("FROM " . T_USUARIO); $sb->append(sprintf("WHERE login_usr = %s", $login->getLoginUsr())); $sb->append(sprintf("AND senha_usr = %s", $login->getSenhaUsr())); $sb->append("AND ativo_usr = 1"); $retorno = $Sql->ExecutaSQL($sb->toString()); if (count($retorno) > 0) { global $Sess; // Dados do Usuario Logado $Sess->usuario = $retorno[0]; // Atualiza o usuário $usuario = new Usuarios(); $usuario->setCodigoUsr(toNumero($retorno[0]['codigo_usr'])); $usuario->setUltimoacessoUsr(toDateTime()); $this->alterar($usuario); // inicia Sessao $Sess->logado_sys = true; $Sess->ultimoacesso_sys = time(); return true; } return false; }
/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $errorMessage = new StringBuilder(); if ($reservationSeries->GetStartReminder()->Enabled()) { if (!$this->minutesValid($reservationSeries->GetStartReminder())) { $errorMessage->AppendLine(Resources::GetInstance()->GetString('InvalidStartReminderTime')); } } if ($reservationSeries->GetEndReminder()->Enabled()) { if (!$this->minutesValid($reservationSeries->GetEndReminder())) { $errorMessage->AppendLine(Resources::GetInstance()->GetString('InvalidEndReminderTime')); } } $message = $errorMessage->ToString(); if (strlen($message) > 0) { return new ReservationRuleResult(false, $message); } return new ReservationRuleResult(); }
public function listaDestinatarios($_prComunicado) { $sb = new StringBuilder(); $Sql = new Sql(); $sb->append("SELECT *"); $sb->append("FROM " . T_COMEMP); $sb->append("LEFT JOIN"); $sb->append(T_EMP); $sb->append("ON codigo_emp = empregado_coe"); $sb->append(sprintf("WHERE comunicado_coe = %s", $_prComunicado)); return $Sql->executaSQL($sb->toString()); }
public function Send(IEmailMessage $emailMessage) { $this->phpMailer->ClearAllRecipients(); $this->phpMailer->ClearReplyTos(); $this->phpMailer->CharSet = $emailMessage->Charset(); $this->phpMailer->Subject = $emailMessage->Subject(); $this->phpMailer->Body = $emailMessage->Body(); $from = $emailMessage->From(); $defaultFrom = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_ADDRESS); $defaultName = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_NAME); $address = empty($defaultFrom) ? $from->Address() : $defaultFrom; $name = empty($defaultName) ? $from->Name() : $defaultName; $this->phpMailer->SetFrom($address, $name); $replyTo = $emailMessage->ReplyTo(); $this->phpMailer->AddReplyTo($replyTo->Address(), $replyTo->Name()); $to = $this->ensureArray($emailMessage->To()); $toAddresses = new StringBuilder(); foreach ($to as $address) { $toAddresses->Append($address->Address()); $this->phpMailer->AddAddress($address->Address(), $address->Name()); } $cc = $this->ensureArray($emailMessage->CC()); foreach ($cc as $address) { $this->phpMailer->AddCC($address->Address(), $address->Name()); } $bcc = $this->ensureArray($emailMessage->BCC()); foreach ($bcc as $address) { $this->phpMailer->AddBCC($address->Address(), $address->Name()); } if ($emailMessage->HasStringAttachment()) { Log::Debug('Adding email attachment %s', $emailMessage->AttachmentFileName()); $this->phpMailer->AddStringAttachment($emailMessage->AttachmentContents(), $emailMessage->AttachmentFileName()); } Log::Debug('Sending %s email to: %s from: %s', get_class($emailMessage), $toAddresses->ToString(), $from->Address()); $success = false; try { $success = $this->phpMailer->Send(); } catch (Exception $ex) { Log::Error('Failed sending email. Exception: %s', $ex); } Log::Debug('Email send success: %d. %s', $success, $this->phpMailer->ErrorInfo); }
/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $errorMessage = new StringBuilder(); foreach ($reservationSeries->AllResources() as $resource) { if (!$resource->HasMaxParticipants()) { continue; } foreach ($reservationSeries->Instances() as $instance) { $numberOfParticipants = count($instance->Participants()); Log::Debug('ResourceParticipationRule Resource=%s,InstanceId=%s,MaxParticipants=%s,CurrentParticipants=%s', $resource->GetName(), $instance->ReservationId(), $resource->GetMaxParticipants(), $numberOfParticipants); if ($numberOfParticipants > $resource->GetMaxParticipants()) { $errorMessage->AppendLine(Resources::GetInstance()->GetString('MaxParticipantsError', array($resource->GetName(), $resource->GetMaxParticipants()))); continue; } } } $message = $errorMessage->ToString(); if (strlen($message) > 0) { return new ReservationRuleResult(false, $message); } return new ReservationRuleResult(); }
public function stem($word) { if (!is_string($word)) { throw new \Exception('Parameter one must be a string!', 111); } if (strlen(\stripslashes($word)) < 3) { return $word; } $this->sb = new StringBuilder(\strtolower(\stripslashes($word))); if (0 === strcmp("'", $this->sb->offsetGet(0))) { $this->sb->Remove(0); } // FIXME: Exceceptions test should go before creating StringBuilder object $this->exceptions->rewind(); while ($this->exceptions->valid()) { if (0 === strcmp($word, $this->exceptions->key())) { return $this->exceptions->current(); } $this->exceptions->next(); } $this->changeY(); $this->computeR1R2(); $this->step0(); $this->step1a(); $this->exceptions2->rewind(); while ($this->exceptions2->valid()) { if (0 === strcmp($this->sb, $this->exceptions2->current())) { return $this->exceptions2->current(); } $this->exceptions2->next(); } $this->step1b(); $this->step1c(); $this->step2(); $this->step3(); $this->step4(); $this->step5(); return strtolower($this->sb); }
/** * @param array $conflicts * @return string */ protected function GetErrorString($conflicts) { $errorString = new StringBuilder(); $errorString->Append(Resources::GetInstance()->GetString('ConflictingAccessoryDates')); $errorString->AppendLine(); $format = Resources::GetInstance()->GetDateFormat(ResourceKeys::DATE_GENERAL); foreach ($conflicts as $conflict) { $errorString->Append(sprintf('(%s) %s', $conflict['date']->ToTimezone($this->timezone)->Format($format), $conflict['name'])); $errorString->AppendLine(); } return $errorString->ToString(); }
/** * @param ConfigSetting $configSetting */ public function AddSectionSetting(ConfigSetting $configSetting) { $this->sectionSettings[$configSetting->Section][] = $configSetting; $this->settingNames->Append($configSetting->Name . ','); }
/** * @param ReservationItemView $reservation * @param string $format * @return string */ public function Format(ReservationItemView $reservation, $format = null) { $shouldHideUser = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter()); $shouldHideDetails = ReservationDetailsFilter::HideReservationDetails($reservation->StartDate, $reservation->EndDate); if (($shouldHideUser || $shouldHideDetails) && (is_null($this->user) || $this->user->UserId != $reservation->UserId && !$this->user->IsAdminForGroup($reservation->OwnerGroupIds()))) { return ''; } if (empty($format)) { $format = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_RESERVATION_LABEL); } if ($format == 'none' || empty($format)) { return ''; } $name = $this->GetFullName($reservation); $timezone = 'UTC'; $dateFormat = Resources::GetInstance()->GetDateFormat('res_popup'); if (!is_null($this->user)) { $timezone = $this->user->Timezone; } $label = $format; $label = str_replace('{name}', $name, $label); $label = str_replace('{title}', $reservation->Title, $label); $label = str_replace('{description}', $reservation->Description, $label); $label = str_replace('{email}', $reservation->OwnerEmailAddress, $label); $label = str_replace('{organization}', $reservation->OwnerOrganization, $label); $label = str_replace('{phone}', $reservation->OwnerPhone, $label); $label = str_replace('{position}', $reservation->OwnerPosition, $label); $label = str_replace('{startdate}', $reservation->StartDate->ToTimezone($timezone)->Format($dateFormat), $label); $label = str_replace('{enddate}', $reservation->EndDate->ToTimezone($timezone)->Format($dateFormat), $label); $label = str_replace('{resourcename}', $reservation->ResourceName, $label); $label = str_replace('{participants}', trim(implode(', ', $reservation->ParticipantNames)), $label); $label = str_replace('{invitees}', trim(implode(', ', $reservation->InviteeNames)), $label); $matches = array(); preg_match_all('/\\{(att\\d+?)\\}/', $format, $matches); $matches = $matches[0]; if (count($matches) > 0) { for ($m = 0; $m < count($matches); $m++) { $id = filter_var($matches[$m], FILTER_SANITIZE_NUMBER_INT); $value = $reservation->GetAttributeValue($id); $label = str_replace($matches[$m], $value, $label); } } if (BookedStringHelper::Contains($label, '{reservationAttributes}')) { $attributesLabel = new StringBuilder(); $attributes = $this->attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION); foreach ($attributes as $attribute) { $attributesLabel->Append($attribute->Label() . ': ' . $reservation->GetAttributeValue($attribute->Id()) . ', '); } $label = str_replace('{reservationAttributes}', rtrim($attributesLabel->ToString(), ', '), $label); } return $label; }
/** * Internal helper function to convert string encodings. * * @param string|StringBuilder $string The input string. * @param string $outputEncoding The output encoding. * * @return string */ private static function convertString($string, $outputEncoding) { if ($string instanceof StringBuilder) { $inputEncoding = $string->getEncoding(); } else { $inputEncoding = mb_detect_encoding((string) $string); } $string = (string) $string; if ($inputEncoding != $outputEncoding) { $string = iconv($inputEncoding, $outputEncoding, $string); } return $string; }
/** * Return a substring of this sequence. * * @param int $start * @param int $end * * @return StringBuilder * @throws OutOfBoundsException */ public function substring($start, $end = null) { $start = (int) $start; $end = $end !== null ? (int) $end : null; if ($start < 0 || $start >= $this->length() || $end !== null && ($end < 0 || $end >= $this->length())) { throw new OutOfBoundsException(); } $string = mb_substr($this->string, $start, $end !== null ? $end + 1 : $this->length(), $this->encoding); $stringBuilder = new StringBuilder($string); $stringBuilder->setEncoding($this->encoding); return $stringBuilder; }
/** * @param StringBuilder $stringBuilder * * Appends the specified value to the sequence as a string. * * @return $this */ public function merge(StringBuilder $stringBuilder) { $this->append($stringBuilder->toString()); return $this; }
/** * @param array|IReservedItemView[] $conflicts * @return string */ protected function GetErrorString($conflicts) { $errorString = new StringBuilder(); $errorString->Append(Resources::GetInstance()->GetString('ConflictingReservationDates')); $errorString->Append("\n"); $format = Resources::GetInstance()->GetDateFormat(ResourceKeys::DATE_GENERAL); $dates = array(); /** @var IReservedItemView $conflict */ foreach ($conflicts as $conflict) { $dates[] = sprintf('%s - %s', $conflict->GetStartDate()->ToTimezone($this->timezone)->Format($format), $conflict->GetResourceName()); } $uniqueDates = array_unique($dates); sort($uniqueDates); foreach ($uniqueDates as $date) { $errorString->Append($date); $errorString->Append("\n"); } return $errorString->ToString(); }
/** * Returns string with style tags (html-like). */ public function getHTML($index) { $raw = $this->getRaw($index); if ($raw == null) { return $raw; } $style = $this->getStyle($index); if ($style == null) { return $raw; } $html = new StringBuilder(strlen($raw) + 32); $offset = 0; while (true) { $i = -1; for ($j = 0; $j != count($style); $j += 3) { if ($style[$j + 1] == -1) { continue; } if ($i == -1 || $style[$i + 1] > $style[$j + 1]) { $i = $j; } } $start = $i != -1 ? $style[$i + 1] : strlen($raw); for ($j = 0; j != $style . length; $j += 3) { $end = $style[$j + 2]; if ($end == -1 || $end >= $start) { continue; } if ($offset <= $end) { $html->append($raw, $offset, $end + 1); $offset = $end + 1; } $style[j + 2] = -1; $html->append('<'); $html->append('/'); $html->append($this->getRaw($style[$j])); $html->append('>'); } if ($offset < $start) { $html->append($raw, $offset, $start); $offset = $start; } if ($i == -1) { break; } $html->append('<'); $html->append($this->getRaw($style[i])); $html->append('>'); $style[i + 1] = -1; } return $html->toString(); }
/** * <p>Capitalizes all the delimiter separated words in a String. * Only the first letter of each word is changed. To convert the * rest of each word to lowercase at the same time, * use {@link #capitalizeFully(String, char[])}.</p> * * <p>The delimiters represent a set of characters understood to separate words. * The first string character and the first non-delimiter character after a * delimiter will be capitalized. </p> * * <p>A <code>null</code> input String returns <code>null</code>. * Capitalization uses the unicode title case, normally equivalent to * upper case.</p> * * <pre> * WordUtils.capitalize(null, *) = null * WordUtils.capitalize("", *) = "" * WordUtils.capitalize(*, new char[0]) = * * WordUtils.capitalize("i am fine", null) = "I Am Fine" * WordUtils.capitalize("i aM.fine", {'.'}) = "I aM.Fine" * </pre> * * @param string $str the string to capitalize, may be null * @param array $delimiters set of characters to determine capitalization, * <tt>null</tt> means whitespace * @return capitalized String, <code>null</code> if null String input * @see #uncapitalize(String) * @see #capitalizeFully(String) * @since 2.1 */ public static function capitalize($str, array $delimiters = array(' ')) { //$delimLen = (delimiters == null ? -1 : delimiters.length); if (is_null($str) || is_empty($str) == 0 || $delimLen == 0) { return $str; } $strLen = strlen($str); $buffer = new StringBuilder(strLen); $capitalizeNext = true; for ($i = 0; $i < $strLen; $i++) { $ch = substr($str, $i, 1); if (WordUtils::isDelimiter($ch, $delimiters)) { $buffer->append($ch); $capitalizeNext = true; } else { if ($capitalizeNext) { $buffer->append(strtoupper($ch)); $capitalizeNext = false; } else { $buffer->append(ch); } } } return $buffer->toString(); }
public function renderAttributesFunction(\Twig_Environment $env, array $attributes) { $builder = new \StringBuilder(); foreach ($attributes as $key => $value) { $value = twig_escape_filter($env, $value, 'html_attr'); $builder->append(' '); $builder->append($key); $builder->append('="'); $builder->append($value); $builder->append('"'); } return $builder->__toString(); }
public function CreatePagination($params, &$smarty) { /** @var PageInfo $pageInfo */ $pageInfo = $params['pageInfo']; if (empty($pageInfo->Total)) { return ''; } $sb = new StringBuilder(); $viewAllText = $this->Resources->GetString('ViewAll'); $sb->Append('<p><br/>'); $sb->Append($this->Resources->GetString('Rows')); $sb->Append(": {$pageInfo->ResultsStart} - {$pageInfo->ResultsEnd} ({$pageInfo->Total})"); $sb->Append('<span> </span>'); if ($pageInfo->TotalPages != 1) { $sb->Append($this->CreatePageLink(array('page' => 1, 'size' => '-1', 'text' => $viewAllText), $smarty)); } $sb->Append('</p><p>'); $sb->Append($this->Resources->GetString('Page')); $sb->Append(': '); $size = $pageInfo->PageSize; $currentPage = $pageInfo->CurrentPage; for ($i = 1; $i <= $pageInfo->TotalPages; $i++) { $isCurrent = $i == $currentPage; $sb->Append($this->CreatePageLink(array('page' => $i, 'size' => $size, 'iscurrent' => $isCurrent), $smarty)); $sb->Append(" "); } $sb->Append('</p>'); return $sb->ToString(); }