/** * Commit changes to this locomotive * @since Version 3.9.1 * @return \Railpage\Locos\Date */ public function commit() { $this->validate(); $data = array("loco_unit_id" => $this->Loco->id, "loco_date_id" => $this->action_id, "date" => $this->Date->getTimestamp(), "date_end" => $this->DateEnd instanceof DateTime ? $this->DateEnd->format("Y-m-d") : NULL, "timestamp" => $this->Date->format("Y-m-d"), "text" => $this->text, "meta" => json_encode($this->meta)); if (filter_var($this->id)) { $this->Redis->delete($this->mckey); $where = array("date_id = ?" => $this->id); $this->db->update("loco_unit_date", $data, $where); } else { $this->db->insert("loco_unit_date", $data); $this->id = $this->db->lastInsertId(); } if (isset($this->Loco->meta['construction_cost'])) { $this->Loco->meta['construction_cost_inflated'] = ContentUtility::convertCurrency($this->Loco->meta['construction_cost'], Utility\LocomotiveUtility::getConstructionDate($this->Loco)); $this->Loco->commit(); } return $this; }
/** * Get construction or in service date * @since Version 3.9.1 * @param \Railpage\Locos\Locomotive $Loco * @return \DateTime */ public static function getConstructionDate(Locomotive $Loco) { $dates = $Loco->loadDates(); $dates = array_reverse($dates, true); $types = [1, 17]; foreach ($dates as $row) { if (in_array($row['date_type_id'], $types)) { return new DateTime("@" . $row['date']); } } }
/** * Find Railpage objects (loco, class, livery) in this image * @since Version 3.8.7 * @param string $namespace */ public function findObjects($namespace = NULL) { if (is_null($namespace)) { throw new Exception("Parameter 1 (namespace) cannot be empty"); } /** * Start the debug timer */ if (RP_DEBUG) { global $site_debug; $debug_timer_start = microtime(true); } switch ($namespace) { case "railpage.locos.loco": if (isset($this->meta['tags'])) { foreach ($this->meta['tags'] as $tag) { if (preg_match("@railpage:class=([0-9]+)@", $tag, $matches)) { $LocoClass = new LocoClass($matches[1]); } } foreach ($this->meta['tags'] as $tag) { if (isset($LocoClass) && $LocoClass instanceof LocoClass && preg_match("@railpage:loco=([a-zA-Z0-9]+)@", $tag, $matches)) { $Loco = new Locomotive(false, $LocoClass->id, $matches[1]); if (filter_var($Loco->id, FILTER_VALIDATE_INT)) { $this->addLink($Loco->namespace, $Loco->id); } } } foreach ($this->db->fetchAll("SELECT id AS class_id, flickr_tag AS class_tag FROM loco_class") as $row) { foreach ($this->meta['tags'] as $tag) { if (stristr($tag, $row['class_tag']) && strlen(str_replace($row['class_tag'] . "-", "", $tag) > 0)) { $loco_num = str_replace($row['class_tag'] . "-", "", $tag); $Loco = new Locomotive(false, $row['class_id'], $loco_num); if (filter_var($Loco->id, FILTER_VALIDATE_INT)) { $this->addLink($Loco->namespace, $Loco->id); if (!$Loco->hasCoverImage()) { $Loco->setCoverImage($this); } if (!$Loco->Class->hasCoverImage()) { $Loco->Class->setCoverImage($this); } } } } } } break; case "railpage.locos.class": if (isset($this->meta['tags'])) { foreach ($this->db->fetchAll("SELECT id AS class_id, flickr_tag AS class_tag FROM loco_class") as $row) { foreach ($this->meta['tags'] as $tag) { if ($tag == $row['class_tag']) { $LocoClass = new LocoClass($row['class_id']); if (filter_var($LocoClass->id, FILTER_VALIDATE_INT)) { $this->addLink($LocoClass->namespace, $LocoClass->id); } } } } foreach ($this->meta['tags'] as $tag) { if (preg_match("@railpage:class=([0-9]+)@", $tag, $matches)) { $LocoClass = new LocoClass($matches[1]); if (filter_var($LocoClass->id, FILTER_VALIDATE_INT)) { $this->addLink($LocoClass->namespace, $LocoClass->id); if (!$LocoClass->hasCoverImage()) { $LocoClass->setCoverImage($this); } } } } } break; case "railpage.locos.liveries.livery": if (isset($this->meta['tags'])) { foreach ($this->meta['tags'] as $tag) { if (preg_match("@railpage:livery=([0-9]+)@", $tag, $matches)) { $Livery = new Livery($matches[1]); if (filter_var($Livery->id, FILTER_VALIDATE_INT)) { $this->addLink($Livery->namespace, $Livery->id); } } } } break; } /** * End the debug timer */ if (RP_DEBUG) { $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "() : completed lookup of " . $namespace . " in for image id " . $this->id . " in " . round(microtime(true) - $debug_timer_start, 5) . "s"; } return $this; }
/** * @depends test_addUser */ public function test_break_rate_set_norating($User) { $this->setExpectedException("Exception", "Cannot set user rating for this loco - no rating given"); $Loco = new Locomotive(); $Loco->setRating($User); }