| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Class for handling concept property values. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | class ConceptPropertyValue extends VocabularyDataObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     /** submembers */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     private $submembers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     /** property type */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     private $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** content language */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private $clang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** whether the property value is external w.r.t. to the subject resource */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $external; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     public function __construct($model, $vocab, $resource, $prop, $clang = '') | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         parent::__construct($model, $vocab, $resource); | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         $this->submembers = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         $this->type = $prop; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $this->clang = $clang; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         // check if the resource is external to the current vocabulary | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         $this->external = ($this->getLabel('', 'null') === null); | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         if ($this->external) { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             // if we find the resource in another vocabulary, use it instead | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |             $exvocab = $this->getExVocab(); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             if ($exvocab !== null) { | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |                 $this->vocab = $exvocab; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function __toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         return is_string($this->getLabel()) ? $this->getLabel() : $this->getLabel()->getValue(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function getLang() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return $this->model->getLocale(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function getSortKey() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         return strtolower($this->getLabel()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function getLabel($lang = '', $fallbackToUri = 'uri') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         if ($this->clang) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             $lang = $this->clang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         if ($this->vocab->getConfig()->getLanguageOrder($lang)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             foreach ($this->vocab->getConfig()->getLanguageOrder($lang) as $fallback) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 if ($this->resource->label($fallback) !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     return $this->resource->label($fallback); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 // We need to check all the labels in case one of them matches a subtag of the current language | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 if ($this->resource->allLiterals('skos:prefLabel')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                     foreach($this->resource->allLiterals('skos:prefLabel') as $label) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                         // the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                         if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                             return EasyRdf\Literal::create($label, $fallback); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         if ($this->resource->label($lang) !== null) { // current language | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             return $this->resource->label($lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } elseif ($this->resource->label($this->vocab->getConfig()->getDefaultLanguage()) !== null) { // vocab default language | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             return $this->resource->label($this->vocab->getConfig()->getDefaultLanguage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } elseif ($this->resource->label() !== null) { // any language | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             return $this->resource->label(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } elseif ($this->resource->getLiteral('rdf:value', $lang) !== null) { // current language | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             return $this->resource->getLiteral('rdf:value', $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         } elseif ($this->resource->getLiteral('rdf:value') !== null) { // any language | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             return $this->resource->getLiteral('rdf:value'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         // see if we can find a label in another vocabulary known by the skosmos instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $label = $this->getExternalLabel($this->vocab, $this->getUri(), $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         if ($label) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             return $label; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         if ($fallbackToUri == 'uri') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             // return uri if no label is found | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             return $this->resource->shorten() ? $this->resource->shorten() : $this->getUri(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     public function getType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         return $this->type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     public function getUri() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         return $this->resource->getUri(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     public function getExVocab() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         return $this->model->guessVocabularyFromURI($this->getUri(), $this->vocab->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function getVocab() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return $this->vocab; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     public function getVocabName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         return $this->vocab->getShortName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     public function addSubMember($member, $lang = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $label = $member->getLabel($lang) ? $member->getLabel($lang) : $member->getLabel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $this->submembers[$label->getValue()] = $member; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $this->sortSubMembers(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     public function getSubMembers() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         if (empty($this->submembers)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         return $this->submembers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     private function sortSubMembers() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         if (!empty($this->submembers)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             ksort($this->submembers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     public function isExternal() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         return $this->external; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     public function getNotation() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         if ($this->vocab->getConfig()->showNotation() && $this->resource->get('skos:notation')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             return $this->resource->get('skos:notation')->getValue(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     public function isReified() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         return (!$this->resource->label() && $this->resource->getLiteral('rdf:value')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     public function getReifiedPropertyValues() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $ret = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $props = $this->resource->propertyUris(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         foreach($props as $prop) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             $prop = (EasyRdf\RdfNamespace::shorten($prop) !== null) ? EasyRdf\RdfNamespace::shorten($prop) : $prop; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |             $propkey = str_starts_with($prop, 'dc11:') ? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |                 str_replace('dc11:', 'dc:', $prop) : $prop; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             foreach ($this->resource->allLiterals($prop) as $val) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |                 if ($prop !== 'rdf:value') { // shown elsewhere | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                     $ret[$this->model->getText($propkey)] = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $val, $prop); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |             foreach ($this->resource->allResources($prop) as $val) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |                 $ret[$this->model->getText($propkey)] = new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         return $ret; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 183 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 184 |  |  |  |