Share Pastebin
Guest
Public paste!

DatabaseObject #2

By: a guest | Sep 9th, 2010 | Syntax: PHP | Size: 1.22 KB | Hits: 22 | Expires: Never
Copy text to clipboard
  1. class Planet extends DatabaseObject
  2. {
  3.         /**
  4.          * Creates a new Planet object with the specified data.
  5.          */
  6.         public function __construct( $data, $callMerge = true )
  7.         {
  8.                 if( $callMerge )
  9.                         $data = $this->mergeUncachedData( $data );
  10.                 parent::__construct( $data );
  11.         }
  12.  
  13.         /**
  14.          * Merges data from the cache and current data from the db like current resource values and TickActions.
  15.          */
  16.         private function mergeUncachedData( $data )
  17.         {
  18.                 $sql =
  19.                 "SELECT         `planets`.`iron`,
  20.                                         `planets`.`crystal`,
  21.                                         `planets`.`tritium`,
  22.                                         (
  23.                                                 SELECT          `tick`.`tickID`
  24.                                                 FROM            `libertyquest".( LIBERTYQUEST_N )."_tick` `tick`
  25.                                                 WHERE           `tick`.`planetID` = `planets`.`planetID`
  26.                                                         AND             `tick`.`function` = 'buildingFinished'
  27.                                         ) AS                    `hasBuildAction`
  28.                 FROM            `libertyquest".( LIBERTYQUEST_N )."_planets` `planets`
  29.                 WHERE           `planets`.`planetID` = '".( $data[ 'planetID' ] )."'";
  30.                 $data = array_merge( $data, WCF::getDB()->getFirstRow( $sql ) );
  31.                 return ( $data );
  32.         }
  33.  
  34.         /**
  35.          * Use this static method to retrieve a new Planet object based on the specified planetID.
  36.          */
  37.         public static function getPlanet( $planetID )
  38.         {
  39.                 return ( new Planet( WCF::getCache()->get( 'planet-' . $planetID ) ) );
  40.         }
  41.  
  42.         // ...
  43. }