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

Commit 00d5816

Browse files
author
Charles Marion
committed
ENH: added date upade in item/Folder
fixed search sorting
1 parent 57a9871 commit 00d5816

File tree

19 files changed

+88
-78
lines changed

19 files changed

+88
-78
lines changed

core/controllers/BrowseController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function getfolderscontentAction()
198198
$tmp = array();
199199
$tmp['folder_id'] = $folder->getFolderId();
200200
$tmp['name'] = $folder->getName();
201-
$tmp['creation'] = $this->Component->Date->ago($folder->getDate(), true);
201+
$tmp['date_update'] = $this->Component->Date->ago($folder->getDateUpdate(), true);
202202
if($tmp['name'] == 'Public' || $tmp['name'] == 'Private')
203203
{
204204
$tmp['deletable'] = 'false';
@@ -218,7 +218,7 @@ public function getfolderscontentAction()
218218
$tmp['item_id'] = $item->getItemId();
219219
$tmp['name'] = $item->getName();
220220
$tmp['parent_id'] = $item->parent_id;
221-
$tmp['creation'] = $this->Component->Date->ago($item->getDate(), true);
221+
$tmp['date_update'] = $this->Component->Date->ago($item->getDateUpdate(), true);
222222
$tmp['size'] = $this->Component->Utility->formatSize($item->getSizebytes());
223223
$tmp['policy'] = $item->policy;
224224
$tmp['privacy_status'] = $item->privacy_status;
@@ -283,7 +283,7 @@ public function getelementinfoAction()
283283
case 'folder':
284284
$folder = $this->Folder->load($id);
285285
$jsonContent = array_merge($jsonContent, $folder->toArray());
286-
$jsonContent['creation'] = $this->Component->Date->formatDate(strtotime($jsonContent['date']));
286+
$jsonContent['creation'] = $this->Component->Date->formatDate(strtotime($jsonContent['date_update']));
287287
if(!isset($this->userSession->Dao->recentFolders))
288288
{
289289
$this->userSession->Dao->recentFolders = array();

core/controllers/ImportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function _recursiveParseDirectory($path, $currentdir)
132132
$child = new FolderDao;
133133
$child->setName($fileInfo->getFilename());
134134
$child->setParentId($currentdir->getFolderId());
135-
$child->setDate(date('c'));
135+
$child->setDateCreation(date('c'));
136136
$this->Folder->save($child);
137137
$this->Folderpolicyuser->createPolicy($this->userSession->Dao, $child, MIDAS_POLICY_ADMIN);
138138
$anonymousGroup = $this->Group->load(MIDAS_GROUP_ANONYMOUS_KEY);

core/controllers/components/SearchComponent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ private function _formatResults($order, $items, $folders, $communities, $users)
5858
foreach($users as $key => $user)
5959
{
6060
$users[$key]->name = $user->getLastname();
61-
$users[$key]->date = $user->getCreation();
61+
$users[$key]->date_update = $user->getCreation();
6262
}
6363
foreach($communities as $key => $community)
6464
{
65-
$communities[$key]->date = $community->getCreation();
65+
$communities[$key]->date_update = $community->getCreation();
6666
}
6767
$results = array_merge($folders, $items, $communities, $users);
6868

@@ -80,7 +80,7 @@ private function _formatResults($order, $items, $folders, $communities, $users)
8080
usort($results, array($sortdaoComponent, 'sortByName'));
8181
break;
8282
case 'date':
83-
$sortdaoComponent->field = 'date';
83+
$sortdaoComponent->field = 'date_update';
8484
$sortdaoComponent->order = 'asc';
8585
usort($results, array($sortdaoComponent, 'sortByDate'));
8686
break;
@@ -105,7 +105,7 @@ private function _formatResults($order, $items, $folders, $communities, $users)
105105
if($result instanceof ItemDao)
106106
{
107107
$tmp['resultType'] = 'item';
108-
$tmp['formattedDate'] = $dateComponent->formatDate($result->getDate());
108+
$tmp['formattedDate'] = $dateComponent->formatDate($result->getDateUpdate());
109109
}
110110
if($result instanceof CommunityDao)
111111
{
@@ -115,7 +115,7 @@ private function _formatResults($order, $items, $folders, $communities, $users)
115115
if($result instanceof FolderDao)
116116
{
117117
$tmp['resultType'] = 'folder';
118-
$tmp['formattedDate'] = $dateComponent->formatDate($result->getDate());
118+
$tmp['formattedDate'] = $dateComponent->formatDate($result->getDateUpdate());
119119
}
120120
unset($tmp['password']);
121121
unset($tmp['email']);

core/controllers/components/UploadComponent.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ public function createLinkItem($userDao, $name, $url, $parent = null)
133133
Zend_Loader::loadClass("ItemDao", BASE_PATH . '/core/models/dao');
134134
$item = new ItemDao;
135135
$item->setName($name);
136-
$item->setDate(date('c'));
137136
$item->setDescription('');
138137
$item->setType(0);
139138
$item->setThumbnail('');

core/database/upgrade/3.0.16.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
class Upgrade_3_0_16 extends MIDASUpgrade
4+
{
5+
public function preUpgrade()
6+
{
7+
}
8+
9+
public function mysql()
10+
{
11+
}
12+
13+
14+
public function pgsql()
15+
{
16+
}
17+
18+
public function postUpgrade()
19+
{
20+
$this->renameTableField('item', 'date', 'date_update', 'timestamp', 'timestamp without time zone', false);
21+
$this->addTableField('item', 'date_creation', 'timestamp', 'timestamp without time zone', false);
22+
$this->renameTableField('folder', 'date', 'date_update', 'timestamp', 'timestamp without time zone', false);
23+
$this->addTableField('folder', 'date_creation', 'timestamp', 'timestamp without time zone', false);
24+
}
25+
}
26+
?>
27+
28+

core/models/base/FolderModelBase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function __construct()
2929
'parent_id' => array('type' => MIDAS_DATA),
3030
'name' => array('type' => MIDAS_DATA),
3131
'description' => array('type' => MIDAS_DATA),
32-
'date' => array('type' => MIDAS_DATA),
32+
'date_update' => array('type' => MIDAS_DATA),
33+
'date_creation' => array('type' => MIDAS_DATA),
3334
'view' => array('type' => MIDAS_DATA),
3435
'teaser' => array('type' => MIDAS_DATA),
3536
'privacy_status' => array('type' => MIDAS_DATA),
@@ -77,7 +78,7 @@ function incrementViewCount($folder)
7778
}
7879
}
7980
$folder->view++;
80-
$this->save($folder);
81+
parent::save($folder);
8182
}//end incrementViewCount
8283

