コード例 #1
0
 /**
  * Convert if possible a supplied argument to a rational
  *
  * @param int|float|string|NumericTypeInterface $value
  *
  * @return \Chippyash\Math\Matrix\RationalNumber
  *
  * @throws \Chippyash\Matrix\Exceptions\MatrixException
  * @throws \Exception
  */
 protected function convertNumberToRational($value)
 {
     if ($value instanceof NumericTypeInterface) {
         return $value->asRational();
     }
     switch (gettype($value)) {
         case 'integer':
             return RationalTypeFactory::create($value, 1);
         case 'double':
             return RationalTypeFactory::fromFloat($value);
         case 'string':
             try {
                 return RationalTypeFactory::fromString($value);
             } catch (\Exception $e) {
                 try {
                     return ComplexTypeFactory::fromString($value)->asRational();
                 } catch (\Exception $ex) {
                     throw new MatrixException('The string representation of the number is invalid for a rational');
                 }
             }
         case 'NULL':
             return RationalTypeFactory::create(0, 1);
         case 'boolean':
             return RationalTypeFactory::create($value ? 1 : 0, 1);
         default:
             throw new MatrixException('Rational expects int, float, string, Rational or NumericTypeInterface ');
     }
 }
コード例 #2
0
ファイル: LocalDate.php プロジェクト: peekandpoke/psi
 /**
  * @param \DateTime|string|float $input    The date or a string the DateTime c'tor can understand or a timestamp
  * @param \DateTimeZone|string   $timezone The timezone or a string the DateTimeZone c'tor can understand
  */
 public function __construct($input, $timezone)
 {
     if (!$timezone instanceof \DateTimeZone) {
         $timezone = new \DateTimeZone((string) $timezone);
     }
     /////
     // We have to trick PHP a bit here, but why?
     //
     // Apparently things behave different, when setting a timezone like
     // a) 'Europe/Berlin'
     // b) '+02:00'
     //
     // When the date already has a timezone set then
     // a) will only set the timezone
     // b) will set the timezone and will also change the timestamp by 2 hours
     //
     // Therefore we create a fresh date, that does not have a timezone yet, set the timestamp, and then apply the
     // timezone
     //
     // See the unit tests for more as well
     ////
     if ($input instanceof \DateTime) {
         $date = (new \DateTime())->setTimestamp($input->getTimestamp())->setTimezone($timezone);
     } elseif (is_numeric($input)) {
         $date = (new \DateTime())->setTimestamp($input)->setTimezone($timezone);
     } else {
         // when we have string input, we immediately use the timezone
         $tmp = new \DateTime($input, $timezone);
         // we reconstruct the date time again in order to set the timezone on the inner one
         $date = (new \DateTime())->setTimestamp($tmp->getTimestamp())->setTimezone($timezone);
     }
     $this->date = $date;
     $this->timezone = $timezone;
 }
コード例 #3
0
ファイル: Option.php プロジェクト: poulikov/mongodb-odm
 /**
  * @return float
  */
 public function getPrice($object = false)
 {
     if (true === $object) {
         return $this->money;
     }
     return $this->money->getAmount();
 }
コード例 #4
0
 public function toArray()
 {
     $queryArr = $this->query->toArray();
     $queryParam = reset($queryArr);
     $first_key = key($queryArr);
     $query = ["not" => [$first_key => $queryParam]];
     return $query;
 }
コード例 #5
0
ファイル: Money.php プロジェクト: lusitanian/phpmoney
 /**
  * Divides $this by $divisor and returns a new value object.
  * Uses the default rounding method (ROUND_HALF_EVEN) which is preferred for financial calculations.
  * @param Money|int|float|string $divisor
  * @return Money|string
  */
 public function divide($divisor)
 {
     if ($divisor instanceof Money) {
         return $this->mathProvider->divide($this->getValue(), $divisor->getValue(), MathProvider::ROUND_MODE_NONE);
     } else {
         return new static($this->mathProvider->divide($this->getValue(), (string) $divisor), $this->mathProvider);
     }
 }
