@@ -11,94 +11,94 @@ |
||
11 | 11 | */ |
12 | 12 | class Work extends Item { |
13 | 13 | |
14 | - const ITEM_WORK = 'Q386724'; |
|
15 | - const PROP_SUBTITLE = 'P1680'; |
|
16 | - const PROP_GENRE = 'P136'; |
|
17 | - const PROP_SUBJECT = 'P921'; |
|
14 | + const ITEM_WORK = 'Q386724'; |
|
15 | + const PROP_SUBTITLE = 'P1680'; |
|
16 | + const PROP_GENRE = 'P136'; |
|
17 | + const PROP_SUBJECT = 'P921'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $lang ISO639 language code. |
|
21 | - * @param CacheItemPoolInterface $cache The cache. |
|
22 | - * @return array|Item[] |
|
23 | - */ |
|
24 | - public static function getBookTypes( $lang = 'en', $cache ) { |
|
25 | - $sparql = "SELECT ?item WHERE { |
|
19 | + /** |
|
20 | + * @param string $lang ISO639 language code. |
|
21 | + * @param CacheItemPoolInterface $cache The cache. |
|
22 | + * @return array|Item[] |
|
23 | + */ |
|
24 | + public static function getBookTypes( $lang = 'en', $cache ) { |
|
25 | + $sparql = "SELECT ?item WHERE { |
|
26 | 26 | ?item wdt:P279 wd:Q571 . |
27 | 27 | ?item rdfs:label ?label . |
28 | 28 | FILTER(LANG(?label) = '$lang') . |
29 | 29 | } ORDER BY ?label "; |
30 | - $query = new Query( $sparql, $lang ); |
|
31 | - $query->setCache( $cache ); |
|
32 | - $bookType = Item::factory( self::ITEM_WORK, $lang, $cache ); |
|
33 | - return [ $bookType ] + $query->getItems(); |
|
34 | - } |
|
30 | + $query = new Query( $sparql, $lang ); |
|
31 | + $query->setCache( $cache ); |
|
32 | + $bookType = Item::factory( self::ITEM_WORK, $lang, $cache ); |
|
33 | + return [ $bookType ] + $query->getItems(); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return bool|string |
|
38 | - */ |
|
39 | - public function getSubtitle() { |
|
40 | - return $this->getPropertyOfTypeText( self::PROP_SUBTITLE ); |
|
41 | - } |
|
36 | + /** |
|
37 | + * @return bool|string |
|
38 | + */ |
|
39 | + public function getSubtitle() { |
|
40 | + return $this->getPropertyOfTypeText( self::PROP_SUBTITLE ); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $subtitle The new subtitle. |
|
45 | - */ |
|
46 | - public function setSubtitle( $subtitle ) { |
|
47 | - $this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle ); |
|
48 | - } |
|
43 | + /** |
|
44 | + * @param string $subtitle The new subtitle. |
|
45 | + */ |
|
46 | + public function setSubtitle( $subtitle ) { |
|
47 | + $this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle ); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $property A property identifier. |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getPropertyOfTypeItems( $property ) { |
|
55 | - $entity = $this->getEntity( $this->id ); |
|
56 | - if ( ! isset( $entity['claims'][ $property ] ) ) { |
|
57 | - return []; |
|
58 | - } |
|
59 | - $items = []; |
|
60 | - foreach ( $entity['claims'][ $property ] as $authorClaim ) { |
|
61 | - $item_id = $authorClaim['mainsnak']['datavalue']['value']['id']; |
|
62 | - $items[] = Item::factory( $item_id, $this->lang, $this->cache ); |
|
63 | - } |
|
50 | + /** |
|
51 | + * @param string $property A property identifier. |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getPropertyOfTypeItems( $property ) { |
|
55 | + $entity = $this->getEntity( $this->id ); |
|
56 | + if ( ! isset( $entity['claims'][ $property ] ) ) { |
|
57 | + return []; |
|
58 | + } |
|
59 | + $items = []; |
|
60 | + foreach ( $entity['claims'][ $property ] as $authorClaim ) { |
|
61 | + $item_id = $authorClaim['mainsnak']['datavalue']['value']['id']; |
|
62 | + $items[] = Item::factory( $item_id, $this->lang, $this->cache ); |
|
63 | + } |
|
64 | 64 | |
65 | - return $items; |
|
66 | - } |
|
65 | + return $items; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getAuthors() { |
|
72 | - return $this->getPropertyOfTypeItems( self::PROP_AUTHOR ); |
|
73 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getAuthors() { |
|
72 | + return $this->getPropertyOfTypeItems( self::PROP_AUTHOR ); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return Item[] |
|
77 | - */ |
|
78 | - public function getSubjects() { |
|
79 | - return $this->getPropertyOfTypeItems( self::PROP_SUBJECT ); |
|
80 | - } |
|
75 | + /** |
|
76 | + * @return Item[] |
|
77 | + */ |
|
78 | + public function getSubjects() { |
|
79 | + return $this->getPropertyOfTypeItems( self::PROP_SUBJECT ); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return Item[] |
|
84 | - */ |
|
85 | - public function getEditions() { |
|
86 | - $sparql = "SELECT ?item WHERE {" |
|
87 | - . " ?item wdt:" . Edition::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId() |
|
88 | - . "}"; |
|
89 | - $query = new Query( $sparql, $this->lang, $this->cache ); |
|
90 | - $editions = $query->getItems(); |
|
91 | - usort( $editions, function ( Item $a, Item $b ) { |
|
92 | - if ( $a instanceof EditionItem and $b instanceof EditionItem ) { |
|
93 | - return $a->getPublicationYear() - $b->getPublicationYear(); |
|
94 | - } |
|
95 | - return 0; |
|
96 | - } ); |
|
82 | + /** |
|
83 | + * @return Item[] |
|
84 | + */ |
|
85 | + public function getEditions() { |
|
86 | + $sparql = "SELECT ?item WHERE {" |
|
87 | + . " ?item wdt:" . Edition::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId() |
|
88 | + . "}"; |
|
89 | + $query = new Query( $sparql, $this->lang, $this->cache ); |
|
90 | + $editions = $query->getItems(); |
|
91 | + usort( $editions, function ( Item $a, Item $b ) { |
|
92 | + if ( $a instanceof EditionItem and $b instanceof EditionItem ) { |
|
93 | + return $a->getPublicationYear() - $b->getPublicationYear(); |
|
94 | + } |
|
95 | + return 0; |
|
96 | + } ); |
|
97 | 97 | |
98 | - return $editions; |
|
99 | - } |
|
98 | + return $editions; |
|
99 | + } |
|
100 | 100 | |
101 | - public function newEdition() { |
|
102 | - } |
|
101 | + public function newEdition() { |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } |
@@ -21,45 +21,45 @@ discard block |
||
21 | 21 | * @param CacheItemPoolInterface $cache The cache. |
22 | 22 | * @return array|Item[] |
23 | 23 | */ |
24 | - public static function getBookTypes( $lang = 'en', $cache ) { |
|
24 | + public static function getBookTypes($lang = 'en', $cache) { |
|
25 | 25 | $sparql = "SELECT ?item WHERE { |
26 | 26 | ?item wdt:P279 wd:Q571 . |
27 | 27 | ?item rdfs:label ?label . |
28 | 28 | FILTER(LANG(?label) = '$lang') . |
29 | 29 | } ORDER BY ?label "; |
30 | - $query = new Query( $sparql, $lang ); |
|
31 | - $query->setCache( $cache ); |
|
32 | - $bookType = Item::factory( self::ITEM_WORK, $lang, $cache ); |
|
33 | - return [ $bookType ] + $query->getItems(); |
|
30 | + $query = new Query($sparql, $lang); |
|
31 | + $query->setCache($cache); |
|
32 | + $bookType = Item::factory(self::ITEM_WORK, $lang, $cache); |
|
33 | + return [$bookType] + $query->getItems(); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @return bool|string |
38 | 38 | */ |
39 | 39 | public function getSubtitle() { |
40 | - return $this->getPropertyOfTypeText( self::PROP_SUBTITLE ); |
|
40 | + return $this->getPropertyOfTypeText(self::PROP_SUBTITLE); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @param string $subtitle The new subtitle. |
45 | 45 | */ |
46 | - public function setSubtitle( $subtitle ) { |
|
47 | - $this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle ); |
|
46 | + public function setSubtitle($subtitle) { |
|
47 | + $this->setPropertyOfTypeText(self::PROP_SUBTITLE, $subtitle); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @param string $property A property identifier. |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function getPropertyOfTypeItems( $property ) { |
|
55 | - $entity = $this->getEntity( $this->id ); |
|
56 | - if ( ! isset( $entity['claims'][ $property ] ) ) { |
|
54 | + public function getPropertyOfTypeItems($property) { |
|
55 | + $entity = $this->getEntity($this->id); |
|
56 | + if (!isset($entity['claims'][$property])) { |
|
57 | 57 | return []; |
58 | 58 | } |
59 | 59 | $items = []; |
60 | - foreach ( $entity['claims'][ $property ] as $authorClaim ) { |
|
61 | - $item_id = $authorClaim['mainsnak']['datavalue']['value']['id']; |
|
62 | - $items[] = Item::factory( $item_id, $this->lang, $this->cache ); |
|
60 | + foreach ($entity['claims'][$property] as $authorClaim) { |
|
61 | + $item_id = $authorClaim['mainsnak']['datavalue']['value']['id']; |
|
62 | + $items[] = Item::factory($item_id, $this->lang, $this->cache); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | return $items; |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | * @return array |
70 | 70 | */ |
71 | 71 | public function getAuthors() { |
72 | - return $this->getPropertyOfTypeItems( self::PROP_AUTHOR ); |
|
72 | + return $this->getPropertyOfTypeItems(self::PROP_AUTHOR); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @return Item[] |
77 | 77 | */ |
78 | 78 | public function getSubjects() { |
79 | - return $this->getPropertyOfTypeItems( self::PROP_SUBJECT ); |
|
79 | + return $this->getPropertyOfTypeItems(self::PROP_SUBJECT); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | $sparql = "SELECT ?item WHERE {" |
87 | 87 | . " ?item wdt:" . Edition::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId() |
88 | 88 | . "}"; |
89 | - $query = new Query( $sparql, $this->lang, $this->cache ); |
|
89 | + $query = new Query($sparql, $this->lang, $this->cache); |
|
90 | 90 | $editions = $query->getItems(); |
91 | - usort( $editions, function ( Item $a, Item $b ) { |
|
92 | - if ( $a instanceof EditionItem and $b instanceof EditionItem ) { |
|
91 | + usort($editions, function(Item $a, Item $b) { |
|
92 | + if ($a instanceof EditionItem and $b instanceof EditionItem) { |
|
93 | 93 | return $a->getPublicationYear() - $b->getPublicationYear(); |
94 | 94 | } |
95 | 95 | return 0; |