Beispiel #1
0
 public static function convertToSweetToothObject($resp, $apiKey)
 {
     $types = array('activity' => 'SweetTooth_Activity', 'channel_environment' => 'SweetTooth_ChannelEnvironment', 'collection' => 'SweetTooth_Collection', 'customer' => 'SweetTooth_Customer', 'ping' => 'SweetTooth_Ping', 'points_product' => 'SweetTooth_PointsProduct', 'points_purchase' => 'SweetTooth_PointsPurchase', 'points_transaction' => 'SweetTooth_PointsTransaction', 'event' => 'SweetTooth_Event', 'redemption' => 'SweetTooth_Redemption', 'redemption_option' => 'SweetTooth_RedemptionOption', 'spending' => 'SweetTooth_Spending', 'spending_option' => 'SweetTooth_SpendingOption');
     if (self::isCollection($resp)) {
         $mapped = array();
         foreach ($resp as $i) {
             array_push($mapped, self::convertToSweetToothObject($i, $apiKey));
         }
         return $mapped;
     } else {
         if (is_array($resp)) {
             if (isset($resp['_object']) && is_string($resp['_object']) && isset($types[$resp['_object']])) {
                 $class = $types[$resp['_object']];
             } else {
                 $class = 'SweetTooth_Object';
             }
             return SweetTooth_Object::scopedConstructFrom($class, $resp, $apiKey);
         } else {
             return $resp;
         }
     }
 }
Beispiel #2
0
 public function refreshFrom($values, $apiKey, $partial = false)
 {
     $this->_apiKey = $apiKey;
     // Wipe old state before setting new.  This is useful for e.g. updating a
     // customer, where there is no persistent card parameter.  Mark those values
     // which don't persist as transient
     if ($partial) {
         $removed = new SweetTooth_Util_Set();
     } else {
         $removed = array_diff(array_keys($this->_values), array_keys($values));
     }
     foreach ($removed as $k) {
         if (self::$_permanentAttributes->includes($k)) {
             continue;
         }
         unset($this->{$k});
     }
     foreach ($values as $k => $v) {
         if (self::$_permanentAttributes->includes($k)) {
             continue;
         }
         if (self::$_nestedUpdatableAttributes->includes($k) && is_array($v)) {
             $this->_values[$k] = SweetTooth_Object::scopedConstructFrom('SweetTooth_AttachedObject', $v, $apiKey);
         } else {
             $this->_values[$k] = SweetTooth_Util::convertToSweetToothObject($v, $apiKey);
         }
         $this->_transientValues->discard($k);
         $this->_unsavedValues->discard($k);
     }
 }