コード例 #6
0
ファイル: Helpers.php プロジェクト: enimiste/l5-math
 /**
  * @param string|int|float|\Enimiste\Math\VO\IntegerNumber $value
  *
  * @return \Enimiste\Math\VO\FloatNumber
  */
 function as_integer_number($value)
 {
     if ($value instanceof \Enimiste\Math\VO\IntegerNumber) {
         return $value;
     } elseif ($value instanceof \Enimiste\Math\VO\FloatNumber) {
         return new \Enimiste\Math\VO\IntegerNumber($value->__toString());
     } else {
         return new \Enimiste\Math\VO\IntegerNumber($value);
     }
 }
コード例 #7
0
ファイル: GlobalExtension.php プロジェクト: Codixis/CSBill
 /**
  * @param int|float $amount
  * @param int       $percentage
  *
  * @return float|int
  */
 public function formatPercentage($amount, $percentage = 0)
 {
     if ($percentage > 0) {
         if ($amount instanceof Money) {
             return $amount->multiply($percentage);
         }
         return $amount * $percentage;
     }
     return 0;
 }
コード例 #8
0
ファイル: money.php プロジェクト: browner12/helpers
 /**
  * money
  *
  * @param float|\browner12\money\Money $money
  * @param string                       $currency
  * @return string
  */
 function money($money, $currency = 'usd')
 {
     //money object
     if ($money instanceof \browner12\money\Money) {
         $currency = $money->getCurrency()->currency();
         $money = $money->value();
     }
     //formatter
     $cf = new NumberFormatter('eng', NumberFormatter::CURRENCY);
     //return
     return $cf->formatCurrency($money, $currency);
 }
コード例 #9
0
ファイル: Style.php プロジェクト: niallmccrudden/zf2
    /**
     * Dump style to a string, which can be directly inserted into content stream
     *
     * @return string
     */
    public function instructions()
    {
        $instructions = '';

        if ($this->_fillColor !== null) {
            $instructions .= $this->_fillColor->instructions(false);
        }

        if ($this->_color !== null) {
            $instructions .= $this->_color->instructions(true);
        }

        if ($this->_lineWidth !== null) {
            $instructions .= $this->_lineWidth->toString() . " w\n";
        }

        if ($this->_lineDashingPattern !== null) {
            $dashPattern = new InternalType\ArrayObject();

            foreach ($this->_lineDashingPattern as $dashItem) {
                $dashElement = new InternalType\NumericObject($dashItem);
                $dashPattern->items[] = $dashElement;
            }

            $instructions .= $dashPattern->toString() . ' '
                           . $this->_lineDashingPhase->toString() . " d\n";
        }

        return $instructions;
    }
コード例 #10
0
ファイル: Style.php プロジェクト: nhp/shopware-4
    /**
     * Dump style to a string, which can be directly inserted into content stream
     *
     * @return string
     */
    public function instructions()
    {
        $instructions = '';

        if ($this->_fillColor !== null) {
            $instructions .= $this->_fillColor->instructions(false);
        }

        if ($this->_color !== null) {
            $instructions .= $this->_color->instructions(true);
        }

        if ($this->_lineWidth !== null) {
            $instructions .= $this->_lineWidth->toString() . " w\n";
        }

        if ($this->_lineDashingPattern !== null) {
            require_once 'Zend/Pdf/Element/Array.php';
            $dashPattern = new Zend_Pdf_Element_Array();

            require_once 'Zend/Pdf/Element/Numeric.php';
            foreach ($this->_lineDashingPattern as $dashItem) {
                $dashElement = new Zend_Pdf_Element_Numeric($dashItem);
                $dashPattern->items[] = $dashElement;
            }

            $instructions .= $dashPattern->toString() . ' '
                           . $this->_lineDashingPhase->toString() . " d\n";
        }

        return $instructions;
    }