8384
/** Create a folder */
@@ -118,7 +119,6 @@ function createFolder($name, $description, $parent)
118119
$folder = new FolderDao();
119120
$folder->setName($name);
120121
$folder->setDescription($description);
121-
$folder->setDate(date('c'));
122122

123123
$folder->setParentId($parentId);
124124
$this->save($folder);

core/models/base/ItemModelBase.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function __construct()
2626
'description' => array('type' => MIDAS_DATA),
2727
'type' => array('type' => MIDAS_DATA),
2828
'sizebytes' => array('type' => MIDAS_DATA),
29-
'date' => array('type' => MIDAS_DATA),
29+
'date_creation' => array('type' => MIDAS_DATA),
30+
'date_update' => array('type' => MIDAS_DATA),
3031
'thumbnail' => array('type' => MIDAS_DATA),
3132
'view' => array('type' => MIDAS_DATA),
3233
'download' => array('type' => MIDAS_DATA),
@@ -56,6 +57,11 @@ public function save($dao)
5657
{
5758
$dao->setUuid(uniqid() . md5(mt_rand()));
5859
}
60+
if(!isset($dao->date_creation) || empty($dao->date_creation))
61+
{
62+
$dao->setDateCreation(date('c'));
63+
}
64+
$dao->setDateUpdate(date('c'));
5965
parent::save($dao);
6066
}
6167

@@ -116,7 +122,7 @@ function incrementViewCount($itemdao)
116122
}
117123
}
118124
$itemdao->view++;
119-
$this->save($itemdao);
125+
parent::save($itemdao);
120126
}//end incrementViewCount
121127

122128
/** plus one download*/
@@ -127,7 +133,7 @@ function incrementDownloadCount($itemdao)
127133
throw new Zend_Exception("Error param.");
128134
}
129135
$itemdao->download++;
130-
$this->save($itemdao);
136+
parent::save($itemdao);
131137
}//end incrementDownloadCount
132138

