Пример #1
0
 /**
  * Get locomotive class timeline
  * @since Version 3.8.7
  * @return array
  */
 public function getTimeline()
 {
     $query = "SELECT d.*, lu.loco_num, ld.loco_date_text FROM loco_unit_date AS d INNER JOIN loco_date_type AS ld ON ld.loco_date_id = d.loco_date_id INNER JOIN loco_unit AS lu ON lu.loco_id = d.loco_unit_id WHERE lu.class_id = ? ORDER BY timestamp ASC";
     $return = array("timeline" => array("headline" => $this->name . " timeline", "type" => "default", "text" => NULL, "asset" => array("media" => NULL, "credit" => NULL, "caption" => NULL), "date" => array()));
     foreach ($this->db->fetchAll($query, $this->id) as $row) {
         if ($row['timestamp'] == "0000-00-00") {
             $row['timestamp'] = date("Y-m-d", $row['date']);
         }
         $row['meta'] = json_decode($row['meta'], true);
         $data = array("startDate" => str_replace("-", ",", $row['timestamp']), "endDate" => str_replace("-", ",", $row['timestamp']), "headline" => $row['loco_num'] . " - " . $row['loco_date_text'], "text" => $row['text'], "asset" => array("media" => NULL, "thumbnail" => NULL, "credit" => NULL, "caption" => NULL), "meta" => array("date_id" => $row['date_id']));
         /**
          * Location
          */
         if (isset($row['meta']['position']['lat']) && isset($row['meta']['position']['lon'])) {
             try {
                 $imageObject = new \Railpage\Images\MapImage($row['meta']['position']['lat'], $row['meta']['position']['lon']);
                 $data['asset']['media'] = $imageObject->sizes['thumb']['source'];
                 $data['asset']['thumbnail'] = $imageObject->sizes['thumb']['source'];
                 $data['asset']['caption'] = "<a href='/place?lat=" . $imageObject->Place->lat . "&lon=" . $imageObject->Place->lon . "'>" . $imageObject->Place->name . ", " . $imageObject->Place->Country->name . "</a>";
             } catch (Exception $e) {
                 // Throw it away. Throw. It. Away. NOW!
             }
         }
         /**
          * Liveries
          */
         if (isset($row['meta']['livery']['id'])) {
             try {
                 $Images = new \Railpage\Images\Images();
                 $imageObject = $Images->findLocoImage($row['loco_unit_id'], $row['meta']['livery']['id']);
                 if ($imageObject instanceof \Railpage\Images\Image) {
                     $data['asset']['media'] = $imageObject->sizes['thumb']['source'];
                     $data['asset']['thumbnail'] = $imageObject->sizes['thumb']['source'];
                     $data['asset']['caption'] = "<a href='/image?id=" . $imageObject->id . "'>" . $imageObject->title . "</a>";
                     $data['asset']['credit'] = $imageObject->author->username;
                 }
             } catch (Exception $e) {
                 // Throw it away. Throw. It. Away. NOW!
             }
         }
         $return['timeline']['date'][] = $data;
     }
     return $return;
 }