示例#1
0
 /**
  * Return a locomotive
  *
  * @since Version 3.9.1
  * @return \Railpage\Locos\Locomotive
  *
  * @param int|bool    $id
  * @param string|bool $class
  * @param string|bool $number
  */
 public static function CreateLocomotive($id = false, $class = false, $number = false)
 {
     $Redis = AppCore::getRedis();
     $Registry = Registry::getInstance();
     if (!filter_var($id, FILTER_VALIDATE_INT)) {
         $id = Utility\LocomotiveUtility::getLocoId($class, $number);
     }
     if ($id = filter_var($id, FILTER_VALIDATE_INT)) {
         $regkey = sprintf(Locomotive::REGISTRY_KEY, $id);
         try {
             $Loco = $Registry->get($regkey);
         } catch (Exception $e) {
             $cachekey = sprintf(Locomotive::CACHE_KEY, $id);
             if (!self::USE_REDIS || !($Loco = $Redis->fetch($cachekey))) {
                 $Loco = new Locomotive($id);
                 if (self::USE_REDIS) {
                     $Redis->save($cachekey, $Loco);
                 }
             }
             $Registry->set($regkey, $Loco);
         }
         return $Loco;
     }
     return false;
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * Generate descriptive text
  * @since Version 3.9.1
  * @return string
  */
 public function generateDescription()
 {
     $mckey = sprintf(self::CACHE_KEY_DESC, $this->id);
     if ($str = $this->Memcached->fetch($mckey)) {
         return $str;
     }
     $bits = array();
     /**
      * Built as... by...
      */
     $bits = Utility\LocomotiveUtility::getDescriptionBits_Manufacturer($this, $bits);
     /**
      * Process the dates
      */
     $bits = Utility\LocomotiveUtility::getDescriptionBits_Dates($this, $bits);
     /**
      * The loco is currently...
      */
     $bits = Utility\LocomotiveUtility::getDescriptionBits_Status($this, $bits);
     /**
      * Join it all together
      */
     $str = trim(implode("", $bits));
     if (preg_match("/([a-zA-Z0-9]+)/", substr($str, -1))) {
         $str .= ".";
     }
     if (substr($str, -1) === ",") {
         $str = substr($str, 0, -1) . ".";
     }
     $this->Memcached->save($mckey, $str, strtotime("+1 year"));
     return $str;
 }
示例#4
0
 /**
  * Get liveries carried by this loco class
  * Based on tagged Flickr photos
  * @since Version 3.2
  * @return array|boolean
  */
 public function getLiveries()
 {
     return Utility\LocomotiveUtility::getLiveriesForLocomotiveClass($this->id);
 }