/** * Créé un obj Book à partir du formulaire d'ajout * @param \Sb\Db\Model\Book $book * @param array $properties */ public static function map(\Sb\Db\Model\Model &$book, array $properties, $prefix = "") { if (array_key_exists($prefix . 'Author', $properties)) { $authorsVal = urldecode($properties[$prefix . 'Author']); // testing if the book has more than one author $hasMany = strpos($authorsVal, ",") !== false; // adding an array of contributor $contributors = new \Doctrine\Common\Collections\ArrayCollection(); if ($hasMany) { $authors = explode(",", $authorsVal); foreach ($authors as $author) { $contributor = \Sb\Db\Dao\ContributorDao::getInstance()->getByFullName($author); if (!$contributor) { $contributor = new \Sb\Db\Model\Contributor(); $contributor->setCreationDate(new \DateTime()); $contributor->setLastModificationDate(new \DateTime()); $contributor->setFullName($author); } $contributors->add($contributor); } $book->setContributors($contributors); } else { // adding just one contributor $contributor = \Sb\Db\Dao\ContributorDao::getInstance()->getByFullName($authorsVal); if (!$contributor) { $contributor = new \Sb\Db\Model\Contributor(); $contributor->setCreationDate(new \DateTime()); $contributor->setLastModificationDate(new \DateTime()); $contributor->setFullName($authorsVal); } $contributors->add($contributor); $book->setContributors($contributors); } } if (array_key_exists($prefix . 'Language', $properties)) { $book->setLanguage(urldecode($properties[$prefix . 'Language'])); } if (array_key_exists($prefix . 'Description', $properties)) { $book->setDescription(urldecode($properties[$prefix . 'Description'])); } if (array_key_exists($prefix . 'ISBN10', $properties)) { $book->setISBN10($properties[$prefix . 'ISBN10']); } if (array_key_exists($prefix . 'ISBN13', $properties)) { $book->setISBN13($properties[$prefix . 'ISBN13']); } if (array_key_exists($prefix . 'ASIN', $properties)) { $book->setASIN($properties[$prefix . 'ASIN']); } if (array_key_exists($prefix . 'Id', $properties)) { $book->setId($properties[$prefix . 'Id']); } if (array_key_exists($prefix . 'ImageBinary', $properties)) { $book->setImageBinary($properties[$prefix . 'ImageBinary']); } if (array_key_exists($prefix . 'ImageUrl', $properties)) { $book->setImageUrl($properties[$prefix . 'ImageUrl']); } if (array_key_exists($prefix . 'LargeImageUrl', $properties)) { $book->setLargeImageUrl($properties[$prefix . 'LargeImageUrl']); } if (array_key_exists($prefix . 'SmallImageUrl', $properties)) { $book->setSmallImageUrl($properties[$prefix . 'SmallImageUrl']); } if (array_key_exists($prefix . 'Publisher', $properties)) { $publisherVal = urldecode($properties[$prefix . 'Publisher']); $publisher = \Sb\Db\Dao\PublisherDao::getInstance()->getByName($publisherVal); if (!$publisher) { $publisher = new \Sb\Db\Model\Publisher(); $publisher->setCreationDate(new \DateTime()); $publisher->setLastModificationDate(new \DateTime()); $publisher->setName($publisherVal); } $book->setPublisher($publisher); } if (array_key_exists($prefix . 'Title', $properties)) { $book->setTitle(urldecode($properties[$prefix . 'Title'])); } if (array_key_exists($prefix . 'CreationDate', $properties)) { $book->setCreationDate(\Sb\Helpers\DateHelper::createDateTime($properties[$prefix . 'CreationDate'])); } if (array_key_exists($prefix . 'LastModificationDate', $properties)) { $book->setLastModificationDate(\Sb\Helpers\DateHelper::createDateTime($properties[$prefix . 'LastModificationDate'])); } if (array_key_exists($prefix . 'PublishingDate', $properties)) { $book->setPublishingDate(\Sb\Helpers\DateHelper::createDateTime($properties[$prefix . 'PublishingDate'])); } if (array_key_exists($prefix . 'AmazonUrl', $properties)) { $book->setAmazonUrl(urldecode($properties[$prefix . 'AmazonUrl'])); } if (array_key_exists($prefix . 'NbOfPages', $properties)) { $book->setNb_of_pages($properties[$prefix . 'NbOfPages']); } }