Skip to content

Commit 31dbff3

Browse files
Merge pull request #899 from beatrycze-volk/add-doc
[MAINTENANCE] Simplify and unify check for doc existence
2 parents e1fef41 + a8c7e26 commit 31dbff3

10 files changed

+34
-44
lines changed

Classes/Controller/AbstractController.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@ protected function loadDocument($requestData)
173173
}
174174
}
175175

176+
/**
177+
* Checks if doc is missing or is empty (no pages)
178+
*
179+
* @return boolean
180+
*/
181+
protected function isDocMissingOrEmpty()
182+
{
183+
return $this->isDocMissing() || $this->document->getDoc()->numPages < 1;
184+
}
185+
186+
/**
187+
* Checks if doc is missing
188+
*
189+
* @return boolean
190+
*/
191+
protected function isDocMissing()
192+
{
193+
return $this->document === null || $this->document->getDoc() === null;
194+
}
195+
176196
/**
177197
* Returns the LanguageService
178198
*

Classes/Controller/AudioPlayerController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ public function mainAction()
7676
{
7777
// Load current document.
7878
$this->loadDocument($this->requestData);
79-
if (
80-
$this->document === null
81-
|| $this->document->getDoc() === null
82-
|| $this->document->getDoc()->numPages < 1
83-
) {
79+
if ($this->isDocMissingOrEmpty()) {
8480
// Quit without doing anything if required variables are not set.
8581
return '';
8682
} else {

Classes/Controller/BasketController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,7 @@ protected function addToBasket($_piVars, $basket)
390390
}
391391
// get document instance to load further information
392392
$this->loadDocument(['id' => $documentItem['id']]);
393-
if (
394-
$this->document === null
395-
|| $this->document->getDoc() === null
396-
) {
393+
if ($this->isDocMissing()) {
397394
// Quit without doing anything if required variables are not set.
398395
return;
399396
}

Classes/Controller/MetadataController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ public function mainAction()
7979

8080
// Load current document.
8181
$this->loadDocument($this->requestData);
82-
if (
83-
$this->document === null
84-
|| $this->document->getDoc() === null
85-
) {
82+
if ($this->isDocMissing()) {
8683
// Quit without doing anything if required variables are not set.
8784
return '';
8885
} else {

Classes/Controller/NavigationController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ public function mainAction()
5757
{
5858
// Load current document.
5959
$this->loadDocument($this->requestData);
60-
if (
61-
$this->document === null
62-
|| $this->document->getDoc() === null
63-
) {
60+
if ($this->isDocMissing()) {
6461
// Quit without doing anything if required variables are not set.
6562
return '';
6663
} else {

Classes/Controller/PageGridController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public function mainAction()
3333
{
3434
$this->loadDocument($this->requestData);
3535
if (
36-
$this->document === null
37-
|| $this->document->getDoc()->numPages < 1
36+
$this->isDocMissingOrEmpty()
3837
|| empty($this->extConf['fileGrpThumbs'])
3938
) {
4039
// Quit without doing anything if required variables are not set.

Classes/Controller/PageViewController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ public function mainAction()
6969
{
7070
// Load current document.
7171
$this->loadDocument($this->requestData);
72-
if (
73-
$this->document === null
74-
|| $this->document->getDoc()->numPages < 1
75-
) {
72+
if ($this->isDocMissingOrEmpty()) {
7673
// Quit without doing anything if required variables are not set.
7774
return '';
7875
} else {

Classes/Controller/TableOfContentsController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ public function mainAction()
4343
{
4444
// Load current document.
4545
$this->loadDocument($this->requestData);
46-
if (
47-
$this->document === null
48-
|| $this->document->getDoc() === null
49-
) {
46+
if ($this->isDocMissing()) {
5047
// Quit without doing anything if required variables are not set.
5148
return;
5249
} else {

Classes/Controller/ToolboxController.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ public function mainAction()
5454
*/
5555
public function annotationtool()
5656
{
57-
if (
58-
$this->document === null
59-
|| $this->document->getDoc()->numPages < 1
60-
) {
57+
if ($this->isDocMissingOrEmpty()) {
6158
// Quit without doing anything if required variables are not set.
6259
return '';
6360
} else {
@@ -97,8 +94,7 @@ public function annotationtool()
9794
public function fulltextdownloadtool()
9895
{
9996
if (
100-
$this->document === null
101-
|| $this->document->getDoc()->numPages < 1
97+
$this->isDocMissingOrEmpty()
10298
|| empty($this->extConf['fileGrpFulltext'])
10399
) {
104100
// Quit without doing anything if required variables are not set.
@@ -143,8 +139,7 @@ public function fulltextdownloadtool()
143139
public function fulltexttool()
144140
{
145141
if (
146-
$this->document === null
147-
|| $this->document->getDoc()->numPages < 1
142+
$this->isDocMissingOrEmpty()
148143
|| empty($this->extConf['fileGrpFulltext'])
149144
) {
150145
// Quit without doing anything if required variables are not set.
@@ -189,8 +184,7 @@ public function fulltexttool()
189184
public function imagedownloadtool()
190185
{
191186
if (
192-
$this->document === null
193-
|| $this->document->getDoc()->numPages < 1
187+
$this->isDocMissingOrEmpty()
194188
|| empty($this->settings['fileGrpsImageDownload'])
195189
) {
196190
// Quit without doing anything if required variables are not set.
@@ -281,9 +275,7 @@ public function imagemanipulationtool()
281275
public function pdfdownloadtool()
282276
{
283277
if (
284-
$this->document === null
285-
|| $this->document->getDoc() === null
286-
|| $this->document->getDoc()->numPages < 1
278+
$this->isDocMissingOrEmpty()
287279
|| empty($this->extConf['fileGrpDownload'])
288280
) {
289281
// Quit without doing anything if required variables are not set.
@@ -396,8 +388,7 @@ protected function getWorkLink()
396388
public function searchindocumenttool()
397389
{
398390
if (
399-
$this->document === null
400-
|| $this->document->getDoc()->numPages < 1
391+
$this->isDocMissingOrEmpty()
401392
|| empty($this->extConf['fileGrpFulltext'])
402393
|| empty($this->settings['solrcore'])
403394
) {

Classes/Controller/View3DController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public function mainAction()
3333
// Load current document.
3434
$this->loadDocument($this->requestData);
3535
if (
36-
$this->document === null
37-
|| $this->document->getDoc() === null
36+
$this->isDocMissingOrEmpty()
3837
|| $this->document->getDoc()->metadataArray['LOG_0001']['type'][0] != 'object'
3938
) {
4039
// Quit without doing anything if required variables are not set.

0 commit comments

Comments
 (0)