/** * Find records based on the passed filter. * * Example usage: * * $f = new ExactTarget_SimpleFilterPart(); * $f->Property = 'id'; * $f->Value = $id; * $f->SimpleOperator = ExactTarget_SimpleOperators::equals; * * $de = new MyDataExtension(); * $records = $de->find($f, ETCore::HYDRATE_ARRAY); * * @param mixed $filter SimpleFilterPart or ComplexFilterPart * @param integer $hydrationMode See ETCore * @return mixed ETCollection or array, depending on hydration mode * @throws Exception */ public function find($filter, $hydrationMode = ETCore::HYDRATE_ARRAY) { try { $typeName = null; if ($filter instanceof ExactTarget_SimpleFilterPart) { $typeName = 'SimpleFilterPart'; } else { if ($filter instanceof ExactTarget_ComplexFilterPart) { $typeName = 'ComplexFilterPart'; } else { throw new ETException('First parameter must be of type ExactTarget_SimpleFilterPart or ExactTarget_ComplexFilterPart.'); } } $res = null; $rr = new ExactTarget_RetrieveRequest(); $rr->ObjectType = 'DataExtensionObject[' . $this->customerKey . ']'; $rr->Properties = $this->schema; $rr->Filter = ETCore::toSoapVar($filter, $typeName); $rr->Options = null; $rrm = new ExactTarget_RetrieveRequestMsg(); $rrm->RetrieveRequest = $rr; $result = $this->soapClient->Retrieve($rrm); $records = array(); if (!property_exists($result, 'Results')) { $result->Results = array(); } if (!is_array($result->Results)) { $result->Results = array($result->Results); } foreach ($result->Results as $fields) { $record = array(); foreach ($fields->Properties->Property as $field) { $record[$field->Name] = $field->Value; } if (count($record) > 0) { $records[] = $record; } } if ($hydrationMode == ETCore::HYDRATE_ARRAY) { $res = $records; } else { $coll = new ETCollection(); foreach ($records as $record) { $eo = new $this->extensionObjectClassName(); $eo->fromArray($record); $coll->add($eo); } $res = $coll; } return $res; } catch (Exception $e) { throw new ETException(__METHOD__ . ':' . __LINE__ . '|' . $e->getMessage()); } }
protected function _find($filter, $hydrationMode = ETCore::HYDRATE_ARRAY, $one = false) { $typeName = null; if ($filter instanceof ExactTarget_SimpleFilterPart) { $typeName = 'SimpleFilterPart'; } else { if ($filter instanceof ExactTarget_ComplexFilterPart) { $typeName = 'ComplexFilterPart'; } else { throw new ETException('First parameter must be of type ExactTarget_SimpleFilterPart or ExactTarget_ComplexFilterPart.'); } } $rr = new ExactTarget_RetrieveRequest(); $rr->ObjectType = "Subscriber"; $rr->Properties = $this->retrievableProperties(); $rr->Filter = ETCore::toSoapVar($filter, $typeName); $rr->Options = null; $rrm = new ExactTarget_RetrieveRequestMsg(); $rrm->RetrieveRequest = $rr; $result = $this->soapClient->Retrieve($rrm); ETCore::evaluateSoapResult($result); return $this->hydrate($result, $hydrationMode, $one); }
/** * Save the record. * * @return type */ public function save() { try { if (count($this->modifiedFiels) == 0) { return false; } $deoSo = $this->makeSoapVarForSave(); $uo = new ExactTarget_UpdateOptions(); $uo->SaveOptions = array(); $so = new ExactTarget_SaveOption(); $so->PropertyName = 'DataExtensionObject'; $so->SaveAction = ExactTarget_SaveAction::UpdateAdd; $uo->SaveOptions[] = $so; $uoSo = ETCore::toSoapVar($uo, 'UpdateOptions'); $request = new ExactTarget_UpdateRequest(); $request->Options = $uoSo; $request->Objects = array($deoSo); $result = $this->soapClient->Update($request); $this->evaluateResult($result); return true; } catch (Exception $e) { throw new ETException(__METHOD__ . ':' . __LINE__ . '|' . $e->getMessage()); } }
/** * ExactTarget SOAP update that allows the update action to be specified. * * @param array $objects Array of SOAP objects to be updated * @param integet $saveAction A constant integer specifying the action. * * @return ExactTarget SOAP response * $throws Exception */ protected static function _update($objects, $saveAction) { try { $soapClient = self::getClient(); $uo = new ExactTarget_UpdateOptions(); $uo->SaveOptions = array(); $so = new ExactTarget_SaveOption(); $so->PropertyName = '*'; $so->SaveAction = $saveAction; $uo->SaveOptions[] = $so; $uoSo = ETCore::toSoapVar($uo, 'UpdateOptions'); $request = new ExactTarget_UpdateRequest(); $request->Options = $uoSo; $request->Objects = $objects; return $soapClient->Update($request); } catch (Exception $e) { throw new ETException(__METHOD__ . ':' . __LINE__ . '|' . $e->getMessage()); } }
/** * Helper method that creates a SoapVar object. * * @return SoapVar */ protected function makeSoapVar() { $subscriber = new ExactTarget_Subscriber(); $this->modifiedProperties = array_unique(array_merge($this->modifiedProperties, $this->requiredProperties)); foreach ($this->modifiedProperties as $propName) { $subscriber->{$propName} = $this->properties[$propName]; } $subscriber->Attributes = array(); $this->modifiedAttributes = array_unique(array_merge($this->modifiedAttributes, $this->requiredAttributes)); foreach ($this->modifiedAttributes as $attrName) { $subscriber->Attributes[] = ETCore::newAttribute($attrName, $this->attributes[$attrName]); } return ETCore::toSoapVar($subscriber, 'Subscriber'); }