/** * 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; }
/** * Find data for managers to fix * @since Version 3.2 * @version 3.5 * @param string $search_type * @param string $args * @return array */ public function find($search_type = false, $args = false) { if (!$search_type) { throw new Exception("Cannot find data - no search type given"); return false; } /** * Find loco classes without a cover photo */ if ($search_type == LOCOS_FIND_CLASS_NOPHOTO || $search_type == self::FIND_CLASS_NOPHOTO) { $return = array(); $classes = $this->listClasses(); foreach ($classes['class'] as $row) { $LocoClass = new LocoClass($row['class_id']); if (!$LocoClass->hasCoverImage()) { $return[$LocoClass->id] = array("id" => $LocoClass->id, "name" => $LocoClass->name, "flickr_tag" => $LocoClass->flickr_tag, "url" => $LocoClass->url->getURLs()); } } return $return; /* // Find classes without a photo $query = "SELECT id, name, flickr_tag FROM loco_class WHERE flickr_image_id = '' ORDER BY name ASC"; if ($this->db instanceof \sql_db) { if ($rs = $this->db->query($query)) { $return = array(); while ($row = $rs->fetch_assoc()) { $return[$row['id']] = $row; } return $return; } else { throw new Exception($this->db->error."\n".$query); return false; } } else { $return = array(); foreach ($this->db->fetchAll($query) as $row) { $return[$row['id']] = $row; } return $return; } */ } /** * Find locomotives without a cover photo */ if ($search_type == LOCOS_FIND_LOCO_NOPHOTO || $search_type == self::FIND_LOCO_NOPHOTO) { // Locos without a photo $query = "SELECT l.loco_id, l.loco_num, l.loco_status_id, s.name AS loco_status, c.id AS class_id, c.name AS class_name \r\n\t\t\t\t\t\t\tFROM loco_unit AS l\r\n\t\t\t\t\t\t\tLEFT JOIN loco_class AS c ON l.class_id = c.id\r\n\t\t\t\t\t\t\tLEFT JOIN loco_status AS s ON s.id = l.loco_status_id\r\n\t\t\t\t\t\t\tWHERE l.photo_id = 0\r\n\t\t\t\t\t\t\tORDER BY c.name, l.loco_num"; if ($this->db instanceof \sql_db) { if ($rs = $this->db->query($query)) { $return = array(); while ($row = $rs->fetch_assoc()) { $return[$row['loco_id']] = $row; } return $return; } else { throw new Exception($this->db->error . "\n" . $query); return false; } } else { $return = array(); foreach ($this->db->fetchAll($query) as $row) { $return[$row['loco_id']] = $row; } return $return; } } /** * Find locomotives from a comma-separated list of numbers */ if ($search_type == LOCOS_FIND_FROM_NUMBERS && $args) { // Find locomotives from a comma-separated list of numbers $numbers = explode(",", $args); foreach ($numbers as $id => $num) { $numbers[$id] = trim($num); } $query = "SELECT l.loco_id, l.loco_num, l.loco_status_id, s.name AS loco_status, l.loco_gauge_id, CONCAT(g.gauge_name, ' (', g.gauge_metric, ')') AS loco_gauge, c.loco_type_id, t.title AS loco_type, c.id AS class_id, c.name AS class_name \r\n\t\t\t\t\t\t\tFROM loco_unit AS l\r\n\t\t\t\t\t\t\tLEFT JOIN loco_class AS c ON l.class_id = c.id\r\n\t\t\t\t\t\t\tLEFT JOIN loco_status AS s ON s.id = l.loco_status_id\r\n\t\t\t\t\t\t\tLEFT JOIN loco_gauge AS g ON g.gauge_id = l.loco_gauge_id\r\n\t\t\t\t\t\t\tLEFT JOIN loco_type AS t ON c.loco_type_id = t.id\r\n\t\t\t\t\t\t\tWHERE l.loco_num IN ('" . implode("','", $numbers) . "')\r\n\t\t\t\t\t\t\tORDER BY l.loco_num, c.name"; $return = array(); foreach ($this->db->fetchAll($query) as $row) { $return[$row['loco_id']] = $row; } return $return; } }