| Conditions | 43 |
| Paths | 60 |
| Total Lines | 133 |
| Code Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 140 | protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
||
| 141 | { |
||
| 142 | if ($useOriginalIiifManifestMetadata) { |
||
| 143 | $iiifData = []; |
||
| 144 | foreach ($metadataArray as $metadata) { |
||
| 145 | foreach ($metadata as $key => $group) { |
||
| 146 | if ($key == '_id') { |
||
| 147 | continue; |
||
| 148 | } |
||
| 149 | if (!is_array($group)) { |
||
| 150 | if ( |
||
| 151 | IRI::isAbsoluteIri($group) |
||
| 152 | && (($scheme = (new IRI($group))->getScheme()) == 'http' || $scheme == 'https') |
||
| 153 | ) { |
||
| 154 | // Build link |
||
| 155 | $iiifData[$key] = [ |
||
| 156 | 'label' => $key, |
||
| 157 | 'value' => $group, |
||
| 158 | 'buildUrl' => true, |
||
| 159 | ]; |
||
| 160 | } else { |
||
| 161 | // Data output |
||
| 162 | $iiifData[$key] = [ |
||
| 163 | 'label' => $key, |
||
| 164 | 'value' => $group, |
||
| 165 | 'buildUrl' => false, |
||
| 166 | ]; |
||
| 167 | } |
||
| 168 | } else { |
||
| 169 | foreach ($group as $label => $value) { |
||
| 170 | if ($label == '_id') { |
||
| 171 | continue; |
||
| 172 | } |
||
| 173 | if (is_array($value)) { |
||
| 174 | $value = implode($this->settings['separator'], $value); |
||
| 175 | } |
||
| 176 | // NOTE: Labels are to be escaped in Fluid template |
||
| 177 | if (IRI::isAbsoluteIri($value) && (($scheme = (new IRI($value))->getScheme()) == 'http' || $scheme == 'https')) { |
||
| 178 | $nolabel = $value == $label; |
||
| 179 | $iiifData[$key]['data'][] = [ |
||
| 180 | 'label' => $nolabel ? '' : $label, |
||
| 181 | 'value' => $value, |
||
| 182 | 'buildUrl' => true, |
||
| 183 | ]; |
||
| 184 | } else { |
||
| 185 | $iiifData[$key]['data'][] = [ |
||
| 186 | 'label' => $label, |
||
| 187 | 'value' => $value, |
||
| 188 | 'buildUrl' => false, |
||
| 189 | ]; |
||
| 190 | } |
||
| 191 | } |
||
| 192 | } |
||
| 193 | $this->view->assign('useIiif', true); |
||
| 194 | $this->view->assign('iiifData', $iiifData); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | |||
| 199 | // findBySettings also sorts entries by the `sorting` field |
||
| 200 | $metadataResult = $this->metadataRepository->findBySettings([ |
||
| 201 | 'is_listed' => !$this->settings['showFull'], |
||
| 202 | ]); |
||
| 203 | |||
| 204 | $buildUrl = []; |
||
| 205 | $i = 0; |
||
| 206 | foreach ($metadataArray as $metadataSection) { |
||
| 207 | foreach ($metadataSection as $metadataName => $metadataValue) { |
||
| 208 | // NOTE: Labels are to be escaped in Fluid template |
||
| 209 | |||
| 210 | if ($metadataName == 'title') { |
||
| 211 | // Get title of parent document if needed. |
||
| 212 | if (empty($metadataValue) && $this->settings['getTitle'] && $this->document->getDoc()->parentId) { |
||
| 213 | $superiorTitle = Doc::getTitle($this->document->getPartof(), true); |
||
| 214 | if (!empty($superiorTitle)) { |
||
| 215 | $metadataArray[$i][$metadataName] = ['[' . $superiorTitle . ']']; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | if (!empty($metadataValue)) { |
||
| 219 | $metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
||
| 220 | // Link title to pageview. |
||
| 221 | if ($this->settings['linkTitle'] && $metadataSection['_id']) { |
||
| 222 | $details = $this->document->getDoc()->getLogicalStructure($metadataSection['_id']); |
||
| 223 | $buildUrl[$i][$metadataName]['buildUrl'] = [ |
||
| 224 | 'id' => $this->document->getUid(), |
||
| 225 | 'page' => (!empty($details['points']) ? intval($details['points']) : 1), |
||
| 226 | 'targetPid' => (!empty($this->settings['targetPid']) ? $this->settings['targetPid'] : 0), |
||
| 227 | ]; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | } elseif ($metadataName == 'owner' && empty($metadataValue)) { |
||
| 231 | // no owner is found by metadata records --> take the one associated to the document |
||
| 232 | $library = $this->document->getOwner(); |
||
| 233 | if ($library) { |
||
| 234 | $metadataArray[$i][$metadataName][0] = $library->getLabel(); |
||
| 235 | } |
||
| 236 | } elseif ($metadataName == 'type' && !empty($metadataValue)) { |
||
| 237 | // Translate document type. |
||
| 238 | $structure = $this->structureRepository->findOneByIndexName($metadataArray[$i][$metadataName][0]); |
||
| 239 | if ($structure) { |
||
| 240 | $metadataArray[$i][$metadataName][0] = $structure->getLabel(); |
||
| 241 | } |
||
| 242 | } elseif ($metadataName == 'collection' && !empty($metadataValue)) { |
||
| 243 | // Check if collections isn't hidden. |
||
| 244 | $j = 0; |
||
| 245 | foreach ($metadataValue as $metadataEntry) { |
||
| 246 | $collection = $this->collectionRepository->findOneByIndexName($metadataEntry); |
||
| 247 | if ($collection) { |
||
| 248 | $metadataArray[$i][$metadataName][$j] = $collection->getLabel() ? : ''; |
||
| 249 | $j++; |
||
| 250 | } |
||
| 251 | } |
||
| 252 | } elseif ($metadataName == 'language' && !empty($metadataValue)) { |
||
| 253 | // Translate ISO 639 language code. |
||
| 254 | $metadataArray[$i][$metadataName][0] = Helper::getLanguageName($metadataArray[$i][$metadataName][0]); |
||
| 255 | } elseif (!empty($metadataValue)) { |
||
| 256 | $metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
||
| 257 | } |
||
| 258 | |||
| 259 | if (is_array($metadataArray[$i][$metadataName])) { |
||
| 260 | $metadataArray[$i][$metadataName] = array_values(array_filter($metadataArray[$i][$metadataName], function($value) |
||
| 261 | { |
||
| 262 | return !empty($value); |
||
| 263 | })); |
||
| 264 | } |
||
| 265 | } |
||
| 266 | $i++; |
||
| 267 | } |
||
| 268 | |||
| 269 | $this->view->assign('buildUrl', $buildUrl); |
||
| 270 | $this->view->assign('documentMetadataSections', $metadataArray); |
||
| 271 | $this->view->assign('configMetadata', $metadataResult); |
||
| 272 | $this->view->assign('separator', $this->settings['separator']); |
||
| 273 | |||
| 338 |