private function setLanguageFile() { //filter language file $config = ParamesHelper::getLanguageConfig(); $this->adminArray = preg_filter('/^/', $this->language . '.', $config['file_admin']); $this->siteArray = preg_filter('/^/', $this->language . '.', $config['file_site']); $site_list_file = JFolder::files($config['folder_site'] . $this->language); $this->itemsSite = MathHelper::filterArray($site_list_file, $this->siteArray); $admin_list_file = JFolder::files($config['folder_admin'] . $this->language); $this->itemsAdmin = MathHelper::filterArray($admin_list_file, $this->adminArray); return true; }
public function postFormatRecords(array &$records = NULL) { parent::postFormatRecords($records); if (!isset($records)) { return; } $valueMin = NULL; $valueMax = NULL; // preparing minimum and maximum values foreach ($records as $record) { if (!isset($record[$this->valuePropertyName])) { continue; } $value = $record[$this->valuePropertyName]; $valueMin = MathHelper::min($valueMin, $value); $valueMax = MathHelper::max($value, $valueMax); } // generating weighted grade foreach ($records as &$record) { if (!isset($record[$this->valuePropertyName])) { continue; } $value = $record[$this->valuePropertyName]; $weightedGrade = ($value - $valueMin) / ($valueMax - $valueMin); $record[$this->weightedGradeProperyName] = $weightedGrade; } }
protected function removeTraceFilePath($message) { $prefix = 'File "'; $suffix = '"'; $index = 0; while (($startIndex = strpos($message, $prefix, $index)) !== FALSE) { $startIndex += strlen($prefix); $endIndex = strpos($message, $suffix, $startIndex); $fileName = substr($message, $startIndex, $endIndex - $startIndex); $p1 = strrpos($fileName, '\\'); if ($p1 === FALSE) { $p1 = NULL; } $p2 = strrpos($fileName, '/'); if ($p2 === FALSE) { $p2 = NULL; } $p = MathHelper::max($p1, $p2); if (isset($p)) { $message = substr_replace($message, '', $startIndex, $p + 1); } $index = $endIndex + 1; } return $message; }
protected function finishImpl(array &$records = NULL) { parent::finishImpl($records); if (!isset($records)) { return; } $valueMin = $valueMax = NULL; // preparing minimum and maximum values foreach ($records as $record) { if (!isset($record[$this->valueColumnName])) { continue; } $value = $record[$this->valueColumnName]; $valueMin = MathHelper::min($valueMin, $value); $valueMax = MathHelper::max($value, $valueMax); } $valueRange = $valueMax - $valueMin; // generating weighted grade foreach ($records as &$record) { if (!isset($record[$this->valueColumnName])) { continue; } $value = $record[$this->valueColumnName]; $rank = ($valueRange == 0) ? 1 : ($value - $valueMin) / $valueRange; $record[$this->memberRankColumnName] = $rank; } unset($record); }
protected function submitRecordImpl(RecordMetaData $recordMetaData, $recordNumber, array &$record) { $datatypeFactory = DataTypeFactory::getInstance(); foreach ($recordMetaData->getColumns(FALSE) as $column) { if (!isset($record[$column->columnIndex])) { continue; } $columnValue = $record[$column->columnIndex]; // calculating length of the column value $column->type->length = MathHelper::max( (isset($column->type->length) ? $column->type->length : NULL), strlen($columnValue)); if (isset($column->type->applicationType) && ($column->type->applicationType === StringDataTypeHandler::DATA_TYPE)) { continue; } $columnDataType = $datatypeFactory->autoDetectDataType($columnValue, DATA_TYPE__ALL); if (isset($column->type->applicationType)) { try { $column->type->applicationType = $datatypeFactory->selectCompatibleDataType( array($column->type->applicationType, $columnDataType)); } catch (IncompatibleDataTypeException $e) { // if the two types are incompatible only 'string' type can resolve the problem $column->type->applicationType = StringDataTypeHandler::DATA_TYPE; } } else { $column->type->applicationType = $columnDataType; } // calculating scale for numeric columns $handler = $datatypeFactory->getHandler($column->type->applicationType); if ($handler instanceof AbstractNumberDataTypeHandler) { $numericColumnValue = $handler->castValue($columnValue); $decimalSeparatorIndex = strpos($numericColumnValue, $handler->decimalSeparatorSymbol); if ($decimalSeparatorIndex !== FALSE) { $scale = strlen($numericColumnValue) - $decimalSeparatorIndex - 1; if (!isset($column->type->scale) || ($column->type->scale < $scale)) { $column->type->scale = $scale; } } } } }
public function getPriceList() { if (!class_exists('MathHelper')) { require_once JPATH_ADMINISTRATOR . '/components/com_bookpro/helpers/math.php'; } $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('*'); $query->from($db->quoteName('#__bookpro_price')); $db->setQuery($query); $data = $db->loadObjectList(); $result = new JObject(); $result->date = MathHelper::filterArrayObjects($data, 'code', 'DATE'); $result->week = MathHelper::filterArrayObjects($data, 'code', 'WEEK'); $result->dayoff = MathHelper::filterArrayObjects($data, 'code', 'DAYOFF'); return $result; }
public function doBeforeRecordSubmitted(RecordMetaData $recordMetaData, $recordNumber, array &$record) { $result = parent::doBeforeRecordSubmitted($recordMetaData, $recordNumber, $record); if ($result) { foreach ($record as &$columnValue) { if (!is_string($columnValue)) { continue; } if (strlen($columnValue) > $this->maxValueLength) { $columnValue = substr($columnValue, 0, MathHelper::max($this->maxValueLength - 3, 0)) . '...'; } } unset($columnValue); } return $result; }
public function getTotal() { $this->depart_price = $this->getPriceType('depart'); // debug($this->price_list); if ($this->price_list->week) { $rate = MathHelper::filterArrayObject($this->price_list->week, 'date', strtoupper($this->date['depart']->format('D'))); } if ($this->price_list->date) { $rate = MathHelper::filterArrayObject($this->price_list->date, 'date', $this->date['depart']->format('d-m')); } if ($rate) { $this->depart_price += $this->depart_price * $rate->params / 100; } if ($this->trips['return']) { $this->return_price = $this->getPriceType('return'); $rate = false; if ($this->price_list->week) { $rate = MathHelper::filterArrayObject($this->price_list->week, 'date', strtoupper($this->date['return']->format('D'))); } if ($this->price_list->date) { $rate = MathHelper::filterArrayObject($this->price_list->date, 'date', $this->date['return']->format('d-m')); } if ($rate) { $this->return_price += $this->return_price * $rate->params / 100; } } if (!empty($this->addons['depart'])) { foreach ($this->addons['depart'] as $addon) { $this->depart_addon_price += $this->adult * $addon->price + $this->child * $addon->child_price; } } if (!empty($this->addons['return'])) { foreach ($this->addons['return'] as $addon) { $this->return_addon_price += $this->adult * $addon->price + $this->child * $addon->child_price; } } $this->total = $this->depart_price + $this->return_price + $this->depart_addon_price + $this->return_addon_price; return parent::getTotal(); }
public static function caculatePriceWithRate($price, $type, $datetime, $time, $rate) { if (!class_exists('MathHelper')) { require_once JPATH_ROOT . '/administrator/components/com_bookpro/helpers/math.php'; } $date = JFactory::getDate($datetime)->format('d-m'); $day = strtoupper(JFactory::getDate($datetime)->format('D')); if ($type == 1) { $rate_param = $rate->private; } else { $rate_param = $rate->share; } $rate = MathHelper::filterArrayObject($rate_param, 'date', $date); if (empty($rate)) { $rate = MathHelper::filterArrayObject($rate_param, 'day', $day); } if ($type == 2 && !empty($rate)) { $rate = self::getPaxGroup($time, array($rate), $type); } if (!empty($rate)) { $price += $rate->promo * $price / 100; } return $price; }
public function getAirport() { return MathHelper::selectGroupList($this->airport, 'filter_dest', ' class="inputbox" ', 'id', 'title', $this->state->get('filter.destfrom'), 'filter_destfrom', JText::_('COM_BOOKPRO_FROM')); }
protected function calculateLinkWeight(ReferenceLink $link, $weightMultiplier, ReferenceLink $parentLink = NULL) { if (isset($parentLink)) { $weight = NULL; foreach ($link->columnNames as $referencePointColumnIndex => $columnName) { $column = $link->dataset->getColumn($columnName); $parentColumnName = $link->parentColumnNames[$referencePointColumnIndex]; $parentColumn = $parentLink->dataset->getColumn($parentColumnName); // calculating the link weight $columnWeight = $parentColumn->isKey() ? ($column->isKey() ? self::$LINK_WEIGHT__PK_to_PK : self::$LINK_WEIGHT__from_LOOKUP) : ($column->isKey() ? self::$LINK_WEIGHT__to_LOOKUP : self::$LINK_WEIGHT__NON_PK_to_NON_PK); $weight = MathHelper::min($weight, $columnWeight); } // calculating the link weight and adjusting the valued based on multiplier $link->weight = $weight / pow($weightMultiplier, count($link->columnNames) - 1); } if (isset($link->nestedLinks)) { foreach ($link->nestedLinks as $nestedLink) { $this->calculateLinkWeight($nestedLink, $weightMultiplier, $link); } } }
public function getJquerySelectList() { $options = MathHelper::selectGroupList($this->dest, 'stops[dest][]', 'class="inputbox" required', 'id', 'title', '', '', JText::_('COM_BOOKPRO_SELECT_LOCATION')); return $options; }
protected function prepareColumnDatabaseType(DataSourceHandler $handler, ColumnMetaData $column) { if (isset($column->type->applicationType)) { $storageDataType = NULL; list($datasetName) = ReferencePathHelper::splitReference($column->type->applicationType); if (isset($datasetName)) { $storageDataType = Sequence::getSequenceColumnType()->applicationType; } else { $datatypeHandler = DataTypeFactory::getInstance()->getHandler($column->type->applicationType); $storageDataType = $datatypeHandler->getStorageDataType(); } switch ($storageDataType) { case StringDataTypeHandler::$DATA_TYPE: break; case IntegerDataTypeHandler::$DATA_TYPE: $this->prepareInteger($column); break; case NumberDataTypeHandler::$DATA_TYPE: case CurrencyDataTypeHandler::$DATA_TYPE: case PercentDataTypeHandler::$DATA_TYPE: $this->prepareNumber($column); break; case BooleanDataTypeHandler::$DATA_TYPE: // calculating length of mapping of TRUE and FALSE values $valueTrue = $handler->castValue(BooleanDataTypeHandler::$DATA_TYPE, TRUE); $valueFalse = $handler->castValue(BooleanDataTypeHandler::$DATA_TYPE, FALSE); // length of the field depends on length of the mappings $lengthValueTrue = strlen($valueTrue); $lengthValueFalse = strlen($valueFalse); $length = MathHelper::max($lengthValueTrue, $lengthValueFalse); // detecting type for each value and selecting primary type $datatype = DataTypeFactory::getInstance()->selectDataType(array(DataTypeFactory::getInstance()->autoDetectDataType($valueTrue), DataTypeFactory::getInstance()->autoDetectDataType($valueFalse))); // for numeric values we use integer storage type, for rest - string if ($datatype === IntegerDataTypeHandler::$DATA_TYPE) { $this->prepareInteger($column, $length); } elseif ($lengthValueTrue === $lengthValueFalse) { $this->prepareFixedLengthString($column, $length); } else { $this->prepareVariableLengthString($column, $length); } break; case DateTimeDataTypeHandler::$DATA_TYPE: $this->prepareDate($column, TRUE, TRUE); break; case DateDataTypeHandler::$DATA_TYPE: $this->prepareDate($column); break; case TimeDataTypeHandler::$DATA_TYPE: $this->prepareDate($column, FALSE, TRUE); break; default: throw new UnsupportedOperationException(t("Unsupported data type for '@columnName' column: @columnType", array('@columnName' => $column->publicName, '@columnType' => $column->type->applicationType))); } } if (!isset($column->type->databaseType)) { $this->prepareVariableLengthString($column); } return $column->type->databaseType; }
public function findLastColumnIndex() { $lastColumnIndex = NULL; foreach ($this->columns as $column) { $lastColumnIndex = MathHelper::max($lastColumnIndex, $column->columnIndex); } return $lastColumnIndex; }
* @author Ngo Van Quan * @link http://joombooking.com * @copyright Copyright (C) 2011 - 2012 Ngo Van Quan * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html * @version $Id: default.php 81 2012-08-11 01:16:36Z quannv $ **/ defined('_JEXEC') or die('Restricted access'); AImporter::helper('vehicle', 'math'); $parking_price = json_decode($displayData); $list_type = VehicleHelper::getTypeList(); ?> <div class="row-fluid"> <table> <?php foreach ($list_type as $li) { $price = MathHelper::filterArrayObject($parking_price, 'type', $li->id); ?> <tr> <td><?php echo $li->title; ?> </td> <td> <input type="text" class="input-mini" name="parking[price][]" value="<?php echo $price->price; ?> "/> <input type="hidden" name="parking[type][]" value="<?php echo $li->id; ?> "/>
private function filterSharePrice(JDate $date, $rate, array $params) { if ($rate == null) { return null; } $datedm = $date->format('d-m'); $param = MathHelper::filterArrayObject($params, 'date', $datedm); if ($param) { $new_rate = clone $rate[0]; $new_rate->start = $param->start; $new_rate->end = $param->end; $new_rate->price += $new_rate->price * $param->promo / 100; array_unshift($rate, $new_rate); } return $rate; }
function ajaxCaculateAddon() { AImporter::model('addons'); AImporter::helper('currency'); $input = JFactory::getApplication()->input; $addon = $input->get('addon', '', 'array'); $modelAddons = new BookProModelAddons(); $cart = $this->getCart(); AImporter::classes('order/transport'); $transport = new BookproTransportOrder(); $transport->cart = $cart; $transport->addons['depart'] = $modelAddons->getDataByIds($addon); $transport->trips = $cart->trips; $cart->total = $transport->setPrice(); $cart->subtotal = MathHelper::removeVat($cart->total, $transport->price->vat); $cart->saveTosession(); $html = JLayoutHelper::render('transport_book_totalprice', $cart, JPATH_ROOT . '/components/com_bookpro/layouts'); echo $html; $transport = null; $html = null; die; }
* @author Ngo Van Quan * @link http://joombooking.com * @copyright Copyright (C) 2011 - 2012 Ngo Van Quan * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html * @version $Id: bookpro.php 27 2012-07-08 17:15:11Z quannv $ **/ defined('_JEXEC') or die; ?> <div class="control-group"> <div class="control-label"><?php echo $this->form->getLabel('desfrom'); ?> </div> <div class="controls"><?php echo MathHelper::selectGroupList($this->dest, 'stops[dest][]', 'class="inputbox"', 'id', 'title', $this->stops[0]->dest, '', JText::_('COM_BOOKPRO_FROM')); ?> </div> </div> <div class="control-group"> <div class="control-label"><?php echo $this->form->getLabel('desto'); ?> </div> <div class="controls"><?php echo MathHelper::selectGroupList($this->dest, 'stops[dest][]', 'class="inputbox"', 'id', 'title', $this->stops[1]->dest, '', JText::_('COM_BOOKPRO_TO')); ?> </div> </div>
public function getMaximumColumnCount() { $count = isset($this->columnNames) ? count($this->columnNames) : NULL; if (isset($this->nestedLinks)) { foreach ($this->nestedLinks as $nestedLink) { $count = MathHelper::max($count, $nestedLink->getMaximumColumnCount()); } } return $count; }
public function readLineFromResource() { $this->incrementLineNumber(); $delimiterSize = 1; $i = 0; $n = strpos($this->buffer, "\n", $this->index); $r = strpos($this->buffer, "\r", $this->index); if ($n === FALSE) { if ($r === FALSE) { // last line in the stream if (($this->index + 1) < $this->bufferSize) { $s = substr($this->buffer, $this->index); $this->index = $this->bufferSize; return $s; } else { return FALSE; } } else { // continue with just $r $i = $r; } } else { if ($r === FALSE) { // continue with just $n $i = $n; } else { // both delimiters are set if (($r + 1) == $n) { // it is one delimiter \r\n $delimiterSize = 2; $i = $r; } else { $i = MathHelper::min($r, $n); } } } $line = ($i == $this->index) ? '' : substr($this->buffer, $this->index, $i - $this->index); $this->index = $i + $delimiterSize; return $line; }
function getReturnAirport($from, $type, $country_id = null) { require_once JPATH_ADMINISTRATOR . '/components/com_bookpro/helpers/math.php'; $t = microtime(1); if (empty($from)) { return array(); } //get parent destination $parents = $this->getParentDest($country_id); $return_dests = $this->getReturnDest($from, $type); $result = array(); foreach ($parents as $pr) { $result[$pr->title] = MathHelper::filterArrayObjects($return_dests, 'parent_id', $pr->id); } // echo 'time:'.(microtime(1)-$t); return TransportHelper::removeEmptyArray($result); }
<?php if (isset($trip->dropoff)) { ?> <small><?php echo DateHelper::formatHours($trip->dropoff); } ?> </small> </td> <td> <?php echo JText::_('COM_BOOKPRO_TRANSPORT_DURATION'); ?> <br/> <small><?php echo MathHelper::getDuration($trip->duration); ?> </small> </td> </tr> </table> <?php if (isset($displayData->showTime)) { echo JText::_('COM_BOOKPRO_TRANSPORT_FLIGHT_TIME') . ': ' . DateHelper::formatHours($trip->flight_time); echo '<br>' . JText::_('COM_BOOKPRO_FLIGHT_NUMBER') . ': ' . $trip->flight_number; } ?> <br> <!--<?php if ($type == 1) { ?>