Example #1
0
 /**
  * Commit changes to this date
  */
 public function commit()
 {
     $this->validate();
     $data = array("date" => $this->Date->format("Y-m-d"), "text" => $this->text, "meta" => json_encode($this->meta), "location_id" => $this->Location->id, "type_id" => $this->Type->id);
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         // Update
         $where = array("id = ?" => $this->id);
         $this->db->update("location_date", $data, $where);
     } else {
         // Insert
         $this->db->insert("location_date", $data);
         $this->id = $this->db->lastInsertId();
     }
     return true;
 }
Example #2
0
 /**
  * Commit changes to a sighting
  * @since Version 3.5
  */
 public function commit()
 {
     $this->validate();
     $data = array("date" => $this->date->format("Y-m-d H:i:s"), "date_added" => $this->date_added->format("Y-m-d H:i:s"), "lat" => $this->lat, "lon" => $this->lon, "text" => $this->text, "traincode" => $this->train_number, "user_id" => $this->user_id, "timezone" => $this->timezone, "loco_ids" => implode(",", array_map('intval', $this->loco_ids)));
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $where = array("id = ?" => $this->id);
         $this->db->update("sighting", $data, $where);
     } else {
         $this->db->insert("sighting", $data);
         $this->id = $this->db->lastInsertId();
     }
     /*
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $where = array(
             "sighting_id = ?" => $this->id
         );
         
         $this->db->delete("sighting_locos", $where); 
         
         foreach ($this->loco_ids as $loco_id) {
             $data = array(
                 "sighting_id" => $this->id,
                 "loco_id" => $loco_id
             );
             
             $this->db->insert("sighting_locos", $data); 
         }
     }
     */
     return true;
 }
Example #3
0
 /**
  * Return last day of current month
  *
  * @since  Oct, 18 2016
  * @return integer
  */
 public function lastDayMonth()
 {
     $days = 0;
     switch ($this->calendar_type) {
         case 'gregorian':
             $days = intval($this->date_time->format('m')) == 2 && $this->config['leap_year']($this->date_time->format('Y')) ? $this->config['month_days_number'][intval($this->date_time->format('m'))] + 1 : $this->config['month_days_number'][intval($this->date_time->format('m'))];
             break;
         case 'jalali':
             $days = intval($this->date_time->format('m')) == 12 && $this->config['leap_year']($this->date_time->format('Y')) ? $this->config['month_days_number'][intval($this->date_time->format('m'))] + 1 : $this->config['month_days_number'][intval($this->date_time->format('m'))];
             break;
         default:
             $days = $this->config['month_days_number'][intval($this->date_time->format('m'))];
             break;
     }
     return $days;
 }
 /**
  * @param object $object
  * @param string $format
  * @param array  $context
  *
  * @return string
  */
 public function normalize($object, $format = null, array $context = array())
 {
     if (!$object instanceof \DateTimeInterface) {
         throw new InvalidArgumentException('The object must implement the "\\DateTimeInterface".');
     }
     $format = isset($context[static::CONTEXT_FORMAT]) ? $context[self::CONTEXT_FORMAT] : $this->format;
     return $object->format($format);
 }
 /**
  * Return a formatted date string.
  *
  * @param int|object|string $date
  * @param string            $format
  *
  * @return string
  */
 public function dateFormat($date, string $format = 'M d Y') : string
 {
     if ($date instanceof DateTime) {
         return $date->format($format);
     } elseif (is_int($date)) {
         return date($format, $date);
     }
     return date($format, strtotime($date));
 }
 /**
  * @param $datetime
  * @return string
  * @throws EE_Error
  */
 private function _convert_from_string_value_to_utc_unix_timestamp($datetime)
 {
     //create a new datetime object using the given string and timezone
     $this->_set_date_obj($datetime, $this->_timezone);
     if (!$this->_date instanceof DateTime && !$this->_nullable) {
         throw new EE_Error(__('Something went wrong with setting the date/time. Likely, either there is an invalid datetime string or an invalid timezone string being used.', 'event_espresso'));
     }
     $this->_date->setTimezone(EE_Datetime_Field::get_UTC_DateTimeZone());
     return $this->_date->format('U');
 }
