33namespace App \Entity ;
44
55use App \Enum \DatasetLifecycleStatus ;
6+ use App \Enum \KeywordType ;
67use App \Util \DatasetCitationUtil ;
8+ use App \Util \GenerateUrl ;
79use Doctrine \Common \Collections \ArrayCollection ;
810use Doctrine \Common \Collections \Collection ;
911use Doctrine \ORM \Mapping as ORM ;
1012use JMS \Serializer \Annotation as Serializer ;
13+ use Symfony \Component \Routing \RouterInterface ;
14+ use Symfony \Component \Serializer \Attribute \Groups ;
15+ use Symfony \Component \Serializer \Attribute \MaxDepth ;
16+ use Symfony \Component \Serializer \Attribute \SerializedName ;
1117
1218/**
1319 * Dataset Entity class.
@@ -93,6 +99,7 @@ class Dataset extends Entity
9399 */
94100 #[ORM \Column(type: 'text ' , nullable: true )]
95101 #[Serializer \Groups(['card ' , 'search ' ])]
102+ #[Groups(['grp-dk-report ' ])]
96103 protected $ udi ;
97104
98105 /**
@@ -102,6 +109,7 @@ class Dataset extends Entity
102109 */
103110 #[ORM \Column(type: 'text ' , nullable: true )]
104111 #[Serializer \Groups(['card ' , 'search ' ])]
112+ #[Groups(['grp-dk-report ' ])]
105113 protected $ title ;
106114
107115 /**
@@ -131,6 +139,8 @@ class Dataset extends Entity
131139 #[ORM \ManyToOne(targetEntity: 'ResearchGroup ' , inversedBy: 'datasets ' )]
132140 #[Serializer \MaxDepth(1 )]
133141 #[Serializer \Groups(['search ' ])]
142+ #[Groups(['grp-dk-report ' ])]
143+ #[MaxDepth(1 )]
134144 protected $ researchGroup ;
135145
136146 /**
@@ -342,7 +352,7 @@ public function setDatasetSubmission(DatasetSubmission $datasetSubmission)
342352 *
343353 * @return DatasetSubmission
344354 */
345- public function getDatasetSubmission ()
355+ public function getDatasetSubmission (): ? DatasetSubmission
346356 {
347357 return $ this ->datasetSubmission ;
348358 }
@@ -439,14 +449,22 @@ public function setDoi(DOI $doi)
439449
440450 /**
441451 * Get the DOI for this Dataset.
442- *
443- * @return DOI
444452 */
445- public function getDoi ()
453+ public function getDoi (): ? DOI
446454 {
447455 return $ this ->doi ;
448456 }
449457
458+ /**
459+ * Get the DOI string for this Dataset.
460+ */
461+ #[Groups(['grp-dk-report ' ])]
462+ #[SerializedName('doi ' )]
463+ public function getDoiString (): string
464+ {
465+ return $ this ->getDoi ()?->getDoi() ?? '' ;
466+ }
467+
450468 /**
451469 * Set the identified status.
452470 *
@@ -1084,4 +1102,106 @@ public function getDatasetLifecycleStatus(): DatasetLifecycleStatus
10841102
10851103 return $ datasetLifeCycleStatus ;
10861104 }
1105+
1106+ /**
1107+ * Get Dataset Lifecycle Status as a string.
1108+ */
1109+ #[Groups(['grp-dk-report ' ])]
1110+ #[SerializedName('datasetLifecycleStatus ' )]
1111+ public function getDatasetLifecycleStatusString (): string
1112+ {
1113+ return $ this ->getDatasetLifecycleStatus ()->value ;
1114+ }
1115+
1116+ /**
1117+ * Get a link to the dataset landing page.
1118+ */
1119+ #[Groups(['grp-dk-report ' ])]
1120+ public function getLandingPage (): string
1121+ {
1122+ return 'https://grp.griidc.org/data/ ' . $ this ->getUdi ();
1123+ }
1124+
1125+ /**
1126+ * Get ANZRC keys as a string.
1127+ */
1128+ #[Groups(['grp-dk-report ' ])]
1129+ public function getAnzrcKeywords (): ?string
1130+ {
1131+ $ keywords = $ this ->getKeywordsByType (KeywordType::TYPE_ANZSRC );
1132+
1133+ if ($ keywords instanceof Collection) {
1134+ $ keywords = $ keywords ->map (
1135+ function (Keyword $ keyword ) {
1136+ return $ keyword ->getLabel ();
1137+ }
1138+ );
1139+ }
1140+
1141+ return implode (', ' , $ keywords ?->toArray() ?? []);
1142+ }
1143+
1144+ /**
1145+ * Get ANZRC keys as a string.
1146+ */
1147+ #[Groups(['grp-dk-report ' ])]
1148+ public function getGcmdKeywords (): ?string
1149+ {
1150+ $ keywords = $ this ->getKeywordsByType (KeywordType::TYPE_GCMD );
1151+
1152+ if ($ keywords instanceof Collection) {
1153+ $ keywords = $ keywords ->map (
1154+ function (Keyword $ keyword ) {
1155+ return $ keyword ->getLabel ();
1156+ }
1157+ );
1158+ }
1159+
1160+ return implode (', ' , $ keywords ?->toArray() ?? []);
1161+ }
1162+
1163+ /**
1164+ * Get theme keywords as string.
1165+ */
1166+ #[Groups(['grp-dk-report ' ])]
1167+ public function getThemeKeywords (): ?string
1168+ {
1169+ $ keywords = $ this ->getDatasetSubmission ()?->getThemeKeywords();
1170+
1171+ return implode (', ' , $ keywords ?? []);
1172+ }
1173+
1174+ /**
1175+ * Get place keywords as string.
1176+ */
1177+ #[Groups(['grp-dk-report ' ])]
1178+ public function getPlaceKeywords (): ?string
1179+ {
1180+ $ keywords = $ this ->getDatasetSubmission ()?->getPlaceKeywords();
1181+
1182+ return implode (', ' , $ keywords ?? []);
1183+ }
1184+
1185+ /**
1186+ * Get topic keywords as string.
1187+ */
1188+ #[Groups(['grp-dk-report ' ])]
1189+ public function getTopicKeywords (): ?string
1190+ {
1191+ $ keywords = $ this ->getDatasetSubmission ()?->getTopicKeywords();
1192+
1193+ return implode (', ' , $ keywords ?? []);
1194+ }
1195+
1196+ /**
1197+ * Key keywords by type.
1198+ */
1199+ private function getKeywordsByType (KeywordType $ type ): ?Collection
1200+ {
1201+ $ keywords = $ this ->getDatasetSubmission ()?->getKeywords();
1202+
1203+ return $ keywords = $ keywords ?->filter(function (Keyword $ keyword ) use ($ type ) {
1204+ return $ keyword ->getType () === $ type ;
1205+ });
1206+ }
10871207}
0 commit comments