summaryrefslogtreecommitdiffstats
path: root/modules/php_musicbrainz/mbEntity.php
blob: 86cfdc0753320bfc53687f81ee89e9fda8d6db71 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
	class MusicBrainzEntity {
		private $id;
		private $relations;
		private $tags;

		protected function MusicBrainzEntity( $id ) {
			$this->id = $id;
			$this->relations = array();
		}

		function getId() {
			return $this->id;
		}

		function setId( $id ) {
			$this->id = $id;
		}

		function &getRelations( $target_type='', $relation_type='' ) {
			if ( $target_type == '' && $relation_type == '' )
				return $this->relations;

			$result = array();

			if ( empty($target_type) ) {
				foreach ( $this->relations as $relation ) {
					if ( $relation->getType() == $relation_type ) {
						$result[] = $relation;
					}
				}
			}
			else if ( empty($relation_type) ) {
				foreach ( $this->relation_tracks as $relation ) {
					if ( $relation->getTargetType() == $target_type ) {
						$result[] = $relation;
					}
				}
			}
			else {
				foreach ( $this->relations as $relation ) {
					if ( $relation->getTargetType() == $target_type
					&&   $relation->getType() == $relation_type ) {
						$result[] = $relation;
					}
				}
			}

			return $result;
		}

		function addRelation( mbRelation $relation ) {
			$this->relations[] = $relation;
		}

		function getNumRelations() {
			return count($this->relations);
		}

		function &getRelation( $i ) {
			return $this->relations[$i];
		}

		function &getTags() {
			return $this->tags;
		}

		function getNumTags() {
			return count($this->tags);
		}

		function &getTag( $i ) {
			return $this->tags[$i];
		}
	}
?>