/** * Adds a PClass to the storage. * * @param KlarnaPClass $pclass PClass object. * * @throws KlarnaException * @return void */ public function addPClass($pclass) { if (!$pclass instanceof KlarnaPClass) { throw new Klarna_InvalidTypeException('pclass', 'KlarnaPClass'); } if (!isset($this->pclasses) || !is_array($this->pclasses)) { $this->pclasses = array(); } if ($pclass->getDescription() === null || $pclass->getType() === null) { //Something went wrong, do not save these! return; } if (!isset($this->pclasses[$pclass->getEid()])) { $this->pclasses[$pclass->getEid()] = array(); } $this->pclasses[$pclass->getEid()][$pclass->getId()] = $pclass; }
/** * Adds a PClass to the storage. * * @param KlarnaPClass $pclass PClass object. * @throws KlarnaException * @return void */ public function addPClass($pclass) { if($pclass instanceof KlarnaPClass) { if(!isset($this->pclasses) || !is_array($this->pclasses)) { $this->pclasses = array(); } if($pclass->getDescription() === null || $pclass->getType() === null) { //Something went wrong, do not save these! return; } if(!isset($this->pclasses[$pclass->getEid()])) { $this->pclasses[$pclass->getEid()] = array(); } $this->pclasses[$pclass->getEid()][$pclass->getId()] = $pclass; } else { throw new KlarnaException('Error in ' . __METHOD__ . ': Supplied pclass object is not an KlarnaPClass instance!'); } }
/** * Creates DOMElement for all fields for specified PClass. * * @ignore Do not show in PHPDoc. * @param KlarnaPClass $pclass * @return array Array of DOMElements. */ protected function createFields($pclass) { $fields = array(); //This is to prevent HTMLEntities to be converted to the real character. $fields[] = $this->dom->createElement('description'); end($fields)->appendChild($this->dom->createTextNode($pclass->getDescription())); $fields[] = $this->dom->createElement('months', $pclass->getMonths()); $fields[] = $this->dom->createElement('startfee', $pclass->getStartFee()); $fields[] = $this->dom->createElement('invoicefee', $pclass->getInvoiceFee()); $fields[] = $this->dom->createElement('interestrate', $pclass->getInterestRate()); $fields[] = $this->dom->createElement('minamount', $pclass->getMinAmount()); $fields[] = $this->dom->createElement('country', $pclass->getCountry()); $fields[] = $this->dom->createElement('expire', $pclass->getExpire()); return $fields; }
/** * Comparison function * * @param KlarnaPClass $a object 1 * @param KlarnaPClass $b object 2 * * @return int */ function pcCmp($a, $b) { if ($a->getDescription() == null && $b->getDescription() == null) { return 0; } else { if ($a->getDescription() == null) { return 1; } else { if ($b->getDescription() == null) { return -1; } else { if ($b->getType() === 2 && $a->getType() !== 2) { return 1; } else { if ($b->getType() !== 2 && $a->getType() === 2) { return -1; } } } } } return strnatcmp($a->getDescription(), $b->getDescription()) * -1; }