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

Commit 301710b

Browse files
author
Charles Marion
committed
ENH: optimized browser
BUG: Fixed keyword import BUG: Fixed community search
1 parent ad3e421 commit 301710b

26 files changed

+287
-188
lines changed

application/controllers/BrowseController.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class BrowseController extends AppController
77
{
88
public $_models=array('Folder','User','Community','Folder','Item');
99
public $_daos=array('Folder','User','Community','Folder','Item');
10-
public $_components=array('Date','Utility');
10+
public $_components=array('Date','Utility','Sortdao');
1111

1212
/** Init Controller */
1313
function init()
@@ -18,17 +18,27 @@ function init()
1818
/** Index Action*/
1919
public function indexAction()
2020
{
21+
2122
$communities=array();
2223
$items=array();
2324
$header="";
2425

2526
$communities=$this->User->getUserCommunities($this->userSession->Dao);
26-
$header.="> Data";
27+
$communities=array_merge($communities, $this->Community->getPubicCommunities());
28+
29+
$header.="<ul class='pathBrowser'>";
30+
$header.=" <li class='pathData'><a href='{$this->view->webroot}/browse'>Data</a></li>";
31+
$header.="</ul>";
2732

2833
$this->view->Date=$this->Component->Date;
2934

35+
$this->Component->Sortdao->field='name';
36+
$this->Component->Sortdao->order='asc';
37+
usort($communities, array($this->Component->Sortdao,'sortByName'));
38+
$communities=$this->Component->Sortdao->arrayUniqueDao($communities );
39+
3040
$this->view->communities=$communities;
31-
$this->view->header=substr($header,2);
41+
$this->view->header=$header;
3242

3343
$javascriptText=array();
3444
$javascriptText['view']=$this->t('View');
@@ -48,10 +58,11 @@ public function indexAction()
4858
/** get getfolders content (ajax function for the treetable) */
4959
public function getfolderscontentAction()
5060
{
51-
if(!$this->getRequest()->isXmlHttpRequest())
61+
/* if(!$this->getRequest()->isXmlHttpRequest())
5262
{
5363
throw new Zend_Exception("Why are you here ? Should be ajax.");
54-
}
64+
}*/
65+
5566
$this->_helper->layout->disableLayout();
5667
$this->_helper->viewRenderer->setNoRender();
5768
$folderIds=$this->_getParam('folders');
@@ -65,6 +76,7 @@ public function getfolderscontentAction()
6576
{
6677
throw new Zend_Exception("Folder doesn't exist");
6778
}
79+
6880
$folders=$this->Folder->getChildrenFoldersFiltered($parents,$this->userSession->Dao,MIDAS_POLICY_READ);
6981
$items=$this->Folder->getItemsFiltered($parents,$this->userSession->Dao,MIDAS_POLICY_READ);
7082
$jsonContent=array();
@@ -84,8 +96,7 @@ public function getfolderscontentAction()
8496
$tmp['item_id']=$item->getItemId();
8597
$tmp['name']=$item->getName();
8698
$tmp['parent_id']=$item->parent_id;
87-
$itemRevision=$this->Item->getLastRevision($item);
88-
$tmp['creation']=$this->Component->Date->ago($itemRevision->getDate(),true);
99+
$tmp['creation']=$this->Component->Date->ago($item->getDate(),true);
89100
$tmp['size']=$this->Component->Utility->formatSize($item->getSizebytes());
90101
$tmp['policy']=$item->policy;
91102
$jsonContent[$item->parent_id]['items'][]=$tmp;
@@ -100,14 +111,15 @@ public function getfolderssizeAction()
100111
if(!$this->getRequest()->isXmlHttpRequest())
101112
{
102113
throw new Zend_Exception("Why are you here ? Should be ajax.");
103-
}
114+
}
104115

105116
$this->_helper->layout->disableLayout();
106117
$this->_helper->viewRenderer->setNoRender();
107118
$folderIds=$this->_getParam('folders');
108119
if(!isset($folderIds))
109120
{
110-
throw new Zend_Exception("Please set the folder Id");
121+
echo "[]";
122+
return;
111123
}
112124
$folderIds=explode('-',$folderIds);
113125
$folders= $this->Folder->load($folderIds);
@@ -145,7 +157,14 @@ public function getelementinfoAction()
145157
case 'folder':
146158
$folder=$this->Folder->load($id);
147159
$jsonContent=array_merge($jsonContent,$folder->_toArray());
148-
$jsonContent['creation']=$jsonContent['date'];
160+
if(isset($jsonContent['date']))
161+
{
162+
$jsonContent['creation']=$jsonContent['date'];
163+
}
164+
else
165+
{
166+
$jsonContent['creation']=date('c');
167+
}
149168
break;
150169
case 'item':
151170
$item=$this->Item->load($id);

application/controllers/CommunityController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CommunityController extends AppController
44
{
55
public $_models=array('Community','Folder','Group','Folderpolicygroup','Group','User','Feed',"Feedpolicygroup","Feedpolicyuser");
66
public $_daos=array('Community','Folder','Group','Folderpolicygroup','Group','User');
7-
public $_components=array();
7+
public $_components=array('Sortdao');
88
public $_forms=array('Community');
99

1010
/** Init Controller */
@@ -26,10 +26,14 @@ function indexAction()
2626
$this->view->json['community']['titleCreateLogin']=$this->t('Please log in');
2727
$this->view->json['community']['contentCreateLogin']=$this->t('You need to be logged in to be able to create a community.');
2828

29-
if($this->logged)
30-
{
31-
$this->view->userCommunities=$this->User->getUserCommunities($this->userSession->Dao);
32-
}
29+
$communities=$this->User->getUserCommunities($this->userSession->Dao);
30+
$communities=array_merge($communities, $this->Community->getPubicCommunities());
31+
$this->Component->Sortdao->field='name';
32+
$this->Component->Sortdao->order='asc';
33+
usort($communities, array($this->Component->Sortdao,'sortByName'));
34+
$communities=$this->Component->Sortdao->arrayUniqueDao($communities );
35+
36+
$this->view->userCommunities=$communities;
3337
}//end index
3438

3539
/** view a community*/

application/controllers/FolderController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function init()
1616
{
1717
$this->_forward('view',null,null,array('folderId'=>$actionName));
1818
}
19+
$this->view->activemenu = 'browse'; // set the active menu
1920
} // end init()
2021

2122
/** View Action*/
@@ -38,25 +39,28 @@ public function viewAction()
3839
{
3940
$folders=$this->Folder->getChildrenFoldersFiltered($folder,$this->userSession->Dao,MIDAS_POLICY_READ);
4041
$items=$this->Folder->getItemsFiltered($folder,$this->userSession->Dao,MIDAS_POLICY_READ);
41-
$header.="> {$folder->getName()}";
42+
$header.=" <li class='pathFolder'><a href='{$this->view->webroot}/folder/{$folder->getKey()}'>{$folder->getName()}</a></li>";
4243
$parent=$folder->getParent();
4344
while($parent!==false)
4445
{
4546
if(strpos($parent->getName(), 'community')!==false&&$this->Folder->getCommunity($parent)!==false)
4647
{
4748
$community=$this->Folder->getCommunity($parent);
48-
$header="> {$community->getName()} ".$header;
49+
$header=" <li class='pathCommunity'><a href='{$this->view->webroot}/community/{$community->getKey()}'>{$community->getName()}</a></li>".$header;
4950
}
5051
else
5152
{
52-
$header="> {$parent->getName()} ".$header;
53+
$header=" <li class='pathFolder'><a href='{$this->view->webroot}/folder/{$parent->getKey()}'>{$parent->getName()}</a></li>".$header;
5354
}
5455
$parent=$parent->getParent();
5556
}
57+
$header="<ul class='pathBrowser'>
58+
<li class='pathData'><a href='{$this->view->webroot}/browse'>Data</a></li>".$header;
59+
$header.="</ul>";
5660
}
5761
$this->view->folders=$folders;
5862
$this->view->items=$items;
59-
$this->view->header=substr($header,2);
63+
$this->view->header=$header;
6064

6165
$javascriptText=array();
6266
$javascriptText['view']=$this->t('View');

application/controllers/ImportController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ private function _recursiveParseDirectory($path,$currentdir)
133133
$this->Item->save($item);
134134

135135
// Set the keyword for the item
136-
$keyword = new KeywordDao;
136+
$keyword = new ItemKeywordDao;
137137
$keyword->setValue($fileInfo->getFilename());
138-
$this->Keyword->insertKeyword($keyword);
138+
$this->ItemKeyword->insertKeyword($keyword);
139139

140140
$this->Item->addKeyword($item,$keyword);
141141

application/controllers/SearchController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function liveAction()
3737

3838
// Search for the items
3939
$ItemsDao = $this->ItemKeyword->getItemsFromSearch($search,$this->userSession->Dao);
40-
4140
// Search for the folders
4241
$FoldersDao = $this->Folder->getFoldersFromSearch($search,$this->userSession->Dao);
4342

@@ -176,7 +175,7 @@ public function liveAction()
176175
echo ', "value":"'.$communityDao->getName().'"';
177176
if($communityDao->count==1)
178177
{
179-
echo ', "communityid":"'.$communityDao->getCommunityId().'"';
178+
echo ', "communityid":"'.$communityDao->getKey().'"';
180179
}
181180
echo ', "category":"Communities"';
182181
$id++;

application/controllers/UploadController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
class UploadController extends AppController
44
{
5-
public $_models=array('User','Item','ItemRevision','Folder','Itempolicyuser','Itempolicygroup','Group','Feed',"Feedpolicygroup","Feedpolicyuser",'Bitstream','Assetstore');
6-
public $_daos=array('User','Item','ItemRevision','Bitstream','Folder');
5+
public $_models=array('User','Item','ItemRevision','Folder','Itempolicyuser',"ItemKeyword",'Itempolicygroup','Group','Feed',"Feedpolicygroup","Feedpolicyuser",'Bitstream','Assetstore');
6+
public $_daos=array('User','Item','ItemRevision','Bitstream','Folder',"ItemKeyword");
77
public $_components=array('Httpupload');
88
public $_forms=array('Upload');
99

@@ -162,6 +162,12 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
162162
$item = new ItemDao;
163163
$item->setName($name);
164164
$this->Item->save($item);
165+
166+
// Set the keyword for the item
167+
$keyword = new ItemKeywordDao();
168+
$keyword->setValue($name);
169+
$this->ItemKeyword->insertKeyword($keyword);
170+
165171
$feed=$this->Feed->createFeed($this->userSession->Dao,MIDAS_FEED_CREATE_ITEM,$item);
166172
if(isset($privacy)&&$privacy=='public')
167173
{
@@ -180,6 +186,8 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
180186
$itemRevisionDao->setChanges('Initial revision');
181187
$itemRevisionDao->setUser_id($userDao->getKey());
182188
$this->Item->addRevision($item,$itemRevisionDao);
189+
190+
$this->Item->addKeyword($item,$keyword);
183191

184192
$defaultAssetStoreId=Zend_Registry::get('configGlobal')->defaultassetstore->id;
185193
$assetstoreDao=$this->Assetstore->load($defaultAssetStoreId);

application/controllers/components/DateComponent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ static public function ago($timestamp,$only_time=false)
77
if(!is_numeric($timestamp))
88
{
99
$timestamp=strtotime($timestamp);
10+
if($timestamp==false)
11+
{
12+
return "";
13+
}
1014
}
1115
$difference = time() - $timestamp;
1216
$periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade");

application/controllers/components/SortDaoComponent.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,29 @@ public function sortByName($a,$b)
5050
return ($a_n < $b_n ) ? 1 : -1;
5151
}
5252
}//end sortByDate
53+
54+
55+
public function arrayUniqueDao($array, $keep_key_assoc = false)
56+
{
57+
$duplicate_keys = array();
58+
$tmp = array();
59+
60+
foreach ($array as $key=>$val)
61+
{
62+
// convert objects to arrays, in_array() does not support objects
63+
if (is_object($val))
64+
$val = (array)$val;
65+
66+
if (!in_array($val, $tmp))
67+
$tmp[] = $val;
68+
else
69+
$duplicate_keys[] = $key;
70+
}
71+
72+
foreach ($duplicate_keys as $key)
73+
unset($array[$key]);
74+
75+
return $keep_key_assoc ? $array : array_values($array);
76+
}
5377
} // end class
5478
?>