Example #7
0
 /**
  * @param object $object
  * @return array
  */
 private function toArray($object)
 {
     if ($object instanceof DateTimeInterface) {
         return ['time' => $object->format('Y-m-d\\TH:i:s.uO')];
     }
     if ($object instanceof UuidInterface) {
         return ['uuid' => (string) $object];
     }
     return $this->extractValuesFromObject($object);
 }
Example #8
0
 /**
  * Save changes
  * @since Version 3.10.0
  * @return \Railpage\Content\Page
  */
 public function commit()
 {
     $this->validate();
     $data = ["title" => $this->title, "subtitle" => $this->subtitle, "active" => $this->active, "page_header" => $this->header, "text" => $this->body, "page_footer" => $this->footer, "date" => $this->date->format("Y-m-d H:i:s"), "counter" => $this->hits, "clanguage" => $this->language, "shortname" => $this->permalink];
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $where = ["pid = ?" => $this->id];
         $this->db->update("nuke_pages", $data, $where);
         return $this;
     }
     $this->db->insert("nuke_pages", $data);
     $this->id = $this->db->lastInsertId();
     return $this;
 }
Example #9
0
 /**
  * Commit changes to this link
  * @since Version 3.7.5
  * @return boolean
  */
 public function commit()
 {
     $this->validate();
     $data = array("cid" => $this->Category->id, "title" => $this->name, "url" => $this->url, "description" => $this->desc, "date" => $this->Date->format("Y-m-d H:i:s"), "user_id" => $this->user_id, "link_broken" => intval($this->broken), "link_approved" => intval($this->approved));
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $where = array("lid = ?" => $this->id);
         $rs = $this->db->update("nuke_links_links", $data, $where);
     } else {
         $rs = $this->db->insert("nuke_links_links", $data);
         $this->id = $this->db->lastInsertId();
     }
     return $rs;
 }
Example #10
0
 /**
  * Reads a string representation from an object
  *
  * @param object $object The object
  *
  * @return string
  */
 protected static function readObject($object) : string
 {
     if ($object instanceof Closure) {
         return 'Function';
     }
     if ($object instanceof DateTime) {
         return sprintf('DateTime(%s)', $object->format('Y-m-d\\TH:i:sP'));
     }
     if (method_exists($object, 'toString')) {
         return (string) $object->toString();
     }
     if (method_exists($object, '__toString')) {
         return (string) $object;
     }
     return sprintf('Object(%s)', get_class($object));
 }
Example #11
0
 /**
  * Specifies the start and end year to use as a date range.
  *
  * Handles a string like -3:+3 or 2001:2010 to describe a dynamic range of
  * minimum and maximum years to use in a date selector.
  *
  * Centers the range around the current year, if any, but expands it far enough
  * so it will pick up the year value in the field in case the value in the field
  * is outside the initial range.
  *
  * @param string $string
  *   A min and max year string like '-3:+1' or '2000:2010' or '2000:+3'.
  * @param object $date
  *   (optional) A date object to test as a default value. Defaults to NULL.
  *
  * @return array
  *   A numerically indexed array, containing the minimum and maximum year
  *   described by this pattern.
  */
 protected static function datetimeRangeYears($string, $date = NULL)
 {
     $datetime = new DrupalDateTime();
     $this_year = $datetime->format('Y');
     list($min_year, $max_year) = explode(':', $string);
     // Valid patterns would be -5:+5, 0:+1, 2008:2010.
     $plus_pattern = '@[\\+|\\-][0-9]{1,4}@';
     $year_pattern = '@^[0-9]{4}@';
     if (!preg_match($year_pattern, $min_year, $matches)) {
         if (preg_match($plus_pattern, $min_year, $matches)) {
             $min_year = $this_year + $matches[0];
         } else {
             $min_year = $this_year;
         }
     }
     if (!preg_match($year_pattern, $max_year, $matches)) {
         if (preg_match($plus_pattern, $max_year, $matches)) {
             $max_year = $this_year + $matches[0];
         } else {
             $max_year = $this_year;
         }
     }
     // We expect the $min year to be less than the $max year. Some custom values
     // for -99:+99 might not obey that.
     if ($min_year > $max_year) {
         $temp = $max_year;
         $max_year = $min_year;
         $min_year = $temp;
     }
     // If there is a current value, stretch the range to include it.
     $value_year = $date instanceof DrupalDateTime ? $date->format('Y') : '';
     if (!empty($value_year)) {
         $min_year = min($value_year, $min_year);
         $max_year = max($value_year, $max_year);
     }
     return array($min_year, $max_year);
 }