133139
/** Add a revision to an item
@@ -158,6 +164,7 @@ function addRevision($itemdao, $revisiondao)
158164
}
159165
$revisiondao->setItemId($itemdao->getItemId());
160166
$ItemRevisionModel->save($revisiondao);
167+
$this->save($itemdao);//update date
161168
} // end addRevision
162169

163170
} // end class ItemModelBase

core/models/base/ItemRevisionModelBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function addBitstream($itemRevisionDao, $bitstreamDao)
5858

5959
$item = $itemRevisionDao->getItem($bitstreamDao);
6060
$item->setSizebytes($this->getSize($itemRevisionDao));
61-
$item->setDate(date('c'));
61+
$item->setDateCreation(date('c'));
6262

6363
$modulesThumbnail = Zend_Registry::get('notifier')->notify(MIDAS_NOTIFY_CREATE_THUMBNAIL);
6464
if(empty($modulesThumbnail))

core/models/pdo/FolderModel.php

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -406,48 +406,6 @@ public function move($folder, $parent)
406406
$folder = $this->load($folder->getKey());
407407
$folder->setParentId($parent->getKey());
408408
parent::save($folder);
409-
/*
410-
411-
$allChildren = $this->getAllChildren($folder, null, true);
412-
413-
$leftIndice = $folder->getLeftIndice();
414-
$rightIndice = $folder->getRightIndice();
415-
$rightParentIndice = $currentParent->getRightIndice();
416-
$this->database->getDB()->update('folder', array('left_indice' => new Zend_Db_Expr('left_indice - '.$diff)),
417-
array('left_indice > ?' => $rightIndice));
418-
$this->database->getDB()->update('folder', array('right_indice' => new Zend_Db_Expr('right_indice - '.$diff)),
419-
array('right_indice > ?' => $rightIndice));
420-
421-
422-
$childrenIds = array();
423-
foreach($allChildren as $child)
424-
{
425-
$childrenIds[] = $child->getKey();
426-
}
427-
$childrenIds[] = $folder->getKey();
428-
$folder = $this->load($folder->getKey());
429-
$parent = $this->load($parent->getKey());
430-
431-
$diff = $folder->getLeftIndice() - $parent->getRightIndice();
432-
433-
$this->database->getDB()->update('folder', array('left_indice' => new Zend_Db_Expr('left_indice - '.$diff)),
434-
array('folder_id IN (?)' => $childrenIds));
435-
$this->database->getDB()->update('folder', array('right_indice' => new Zend_Db_Expr('right_indice - '.$diff)),
436-
array('folder_id IN (?)' => $childrenIds));
437-
438-
$this->getLogger()->info('2:'.$diff);
439-
$parent = $this->load($parent->getKey());
440-
$folder = $this->load($folder->getKey());
441-
$diff = $folder->getRightIndice() - $parent->getRightIndice() + 1;
442-
443-
$this->database->getDB()->update('folder', array('right_indice' => new Zend_Db_Expr($diff.' + right_indice')),
444-
array('right_indice >= ?' => $parent->getRightIndice()));
445-
$this->database->getDB()->update('folder', array('left_indice' => new Zend_Db_Expr($diff.' + left_indice')),
446-
array('left_indice >= ?' => $parent->getRightIndice()));
447-
$folder = $this->load($folder->getKey());
448-
$folder->setParentId($parent->getKey());
449-
$this->getLogger()->info('3:'.$diff);
450-
parent::save($folder);*/
451409
}//end move
452410

453411
/** Custom save function*/
@@ -500,11 +458,18 @@ public function save($folder)
500458
unset($data['folder_id']);
501459
unset($data['left_indice']);
502460
unset($data['right_indice']);
461+
$data['date_update'] = date('c');
503462
$this->database->update($data, array('folder_id = ?' => $key));
504463
return $key;
505464
}
506465
else
507466
{
467+
if(!isset($data['date_creation']) || empty($data['date_creation']))
468+
{
469+
$data['date_creation'] = date('c');
470+
}
471+
$data['date_update'] = date('c');
472+
508473
$this->database->getDB()->update('folder', array('right_indice' => new Zend_Db_Expr('2 + right_indice')),
509474
array('right_indice >= ?' => $rightParent));
510475
$this->database->getDB()->update('folder', array('left_indice' => new Zend_Db_Expr('2 + left_indice')),
@@ -931,7 +896,7 @@ function getFoldersFromSearch($search, $userDao, $limit = 14, $group = true, $or
931896
$sql->order(array('f.name ASC'));
932897
break;
933898
case 'date':
934-
$sql->order(array('f.date ASC'));
899+
$sql->order(array('f.date_update ASC'));
935900
break;
936901
case 'view':
937902
default:

core/models/pdo/ItemKeywordModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function getItemsFromSearch($searchterm, $userDao, $limit = 14, $group = true, $
145145
$sql->order(array('i.name ASC'));
146146
break;
147147
case 'date':
148-
$sql->order(array('i.date ASC'));
148+
$sql->order(array('i.date_update ASC'));
149149
break;
150150
case 'view':
151151
default:

0 commit comments

Comments
 (0)