Relations.php
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace ACA\JetEngine\Utils;
final class Relations {
const RELATION_ONE_TO_ONE = 'one_to_one';
const RELATION_ONE_TO_MANY = 'one_to_many';
const RELATION_MANY_TO_MANY = 'many_to_many';
/**
* @param array $relation
* @param string $current_post_type
*
* @return string|null
*/
static function get_related_post_type( $relation, $current_post_type ) {
if ( ! $relation || ! isset( $relation['post_type_1'] ) || ! isset( $relation['post_type_2'] ) ) {
return null;
}
return $relation['post_type_1'] === $current_post_type
? $relation['post_type_2']
: $relation['post_type_1'];
}
/**
* @param array $relation
* @param string $current_post_type
*
* @return boolean
*/
static function has_multiple_relations( $relation, $current_post_type ) {
switch ( $relation['type'] ) {
case self::RELATION_ONE_TO_MANY:
return $relation['post_type_1'] === $current_post_type;
case self::RELATION_MANY_TO_MANY:
return true;
case self::RELATION_ONE_TO_ONE:
default:
return false;
}
}
}