Example #12
0
 /**
  * Returns number of days to start of this week.
  *
  * @brief      Days number
  *
  * @author     =stid= <*****@*****.**>
  *
  * @param object $date Date object
  * @param string $first_day
  *
  * @return int $date
  */
 public static function daysToWeekStart($date, $first_day = 'monday')
 {
     $week_days = array('monday' => 0, 'tuesday' => 1, 'wednesday' => 2, 'thursday' => 3, 'friday' => 4, 'saturday' => 5, 'sunday' => 6);
     $start_day_number = $week_days[$first_day];
     $wday = $date->format("w");
     $current_day_number = $wday != 0 ? $wday - 1 : 6;
     return WPDKMath::rModulus($current_day_number - $start_day_number, 7);
 }
Example #13
0
 /**
  * Generate JSON object for this article
  * @since Version 3.8.7
  * @return string
  */
 public function makeJSON()
 {
     if ($this->date instanceof DateTime) {
         $timezone = $this->date->getTimezone();
     } else {
         $timezone = new DateTimeZone("Australia/Melbourne");
     }
     if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
         throw new Exception("Cannot make a JSON object for the requested news article beacuse no valid article ID was found. Something's wrong....");
     }
     $response = array("namespace" => $this->Module->namespace, "module" => $this->Module->name, "article" => array("id" => $this->id, "title" => $this->title, "hits" => $this->hits, "blub" => is_object($this->blurb) ? $this->blurb->__toString() : $this->blurb, "body" => is_object($this->body) ? $this->body->__toString() : $this->body, "image" => $this->featured_image, "approved" => $this->approved, "url" => $this->url instanceof Url ? $this->url->getURLs() : array("url" => sprintf("/news/article-%d", $this->id)), "topic" => array("id" => $this->Topic->id, "title" => $this->Topic->title, "url" => $this->Topic->url instanceof Url ? $this->Topic->url->getURLs() : array("url" => sprintf("/news/topic-%d", $this->Topic->id))), "thread" => array("id" => $this->topic_id, "url" => array("view" => filter_var($this->topic_id, FILTER_VALIDATE_INT) ? sprintf("/f-t%d.htm", $this->topic_id) : "")), "date" => array("absolute" => $this->date->format("Y-m-d H:i:s"), "timezone" => $timezone->getName(), "unixtime" => $this->date->getTimestamp()), "author" => array("id" => $this->Author->id, "username" => $this->Author->username, "url" => array("view" => $this->Author->url instanceof Url ? $this->Author->url->url : $this->Author->url)), "staff" => array("id" => $this->Staff->id, "username" => $this->Staff->username, "url" => array("view" => $this->Staff->url instanceof Url ? $this->Staff->url->url : $this->Staff->url))));
     $response = json_encode($response);
     setMemcacheObject(sprintf("json:railpage.news.article=%d", $this->id), $response);
     return $response;
 }
