示例#1
0
 /**
  * Retrieves the field from the object and returns the desired field, if exists.
  * @param string The name of the called method
  * @param string The name of the field to retrieve
  * @param array The arguments given to the function call
  * @return mixed The requested field
  */
 private final function retrieveField($name, $fieldName, array $arguments)
 {
     $fieldMap = self::validateMap(self::$fieldMap);
     $virtualMap = self::validateMap(self::$virtualMap);
     $dataMap = $this->validateInstanceMap($this->data);
     //check for the existance of a property that adheres to the given fieldName
     if ($fieldMap->keyExists($fieldName)) {
         $fieldData = $fieldMap->{$fieldName};
         //first check if we are allowed to access this field
         if (isset($fieldData['noget']) && mb_strtolower((string) $fieldData['noget']) == 'true') {
             throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not exist in this context.');
         }
         //we retrieve the data from the object
         $value = $dataMap->{$fieldName};
         //if the internal data equals the optional nullify property, we pretend the value to be an empty string, thus uninitialized.
         if (isset($fieldData['nullify']) && (string) $fieldData['nullify'] == $value) {
             $value = '';
         }
         //we interpret our data as the given type
         switch (mb_strtolower((string) $fieldData['type'])) {
             case \System\Type::TYPE_TIMESTAMP:
                 return \System\Calendar\Time::fromMySQLTimestamp($value);
             case \System\Type::TYPE_BOOL:
             case \System\Type::TYPE_BOOLEAN:
                 return (bool) $value;
             case \System\Type::TYPE_SERIALIZED:
                 //this type is deprecated and we try to convert current existing fields to array type
             //this type is deprecated and we try to convert current existing fields to array type
             case \System\Type::TYPE_ARRAY:
                 return self::decodeArray($value);
             case \System\Type::TYPE_INT:
             case \System\Type::TYPE_INTEGER:
                 return (int) $value;
             default:
                 return $value;
         }
     } elseif ($virtualMap->keyExists($fieldName)) {
         //we can use different databases, but default to one used by this instance
         $db = $this->getDatabase();
         //first check the parameter count
         if (count($arguments) > 1 || count($arguments) == 1 && !$arguments[0] instanceof \System\Db\Database) {
             throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not accept the given parameters. Expected: ' . $this->getClassName() . '->' . $name . '(\\System\\Db\\Database) or ' . $this->getClassName() . '->' . $name . '().');
         }
         //check if there is an optional database given to use for the virtual function
         if (count($arguments) == 1 && $arguments[0] instanceof \System\Db\Database) {
             $db = $arguments[0];
         }
         $virtualMethod = $virtualMap->{$fieldName};
         $parameters = new \System\Collection\Vector();
         //virtuals only have <value> nodes as children
         foreach ($virtualMethod->children() as $parameterElement) {
             //during the creation of the object we included these fields, so we dont need to check their existence in the field list; we know they exist.
             $queryField = 'virtual_' . (string) $parameterElement;
             $parameters->add($dataMap[$queryField]);
         }
         //do we want the result as a set?
         $alwaysUseContainer = isset($virtualMethod['alwaysusecontainer']) && (mb_strtolower((string) $virtualMethod['alwaysusecontainer']) == 'true' || mb_strtolower((string) $virtualMethod['alwaysusecontainer']) == 'yes');
         return \System\Db\Object::load($db, (string) $virtualMethod['type'], (string) $virtualMethod['condition'], $parameters, $alwaysUseContainer);
     } else {
         throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not exist in this context.');
     }
 }
示例#2
0
 /**
  * Function to check if the given time falls between starttime and stoptime of the current starsign
  * @param \System\Calendar\Time the time to check
  * @return boolean indicating if the given time falls betwqeen starttime and stoptime of the current starsign
  */
 protected final function containsDate(\System\Calendar\Time $time)
 {
     return $time->getMonth() == $this->startTime->getMonth() && $time->GetDay() >= $this->startTime->getDay() || $time->getMonth() == $this->stopTime->getMonth() && $time->getDay() <= $this->stopTime->getDay();
 }
示例#3
0
 /**
  * Compares two Times with eachother. When the given parameter is before
  * the current Time object, then we return \System\Math\Math::COMPARE_LESSTHAN,
  * if it equals we return \System\Math\Math::COMPARE_EQUAL, else \System\Math\Math::COMPARE_GREATERTHAN.
  * @param \System\Calendar\Time A Time object to compare with.
  * @return int An integer representing the equality.
  */
 public final function compare(\System\Calendar\Time $time)
 {
     if ($this->toUNIX() == $time->toUNIX()) {
         return \System\Math\Math::COMPARE_EQUAL;
     }
     return $this->toUNIX() > $time->toUNIX() ? \System\Math\Math::COMPARE_LESSTHAN : \System\Math\Math::COMPARE_GREATERTHAN;
 }
示例#4
0
 /**
  * Sets the modified time of the file
  * @param \System\Calendar\Time The modified time
  * @return File The current instance
  */
 public final function setModifiedTime(\System\Calendar\Time $time)
 {
     touch($this->getAbsoluteFilename(), $time->toUNIX(), fileatime($this->fullPath));
     return $this;
 }
示例#5
0
 /**
  * Returns the amount of days between two given times. The order of the Time objects is not relevant.
  * @param \System\Calendar\Time The first time
  * @param \System\Calendar\Time The second time
  * @return int The amount of days between the given Time objects
  */
 public static final function getAmountOfDaysBetweenTimes(\System\Calendar\Time $time1, \System\Calendar\Time $time2)
 {
     $diff = abs($time1->toUNIX() - $time2->toUNIX());
     return floor($diff / \System\Calendar\Time::SECONDS_IN_DAY);
 }
示例#6
0
 /**
  * Get the timestamp of the onetimecall object
  * @return \System\Calendar\Time the converted timestamp object
  */
 public final function getTimestamp()
 {
     return \System\Calendar\Time::fromMySQLTimestamp($this->internal('getTimestamp'));
 }