/** * Overridden constructor. * * @param $time * time string, flexible format including timestamp. * @param $tz * PHP DateTimeZone object, string or NULL allowed, defaults to site timezone. * @param $format * PHP date() type format for parsing. Doesn't support timezones; if you have a timezone, send NULL * and the default constructor method will hopefully parse it. * $format is recommended in order to use negative or large years, which php's parser fails on. */ public function __construct($time = 'now', $tz = NULL, $format = NULL) { $this->timeOnly = FALSE; $this->dateOnly = FALSE; // Allow string timezones if (!empty($tz) && !is_object($tz)) { $tz = new DateTimeZone($tz); } elseif (empty($tz)) { $tz = date_default_timezone_object(); } // Special handling for Unix timestamps expressed in the local timezone. // Create a date object in UTC and convert it to the local timezone. // Don't try to turn things like '2010' with a format of 'Y' into a timestamp. if (is_numeric($time) && (empty($format) || $format == 'U')) { // Assume timestamp. $time = "@" . $time; $date = new DateObject($time, 'UTC'); if ($tz->getName() != 'UTC') { $date->setTimezone($tz); } $time = $date->format(DATE_FORMAT_DATETIME); $format = DATE_FORMAT_DATETIME; } if (is_array($time)) { // Assume we were passed an indexed array. if (empty($time['year']) && empty($time['month']) && empty($time['day'])) { $this->timeOnly = TRUE; } if (empty($time['hour']) && empty($time['minute']) && empty($time['second'])) { $this->dateOnly = TRUE; } $this->errors = $this->arrayErrors($time); // Make this into an ISO date, // forcing a full ISO date even if some values are missing. $time = $this->toISO($time, TRUE); // We checked for errors already, skip the step of parsing the input values. $format = NULL; } // The parse function will also set errors on the date parts. if (!empty($format)) { $arg = self::$allgranularity; $element = array_pop($arg); while (!$this->parse($time, $tz, $format) && $element != 'year') { $element = array_pop($arg); $format = date_limit_format($format, $arg); } if ($element == 'year') { return FALSE; } } elseif (is_string($time)) { // PHP < 5.3 doesn't like the GMT- notation for parsing timezones. $time = str_replace("GMT-", "-", $time); $time = str_replace("GMT+", "+", $time); // We are going to let the parent dateObject do a best effort attempt to turn this // string into a valid date. It might fail and we want to control the error messages. try { @parent::__construct($time, $tz); } catch (Exception $e) { $this->errors['date'] = $e; return; } $this->setGranularityFromTime($time, $tz); } // This tz was given as just an offset, which causes problems, // or the timezone was invalid. if (!$this->getTimezone() || !preg_match('/[a-zA-Z]/', $this->getTimezone()->getName())) { $this->setTimezone(new DateTimeZone("UTC")); } }
if (!empty($node->node_announce_start_date['und'][0]['value'])) { $start = new DateObject($node->node_announce_start_date['und'][0]['value'], new DateTimeZone($node->node_announce_start_date['und'][0]['timezone_db']), 'Y-m-d\\TH:i:s'); $start->setTimeZone(new DateTimeZone($node->node_announce_start_date['und'][0]['timezone'])); } $end = NULL; if (!empty($node->node_announce_end_date['und'][0]['value'])) { $end = new DateObject($node->node_announce_end_date['und'][0]['value'], new DateTimeZone($node->node_announce_end_date['und'][0]['timezone_db']), 'Y-m-d\\TH:i:s'); $end->setTimeZone(new DateTimeZone($node->node_announce_end_date['und'][0]['timezone'])); } if (!empty($node->node_announce_start_date['und'][0]['value'])) { ?> <tr> <td width="45%"> <p style="font-size: 12px; font-weight: normal; color: #56667d; margin: 0;margin-left:17px;"> <?php echo $start->format('d.m.y H:i') . " :: "; echo !empty($node->node_announce_shorttitle['de'][0]['safe_value']) ? $node->node_announce_shorttitle['de'][0]['safe_value'] : $node->node_announce_shorttitle['en'][0]['safe_value']; ?> </p> </td> <td> <p style="font-size: 12px; font-weight: normal; color: #56667d; margin: 0;margin-left:17px;"> <?php $info = array(); if (!empty($node->node_announce_location['de'][0]['safe_value']) || !empty($node->node_announce_location['en'][0]['safe_value'])) { $location = !empty($node->node_announce_location['de'][0]['safe_value']) ? $node->node_announce_location['de'][0]['safe_value'] : $node->node_announce_location['en'][0]['safe_value']; $location = isset($node->node_announce_location_link['und'][0]['safe_value']) ? "<a href=\"" . $node->node_announce_location_link['und'][0]['safe_value'] . "\">{$location}</a>" : $location; $info[] = $location; } if (!empty($node->node_announce_signup_link['und'][0]['safe_value'])) { $signup = '<a href="' . $node->node_announce_signup_link['und'][0]['safe_value'] . '">Anmeldung</a>';
function unity_lab_it_preprocess_paragraphs_item_system_status_section(&$vars, $hook) { if (arg(0) == 'node' && is_numeric(arg(1))) { // creating the node variable $node = node_load(arg(1), NULL, TRUE); } $vars['content']['show_all_link'] = false; $vars['content']['show_archive_link'] = false; if ($node->nid == 19906) { $vars['content']['system_status_html'] = doit_system_status_front_view_unity3(); $vars['content']['show_all_link'] = true; } else { if ($node->nid == 20616) { $vars['content']['system_status_html'] = doit_system_status_all_view_unity3(); $vars['content']['show_archive_link'] = true; } } $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'system_status')->propertyCondition('status', 1)->fieldCondition('field_status_start_date', 'value', date("Y-m-d g:i:s"), '>')->fieldOrderBy('field_status_start_date', 'value', 'ASC')->range(0, 6); $result = $query->execute(); if (isset($result['node'])) { $nids = array_keys($result['node']); $nodes = entity_load('node', $nids); } $nodeItems = array(); $items = array(); foreach ($nodes as $node) { $item['title'] = 'Scheduled Maintenance'; $item['url'] = url('node/' . $node->nid); $start = field_get_items('node', $node, 'field_status_start_date'); $start = empty($start[0]['value']) ? '' : $start[0]['value']; if ($start) { $start = new DateObject($start, 'UTC'); $start->setTimeZone(new DateTimeZone('America/New_York')); $item['start-date'] = $start->format('F jS, Y g:i a'); $item['start-date-only'] = $start->format('F jS, Y'); $item['start-time-only'] = $start->format('g:i a'); } $end = field_get_items('node', $node, 'field_status_end_date'); $end = empty($end[0]['value']) ? '' : $end[0]['value']; if ($end) { $end = new DateObject($end, 'UTC'); $end->setTimeZone(new DateTimeZone('America/New_York')); $item['end-date'] = $end->format('F jS, Y g:i a'); $item['end-date-only'] = $end->format('F jS, Y'); $item['end-time-only'] = $end->format('g:i a'); } $systems = field_get_items('node', $node, 'field_system'); $system = empty($systems[0]['target_id']) ? '' : $systems[0]['target_id']; if ($system) { $system = node_load($system); $item['title'] = $system->title; } if (count($systems) > 1) { $item['title'] .= ' and Additional Services'; } $vars['content']['items'][] = $item; } }
protected function calcola_costo_listino_base($sito_parcheggio, $nr_giorni, $nr_giorni_aggiuntivi) { $result = 0; $this->valore_sct_p_online = 0; $this->sct_p_online = 0; $oggi = new DateObject(); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'listino_base')->propertyCondition('status', 1)->fieldCondition('field_lb_sp_codice', 'nid', $sito_parcheggio)->fieldCondition('field_lb_classe_servizio', 'value', ucfirst($this->ar_data['tipo_parcheggio']))->fieldCondition('field_lb_data_validita_finale', 'value', $oggi->format("Y-m-d"), '>=')->addMetaData('account', user_load(1)); $qryres = $query->execute(); if (isset($qryres['node'])) { $items_nids = array_keys($qryres['node']); $k = $items_nids[0]; $items = entity_load('node', $items_nids); $costo = $this->getCostiSingoloGiorno($items, $nr_giorni, $nr_giorni_aggiuntivi); // sconto p online $this->sct_p_online = $items[$k]->field_sct_prenotazione_online['und']['0']['value']; if ($this->ar_data['p_online'] == 1 && $this->sct_p_online != 0) { $this->valore_sct_p_online = $costo * ($this->sct_p_online / 100); $costo = $costo - $this->valore_sct_p_online; } $result = $costo; } return $result; }
public function render($row) { if (!$this->isUdate) { return parent::render($row); } $rows = array(); $id = $row->{$this->field_alias}; if (!is_numeric($id)) { return $rows; } // Load the specified node: // We have to clone this or nodes on other views on this page, // like an Upcoming block on the same page as a calendar view, // will end up acquiring the values we set here. $entity = clone $this->entities[$id]; if (empty($entity)) { return $rows; } $info = entity_get_info($this->entity_type); $this->id_field = $info['entity keys']['id']; $this->id = $entity->{$this->id_field}; $this->type = !empty($info['entity keys']['bundle']) ? $info['entity keys']['bundle'] : $this->entity_type; $this->title = entity_label($this->entity_type, $entity); $uri = entity_uri($this->entity_type, $entity); $uri['options']['absolute'] = TRUE; $this->url = url($uri['path'], $uri['options']); $field_name = $this->udateField; $entity->date_id = array(); $granularity = 'second'; $this->date_argument->view->date_info->display_timezone_name = date_default_timezone_get(); // Set the date_id for the node, used to identify which field // value to display for fields that have multiple values. The // theme expects it to be an array. $date_id = 'date_id_' . $field_name; $date_delta = 'date_delta_' . $field_name; $delta = 0; if (isset($row->{$date_id})) { $entity->date_id = array('calendar.' . $row->{$date_id} . '.' . $field_name . '.' . $delta); } else { $entity->date_id = array('calendar.' . $id . '.' . $field_name . '.' . $delta); } if (!($items = field_get_items($this->entity_type, $entity, $field_name)) || !isset($items[$delta])) { return; } $item = $items[$delta]; $fieldinfo = field_info_field($field_name); switch ($fieldinfo['type']) { case 'udate': $item_start_date = $item['date']; break; case 'udate_range': $item_start_date = $item['date_start']; $item_end_date = $item['date_end']; break; default: return; } if (empty($item_start_date)) { return; } if (empty($item_end_date)) { $item_end_date = $item_start_date; } if (class_exists('DateObject')) { $item_start_date = new DateObject($item_start_date->format(DateTime::ISO8601)); $item_end_date = new DateObject($item_end_date->format(DateTime::ISO8601)); } $event = new stdClass(); $event->id = $this->id; $event->title = $this->title; $event->type = $this->type; $event->date_start = $item_start_date; $event->date_end = $item_end_date; $event->db_tz = date_default_timezone_get(); $event->to_zone = date_default_timezone_get(); $event->granularity = $granularity; $event->increment = 1; $event->field = $item; $event->url = $this->url; $event->row = $row; $event->entity = $entity; $event->stripe = array(); $event->stripe_label = array(); // All calendar row plugins should provide a date_id that the // theme can use. $event->date_id = $entity->date_id[0]; // We are working with an array of partially rendered items // as we process the calendar, so we can group and organize them. // At the end of our processing we'll need to swap in the fully formatted // display of the row. We save it here and switch it in // template_preprocess_calendar_item(). $event->rendered = theme($this->theme_functions(), array('view' => $this->view, 'options' => $this->options, 'row' => $row, 'field_alias' => isset($this->field_alias) ? $this->field_alias : '')); $entities = $this->explode_values($event); foreach ($entities as $entity) { switch ($this->options['colors']['legend']) { case 'type': $this->calendar_node_type_stripe($entity); break; case 'taxonomy': $this->calendar_taxonomy_stripe($entity); break; case 'group': $this->calendar_group_stripe($entity); break; } $rows[] = $entity; } return $rows; }