Example #14
0
 /**
  * Converts the given $object to a string representation considering the $element FormElement definition
  *
  * @param FormElementInterface $element
  * @param object $object
  * @return string
  */
 protected function processObject(FormElementInterface $element, $object) : string
 {
     $properties = $element->getProperties();
     if ($object instanceof \DateTime) {
         if (isset($properties['dateFormat'])) {
             $dateFormat = $properties['dateFormat'];
             if (isset($properties['displayTimeSelector']) && $properties['displayTimeSelector'] === true) {
                 $dateFormat .= ' H:i';
             }
         } else {
             $dateFormat = \DateTime::W3C;
         }
         return $object->format($dateFormat);
     }
     if ($object instanceof File || $object instanceof FileReference) {
         if ($object instanceof FileReference) {
             $object = $object->getOriginalResource();
         }
         return $object->getName();
     }
     if (method_exists($object, '__toString')) {
         return (string) $object;
     }
     return 'Object [' . get_class($object) . ']';
 }
Example #15
0
 /**
  * Converts the given $object to a string representation considering the $element FormElement definition
  *
  * @param FormElementInterface $element
  * @param object $object
  * @return string
  */
 protected function processObject(FormElementInterface $element, $object)
 {
     $properties = $element->getProperties();
     if ($object instanceof \DateTime) {
         if (isset($properties['dateFormat'])) {
             $dateFormat = $properties['dateFormat'];
             if (isset($properties['displayTimeSelector']) && $properties['displayTimeSelector'] === true) {
                 $dateFormat .= ' H:i';
             }
         } else {
             $dateFormat = \DateTime::W3C;
         }
         return $object->format($dateFormat);
     }
     if ($object instanceof Image) {
         return sprintf('%s Image (%d x %d)', $object->getFileExtension(), $object->getWidth(), $object->getHeight());
     }
     if (method_exists($object, '__toString')) {
         return (string) $object;
     }
     return 'Object [' . get_class($object) . ']';
 }
 /**
  * check if dates are in scope
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.21.7 - 2015-03-25
  * @param object $start       datetime
  * @param object $scopeStart  datetime
  * @param object $end         datetime
  * @param object $scopeEnd    datetime
  * @param string $format
  * @return bool
  */
 public static function _inScope($start, $scopeStart, $end, $scopeEnd, $format)
 {
     return $start->format($format) >= $scopeStart->format($format) && $end->format($format) <= $scopeEnd->format($format);
 }
Example #17
0
	/**
	 * Gets the localized date according to a specific mask
	 * @param object $datetime A PHP DateTime Object
	 * @param string $mask 
	 * @return string 
	 */
	public function dateTimeFormatLocal(&$datetime,$mask) {
		$locale = new Zend_Locale(Localization::activeLocale());

		$date = new Zend_Date($datetime->format(DATE_ATOM),DATE_ATOM, $locale);
		$date->setTimeZone($datetime->format("e"));
		return $date->toString($mask);
	}
Example #18
0
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param mixed $configuration Configuration for transforming the given object or NULL
  * @return array Object structure as an aray
  */
 protected function transformObject($object, $configuration)
 {
     if ($object instanceof \DateTime) {
         return $object->format('Y-m-d\\TH:i:s');
     } else {
         $propertyNames = \TYPO3\FLOW3\Reflection\ObjectAccess::getGettablePropertyNames($object);
         $propertiesToRender = array();
         foreach ($propertyNames as $propertyName) {
             if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) {
                 continue;
             }
             if (isset($configuration['_exclude']) && is_array($configuration['_exclude']) && in_array($propertyName, $configuration['_exclude'])) {
                 continue;
             }
             $propertyValue = \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($object, $propertyName);
             if (!is_array($propertyValue) && !is_object($propertyValue)) {
                 $propertiesToRender[$propertyName] = $propertyValue;
             } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) {
                 $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]);
             }
         }
         if (isset($configuration['_exposeObjectIdentifier']) && $configuration['_exposeObjectIdentifier'] === TRUE) {
             if (isset($configuration['_exposedObjectIdentifierKey']) && strlen($configuration['_exposedObjectIdentifierKey']) > 0) {
                 $identityKey = $configuration['_exposedObjectIdentifierKey'];
             } else {
                 $identityKey = '__identity';
             }
             $propertiesToRender[$identityKey] = $this->persistenceManager->getIdentifierByObject($object);
         }
         return $propertiesToRender;
     }
 }
