/** * Get event ticket price in event day's currency or Free! * * @return string */ public function price() { if ($this->price === 0) { return __('Free!'); } elseif ($this->price > 0) { return Num::currency($this->price, $this->stamp_begin); } else { return null; } }
/** * Render content. * * @return string */ public function content() { ob_start(); /* // Stamp if ($this->event->stamp_begin != $this->event->stamp_end): echo ($this->event->stamp_end ? '<i class="icon-time icon-white"></i> ' . __('From :from to :to', array( ':from' => HTML::time(Date::format('HHMM', $this->event->stamp_begin), $this->event->stamp_begin), ':to' => HTML::time(Date::format('HHMM', $this->event->stamp_end), $this->event->stamp_end) )) : '<i class="icon-time icon-white"></i> ' . __('From :from onwards', array( ':from' => HTML::time(Date::format('HHMM', $this->event->stamp_begin), $this->event->stamp_begin), ))) . '<br />'; endif; */ // Price if ($this->event->price == 0) { echo '<i class="icon-shopping-cart icon-white"></i> ' . __('Free entry') . '<br />'; } elseif ($this->event->price > 0) { echo '<i class="icon-shopping-cart icon-white"></i> ' . __('Tickets :price', array(':price' => '<var>' . Num::currency($this->event->price, $this->event->stamp_begin) . '</var>')); echo ($this->event->price2 !== null ? ', ' . __('presale :price', array(':price' => '<var>' . Num::currency($this->event->price2, $this->event->stamp_begin) . '</var>')) : '') . '<br />'; } // Age limit if ($this->event->age > 0) { echo '<i class="icon-user icon-white"></i> ' . __('Age limit') . ': ' . __(':years years', array(':years' => '<var>' . $this->event->age . '</var>')) . '<br />'; } // Homepage if (!empty($this->event->homepage)) { echo '<i class="icon-home icon-white"></i> ' . HTML::anchor($this->event->homepage, Text::limit_url($this->event->homepage, 25)) . '<br />'; } // Tags if ($tags = $this->event->tags()) { echo '<i class="icon-music icon-white"></i> ' . implode(', ', $tags) . '<br />'; } elseif (!empty($this->event->music)) { echo '<i class="icon-music icon-white"></i> ' . $this->event->music . '<br />'; } /* // Venue if ($_venue = $this->event->venue()): // Venue found from db $venue = HTML::anchor(Route::model($_venue), HTML::chars($_venue->name)); $address = $_venue->address ? HTML::chars($_venue->address) . ', ' . HTML::chars($_venue->city_name) : HTML::chars($_venue->city_name); if ($_venue->latitude): $map = array( 'marker' => HTML::chars($_venue->name), 'infowindow' => HTML::chars($_venue->address) . '<br />' . HTML::chars($_venue->city_name), 'lat' => $_venue->latitude, 'long' => $_venue->longitude ); Widget::add('foot', HTML::script_source(' head.ready("anqh", function() { $("#event-info a[href=#map]").on("click", function toggleMap(event) { $("#map").toggle("fast", function openMap() { $("#map").googleMap(' . json_encode($map) . '); }); return false; }); }); ')); endif; elseif ($this->event->venue_name): // No venue in db $venue = $this->event->venue_url ? HTML::anchor($this->event->venue_url, HTML::chars($this->event->venue_name)) : HTML::chars($this->event->venue_name); $address = HTML::chars($this->event->city_name); else: // Venue not set $venue = $this->event->venue_hidden ? __('Underground') : __('(Unknown)'); $address = HTML::chars($this->event->city_name); endif; echo '<address><strong><i class="icon-map-marker icon-white"></i> ', $venue, '</strong>' . ($address ? ', ' . $address : '') . '<br />'; if (isset($map)): echo HTML::anchor('#map', __('Toggle map')) . '<br />'; echo '<div id="map" style="display: none">', __('Map loading') . '</div>'; endif; echo '</address>'; */ // Meta echo '<br /><footer class="meta">'; echo __('Added') . ' ' . HTML::time(Date::format(Date::DMY_SHORT, $this->event->created), $this->event->created); if ($this->event->modified) { echo ', ' . __('last modified') . ' ' . HTML::time(Date::short_span($this->event->modified, false), $this->event->modified); } echo '</footer>'; return ob_get_clean(); }
/** * Update price and availability * * @param boolean $cached Update from already downloaded files * @return boolean All products have been processed */ public function change($cached = false) { // Get data from supplier if (!($products = $this->_change($cached))) { return true; } // Get current prices from supplier $price = \DB::select('external_id', 'price', 'available')->from(Model_Price::table())->where('supplier_id', $this->model->id)->execute()->as_array('external_id'); // Cast values to the appropriate data type array_walk($price, function (&$product, $id) use(&$price) { $product['price'] = \Num::currency($product['price']); $product['available'] = intval($product['available']); unset($price[$id]['external_id']); }); $count = array(0); $available = array(); foreach ($products as $id => $product) { // Are we sure that it exists? if (!array_key_exists($id, $price)) { continue; } // Default data casting and values $product['price'] = \Arr::get($product, 'price'); is_null($product['price']) or $product['price'] = \Num::currency($product['price']); $a = \Arr::get($product, 'available'); // Check if product's price has been changed, or just became (un)available if (!is_null($product['price'])) { // Foolproofness: set the update array manually $product = array('price' => $product['price'], 'external_id' => $id, 'supplier_id' => $this->model->id); // Update availability if changed is_null($a) or $product['available'] = $a; // Get job and queue $job = $this->get_config('change.job', 'Indigo\\Erp\\Stock\\Job_Supplier_Change'); $queue = $this->get_config('change.queue', 'update'); // Use Queue if available (greater performance) if (\Package::loaded('queue')) { $count[0] += \Queue::push($queue, $job, array($product, $price[$id])) ? 1 : 0; } else { try { $job = new $job(); $count[0] += $job->execute(null, $product); } catch (\Exception $e) { } } } elseif (!is_null($a)) { $available[$a][] = $id; } } // Update availability information $available = $this->_available($available); $count[1] = $available[0]; $count[2] = $available[1]; // Set the last updated time for supplier prices $this->model->set('last_update', time())->save(); // Log success \Log::info($this->model->name . ' frissítve: ' . $count[0] . ' frissítés, ' . $count[1] . ' lett elérhetetlen, ' . $count[2] . ' lett elérhető.'); // All product have been processed return array_sum($count) == count($products); }
/** * Add event subtitle. * * @param Model_Event $event * @return string */ public static function _event_subtitle(Model_Event $event) { $subtitle = array(); // Date if ($event->stamp_end - $event->stamp_begin > Date::DAY) { // Multi day event $subtitle[] = '<i class="fa fa-calendar"></i> ' . HTML::time(Date('l', $event->stamp_begin) . ', <strong>' . Date::format(Date::DM_LONG, $event->stamp_begin) . ' – ' . Date::format(Date::DMY_LONG, $event->stamp_end) . '</strong>', $event->stamp_begin, true); } else { // Single day event $subtitle[] = '<i class="fa fa-calendar"></i> ' . HTML::time(Date('l', $event->stamp_begin) . ', <strong>' . Date::format(Date::DMY_LONG, $event->stamp_begin) . '</strong>', $event->stamp_begin, true); } // Time if ($event->stamp_begin != $event->stamp_end) { $subtitle[] = $event->stamp_end ? '<i class="fa fa-clock-o"></i> ' . __('From :from until :to', array(':from' => '<strong>' . HTML::time(Date::format('HHMM', $event->stamp_begin), $event->stamp_begin) . '</strong>', ':to' => '<strong>' . HTML::time(Date::format('HHMM', $event->stamp_end), $event->stamp_end) . '</strong>')) : '<i class="fa fa-clock-o"></i> ' . __('From :from onwards', array(':from' => HTML::time(Date::format('HHMM', $event->stamp_begin), $event->stamp_begin))); } // Tickets $tickets = ''; if ($event->price === 0 || $event->price > 0 || $event->ticket_url) { $tickets = '<i class="fa fa-ticket"></i> '; } if ($event->price === 0) { $tickets .= '<strong>' . __('Free entry') . '</strong> '; } else { if ($event->price > 0) { $tickets .= __('Tickets :price', array(':price' => '<strong>' . Num::currency($event->price, $event->stamp_begin) . '</strong>')) . ' '; } } if ($event->ticket_url) { $tickets .= HTML::anchor($event->ticket_url, __('Buy tickets'), array('target' => '_blank')); } if ($tickets) { $subtitle[] = $tickets; } // Age limit if ($event->age > 0) { $subtitle[] = '<i class="fa fa-user"></i> ' . __('Age limit') . ': <strong>' . $event->age . '</strong>'; } // Homepage if (!empty($event->url)) { $subtitle[] = '<i class="fa fa-link"></i> ' . HTML::anchor($event->url, Text::limit_url($event->url, 25)); } // Venue if ($_venue = $event->venue()) { // Venue found from db $venue = HTML::anchor(Route::model($_venue), HTML::chars($_venue->name)); $address = HTML::chars($_venue->city_name); if ($_venue->latitude) { $map = array('marker' => HTML::chars($_venue->name), 'infowindow' => HTML::chars($_venue->address) . '<br />' . HTML::chars($_venue->city_name), 'lat' => $_venue->latitude, 'long' => $_venue->longitude); Widget::add('foot', HTML::script_source(' head.ready("anqh", function() { $("a[href=#map]").on("click", function toggleMap(event) { $("#map").toggle("fast", function openMap() { $("#map").googleMap(' . json_encode($map) . '); }); return false; }); }); ')); } } else { if ($event->venue_name) { // No venue in db $venue = $event->venue_url ? HTML::anchor($event->venue_url, HTML::chars($event->venue_name)) : HTML::chars($event->venue_name); $address = HTML::chars($event->city_name); } else { // Venue not set $venue = $event->venue_hidden ? __('Underground') : __('(Unknown)'); $address = HTML::chars($event->city_name); } } $subtitle[] = '<br /><i class="fa fa-map-marker"></i> <strong>' . $venue . '</strong>' . ($address ? ', ' . $address : ''); if (isset($map)) { $subtitle[] = HTML::anchor('#map', __('Show map')); } // Tags if ($tags = $event->tags()) { $subtitle[] = '<br /><i class="fa fa-music"></i> <em>' . implode(', ', $tags) . '</em>'; } else { if (!empty($event->music)) { $subtitle[] = '<br /><i class="fa fa-music"></i> <em>' . $event->music . '</em>'; } } return implode(' ', $subtitle) . (isset($map) ? '<div id="map" style="display: none">' . __('Map loading') . '</div>' : ''); }