/** * Get events from a given date range * @since Version 3.9 * @param \DateTime $dateFrom * @param \DateTime $dateTo * @return \Railpage\Chronicle\Entry * @yield \Railpage\Chronicle\Entry */ public function getEventsForDates($dateFrom = null, $dateTo = null) { $events = array(); $Locos = new Locos_Module(); if (!$dateFrom instanceof DateTime) { throw new Exception("dateFrom is not an instance of \\DateTime"); } if (!$dateTo instanceof DateTime) { throw new Exception("dateTo is not an instance of \\DateTime"); } foreach ($Locos->yieldDatesWithinRange($dateFrom, $dateTo) as $Date) { $events[] = array("provider" => self::PROVIDER_NAME, "id" => $Date->id, "title" => $Date->text, "date" => $Date->Date, "url" => $Date->url->getURLs()); } return $events; }
/** * Constructor * @since Version 3.8.7 * * @param int|string $id */ public function __construct($id = NULL) { $timer = Debug::getTimer(); parent::__construct(); if (!is_null($id)) { if (filter_var($id, FILTER_VALIDATE_INT)) { $query = "SELECT * FROM loco_manufacturer WHERE manufacturer_id = ?"; $row = $this->db->fetchRow($query, $id); } elseif (is_string($id)) { $query = "SELECT * FROM loco_manufacturer WHERE slug = ?"; $row = $this->db->fetchRow($query, $id); } if (isset($row) && count($row)) { $this->id = $row['manufacturer_id']; $this->name = $row['manufacturer_name']; $this->desc = $row['manufacturer_desc']; $this->slug = $row['slug']; if (empty($this->slug)) { $proposal = ContentUtility::generateUrlSlug($this->name, 30); $query = "SELECT manufacturer_id FROM loco_manufacturer WHERE slug = ?"; $result = $this->db->fetchAll($query, $proposal); if (count($result)) { $proposal = $proposal . count($result); } $this->slug = $proposal; $this->commit(); } $this->url = new Url(sprintf("/locos/builder/%s", $this->slug)); } } Debug::logEvent(__METHOD__, $timer); }
/** * Constructor * @since Version 3.8.7 * @param int|string $id */ public function __construct($id = NULL) { parent::__construct(); if (!is_null($id)) { if (filter_var($id, FILTER_VALIDATE_INT)) { $query = "SELECT * FROM loco_manufacturer WHERE manufacturer_id = ?"; $row = $this->db->fetchRow($query, $id); } elseif (is_string($id)) { $query = "SELECT * FROM loco_manufacturer WHERE slug = ?"; $row = $this->db->fetchRow($query, $id); } if (isset($row) && count($row)) { $this->id = $row['manufacturer_id']; $this->name = $row['manufacturer_name']; $this->desc = $row['manufacturer_desc']; $this->slug = $row['slug']; if (empty($this->slug)) { $proposal = create_slug($this->name); $proposal = substr($proposal, 0, 30); $query = "SELECT manufacturer_id FROM loco_manufacturer WHERE slug = ?"; $result = $this->db->fetchAll($query, $proposal); if (count($result)) { $proposal = $proposal . count($result); } $this->slug = $proposal; $this->commit(); } $this->url = sprintf("/locos/builder/%s", $this->slug); } } }
/** * Constructor * @since Version 3.8.7 * @var int|string $id */ public function __construct($id = NULL) { parent::__construct(); if (!is_null($id)) { if (filter_var($id, FILTER_VALIDATE_INT)) { $row = $this->db->fetchRow("SELECT * FROM loco_type WHERE id = ?", $id); } elseif (is_string($id)) { $row = $this->db->fetchRow("SELECT * FROM loco_type WHERE slug = ?", $id); } if (isset($row) && count($row)) { $this->id = $row['id']; $this->name = $row['title']; $this->slug = $row['slug']; if (empty($this->slug)) { $proposal = create_slug($this->name); $proposal = substr($proposal, 0, 30); $query = "SELECT id FROM loco_type WHERE slug = ?"; $result = $this->db->fetchAll($query, $proposal); if (count($result)) { $proposal = $proposal . count($result); } $this->slug = $proposal; $this->commit(); } $this->url = sprintf("%s/type/%s", $this->Module->url, $this->slug); } } }
/** * Constructor * @since Version 3.2 * @version 3.2 * @param int $operator_id */ public function __construct($operator_id = false) { $timer = Debug::getTimer(); parent::__construct(); if (filter_var($operator_id, FILTER_VALIDATE_INT)) { $this->fetch($operator_id); } Debug::logEvent(__METHOD__, $timer); }
/** * Constructor * @param int $id */ public function __construct($id = false) { parent::__construct(); $update = false; if ($id && ($row = $this->db->fetchRow("SELECT d.*, dt.* FROM loco_unit_date AS d INNER JOIN loco_date_type AS dt ON d.loco_date_id = dt.loco_date_id WHERE d.date_id = ?", $id))) { $this->id = $id; $this->text = $row['text']; $this->rich_text = $row['text']; $this->meta = json_decode($row['meta'], true); $this->action = $row['loco_date_text']; $this->action_id = $row['loco_date_id']; if ($row['timestamp'] == "0000-00-00") { $this->Date = new DateTime(); $this->Date->setTimestamp($row['date']); $update = true; } else { $this->Date = new DateTime($row['timestamp']); } /** * Create the rich text entry */ if (count($this->meta)) { foreach ($this->meta as $key => $data) { $this->rich_text .= "\n<strong>" . ucfirst($key) . ": </strong>"; switch ($key) { case "livery": #$this->rich_text .= "[url=/flickr?tag=railpage:livery=" . $data['id'] . "]" . $data['name'] . "[/url]"; $this->rich_text .= "<a data-livery-id=\"" . $data['id'] . "\" data-livery-name=\"" . $data['name'] . "\" href='#' class='rp-modal-livery'>" . $data['name'] . "</a>"; break; case "owner": $Operator = new Operator($data['id']); $this->rich_text .= "[url=" . $Operator->url_owner . "]" . $Operator->name . "[/url]"; break; case "operator": $Operator = new Operator($data['id']); $this->rich_text .= "[url=" . $Operator->url_operator . "]" . $Operator->name . "[/url]"; break; case "position": if (!isset($data['title']) || empty($data['title'])) { $data['title'] = "Location"; } $this->rich_text .= "<a data-lat=\"" . $data['lat'] . "\" data-lon=\"" . $data['lon'] . "\" data-zoom=\"" . $data['zoom'] . "\" data-title=\"" . $data['title'] . "\" data-toggle='modal' href='#' class='rp-modal-map'>Click to view</a>"; break; } } } $this->Loco = new Locomotive($row['loco_unit_id']); } /** * Update this object if required */ if ($update) { $this->commit(); } }
/** * Constructor * @since Version 3.2 * @version 3.2 * @param int $operator_id */ public function __construct($operator_id = false) { parent::__construct(); if (filter_var($operator_id, FILTER_VALIDATE_INT)) { try { $this->fetch($operator_id); } catch (Exception $e) { throw new Exception($e->getMessage()); } } }
/** * Constructor * @since Version 3.8.7 * @var int|string $id */ public function __construct($id = NULL) { $timer = Debug::getTimer(); parent::__construct(); if (!is_null($id)) { if (filter_var($id, FILTER_VALIDATE_INT)) { $row = $this->db->fetchRow("SELECT * FROM wheel_arrangements WHERE id = ?", $id); } elseif (is_string($id)) { $row = $this->db->fetchRow("SELECT * FROM wheel_arrangements WHERE slug = ?", $id); } $this->load($row); } Debug::logEvent(__METHOD__, $timer); }
/** * Constructor * @since Version 3.8.7 * @var int|string $id */ public function __construct($id = NULL) { $timer = Debug::getTimer(); parent::__construct(); if (filter_var($id, FILTER_VALIDATE_INT)) { $row = $this->db->fetchRow("SELECT * FROM loco_type WHERE id = ?", $id); $this->load($row); } $id = filter_var($id, FILTER_SANITIZE_STRING); if (!is_null($id)) { $row = $this->db->fetchRow("SELECT * FROM loco_type WHERE slug = ?", $id); $this->load($row); } Debug::logEvent(__METHOD__, $timer); }
/** * Constructor * * @param int $id */ public function __construct($id = null) { $timer = Debug::getTimer(); parent::__construct(); if ($id = filter_var($id, FILTER_VALIDATE_INT)) { $this->id = $id; $this->populate(); } Debug::logEvent(__METHOD__, $timer); }
/** * Constructor * @since Version 3.2 * @param int $id * @param int|string $class_id_or_slug * @param string $number */ public function __construct($id = NULL, $class_id_or_slug = NULL, $number = NULL) { parent::__construct(); /** * Record this in the debug log */ if (function_exists("debug_recordInstance")) { debug_recordInstance(__CLASS__); } $this->namespace = sprintf("%s.%s", $this->Module->namespace, "loco"); /** * List of templates */ $this->Templates = new stdClass(); $this->Templates->view = "loco"; $this->Templates->edit = "loco.edit"; $this->Templates->sightings = "loco.sightings"; if (filter_var($id, FILTER_VALIDATE_INT)) { $this->id = $id; } if ((is_null($id) || $id == false) && !is_null($number)) { if (!filter_var($class_id_or_slug, FILTER_VALIDATE_INT) && is_string($class_id_or_slug)) { // Assume Zend_DB $class_id_or_slug = $this->db->fetchOne("SELECT id FROM loco_class WHERE slug = ?", $class_id_or_slug); } // We are searching by loco number - we need to find it first if ($this->db instanceof \sql_db) { $query = "SELECT loco_id FROM loco_unit WHERE class_id = " . $this->db->real_escape_string($class_id_or_slug) . " AND loco_num = '" . $this->db->real_escape_string($number) . "'"; if ($rs = $this->db->query($query)) { $row = $rs->fetch_assoc(); $this->id = $row['loco_id']; } } else { $this->id = $this->db->fetchOne("SELECT loco_id FROM loco_unit WHERE class_id = ? AND loco_num = ?", array($class_id_or_slug, $number)); } } else { $this->id = $id; } // Load the loco object if (!empty($this->id)) { $this->fetch(); } }
/** * Constructor * @since Version 3.2 * @param int $id * @param int|string $classIdOrSlug * @param string $number */ public function __construct($id = NULL, $classIdOrSlug = NULL, $number = NULL) { parent::__construct(); $timer = Debug::getTimer(); /** * Record this in the debug log */ Debug::RecordInstance(NULL, $id); $this->bootstrap(); if (filter_var($id, FILTER_VALIDATE_INT)) { $this->id = filter_var($id, FILTER_VALIDATE_INT); } else { $this->id = Utility\LocomotiveUtility::getLocoId($classIdOrSlug, $number); } // Load the loco object if (filter_var($this->id, FILTER_VALIDATE_INT)) { $this->fetch(); } $this->id = intval($this->id); Debug::logEvent(sprintf("%s(%d)", __METHOD__, $this->id), $timer); }
/** * Validate changes to this gauge * Attempts to generate an imperial width if a metric width is present * * @since Version 3.9.1 * @throws \Exception if $this->name is empty * @throws \Exception if $this->width_metric is empty * @throws \Exception if $this->width_imperial is empty */ private function validate() { if (empty($this->name)) { throw new Exception("Name cannot be empty"); } if (empty($this->width_metric)) { throw new Exception("Metric gauge width cannot be empty"); } if (substr($this->width_metric, -2) != "mm") { $this->width_metric .= "mm"; } if (empty($this->width_imperial) && !empty($this->width_metric)) { $width = Locos::convert_to_inches($this->width_metric); if (isset($width['ft']) && filter_var($width['ft'], FILTER_VALIDATE_INT) && $width['ft'] != 0) { $this->width_imperial = sprintf("%d' ", $width['ft']); } if (isset($width['in']) && filter_var($width['in'], FILTER_VALIDATE_INT) && $width['in'] != 0) { $this->width_imperial = sprintf("%s%d\"", $this->width_imperial, $width['in']); } $this->width_imperial = trim($this->width_imperial); } if (empty($this->width_imperial)) { throw new Exception("Could not create an imperial width for this gauge"); } if (empty($this->slug)) { $this->createSlug(); } return true; }
/** * Constructor * @since Version 3.2 * @param int|string $idOrSlug * @param boolean $recurse */ public function __construct($idOrSlug = null, $recurse = null) { parent::__construct(); $timer = Debug::getTimer(); /** * Record this in the debug log */ Debug::RecordInstance(); $this->getTemplates(); $this->namespace = sprintf("%s.%s", $this->Module->namespace, "class"); if ($recurse == null) { $recurse = false; } // Set the ID if (filter_var($idOrSlug, FILTER_VALIDATE_INT) || $idOrSlug != null) { $this->id = $idOrSlug; $this->fetch($recurse); } Debug::logEvent(__METHOD__, $timer); }
/** * Constructor * @since Version 3.2 * @param int|string $id_or_slug * @param boolean $recurse */ public function __construct($id_or_slug = false, $recurse = true) { parent::__construct(); /** * Record this in the debug log */ if (function_exists("debug_recordInstance")) { debug_recordInstance(__CLASS__); } $this->Templates = new stdClass(); $this->Templates->view = "class"; $this->Templates->sightings = "loco.sightings"; $this->Templates->bulkedit = "class.bulkedit"; $this->Templates->bulkedit_operators = "class.bulkedit.operators"; $this->Templates->bulkedit_buildersnumbers = "class.bulkedit.buildersnumbers"; $this->Templates->bulkedit_status = "class.bulkedit.status"; $this->Templates->bulkedit_gauge = "class.bulkedit.gauge"; $this->namespace = sprintf("%s.%s", $this->Module->namespace, "class"); // Set the ID if (filter_var($id_or_slug, FILTER_VALIDATE_INT) || is_string($id_or_slug)) { $this->id = $id_or_slug; $this->fetch($recurse); } }
/** * @depends testAddLoco */ public function test_listAllTheThings($loco_id) { $Loco = LocosFactory::CreateLocomotive($loco_id); $Locos = new Locos(); $Locos->listModels(); $Locos->listGroupings(); $Locos->listGauges(); $Locos->listLiveries(); $Locos->listOperators(); $Locos->listLiveries(); $Locos->listAllLocos(); $Locos->listYears(); $Locos->listStatus(); $Locos->listTypes(); $Locos->listManufacturers(); $Locos->listWheelArrangements(); $Locos->listOrgLinkTypes(); $Locos->classByManufacturer(); $Locos->classByWheelset(); $Locos->classByType(); $Locos->listClasses(); $Locos->listClasses($Loco->Class->getType()->id); $Locos->listClasses(array($Loco->Class->getType()->id)); }