Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit d1f8ef7

Browse files
author
Michael Grauer
committed
BUG: refs #0342. Fix for viewing an item with 0 revisions.
1 parent 7bff273 commit d1f8ef7

File tree

4 files changed

+64
-33
lines changed

4 files changed

+64
-33
lines changed

core/controllers/BrowseController.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,18 @@ public function getelementinfoAction()
362362
$item = $this->Item->load($id);
363363
$jsonContent = array_merge($jsonContent, $item->toArray());
364364
$itemRevision = $this->Item->getLastRevision($item);
365-
$jsonContent['creation'] = $this->Component->Date->formatDate(strtotime($itemRevision->getDate()));
366-
$jsonContent['uploaded'] = $itemRevision->getUser()->toArray();
367-
$jsonContent['revision'] = $itemRevision->toArray();
368-
$jsonContent['nbitstream'] = count($itemRevision->getBitstreams());
365+
if(isset($itemRevision) && $itemRevision !== false)
366+
{
367+
$jsonContent['creation'] = $this->Component->Date->formatDate(strtotime($itemRevision->getDate()));
368+
$jsonContent['uploaded'] = $itemRevision->getUser()->toArray();
369+
$jsonContent['revision'] = $itemRevision->toArray();
370+
$jsonContent['nbitstream'] = count($itemRevision->getBitstreams());
371+
}
372+
else
373+
{
374+
$jsonContent['creation'] = $this->Component->Date->formatDate(strtotime($item->getDateCreation()));
375+
$jsonContent['norevisions'] = true;
376+
}
369377
$jsonContent['type'] = 'item';
370378
break;
371379
default:

core/controllers/ItemController.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,33 @@ function viewAction()
171171
// Display the good link if the item is pointing to a website
172172
$this->view->itemIsLink = false;
173173

174-
$bitstreams = $itemRevision->getBitstreams();
175-
if(count($bitstreams) == 1)
174+
175+
if(isset($itemRevision) && $itemRevision !== false)
176176
{
177-
$bitstream = $bitstreams[0];
178-
if(strpos($bitstream->getPath(), 'http://') !== false)
177+
$bitstreams = $itemRevision->getBitstreams();
178+
if(count($bitstreams) == 1)
179179
{
180-
$this->view->itemIsLink = true;
180+
$bitstream = $bitstreams[0];
181+
if(strpos($bitstream->getPath(), 'http://') !== false)
182+
{
183+
$this->view->itemIsLink = true;
184+
}
181185
}
186+
$itemDao->creation = $this->Component->Date->formatDate(strtotime($itemRevision->getDate()));
187+
$this->view->metadatavalues = $this->ItemRevision->getMetadata($itemRevision);
182188
}
183189

184-
185190
$this->Component->Sortdao->field = 'revision';
186191
$this->Component->Sortdao->order = 'desc';
187192
usort($itemDao->revisions, array($this->Component->Sortdao, 'sortByNumber'));
188193

189-
$itemDao->creation = $this->Component->Date->formatDate(strtotime($itemRevision->getDate()));
190194
$this->view->itemDao = $itemDao;
191195

192196
$this->view->itemSize = $this->Component->Utility->formatSize($itemDao->getSizebytes());
193197

194198
$this->view->title .= ' - '.$itemDao->getName();
195199
$this->view->metaDescription = substr($itemDao->getDescription(), 0, 160);
196200

197-
$this->view->metadatavalues = $this->ItemRevision->getMetadata($itemRevision);
198201

199202

200203
$tmp = Zend_Registry::get('notifier')->callback("CALLBACK_VISUALIZE_CAN_VISUALIZE", array('item' => $itemDao));

