2
0

VolumeEntry.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Books
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc.
  19. * (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /**
  23. * @see Zend_Gdata_Entry
  24. */
  25. require_once 'Zend/Gdata/Entry.php';
  26. /**
  27. * @see Zend_Gdata_Extension_Comments
  28. */
  29. require_once 'Zend/Gdata/Extension/Comments.php';
  30. /**
  31. * @see Zend_Gdata_DublinCore_Extension_Creator
  32. */
  33. require_once 'Zend/Gdata/DublinCore/Extension/Creator.php';
  34. /**
  35. * @see Zend_Gdata_DublinCore_Extension_Date
  36. */
  37. require_once 'Zend/Gdata/DublinCore/Extension/Date.php';
  38. /**
  39. * @see Zend_Gdata_DublinCore_Extension_Description
  40. */
  41. require_once 'Zend/Gdata/DublinCore/Extension/Description.php';
  42. /**
  43. * @see Zend_Gdata_Books_Extension_Embeddability
  44. */
  45. require_once 'Zend/Gdata/Books/Extension/Embeddability.php';
  46. /**
  47. * @see Zend_Gdata_DublinCore_Extension_Format
  48. */
  49. require_once 'Zend/Gdata/DublinCore/Extension/Format.php';
  50. /**
  51. * @see Zend_Gdata_DublinCore_Extension_Identifier
  52. */
  53. require_once 'Zend/Gdata/DublinCore/Extension/Identifier.php';
  54. /**
  55. * @see Zend_Gdata_DublinCore_Extension_Language
  56. */
  57. require_once 'Zend/Gdata/DublinCore/Extension/Language.php';
  58. /**
  59. * @see Zend_Gdata_DublinCore_Extension_Publisher
  60. */
  61. require_once 'Zend/Gdata/DublinCore/Extension/Publisher.php';
  62. /**
  63. * @see Zend_Gdata_Extension_Rating
  64. */
  65. require_once 'Zend/Gdata/Extension/Rating.php';
  66. /**
  67. * @see Zend_Gdata_Books_Extension_Review
  68. */
  69. require_once 'Zend/Gdata/Books/Extension/Review.php';
  70. /**
  71. * @see Zend_Gdata_DublinCore_Extension_Subject
  72. */
  73. require_once 'Zend/Gdata/DublinCore/Extension/Subject.php';
  74. /**
  75. * @see Zend_Gdata_DublinCore_Extension_Title
  76. */
  77. require_once 'Zend/Gdata/DublinCore/Extension/Title.php';
  78. /**
  79. * @see Zend_Gdata_Books_Extension_Viewability
  80. */
  81. require_once 'Zend/Gdata/Books/Extension/Viewability.php';
  82. /**
  83. * Describes an entry in a feed of Book Search volumes
  84. *
  85. * @category Zend
  86. * @package Zend_Gdata
  87. * @subpackage Books
  88. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc.
  89. * (http://www.zend.com)
  90. * @license http://framework.zend.com/license/new-bsd New BSD License
  91. */
  92. class Zend_Gdata_Books_VolumeEntry extends Zend_Gdata_Entry
  93. {
  94. const THUMBNAIL_LINK_REL = 'http://schemas.google.com/books/2008/thumbnail';
  95. const PREVIEW_LINK_REL = 'http://schemas.google.com/books/2008/preview';
  96. const INFO_LINK_REL = 'http://schemas.google.com/books/2008/info';
  97. const ANNOTATION_LINK_REL = 'http://schemas.google.com/books/2008/annotation';
  98. protected $_comments = null;
  99. protected $_creators = array();
  100. protected $_dates = array();
  101. protected $_descriptions = array();
  102. protected $_embeddability = null;
  103. protected $_formats = array();
  104. protected $_identifiers = array();
  105. protected $_languages = array();
  106. protected $_publishers = array();
  107. protected $_rating = null;
  108. protected $_review = null;
  109. protected $_subjects = array();
  110. protected $_titles = array();
  111. protected $_viewability = null;
  112. /**
  113. * Constructor for Zend_Gdata_Books_VolumeEntry which
  114. * Describes an entry in a feed of Book Search volumes
  115. *
  116. * @param DOMElement $element (optional) DOMElement from which this
  117. * object should be constructed.
  118. */
  119. public function __construct($element = null)
  120. {
  121. $this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
  122. parent::__construct($element);
  123. }
  124. /**
  125. * Retrieves DOMElement which corresponds to this element and all
  126. * child properties. This is used to build this object back into a DOM
  127. * and eventually XML text for sending to the server upon updates, or
  128. * for application storage/persistance.
  129. *
  130. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  131. * @return DOMElement The DOMElement representing this element and all
  132. * child properties.
  133. */
  134. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  135. {
  136. $element = parent::getDOM($doc);
  137. if ($this->_creators !== null) {
  138. foreach ($this->_creators as $creators) {
  139. $element->appendChild($creators->getDOM(
  140. $element->ownerDocument));
  141. }
  142. }
  143. if ($this->_dates !== null) {
  144. foreach ($this->_dates as $dates) {
  145. $element->appendChild($dates->getDOM($element->ownerDocument));
  146. }
  147. }
  148. if ($this->_descriptions !== null) {
  149. foreach ($this->_descriptions as $descriptions) {
  150. $element->appendChild($descriptions->getDOM(
  151. $element->ownerDocument));
  152. }
  153. }
  154. if ($this->_formats !== null) {
  155. foreach ($this->_formats as $formats) {
  156. $element->appendChild($formats->getDOM(
  157. $element->ownerDocument));
  158. }
  159. }
  160. if ($this->_identifiers !== null) {
  161. foreach ($this->_identifiers as $identifiers) {
  162. $element->appendChild($identifiers->getDOM(
  163. $element->ownerDocument));
  164. }
  165. }
  166. if ($this->_languages !== null) {
  167. foreach ($this->_languages as $languages) {
  168. $element->appendChild($languages->getDOM(
  169. $element->ownerDocument));
  170. }
  171. }
  172. if ($this->_publishers !== null) {
  173. foreach ($this->_publishers as $publishers) {
  174. $element->appendChild($publishers->getDOM(
  175. $element->ownerDocument));
  176. }
  177. }
  178. if ($this->_subjects !== null) {
  179. foreach ($this->_subjects as $subjects) {
  180. $element->appendChild($subjects->getDOM(
  181. $element->ownerDocument));
  182. }
  183. }
  184. if ($this->_titles !== null) {
  185. foreach ($this->_titles as $titles) {
  186. $element->appendChild($titles->getDOM($element->ownerDocument));
  187. }
  188. }
  189. if ($this->_comments !== null) {
  190. $element->appendChild($this->_comments->getDOM(
  191. $element->ownerDocument));
  192. }
  193. if ($this->_embeddability !== null) {
  194. $element->appendChild($this->_embeddability->getDOM(
  195. $element->ownerDocument));
  196. }
  197. if ($this->_rating !== null) {
  198. $element->appendChild($this->_rating->getDOM(
  199. $element->ownerDocument));
  200. }
  201. if ($this->_review !== null) {
  202. $element->appendChild($this->_review->getDOM(
  203. $element->ownerDocument));
  204. }
  205. if ($this->_viewability !== null) {
  206. $element->appendChild($this->_viewability->getDOM(
  207. $element->ownerDocument));
  208. }
  209. return $element;
  210. }
  211. /**
  212. * Creates individual objects of the appropriate type and stores
  213. * them in this object based upon DOM data.
  214. *
  215. * @param DOMNode $child The DOMNode to process.
  216. */
  217. protected function takeChildFromDOM($child)
  218. {
  219. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  220. switch ($absoluteNodeName) {
  221. case $this->lookupNamespace('dc') . ':' . 'creator':
  222. $creators = new Zend_Gdata_DublinCore_Extension_Creator();
  223. $creators->transferFromDOM($child);
  224. $this->_creators[] = $creators;
  225. break;
  226. case $this->lookupNamespace('dc') . ':' . 'date':
  227. $dates = new Zend_Gdata_DublinCore_Extension_Date();
  228. $dates->transferFromDOM($child);
  229. $this->_dates[] = $dates;
  230. break;
  231. case $this->lookupNamespace('dc') . ':' . 'description':
  232. $descriptions = new Zend_Gdata_DublinCore_Extension_Description();
  233. $descriptions->transferFromDOM($child);
  234. $this->_descriptions[] = $descriptions;
  235. break;
  236. case $this->lookupNamespace('dc') . ':' . 'format':
  237. $formats = new Zend_Gdata_DublinCore_Extension_Format();
  238. $formats->transferFromDOM($child);
  239. $this->_formats[] = $formats;
  240. break;
  241. case $this->lookupNamespace('dc') . ':' . 'identifier':
  242. $identifiers = new Zend_Gdata_DublinCore_Extension_Identifier();
  243. $identifiers->transferFromDOM($child);
  244. $this->_identifiers[] = $identifiers;
  245. break;
  246. case $this->lookupNamespace('dc') . ':' . 'language':
  247. $languages = new Zend_Gdata_DublinCore_Extension_Language();
  248. $languages->transferFromDOM($child);
  249. $this->_languages[] = $languages;
  250. break;
  251. case $this->lookupNamespace('dc') . ':' . 'publisher':
  252. $publishers = new Zend_Gdata_DublinCore_Extension_Publisher();
  253. $publishers->transferFromDOM($child);
  254. $this->_publishers[] = $publishers;
  255. break;
  256. case $this->lookupNamespace('dc') . ':' . 'subject':
  257. $subjects = new Zend_Gdata_DublinCore_Extension_Subject();
  258. $subjects->transferFromDOM($child);
  259. $this->_subjects[] = $subjects;
  260. break;
  261. case $this->lookupNamespace('dc') . ':' . 'title':
  262. $titles = new Zend_Gdata_DublinCore_Extension_Title();
  263. $titles->transferFromDOM($child);
  264. $this->_titles[] = $titles;
  265. break;
  266. case $this->lookupNamespace('gd') . ':' . 'comments':
  267. $comments = new Zend_Gdata_Extension_Comments();
  268. $comments->transferFromDOM($child);
  269. $this->_comments = $comments;
  270. break;
  271. case $this->lookupNamespace('gbs') . ':' . 'embeddability':
  272. $embeddability = new Zend_Gdata_Books_Extension_Embeddability();
  273. $embeddability->transferFromDOM($child);
  274. $this->_embeddability = $embeddability;
  275. break;
  276. case $this->lookupNamespace('gd') . ':' . 'rating':
  277. $rating = new Zend_Gdata_Extension_Rating();
  278. $rating->transferFromDOM($child);
  279. $this->_rating = $rating;
  280. break;
  281. case $this->lookupNamespace('gbs') . ':' . 'review':
  282. $review = new Zend_Gdata_Books_Extension_Review();
  283. $review->transferFromDOM($child);
  284. $this->_review = $review;
  285. break;
  286. case $this->lookupNamespace('gbs') . ':' . 'viewability':
  287. $viewability = new Zend_Gdata_Books_Extension_Viewability();
  288. $viewability->transferFromDOM($child);
  289. $this->_viewability = $viewability;
  290. break;
  291. default:
  292. parent::takeChildFromDOM($child);
  293. break;
  294. }
  295. }
  296. /**
  297. * Returns the Comments class
  298. *
  299. * @return Zend_Gdata_Extension_Comments|null The comments
  300. */
  301. public function getComments()
  302. {
  303. return $this->_comments;
  304. }
  305. /**
  306. * Returns the creators
  307. *
  308. * @return array The creators
  309. */
  310. public function getCreators()
  311. {
  312. return $this->_creators;
  313. }
  314. /**
  315. * Returns the dates
  316. *
  317. * @return array The dates
  318. */
  319. public function getDates()
  320. {
  321. return $this->_dates;
  322. }
  323. /**
  324. * Returns the descriptions
  325. *
  326. * @return array The descriptions
  327. */
  328. public function getDescriptions()
  329. {
  330. return $this->_descriptions;
  331. }
  332. /**
  333. * Returns the embeddability
  334. *
  335. * @return Zend_Gdata_Books_Extension_Embeddability|null The embeddability
  336. */
  337. public function getEmbeddability()
  338. {
  339. return $this->_embeddability;
  340. }
  341. /**
  342. * Returns the formats
  343. *
  344. * @return array The formats
  345. */
  346. public function getFormats()
  347. {
  348. return $this->_formats;
  349. }
  350. /**
  351. * Returns the identifiers
  352. *
  353. * @return array The identifiers
  354. */
  355. public function getIdentifiers()
  356. {
  357. return $this->_identifiers;
  358. }
  359. /**
  360. * Returns the languages
  361. *
  362. * @return array The languages
  363. */
  364. public function getLanguages()
  365. {
  366. return $this->_languages;
  367. }
  368. /**
  369. * Returns the publishers
  370. *
  371. * @return array The publishers
  372. */
  373. public function getPublishers()
  374. {
  375. return $this->_publishers;
  376. }
  377. /**
  378. * Returns the rating
  379. *
  380. * @return Zend_Gdata_Extension_Rating|null The rating
  381. */
  382. public function getRating()
  383. {
  384. return $this->_rating;
  385. }
  386. /**
  387. * Returns the review
  388. *
  389. * @return Zend_Gdata_Books_Extension_Review|null The review
  390. */
  391. public function getReview()
  392. {
  393. return $this->_review;
  394. }
  395. /**
  396. * Returns the subjects
  397. *
  398. * @return array The subjects
  399. */
  400. public function getSubjects()
  401. {
  402. return $this->_subjects;
  403. }
  404. /**
  405. * Returns the titles
  406. *
  407. * @return array The titles
  408. */
  409. public function getTitles()
  410. {
  411. return $this->_titles;
  412. }
  413. /**
  414. * Returns the viewability
  415. *
  416. * @return Zend_Gdata_Books_Extension_Viewability|null The viewability
  417. */
  418. public function getViewability()
  419. {
  420. return $this->_viewability;
  421. }
  422. /**
  423. * Sets the Comments class
  424. *
  425. * @param Zend_Gdata_Extension_Comments|null $comments Comments class
  426. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  427. */
  428. public function setComments($comments)
  429. {
  430. $this->_comments = $comments;
  431. return $this;
  432. }
  433. /**
  434. * Sets the creators
  435. *
  436. * @param array $creators Creators|null
  437. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  438. */
  439. public function setCreators($creators)
  440. {
  441. $this->_creators = $creators;
  442. return $this;
  443. }
  444. /**
  445. * Sets the dates
  446. *
  447. * @param array $dates dates
  448. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  449. */
  450. public function setDates($dates)
  451. {
  452. $this->_dates = $dates;
  453. return $this;
  454. }
  455. /**
  456. * Sets the descriptions
  457. *
  458. * @param array $descriptions descriptions
  459. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  460. */
  461. public function setDescriptions($descriptions)
  462. {
  463. $this->_descriptions = $descriptions;
  464. return $this;
  465. }
  466. /**
  467. * Sets the embeddability
  468. *
  469. * @param Zend_Gdata_Books_Extension_Embeddability|null $embeddability
  470. * embeddability
  471. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  472. */
  473. public function setEmbeddability($embeddability)
  474. {
  475. $this->_embeddability = $embeddability;
  476. return $this;
  477. }
  478. /**
  479. * Sets the formats
  480. *
  481. * @param array $formats formats
  482. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  483. */
  484. public function setFormats($formats)
  485. {
  486. $this->_formats = $formats;
  487. return $this;
  488. }
  489. /**
  490. * Sets the identifiers
  491. *
  492. * @param array $identifiers identifiers
  493. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  494. */
  495. public function setIdentifiers($identifiers)
  496. {
  497. $this->_identifiers = $identifiers;
  498. return $this;
  499. }
  500. /**
  501. * Sets the languages
  502. *
  503. * @param array $languages languages
  504. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  505. */
  506. public function setLanguages($languages)
  507. {
  508. $this->_languages = $languages;
  509. return $this;
  510. }
  511. /**
  512. * Sets the publishers
  513. *
  514. * @param array $publishers publishers
  515. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  516. */
  517. public function setPublishers($publishers)
  518. {
  519. $this->_publishers = $publishers;
  520. return $this;
  521. }
  522. /**
  523. * Sets the rating
  524. *
  525. * @param Zend_Gdata_Extension_Rating|null $rating rating
  526. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  527. */
  528. public function setRating($rating)
  529. {
  530. $this->_rating = $rating;
  531. return $this;
  532. }
  533. /**
  534. * Sets the review
  535. *
  536. * @param Zend_Gdata_Books_Extension_Review|null $review review
  537. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  538. */
  539. public function setReview($review)
  540. {
  541. $this->_review = $review;
  542. return $this;
  543. }
  544. /**
  545. * Sets the subjects
  546. *
  547. * @param array $subjects subjects
  548. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  549. */
  550. public function setSubjects($subjects)
  551. {
  552. $this->_subjects = $subjects;
  553. return $this;
  554. }
  555. /**
  556. * Sets the titles
  557. *
  558. * @param array $titles titles
  559. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  560. */
  561. public function setTitles($titles)
  562. {
  563. $this->_titles = $titles;
  564. return $this;
  565. }
  566. /**
  567. * Sets the viewability
  568. *
  569. * @param Zend_Gdata_Books_Extension_Viewability|null $viewability
  570. * viewability
  571. * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
  572. */
  573. public function setViewability($viewability)
  574. {
  575. $this->_viewability = $viewability;
  576. return $this;
  577. }
  578. /**
  579. * Gets the volume ID based upon the atom:id value
  580. *
  581. * @return string The volume ID
  582. * @throws Zend_Gdata_App_Exception
  583. */
  584. public function getVolumeId()
  585. {
  586. $fullId = $this->getId()->getText();
  587. $position = strrpos($fullId, '/');
  588. if ($position === false) {
  589. require_once 'Zend/Gdata/App/Exception.php';
  590. throw new Zend_Gdata_App_Exception('Slash not found in atom:id');
  591. } else {
  592. return substr($fullId, strrpos($fullId,'/') + 1);
  593. }
  594. }
  595. /**
  596. * Gets the thumbnail link
  597. *
  598. * @return Zend_Gdata_App_Extension_link|null The thumbnail link
  599. */
  600. public function getThumbnailLink()
  601. {
  602. return $this->getLink(self::THUMBNAIL_LINK_REL);
  603. }
  604. /**
  605. * Gets the preview link
  606. *
  607. * @return Zend_Gdata_App_Extension_Link|null The preview link
  608. */
  609. public function getPreviewLink()
  610. {
  611. return $this->getLink(self::PREVIEW_LINK_REL);
  612. }
  613. /**
  614. * Gets the info link
  615. *
  616. * @return Zend_Gdata_App_Extension_Link|null The info link
  617. */
  618. public function getInfoLink()
  619. {
  620. return $this->getLink(self::INFO_LINK_REL);
  621. }
  622. /**
  623. * Gets the annotations link
  624. *
  625. * @return Zend_Gdata_App_Extension_Link|null The annotations link
  626. */
  627. public function getAnnotationLink()
  628. {
  629. return $this->getLink(self::ANNOTATION_LINK_REL);
  630. }
  631. }