VocabularyCategory::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Groups vocabularies of a specific category into a DataObject.
5
 */
6
class VocabularyCategory extends DataObject
7
{
8
    public function __construct($model, $resource)
9
    {
10
        if (!($model instanceof Model)) {
11
            throw new InvalidArgumentException('Invalid constructor parameter given to DataObject.');
12
        }
13
14
        $this->model = $model;
15
        $this->resource = $resource;
16
        $this->order = array();
17
    }
18
19
    /**
20
     * Returns all vocabularies in the category.
21
     */
22
    public function getVocabularies()
23
    {
24
        if ($this->resource) {
25
            return $this->model->getVocabulariesInCategory($this->resource);
26
        }
27
        return $this->model->getVocabularies();
28
    }
29
30
    /**
31
     * Returns the title of the category.
32
     */
33
    public function getTitle()
34
    {
35
        if ($this->resource) {
36
            $label = $this->resource->label($this->getLang());
37
            return is_null($label) ? $this->resource->localName() : $label->getValue();
38
        }
39
        return $this->model->getText('Vocabularies');
40
    }
41
42
}
43