Completed
Pull Request — develop (#1282)
by David
03:36
created

Sync_Hooks_Wordpress_Ontology::jsonld()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 3
dl 0
loc 36
rs 9.344
c 0
b 0
f 0
1
<?php
2
3
namespace Wordlift\Dataset;
4
5
use Wordlift\Object_Type_Enum;
6
7
class Sync_Hooks_Wordpress_Ontology {
8
9
	const HTTP_PURL_ORG_WORDPRESS_1_0 = 'http://purl.org/wordpress/1.0/';
10
11
	public function __construct() {
12
		add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
13
	}
14
15
	public function jsonld( $jsonld, $type, $object_id ) {
16
17
		$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'id' ] = $object_id;
18
19
		switch ( $type ) {
20
21
			case Object_Type_Enum::TERM:
22
				$term = get_term( $object_id );
23
24
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'contentType' ] = 'term';
25
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'name' ]        = $term->name;
26
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'description' ] = $term->description;
27
				break;
28
29
			case Object_Type_Enum::USER:
30
				$user = get_userdata( $object_id );
31
32
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'contentType' ] = 'user';
33
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'displayName' ] = $user->display_name;
34
				break;
35
36
			case Object_Type_Enum::POST:
37
				$post = get_post( $object_id );
38
39
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'contentType' ] = 'post';
40
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'postType' ]    = $post->post_type;
41
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'postTitle' ]   = $post->post_title;
42
				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'postStatus' ]  = $post->post_status;
43
				break;
44
45
			default:
46
47
		}
48
49
		return $jsonld;
50
	}
51
52
}
53