application/models/pdo/CommunityModel.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ class CommunityModel extends AppModelPdo
2929
'feeds' => array('type'=>MIDAS_MANY_TO_MANY, 'model'=>'Feed', 'table' => 'feed2community', 'parent_column'=> 'community_id', 'child_column' => 'feed_id'),
3030
);
3131

32+
/* get public Communities
33+
*
34+
* @return Array of Community Dao
35+
*/
36+
function getPubicCommunities($limit=20)
37+
{
38+
if(!is_numeric($limit))
39+
{
40+
throw new Zend_Exception("Error parameter.");
41+
}
42+
$sql = $this->select()->from($this->_name)
43+
->where('privacy != ?',MIDAS_COMMUNITY_PRIVATE)
44+
->limit($limit);
45+
46+
$rowset = $this->fetchAll($sql);
47+
$return = array();
48+
foreach($rowset as $row)
49+
{
50+
$return[] = $this->initDao('Community', $row);
51+
}
52+
return $return;
53+
}
3254

3355
/** Return a list of communities corresponding to the search */
3456
function getCommunitiesFromSearch($search,$userDao)
@@ -56,10 +78,10 @@ function getCommunitiesFromSearch($search,$userDao)
5678
$return = array();
5779
foreach($rowset as $row)
5880
{
59-
$tmpDao = new FolderDao();
81+
$tmpDao = new CommunityDao();
6082
$tmpDao->count = $row['count(*)'];
6183
$tmpDao->setName($row->name);
62-
$tmpDao->setFolderId($row->folder_id);
84+
$tmpDao->setCommunityId($row->community_id);
6385
$return[] = $tmpDao;
6486
unset($tmpDao);
6587
}

0 commit comments

Comments
 (0)