/**
  * Update last owner and operator for the fleet
  * @since Version 3.9.1
  * @return void
  * @param \Railpage\Locos\LocoClass $Class
  */
 public static function updateFleet_OwnerOperator(LocoClass $Class)
 {
     $Database = (new AppCore())->getDatabaseConnection();
     $members = $Class->members();
     foreach ($members['locos'] as $row) {
         $Loco = LocosFactory::CreateLocomotive($row['loco_id']);
         $query = "(SELECT operator_id AS owner_id, link_type FROM loco_org_link WHERE loco_id = ? AND link_type = 1 ORDER BY link_weight DESC LIMIT 0,1)\r\nUNION ALL\r\n(SELECT operator_id, link_type FROM loco_org_link WHERE loco_id = ? AND link_type = 2 ORDER BY link_weight DESC LIMIT 0,1)";
         $result = $Database->fetchAll($query, array($Loco->id, $Loco->id));
         #$commit = false;
         foreach ($result as $row) {
             #printArray($row['organisation_id']); printArray($Loco->owner_id); die;
             if ($row['link_type_id'] == 1) {
                 $Loco->owner_id = $row['operator_id'];
                 #$commit = true;
             }
             if ($row['link_type_id'] == 2) {
                 $Loco->operator_id = $row['operator_id'];
                 #$commit = true;
             }
         }
         #if ($commit) {
         $Loco->commit();
         #}
         #break;
     }
     $Class->flushMemcached();
     return;
 }
示例#2
0
 /**
  * Load the locomotive associated with this date
  * @since Version 3.9.1
  * @return \Railpage\Locos\Date
  */
 public function loadLoco()
 {
     $this->Loco = Factory::CreateLocomotive($this->loco_id);
     $this->url = new Url($this->Loco->url);
     return $this;
 }
示例#3
0
 /**
  * Get the loco manufacturer
  * @since Version 3.9.1
  * @return \Railpage\Locos\Manufacturer
  */
 public function getManufacturer()
 {
     return Factory::Create("Manufacturer", $this->manufacturer_id);
 }
示例#4
0
 /**
  * Find Railpage objects (loco, class, livery) in this image
  *
  * @since Version 3.8.7
  *
  * @param string  $namespace
  * @param boolean $force
  *
  * @return \Railpage\Images\Image;
  * @throws \Exception if $namespace is null or empty
  */
 public function findObjects($namespace = null, $force = false)
 {
     if (is_null($namespace)) {
         throw new Exception("Parameter 1 (namespace) cannot be empty");
     }
     $key = sprintf("railpage:images.image=%d;objects.namespace=%s;lastupdate", $this->id, $namespace);
     $lastupdate = $this->Memcached->fetch($key);
     if (!$force && $lastupdate && $lastupdate > strtotime("1 day ago")) {
         return $this;
     }
     /**
      * Start the debug timer
      */
     $timer = Debug::GetTimer();
     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)) {
                         Debug::LogEvent(__METHOD__ . " :: #1 Instantating new LocoClass object with ID " . $matches[1] . "  ");
                         $LocoClass = LocosFactory::CreateLocoClass($matches[1]);
                     }
                 }
                 foreach ($this->meta['tags'] as $tag) {
                     if (isset($LocoClass) && $LocoClass instanceof LocoClass && preg_match("@railpage:loco=([a-zA-Z0-9]+)@", $tag, $matches)) {
                         Debug::LogEvent(__METHOD__ . " :: #2 Instantating new LocoClass object with class ID " . $LocoClass->id . " and loco number " . $matches[1] . "  ");
                         $Loco = LocosFactory::CreateLocomotive(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);
                             Debug::LogEvent(__METHOD__ . " :: #3 Instantating new LocoClass object with class ID " . $row['class_id'] . " and loco number " . $loco_num . "  ");
                             $Loco = LocosFactory::CreateLocomotive(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 = LocosFactory::CreateLocoClass($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 = LocosFactory::CreateLocoClass($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;
     }
     Debug::LogEvent(__METHOD__ . "(\"" . $namespace . "\")", $timer);
     $this->Memcached->save($key, time());
     return $this;
 }
 /**
  * Get locomotive classes built by this wheel arrangement
  * @return array
  */
 public function getClasses()
 {
     $query = "SELECT id, name, loco_type_id, introduced AS year_introduced, manufacturer_id, wheel_arrangement_id FROM loco_class WHERE wheel_arrangement_id = ? ORDER BY name";
     $return = array();
     foreach ($this->db->fetchAll($query, $this->id) as $row) {
         $LocoClass = Factory::CreateLocoClass($row['id']);
         $return[] = $LocoClass->getArray();
     }
     return $return;
 }
示例#6
0
 /**
  * Process this row as a locomotive class
  * @since Version 3.9.1
  * @return void
  */
 private static function processLocomotiveClass()
 {
     $LocoClass = LocosFactory::CreateLocoClass(self::$row['value']);
     if (!$LocoClass instanceof LocoClass) {
         return;
     }
     self::$row['meta']['object']['title'] = $LocoClass->name;
     self::$row['meta']['namespace'] = $LocoClass->namespace;
     self::$row['meta']['id'] = $LocoClass->id;
 }
示例#7
0
 /**
  * @depends testAddLoco
  */
 public function test_addDate($loco_id)
 {
     $TestLoco = LocosFactory::CreateLocomotive($loco_id);
     $Date = new Date();
     $Date->Loco = $TestLoco;
     $Date->Date = new DateTime();
     $Date->action_id = 1;
     $Date->meta = ["test" => "blalh"];
     $Date->commit();
     $id = $Date->id;
     $Date = new Date($id);
 }