Esempio n. 1
0
 /**
  * Export to a simple array for the purposes of easily
  * serializing the structure into JSON
  */
 public function __toArray()
 {
     $ret = array('season' => $this->season, 'turnId' => $this->turn->getPrimaryKey(), 'orders' => array(), 'retreatsRequired' => array(), 'unitSupply' => array());
     // Format the orders
     foreach ($this->turn->getOrders() as $o) {
         $o = Order::downCast($o);
         try {
             //$ret['orders'][] = $o->__toArray();
         } catch (Exception $e) {
             $this->log->warning($e->getMessage());
         }
     }
     // Retreats.
     foreach ($this->retreats as $r) {
         $ret['required_retreats'] = array('territory' => $r['territory']->__toArray(), 'winner' => $r['winner']->__toArray(), 'loser' => $r['winner']->__toArray());
     }
     // Retreats.
     $ret['unit-supply'] = $this->unit_supply->__toArray();
     return $ret;
 }
Esempio n. 2
0
 /**
  * Not proper downcasting, really replacing an object with it's
  * child.
  */
 public static function downCast(Order $o)
 {
     if ($o->hasChildObject()) {
         //print "Downcasting to ". $o->getDescendantClass() . "\n";
         return $o->getChildObject();
     } else {
         return $o;
     }
 }