Example #19
0
 /**
  * Useful method for formatting data before passing
  * it into the make method. Totally optional and
  * need not be included in your template if you
  * don't need it.
  * 
  * @param  array  $order        OpenCart order array as example
  * @param  object $currency     OpenCart currency object as example
  * @return array  $data
  */
 public function format(array $order, $currency)
 {
     $data = ['name' => $order["firstname"] . ' ' . $order["lastname"], 'order_id' => $order["order_id"], 'total' => $currency->format($order["total"])];
     return $data;
 }
Example #20
0
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param array $configuration Configuration for transforming the given object
  * @param boolean $onlyIdentifier
  * @return array Object structure as an array
  * @todo implement sideloading
  */
 protected function transformObject($object, array $configuration, $onlyIdentifier = TRUE)
 {
     if ($object instanceof \DateTime) {
         return $object->format('Y-m-d\\TH:i:s');
     } elseif ($onlyIdentifier === TRUE) {
         $objectIdentifier = $this->persistenceManager->getIdentifierByObject($object);
         if ($objectIdentifier === NULL && method_exists($object, 'getId')) {
             $objectIdentifier = $object->getId();
         }
         return $objectIdentifier;
     } else {
         $transformedObject = array();
         if ($this->excludeIdentifier === FALSE) {
             $objectIdentifier = $this->persistenceManager->getIdentifierByObject($object);
             $transformedObject['id'] = $objectIdentifier;
         }
         $propertyNames = ObjectAccess::getGettablePropertyNames($object);
         foreach ($propertyNames as $propertyName) {
             if (substr($propertyName, 0, 1) !== '_') {
                 if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) {
                     continue;
                 }
                 if ($this->propertyIsExcluded($propertyName, $configuration)) {
                     continue;
                 }
                 $propertyValue = ObjectAccess::getProperty($object, $propertyName);
                 $objectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($object));
                 if (!$this->reflectionService->isPropertyAnnotatedWith($objectName, $propertyName, 'TYPO3\\Flow\\Annotations\\Transient')) {
                     if (is_array($propertyValue) || $propertyValue instanceof \ArrayAccess) {
                         $transformedObject[EmberDataUtility::uncamelize($propertyName)] = $this->transformValue($propertyValue, array());
                     } elseif ($propertyValue instanceof \DateTime) {
                         $transformedObject[EmberDataUtility::uncamelize($propertyName)] = $propertyValue->format('Y-m-d\\TH:i:s');
                     } elseif (is_object($propertyValue)) {
                         $objectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($object));
                         if ($this->objectManager->getScope($objectName) !== \TYPO3\Flow\Object\Configuration\Configuration::SCOPE_SINGLETON) {
                             $transformedObject[EmberDataUtility::uncamelize($propertyName) . '_id'] = $this->persistenceManager->getIdentifierByObject($propertyValue);
                             if (isset($configuration['sideloadedAssociations']) && in_array($propertyName, $configuration['sideloadedAssociations'])) {
                                 // sideload this propertyvalue
                             }
                         }
                     } else {
                         $transformedObject[EmberDataUtility::uncamelize($propertyName)] = $propertyValue;
                     }
                 }
             }
         }
         return $transformedObject;
     }
 }
Example #21
0
 /**
  * Handles a message.
  *
  * @param  integer  $code  Log level code.
  * @param  string  $message  Message to handle.
  *
  * @return  void
  */
 public function handle($code, $message)
 {
     if ($code >= $this->_level) {
         $message = $this->_formatter->format($code, $message);
         $this->_make_writeable();
         fwrite($this->_output, $message);
     }
 }