core/public/js/common/common.browser.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -450,28 +450,38 @@ function createInfo(jsonContent)
450450
}
451451
if(arrayElement['type']=='item')
452452
{
453-
html+=' <tr>';
454-
html+=' <td>'+arrayElement.translation.Uploaded+'</td>';
455-
html+=' <td><a href="'+json.global.webroot+'/user/'+arrayElement['uploaded']['user_id']+'">'+arrayElement['uploaded']['firstname']+' '+arrayElement['uploaded']['lastname']+'</a></td>';
456-
html+=' </tr>';
457-
html+=' <tr>';
458-
html+=' <td>Revision';
459-
if(parseInt(arrayElement['revision']['revision'])>1)
453+
if(arrayElement['norevisions'] == true)
460454
{
461-
html+='s';
455+
html+=' <tr>';
456+
html+=' <td>No Revisions</td>';
457+
html+=' </tr>';
458+
html+=' <tr>';
462459
}
463-
html+= '</td>';
464-
html+=' <td>'+arrayElement['revision']['revision']+'</td>';
465-
html+=' </tr>';
466-
html+=' <tr>';
467-
html+=' <td>'+arrayElement.translation.File;
468-
if(parseInt(arrayElement['nbitstream'])>1)
460+
else
469461
{
470-
html+='s';
462+
html+=' <tr>';
463+
html+=' <td>'+arrayElement.translation.Uploaded+'</td>';
464+
html+=' <td><a href="'+json.global.webroot+'/user/'+arrayElement['uploaded']['user_id']+'">'+arrayElement['uploaded']['firstname']+' '+arrayElement['uploaded']['lastname']+'</a></td>';
465+
html+=' </tr>';
466+
html+=' <tr>';
467+
html+=' <td>Revision';
468+
if(parseInt(arrayElement['revision']['revision'])>1)
469+
{
470+
html+='s';
471+
}
472+
html+= '</td>';
473+
html+=' <td>'+arrayElement['revision']['revision']+'</td>';
474+
html+=' </tr>';
475+
html+=' <tr>';
476+
html+=' <td>'+arrayElement.translation.File;
477+
if(parseInt(arrayElement['nbitstream'])>1)
478+
{
479+
html+='s';
480+
}
481+
html+= '</td>';
482+
html+=' <td>'+arrayElement['nbitstream']+'</td>';
483+
html+=' </tr>';
471484
}
472-
html+= '</td>';
473-
html+=' <td>'+arrayElement['nbitstream']+'</td>';
474-
html+=' </tr>';
475485
}
476486

477487
if(arrayElement['type']=='folder')

core/views/item/view.phtml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ if($this->preview) // module visualize
144144
<a onclick="$('#revisionContent').show();$(this).remove();"><?php echo $this->t('Show Content')?></a>
145145

146146
<div id="revisionContent">
147-
147+
<?php if(isset($this->itemDao->lastrevision) && $this->itemDao->lastrevision !== false)
148+
{ ?>
148149
<h4 style="margin-top: 0px;margin-bottom: 5px;"><?php echo $this->t('Latest revision content')?>:</h4>
149150

150151
<table style='display:block;' id="browseTable" class="midasTree">
@@ -167,6 +168,7 @@ if($this->preview) // module visualize
167168
echo "</tr>";
168169
}
169170
?>
171+
<?php } // check for $this->itemDao->lastRevision ?>
170172
</tbody>
171173
</table>
172174
</div>
@@ -229,12 +231,13 @@ if($this->preview) // module visualize
229231
?>
230232
</ul>
231233
</div>
232-
<?php
233-
}?>
234+
<?php } ?>
234235
<div class="<?php echo (!$this->preview && !$this->isModerator && !$this->isAdmin)?'sideElementFirst':''; ?>sideElement<?php if(count($this->sameLocation) > 1) echo "Last"?> viewInfo">
235236
<h1>Info</h1>
236237
<table>
237238
<tbody>
239+
<?php if(isset($this->itemDao->lastrevision) && $this->itemDao->lastrevision !== false)
240+
{ ?>
238241
<tr>
239242
<td><?php echo $this->t('Created')?></td>
240243
<td><?php echo $this->itemDao->creation?></td>
@@ -251,6 +254,13 @@ if($this->preview) // module visualize
251254
<td><?php echo $this->t('Files');?></td>
252255
<td><?php echo count($this->itemDao->lastrevision->getBitstreams())?></td>
253256
</tr>
257+
<?php } // check for $this->itemDao->lastRevision
258+
else
259+
{ ?>
260+
<tr>
261+
<td><?php echo $this->t('No Revisions');?></td>
262+
</tr>
263+
<?php } // else ?>
254264
</tbody>
255265
</table>
256266
<?php

0 commit comments

Comments
 (0)