public static function map($response) { $responseDOM = new \DOMDocument(); $responseDOM->loadXML($response); $purchaseInvoiceTags = array('date' => 'setDate', 'duedate' => 'setDueDate', 'inputdate' => 'setInputDate', 'invoicenumber' => 'setInvoiceNumber', 'modificationdate' => 'setModificationDate', 'number' => 'setNumber', 'origin' => 'setOrigin', 'originreference' => 'setOriginReference', 'period' => 'setPeriod', 'regime' => 'setRegime'); $purchaseInvoice = new PurchaseInvoice(); foreach ($purchaseInvoiceTags as $tag => $method) { $_tag = $responseDOM->getElementsByTagName($tag)->item(0); if (isset($_tag) && isset($_tag->textContent)) { $purchaseInvoice->{$method}($_tag->textContent); } } $currencyTag = $responseDOM->getElementsByTagName('currency')->item(0); if (isset($currencyTag)) { $currency = new Currency(); $currency->setCode($currencyTag->textContent); $currency->setName($currencyTag->attributes->getNamedItem('name')->textContent); $currency->setShortName($currencyTag->attributes->getNamedItem('shortname')->textContent); $purchaseInvoice->setCurrency($currency); } $userTag = $responseDOM->getElementsByTagName('user')->item(0); if (isset($userTag)) { $user = new User(); $user->setCode($userTag->textContent); $user->setName($userTag->attributes->getNamedItem('name')->textContent); $user->setShortName($userTag->attributes->getNamedItem('shortname')->textContent); $purchaseInvoice->setUser($user); } return $purchaseInvoice; }
/** * List all users. * @param string $officeCode the office code, if only users from one office should be listed * @param integer $accessRules * @param integer $mutualOffices * @param string $pattern The search pattern. May contain wildcards * and ? * @param int $field The search field determines which field or fields will be searched. The available fields * depends on the finder type. Passing a value outside the specified values will cause an error. * @param int $firstRow First row to return, useful for paging * @param int $maxRows Maximum number of rows to return, useful for paging * @param array $options The Finder options. Passing an unsupported name or value causes an error. It's possible to * add multiple options. An option name may be used once, specifying an option multiple times will cause an error. * @return User[] the users found */ public function listAll($officeCode = null, $accessRules = null, $mutualOffices = null, $pattern = '*', $field = 0, $firstRow = 1, $maxRows = 100, $options = array()) { if (!is_null($officeCode)) { $options['office'] = $officeCode; } if (!is_null($accessRules)) { $options['accessRules'] = $accessRules; } if (!is_null($mutualOffices)) { $options['mutualOffices'] = $mutualOffices; } $response = $this->searchFinder(self::TYPE_USERS, $pattern, $field, $firstRow, $maxRows, $options); $users = []; foreach ($response->data->Items->ArrayOfString as $userArray) { $user = new User(); $user->setCode($userArray->string[0]); $user->setName($userArray->string[1]); $users[] = $user; } return $users; }