コード例 #11
0
    /**
     * @dataProvider responseConditionMatchCorrectProvider
     * 
     * @param string $response A QTI Identifier
     * @param float $expectedScore The expected score for a given $response
     */
    public function testResponseConditionMatchCorrect($response, $expectedScore)
    {
        $rule = $this->createComponentFromXml('
			<responseCondition>
				<responseIf>
					<match>
						<variable identifier="RESPONSE"/>
						<correct identifier="RESPONSE"/>
					</match>
					<setOutcomeValue identifier="SCORE">
						<baseValue baseType="float">1</baseValue>
						</setOutcomeValue>
				</responseIf>
				<responseElse>
					<setOutcomeValue identifier="SCORE">
						<baseValue baseType="float">0</baseValue>
					</setOutcomeValue>
				</responseElse>
			</responseCondition>
		');
        $responseVarDeclaration = $this->createComponentFromXml('
			<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier">
				<correctResponse>
					<value>ChoiceA</value>
				</correctResponse>
			</responseDeclaration>
		');
        $responseVar = ResponseVariable::createFromDataModel($responseVarDeclaration);
        $this->assertTrue($responseVar->getCorrectResponse()->equals(new Identifier('ChoiceA')));
        // Set 'ChoiceA' to 'RESPONSE' in order to get a score of 1.0.
        $responseVar->setValue($response);
        $outcomeVarDeclaration = $this->createComponentFromXml('
			<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">
				<defaultValue>
					<value>0</value>
				</defaultValue>
			</outcomeDeclaration>		
		');
        $outcomeVar = OutcomeVariable::createFromDataModel($outcomeVarDeclaration);
        $this->assertEquals(0, $outcomeVar->getDefaultValue()->getValue());
        $state = new State(array($responseVar, $outcomeVar));
        $processor = new ResponseConditionProcessor($rule);
        $processor->setState($state);
        $processor->process();
        $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $state['SCORE']);
        $this->assertTrue($expectedScore->equals($state['SCORE']));
    }
コード例 #12
0
ファイル: Order.php プロジェクト: bardascat/blogify
 public function getShippedOn()
 {
     if ($this->shippedOn) {
         return $this->shippedOn->format('d-m-Y');
     } else {
         return false;
     }
 }
コード例 #13
0
 /**
  * Add custom options to buy request.
  *
  * @param CartItemInterface $cartItem
  * @param \Magento\Framework\DataObject|float $params
  * @return \Magento\Framework\DataObject|float
  */
 private function addCustomOptionsToBuyRequest(CartItemInterface $cartItem, $params)
 {
     if (isset($this->cartItemProcessors['custom_options'])) {
         $buyRequestUpdate = $this->cartItemProcessors['custom_options']->convertToBuyRequest($cartItem);
         if (!$buyRequestUpdate) {
             return $params;
         }
         if ($params instanceof \Magento\Framework\DataObject) {
             $buyRequestUpdate->addData($params->getData());
         } else {
             if (is_numeric($params)) {
                 $buyRequestUpdate->setData('qty', $params);
             }
         }
         return $buyRequestUpdate;
     }
     return $params;
 }
コード例 #14
0
 /**
  * Filter XHtml document
  *
  * Filter for the document, which may modify / restructure a document and
  * assign semantic information bits to the elements in the tree.
  *
  * @param DOMDocument $document
  * @return DOMDocument
  */
 public function filter(DOMDocument $document)
 {
     $xpath = new DOMXPath($document);
     $body = $xpath->query('/*[local-name() = "html"]/*[local-name() = "body"]')->item(0);
     $this->calculateContentFactors($body);
     if ($this->mostImportantNode !== false) {
         // Replace contents of body node with the found "most important"
         // section, so we keep the metadata, but omit everything we consider as
         // layout.
         $contentNode = $this->mostImportantNode->cloneNode(true);
         // Remove all childs from HTML body
         for ($i = $body->childNodes->length - 1; $i >= 0; --$i) {
             $body->removeChild($body->childNodes->item($i));
         }
         // Readd detected content node
         $body->appendChild($contentNode);
     }
 }
コード例 #15
0
ファイル: Number.php プロジェクト: rtsantos/mais
 /**
  * Retorna o conteúdo no formato ISO
  */
 public function getValueToDb()
 {
     $value = $this->_value;
     if ($value instanceof ZendT_Type) {
         $value = $value->getValueToDb();
     }
     if ($value != null) {
         if ($value instanceof ZendT_Type_Number) {
             $value = $value->get();
         }
         if (is_string($value)) {
             if ($this->_value instanceof ZendT_Type) {
                 $this->_value = $this->_value->get();
             }
             if (strpos($value, ',') !== false && strpos($value, '.') !== false) {
                 $value = str_replace('.', '', $value);
                 $value = str_replace(',', '.', $value);
                 $value *= 1;
             } elseif (strpos($this->_value, '.') !== false) {
                 $value = str_replace('.', '', $value);
                 $value *= 1;
             } elseif (strpos($this->_value, ',') !== false) {
                 $value = str_replace(',', '.', $value);
                 $value *= 1;
             }
         }
         if (isset($this->_part['numDecimal']) && $this->_part['numDecimal']) {
             $this->_part['numDecimal'] = $this->_part['numDecimal'] * 1;
             $value = round($value, $this->_part['numDecimal']);
         }
     }
     if (!$value && $value !== '0' && $this->_part['numDecimal'] === null) {
         $value = null;
     }
     return $value;
 }
コード例 #16
0
ファイル: cairo.php プロジェクト: jordanmanning/ezpublish
 /**
  * Render text depending of font type and available font extensions
  * 
  * @param string $id 
  * @param string $text 
  * @param string $font 
  * @param ezcGraphColor $color 
  * @param ezcGraphCoordinate $position 
  * @param float $size 
  * @param float $rotation 
  * @return void
  */
 protected function renderText($text, $font, ezcGraphColor $color, ezcGraphCoordinate $position, $size, $rotation = null)
 {
     cairo_select_font_face($this->context, $font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
     cairo_set_font_size($this->context, $size);
     // Store current state of context
     cairo_save($this->context);
     cairo_move_to($this->context, 0, 0);
     if ($rotation !== null) {
         // Move to the center
         cairo_translate($this->context, $rotation->getCenter()->x, $rotation->getCenter()->y);
         // Rotate around text center
         cairo_rotate($this->context, deg2rad($rotation->getRotation()));
         // Center the text
         cairo_translate($this->context, $position->x - $rotation->getCenter()->x, $position->y - $rotation->getCenter()->y - $size * 0.15);
     } else {
         cairo_translate($this->context, $position->x, $position->y - $size * 0.15);
     }
     cairo_new_path($this->context);
     $this->getStyle($color, true);
     cairo_show_text($this->context, $text);
     cairo_stroke($this->context);
     // Restore state of context
     cairo_restore($this->context);
 }
コード例 #17
0
ファイル: Integer.php プロジェクト: kdyby/money
 /**
  * @param self|int|string|float $arg
  * @throws InvalidArgumentException
  * @return int|float
  */
 protected function valueToNumber($arg)
 {
     if ($arg instanceof self) {
         return $arg->toInt();
     }
     return Math::parseNumber($arg);
 }
コード例 #18
0
ファイル: form.php プロジェクト: degami/php-forms-api
 /**
  * return field value
  * @return array field value
  */
 public function values()
 {
     return array('latitude' => $this->latitude->values(), 'longitude' => $this->longitude->values());
 }
コード例 #19
0
ファイル: flash.php プロジェクト: jordanmanning/ezpublish
 /**
  * Render text depending of font type and available font extensions
  * 
  * @param string $id 
  * @param string $text 
  * @param string $chars 
  * @param int $type 
  * @param string $path 
  * @param ezcGraphColor $color 
  * @param ezcGraphCoordinate $position 
  * @param float $size 
  * @param float $rotation 
  * @return void
  */
 protected function renderText($id, $text, $chars, $type, $path, ezcGraphColor $color, ezcGraphCoordinate $position, $size, $rotation = null)
 {
     $movie = $this->getDocument();
     $tb = new SWFTextField(SWFTEXTFIELD_NOEDIT);
     $tb->setFont(new SWFFont($path));
     $tb->setHeight($size);
     $tb->setColor($color->red, $color->green, $color->blue, 255 - $color->alpha);
     $tb->addString($text);
     $tb->addChars($chars);
     $object = $movie->add($tb);
     $object->rotate($rotation !== null ? -$rotation->getRotation() : 0);
     $object->moveTo($position->x + ($rotation === null ? 0 : $this->modifyCoordinate($rotation->get(0, 2))), $position->y - $size * (1 + $this->options->lineSpacing) + ($rotation === null ? 0 : $this->modifyCoordinate($rotation->get(1, 2))));
     $object->setName($id);
 }
コード例 #20
0
ファイル: Ceil.php プロジェクト: void-sector/scalar-objects
 /**
  * Ceil a float
  * 
  * @param \Scalar\Float $float eg 13.22222
  * @return float eg 14.0
  */
 public function direct(float $float)
 {
     return ceil($float->getValue());
 }
コード例 #21
0
ファイル: Writer.php プロジェクト: clue/qdatastream
 /**
  * Writes a QTime for the given timestamp or DateTime object
  *
  * The QTime will only carry the number of milliseconds since midnight.
  * This means you should probably only use this for times within the current
  * day.
  *
  * If you pass a timestamp from any other day, it will write the number of
  * milliseconds that passed since that day's midnight. Note that reading
  * this number has no indication this is not the current day, so you're
  * likely going to lose the day information and may end up with wrong dates.
  *
  * The QTime will be sent as the number of milliseconds since midnight,
  * without any awareness of timezone or DST properties. Thus, writing this
  * will assume it is relative to the current timezone. This means that the
  * time "14:10:34.5108" will be 14h after midnight, irrespective of its
  * actual timezone. The receiving side may not be aware of your local
  * timezone, so it can only assume its own local timezone as a base.
  *
  * Make sure to use (i.e. convert via `setTimeZone()`) to the same timezone
  * on both sides or consider using the `writeQDateTime()` method instead,
  * which uses absolute time stamps and does not suffer from this.
  *
  * You can also pass a Unix timestamp to this function, this will be assumed
  * to be relative to the local midnight timestamp. If you need more control
  * over your timezone, consider passing a `DateTime` object instead.
  *
  * @param DateTime|float $timestamp
  * @see self::writeQDateTime
  */
 public function writeQTime($timestamp)
 {
     if ($timestamp instanceof \DateTime) {
         $msec = $timestamp->format('H') * 3600000 + $timestamp->format('i') * 60000 + $timestamp->format('s') * 1000 + (int) ($timestamp->format('0.u') * 1000);
     } else {
         $msec = round(($timestamp - strtotime('midnight', (int) $timestamp)) * 1000);
     }
     $this->writer->writeUInt32BE($msec);
 }
コード例 #22
0
 /**
  * @see Object_Class_Data::getVersionPreview
  * @param float $data
  * @return float
  */
 public function getVersionPreview($data)
 {
     if ($data instanceof \Pimcore\Model\Object\Data\IndexFieldSelection) {
         return $data->getTenant() . " " . $data->getField() . " " . $data->getPreSelect();
     }
     return "";
 }
コード例 #23
0
ファイル: Authorizenet.php プロジェクト: aiesh/magento2
 /**
  * Set split_tender_id to quote payment if needed
  *
  * @param \Magento\Framework\Object $response
  * @param float $orderPayment
  * @throws \Magento\Payment\Model\Info\Exception
  * @return bool
  */
 protected function _processPartialAuthorizationResponse($response, $orderPayment)
 {
     if (!$response->getSplitTenderId()) {
         return false;
     }
     $quotePayment = $orderPayment->getOrder()->getQuote()->getPayment();
     $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
     $exceptionMessage = null;
     try {
         switch ($response->getResponseCode()) {
             case self::RESPONSE_CODE_APPROVED:
                 $this->_registerCard($response, $orderPayment);
                 $this->_clearAssignedData($quotePayment);
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
                 return true;
             case self::RESPONSE_CODE_HELD:
                 if ($response->getResponseReasonCode() != self::RESPONSE_REASON_CODE_PARTIAL_APPROVE) {
                     return false;
                 }
                 if ($this->getCardsStorage($orderPayment)->getCardsCount() + 1 >= self::PARTIAL_AUTH_CARDS_LIMIT) {
                     $this->cancelPartialAuthorization($orderPayment);
                     $this->_clearAssignedData($quotePayment);
                     $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_CARDS_LIMIT_EXCEEDED);
                     $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                     $exceptionMessage = __('You have reached the maximum number of credit cards ' . 'allowed to be used for the payment.');
                     break;
                 }
                 $orderPayment->setAdditionalInformation($this->_splitTenderIdKey, $response->getSplitTenderId());
                 $this->_registerCard($response, $orderPayment);
                 $this->_clearAssignedData($quotePayment);
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
                 $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                 $exceptionMessage = null;
                 break;
             case self::RESPONSE_CODE_DECLINED:
             case self::RESPONSE_CODE_ERROR:
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
                 $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                 $exceptionMessage = $this->_wrapGatewayError($response->getResponseReasonText());
                 break;
             default:
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
                 $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                 $exceptionMessage = $this->_wrapGatewayError(__('Something went wrong while authorizing the partial payment.'));
         }
     } catch (\Exception $e) {
         $exceptionMessage = $e->getMessage();
     }
     throw new \Magento\Payment\Model\Info\Exception($exceptionMessage);
 }
コード例 #24
0
ファイル: QuantityValue.php プロジェクト: rolandstoll/pimcore
 /**
  * @see Object_Class_Data::getVersionPreview
  * @param float $data
  * @return float
  */
 public function getVersionPreview($data)
 {
     if ($data instanceof \Object_Data_QuantityValue) {
         return $data->getValue() . " " . $data->getUnit()->getAbbreviation();
     }
     return "";
 }
コード例 #25
0
ファイル: Currency.php プロジェクト: nevvermind/zf2
 /**
  * Internal method which calculates the exchanges currency
  *
  * @param float|integer|Zend\Currency\Currency $value    Compares the currency with this value
  * @param string|Zend\Currency\Currency        $currency The currency to compare this value from
  * @return float
  */
 protected function _exchangeCurrency($value, $currency)
 {
     if ($value instanceof Currency) {
         $currency = $value->getShortName();
         $value = $value->getValue();
     } else {
         $currency = $this->getShortName($currency, $this->getLocale());
     }
     $rate = 1;
     if ($currency !== $this->getShortName()) {
         $service = $this->getService();
         if (!$service instanceof CurrencyService) {
             throw new Exception\RuntimeException('No exchange service applied');
         }
         $rate = $service->getRate($currency, $this->getShortName());
     }
     $value *= $rate;
     return $value;
 }
コード例 #26
0
ファイル: date.php プロジェクト: alanaipe2015/moodle
 /**
  * Normalise the timezone name. If timezone not supported
  * this method falls back to server timezone (if valid)
  * or default PHP timezone.
  *
  * @param int|string|float|DateTimeZone $tz
  * @return string timezone compatible with PHP
  */
 public static function normalise_timezone($tz)
 {
     global $CFG;
     if ($tz instanceof DateTimeZone) {
         return $tz->getName();
     }
     self::init_zones();
     $tz = (string) $tz;
     if (isset(self::$goodzones[$tz]) or isset(self::$bczones[$tz])) {
         return $tz;
     }
     $fixed = false;
     if (isset(self::$badzones[$tz])) {
         // Convert to known zone.
         $tz = self::$badzones[$tz];
         $fixed = true;
     } else {
         if (is_number($tz)) {
             // Half hour numeric offsets were already tested, try rounding to integers here.
             $roundedtz = (string) (int) $tz;
             if (isset(self::$badzones[$roundedtz])) {
                 $tz = self::$badzones[$roundedtz];
                 $fixed = true;
             }
         }
     }
     if ($fixed and isset(self::$goodzones[$tz]) or isset(self::$bczones[$tz])) {
         return $tz;
     }
     // Is server timezone usable?
     if (isset($CFG->timezone) and !is_numeric($CFG->timezone)) {
         $result = @timezone_open($CFG->timezone);
         // Hide notices if invalid.
         if ($result !== false) {
             return $result->getName();
         }
     }
     // Bad luck, use the php.ini default or value set in config.php.
     return self::get_default_php_timezone();
 }
コード例 #27
0
ファイル: cairo_oo.php プロジェクト: Adeelgill/livehelperchat
 /**
  * Render text depending of font type and available font extensions
  * 
  * @param string $id 
  * @param string $text 
  * @param string $font 
  * @param ezcGraphColor $color 
  * @param ezcGraphCoordinate $position 
  * @param float $size 
  * @param float $rotation 
  * @return void
  */
 protected function renderText($text, $font, ezcGraphColor $color, ezcGraphCoordinate $position, $size, $rotation = null)
 {
     $this->context->selectFontFace($font, CairoFontSlant::NORMAL, CairoFontWeight::NORMAL);
     $this->context->setFontSize($size);
     // Store current state of context
     $this->context->save();
     $this->context->moveTo(0, 0);
     if ($rotation !== null) {
         // Move to the center
         $this->context->translate($rotation->getCenter()->x, $rotation->getCenter()->y);
         // Rotate around text center
         $this->context->rotate(deg2rad($rotation->getRotation()));
         // Center the text
         $this->context->translate($position->x - $rotation->getCenter()->x, $position->y - $rotation->getCenter()->y - $size * 0.15);
     } else {
         $this->context->translate($position->x, $position->y - $size * 0.15);
     }
     $this->context->newPath();
     $this->getStyle($color, true);
     $this->context->showText($text);
     $this->context->stroke();
     // Restore state of context
     $this->context->restore();
 }
コード例 #28
0
ファイル: QuantityValue.php プロジェクト: pimcore/pimcore
 /**
  * @see Object_Class_Data::getVersionPreview
  * @param float $data
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return float
  */
 public function getVersionPreview($data, $object = null, $params = [])
 {
     if ($data instanceof \Pimcore\Model\Object\Data\QuantityValue) {
         $unit = "";
         if ($data->getUnitId()) {
             $unitDefinition = Model\Object\QuantityValue\Unit::getById($data->getUnitId());
             if ($unitDefinition) {
                 $unit = " " . $unitDefinition->getAbbreviation();
             }
         }
         return $data->getValue() . $unit;
     }
     return "";
 }
コード例 #29
0
 /**
  * Internal method which calculates the exchanges currency
  *
  * @param float|integer|Zend_Currency $value    Compares the currency with this value
  * @param string|Zend_Currency        $currency The currency to compare this value from
  * @return unknown
  */
 protected function _exchangeCurrency($value, $currency)
 {
     if ($value instanceof Zend_Currency) {
         $currency = $value->getShortName();
         $value = $value->getValue();
     } else {
         $currency = $this->getShortName($currency, $this->getLocale());
     }
     $rate = 1;
     if ($currency !== $this->getShortName()) {
         $service = $this->getService();
         if (!$service instanceof Zend_Currency_CurrencyInterface) {
             require_once 'Zend/Currency/Exception.php';
             throw new Zend_Currency_Exception('No exchange service applied');
         }
         $rate = $service->getRate($currency, $this->getShortName());
     }
     $value *= $rate;
     return $value;
 }
コード例 #30
0
ファイル: Handler.php プロジェクト: pavelnovitsky/magento2
 /**
  * Convert service response into format acceptable by SoapServer.
  *
  * @param object|array|string|int|float|null $data
  * @return array
  * @throws \InvalidArgumentException
  */
 protected function _prepareResponseData($data)
 {
     $result = null;
     if ($data instanceof AbstractSimpleObject) {
         $result = $this->_dataObjectConverter->convertKeysToCamelCase($data->__toArray());
     } elseif (is_array($data)) {
         foreach ($data as $key => $value) {
             if ($value instanceof AbstractSimpleObject) {
                 $result[] = $this->_dataObjectConverter->convertKeysToCamelCase($value->__toArray());
             } else {
                 $result[$key] = $value;
             }
         }
     } elseif (is_scalar($data) || is_null($data)) {
         $result = $data;
     } else {
         throw new \InvalidArgumentException("Service returned result in invalid format.");
     }
     return array(self::RESULT_NODE_NAME => $result);
 }