Example #22
0
 /**
  * Formats the response according the invoked action.
  * Performs a content negotiation with the request if the applicable format is `true`;
  *
  * @param object $request  A request instance.
  * @param object $response A response instance.
  * @param string $action   The action name.
  */
 protected function _format($request, $response, $action)
 {
     if (!is_array($this->_formats)) {
         $format = $this->_formats;
     } elseif (isset($this->_formats[$action])) {
         $format = $this->_formats[$action];
     } elseif (isset($this->_formats[0])) {
         $format = $this->_formats[0];
     } else {
         $format = true;
     }
     if ($format === true) {
         $response->negotiate($request);
     } elseif ($format) {
         $response->format($format);
     }
 }
Example #23
0
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param mixed $configuration Configuration for transforming the given object or NULL
  * @return array Object structure as an aray
  * @author Christopher Hlubek <*****@*****.**>
  * @author Dennis Ahrens <*****@*****.**>
  */
 protected function transformObject($object, $configuration)
 {
     // hand over DateTime as ISO formatted string
     if ($object instanceof DateTime) {
         return $object->format('c');
     }
     // load LayzyLoadingProxy instances
     if ($object instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
         $object = $object->_loadRealInstance();
     }
     $propertyNames = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames($object);
     $propertiesToRender = array();
     foreach ($propertyNames as $propertyName) {
         if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) {
             continue;
         }
         if (isset($configuration['_exclude']) && is_array($configuration['_exclude']) && in_array($propertyName, $configuration['_exclude'])) {
             continue;
         }
         $propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($object, $propertyName);
         if (!is_array($propertyValue) && !is_object($propertyValue)) {
             $propertiesToRender[$propertyName] = $propertyValue;
         } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) {
             $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]);
         } else {
         }
     }
     if (isset($configuration['_exposeObjectIdentifier']) && $configuration['_exposeObjectIdentifier'] === true) {
         // we don't use the IdentityMap like its done in FLOW3 because there are some cases objects are not registered there.
         // TODO: rethink this solution - it is really quick and dirty...
         $propertiesToRender['__identity'] = $object->getUid();
     }
     return $propertiesToRender;
 }
Example #24
0
 /**
  * Formats the value $value according to the action of the option and 
  * updates the passed Console_CommandLine_Result object.
  *
  * @param mixed                      $value  The value to format
  * @param Console_CommandLine_Result $result The result instance
  * @param Console_CommandLine        $parser The parser instance
  *
  * @return void
  * @throws Console_CommandLine_Exception
  */
 public function dispatchAction($value, $result, $parser)
 {
     $actionInfo = Console_CommandLine::$actions[$this->action];
     if (true === $actionInfo[1]) {
         // we have a "builtin" action
         $tokens = explode('_', $actionInfo[0]);
         include_once implode('/', $tokens) . '.php';
     }
     $clsname = $actionInfo[0];
     if ($this->_action_instance === null) {
         $this->_action_instance = new $clsname($result, $this, $parser);
     }
     // check value is in option choices
     if (!empty($this->choices) && !in_array($this->_action_instance->format($value), $this->choices)) {
         throw Console_CommandLine_Exception::factory('OPTION_VALUE_NOT_VALID', array('name' => $this->name, 'choices' => implode('", "', $this->choices), 'value' => $value), $parser, $this->messages);
     }
     $this->_action_instance->execute($value, $this->action_params);
 }
Example #25
0
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param array $configuration Configuration for transforming the given object or NULL
  * @return array Object structure as an array
  */
 protected function transformObject($object, array $configuration)
 {
     if ($object instanceof \DateTime) {
         return $object->format(\DateTime::ISO8601);
     } else {
         $propertyNames = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames($object);
         $propertiesToRender = array();
         foreach ($propertyNames as $propertyName) {
             if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) {
                 continue;
             }
             if (isset($configuration['_exclude']) && is_array($configuration['_exclude']) && in_array($propertyName, $configuration['_exclude'])) {
                 continue;
             }
             $propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($object, $propertyName);
             if (!is_array($propertyValue) && !is_object($propertyValue)) {
                 $propertiesToRender[$propertyName] = $propertyValue;
             } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) {
                 $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]);
             }
         }
         if (isset($configuration['_exposeObjectIdentifier']) && $configuration['_exposeObjectIdentifier'] === TRUE) {
             if (isset($configuration['_exposedObjectIdentifierKey']) && strlen($configuration['_exposedObjectIdentifierKey']) > 0) {
                 $identityKey = $configuration['_exposedObjectIdentifierKey'];
             } else {
                 $identityKey = '__identity';
             }
             $propertiesToRender[$identityKey] = $this->persistenceManager->getIdentifierByObject($object);
         }
         if (isset($configuration['_exposeClassName']) && ($configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED || $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_UNQUALIFIED)) {
             $className = get_class($object);
             $classNameParts = explode('\\', $className);
             $propertiesToRender['__class'] = $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED ? $className : array_pop($classNameParts);
         }
         return $propertiesToRender;
     }
 }
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param array $configuration Configuration for transforming the given object
  * @param boolean $onlyIdentifier
  * @param boolean $enableSideLoading
  * @return array Object structure as an array
  * @todo implement sideloading
  */
 protected function transformObject($object, array $configuration, $onlyIdentifier = TRUE, $enableSideLoading = TRUE)
 {
     if ($object instanceof \DateTime) {
         return $object->format('Y-m-d\\TH:i:s');
     } elseif ($onlyIdentifier === TRUE) {
         return $this->persistenceManager->getIdentifierByObject($object);
     } else {
         $transformedObject = array('id' => $this->persistenceManager->getIdentifierByObject($object));
         $objectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($object));
         foreach (ObjectAccess::getGettablePropertyNames($object) as $propertyName) {
             if ($this->isPropertyIgnored($objectName, $propertyName)) {
                 continue;
             }
             $propertyValue = ObjectAccess::getProperty($object, $propertyName);
             if (is_array($propertyValue) || $propertyValue instanceof \ArrayAccess) {
                 $propertyValue = $this->transformValue($propertyValue, array(), TRUE, $enableSideLoading);
                 if ($this->isRelation($objectName, $propertyName)) {
                     $this->addLink($transformedObject, $propertyName, $propertyValue);
                     if ($enableSideLoading === TRUE && !$this->reflectionService->isPropertyAnnotatedWith($objectName, $propertyName, 'TYPO3\\Flow\\Annotations\\Lazy')) {
                         $propertyTags = $this->reflectionService->getPropertyTagValues($objectName, $propertyName, 'var');
                         $propertyObjectType = TypeHandling::parseType($propertyTags[0]);
                         $this->sideLoad($propertyObjectType['elementType'], $propertyValue);
                     }
                     $propertyValue = NULL;
                 } elseif (empty($propertyValue)) {
                     $propertyValue = NULL;
                 }
             } elseif ($this->isSimpleValue($propertyValue)) {
                 if (is_object($propertyValue)) {
                     $propertyValue = $this->transformObject($propertyValue, $configuration, FALSE, $enableSideLoading);
                 }
             } elseif (is_object($propertyValue)) {
                 $propertyObjectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($propertyValue));
                 if (!$this->isObjectIgnored($propertyObjectName)) {
                     $propertyValue = $this->transformObject($propertyValue, $configuration, TRUE, $enableSideLoading);
                     if ($this->isRelation($objectName, $propertyName)) {
                         $this->addLink($transformedObject, $propertyName, $propertyValue);
                         if ($enableSideLoading === TRUE && !$this->reflectionService->isPropertyAnnotatedWith($objectName, $propertyName, 'TYPO3\\Flow\\Annotations\\Lazy')) {
                             $this->sideLoad($propertyObjectName, $propertyValue);
                         }
                         $propertyValue = NULL;
                     } elseif (empty($propertyValue)) {
                         $propertyValue = NULL;
                     }
                 }
             }
             if ($propertyValue !== NULL) {
                 if (is_object($propertyValue)) {
                     $propertyObjectName = $this->objectManager->getObjectNameByClassName($this->reflectionService->getClassNameByObject($propertyValue));
                     if (!$this->isObjectIgnored($propertyObjectName)) {
                         $transformedObject[$propertyName] = $propertyValue;
                     }
                 } else {
                     $transformedObject[$propertyName] = $propertyValue;
                 }
             }
         }
         return $transformedObject;
     }
 }
Example #27
0
    /**
     * Formats the value $value according to the action of the option and 
     * updates the passed PEAR2\Console\CommandLine_Result object.
     *
     * @param mixed                            $value  The value to format
     * @param PEAR2\Console\CommandLine_Result $result The result instance
     * @param PEAR2\Console\CommandLine        $parser The parser instance
     *
     * @return void
     * @throws PEAR2\Console\CommandLine_Exception
     */
    public function dispatchAction($value, $result, $parser)
    {
        $actionInfo = Console\CommandLine::$actions[$this->action];
        $clsname    = $actionInfo[0];
        if ($this->_action_instance === null) {
            $this->_action_instance  = new $clsname($result, $this, $parser);
        }

        // check value is in option choices
        if (!empty($this->choices) && !in_array($this->_action_instance->format($value), $this->choices)) {
            throw Console\CommandLine\Exception::factory(
                'OPTION_VALUE_NOT_VALID',
                array(
                    'name'    => $this->name,
                    'choices' => implode('", "', $this->choices),
                    'value'   => $value,
                ),
                $parser,
                $this->messages
            );
        }
        $this->_action_instance->execute($value, $this->action_params);
    }
 /**
  * Filters sitewide data that involves a user ID and a datetime by these fields.
  *
  * This mainly applies to sitewide data that closely resembles core NXTClass
  * data, such as the comments and posts, both of which contain information
  * about the originating user and a creation datetime.
  *
  * @param  string $table      the name of the table on which to make a query
  * @param  string $id_field   the name of the field that stores a user ID
  * @param  int    $user_id    the ID of the user who created the content
  * @param  string $date_field the optional name of the field that holds datetime information
  * @param  object $start_dt   an optional DateTime after which to find data
  * @param  object $end_dt     an optional DateTime before which to find data
  * @return array              a list of database results
  *
  * @access protected
  * @since 0.2
  */
 protected function filter_sitewide_resources($table, $id_field, $user_id, $date_field = null, $start_dt = null, $end_dt = null)
 {
     global $nxtdb;
     // Build our base query by user ID and add in any optional parameters
     // required to make the datetime search work properly
     $query = "SELECT * FROM {$table} WHERE {$id_field}=%d";
     $params = array($user_id);
     if ($date_field) {
         if ($start_dt) {
             $query .= " AND {$date_field} >= %s";
             $params[] = $start_dt->format('YmdHis');
         }
         if ($end_dt) {
             $query .= " AND {$date_field} <= %s";
             $params[] = $end_dt->format('YmdHis');
         }
     }
     array_unshift($params, $query);
     // Get the filtered posts using our assembled query
     return $nxtdb->get_results(call_user_func_array(array($nxtdb, 'prepare'), $params));
 }
 /**
  * converts datetime back to xml schema format
  * @access protected
  * @param object $dateTime
  * @return var XML schema formatted timestamp
  */
 private static function _dateTimeToXmlTimestamp($dateTime)
 {
     $dateTime->setTimeZone(new DateTimeZone('UTC'));
     return $dateTime->format('Y-m-d\\TH:i:s') . 'Z';
 }
Example #30
0
/**
 * Alter the dates after they're loaded, before they're added for rendering.
 *
 * @param object $date1
 *   The start date object.
 * @param object $date2
 *   The end date object.
 * @param array $context
 *   An associative array containing the following key-value pairs:
 *   - instance: The field instance.
 *   - entity: The entity object for this date.
 *   - field: The field info.
 */
function hook_fullcalendar_process_dates_alter(&$date1, &$date2, $context)
{
    // Always display dates only on one day.
    if ($date1->format(DATE_FORMAT_DATE) != $date2->format(DATE_FORMAT_DATE)) {
        $date2 = $date1;
    }
}