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

Commit b4460f1

Browse files
author
Charles Marion
committed
ENH : Moved SQL
Improved search
1 parent bcf0461 commit b4460f1

32 files changed

+1423
-893
lines changed

core/controllers/CommunityController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ function viewAction()
237237
$member_group=$communityDao->getMemberGroup();
238238
$this->Group->addUser($member_group,$this->userSession->Dao);
239239
}
240-
240+
241+
$this->Community->plusOneView($communityDao);
241242
$this->view->communityDao=$communityDao;
242243
$this->view->information=array();
243244
$this->view->feeds=$this->Feed->getFeedsByCommunity($this->userSession->Dao,$communityDao);

core/controllers/DownloadController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function indexAction()
6868
{
6969
continue;
7070
}
71+
$this->Item->plusOneDownload($item);
7172
if(isset($tmp[1]))
7273
{
7374
$tmp=$this->Item->getRevision($item,$tmp[1]);

core/controllers/FeedController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function indexAction()
2626
$this->view->notifications=array();
2727
$this->view->header=$this->t('Feed');
2828
}
29-
29+
3030
/** get getfolders Items' size */
3131
public function deleteajaxAction()
3232
{

core/controllers/FolderController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public function viewAction()
7070
<li class='pathData'><a href='{$this->view->webroot}/browse'>{$this->t('Data')}</a></li>".$header;
7171
$header.="</ul>";
7272
}
73+
74+
$this->Folder->plusOneView($folder);
7375
$this->view->mainFolder=$folder;
7476
$this->view->folders=$folders;
7577
$this->view->items=$items;

core/controllers/InstallController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function step2Action()
7171

7272
foreach($phpextensions as $key => $t)
7373
{
74-
if(!file_exists(BASE_PATH."/sql/{$key}/{$this->view->version}.sql"))
74+
if(!file_exists(BASE_PATH."/core/sql/{$key}/{$this->view->version}.sql"))
7575
{
7676
unset($phpextensions[$key]);
7777
}
@@ -95,7 +95,7 @@ function step2Action()
9595
switch($type)
9696
{
9797
case 'mysql':
98-
$this->run_mysql_from_file(BASE_PATH."/sql/{$type}/{$this->view->version}.sql",
98+
$this->run_mysql_from_file(BASE_PATH."/core/sql/{$type}/{$this->view->version}.sql",
9999
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'),$form->getValue('port'));
100100
$params= array(
101101
'host' => $form->getValue('host'),
@@ -124,7 +124,7 @@ function step2Action()
124124
Zend_Registry::set('dbAdapter', $db);
125125
break;
126126
case 'pgsql':
127-
$this->run_pgsql_from_file(BASE_PATH."/sql/{$type}/{$this->view->version}.sql",
127+
$this->run_pgsql_from_file(BASE_PATH."/core/sql/{$type}/{$this->view->version}.sql",
128128
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'),$form->getValue('port'));
129129
$params= array(
130130
'host' => $form->getValue('host'),

core/controllers/ItemController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function viewAction()
7272
setcookie('recentItems'.$this->userSession->Dao->getKey(), serialize($recentItems), time()+60*60*24*30,'/'); //30 days
7373
}
7474
$itemRevision=$this->Item->getLastRevision($itemDao);
75+
$this->Item->plusOneView($itemDao);
7576
$itemDao->lastrevision=$itemRevision;
7677
$itemDao->revisions=$itemDao->getRevisions();
7778
$itemDao->creation=$this->Component->Date->formatDate(strtotime($itemRevision->getDate()));

core/controllers/SearchController.php

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

1212
/** Init Controller */
1313
function init()
1414
{
1515
$this->view->activemenu = 'feed'; // set the active menu
1616

17-
// if the number of parameters is more than 3 then it's the liveAction
17+
// if the number of parameters is more than 3 then it's the liveAction or advanced search
1818
if(count($this->_getAllParams()) == 3)
1919
{
2020
$actionName=Zend_Controller_Front::getInstance()->getRequest()->getActionName();
@@ -32,29 +32,134 @@ public function indexAction()
3232
$keyword = $this->getRequest()->getParam('q');
3333
$this->view->json['search']['keyword'] = $keyword;
3434

35+
$ajax=$this->_getParam('ajax');
36+
$order=$this->_getParam('order');
37+
if(!isset($order))
38+
{
39+
$order='view';
40+
}
3541
// Get the items corresponding to the search
36-
$ItemsDao = $this->ItemKeyword->getItemsFromSearch($keyword,$this->userSession->Dao);
37-
$this->view->items=$ItemsDao;
42+
$ItemsDao = $this->ItemKeyword->getItemsFromSearch($keyword,$this->userSession->Dao,200,false,$order);
3843

3944
// Search for the folders
40-
$FoldersDao = $this->Folder->getFoldersFromSearch($keyword,$this->userSession->Dao);
41-
$this->view->folders=$FoldersDao;
45+
$FoldersDao = $this->Folder->getFoldersFromSearch($keyword,$this->userSession->Dao,15,false,$order);
4246

4347
// Search for the communities
44-
$CommunitiesDao = $this->Community->getCommunitiesFromSearch($keyword,$this->userSession->Dao);
45-
$this->view->communities=$CommunitiesDao;
48+
$CommunitiesDao = $this->Community->getCommunitiesFromSearch($keyword,$this->userSession->Dao,15,false,$order);
4649

4750
// Search for the users
48-
$UsersDao = $this->User->getUsersFromSearch($keyword,$this->userSession->Dao);
49-
$this->view->users=$UsersDao;
50-
}
51+
$UsersDao = $this->User->getUsersFromSearch($keyword,$this->userSession->Dao,15,false,$order);
52+
53+
$results=$this->formatResults($order, $ItemsDao, $FoldersDao, $CommunitiesDao, $UsersDao);
54+
55+
if(isset($ajax))
56+
{
57+
$this->_helper->layout->disableLayout();
58+
$this->_helper->viewRenderer->setNoRender();
59+
echo JsonComponent::encode($results);
60+
}
61+
else
62+
{
63+
$this->view->nitems=count($ItemsDao);
64+
$this->view->nfolders=count($FoldersDao);
65+
$this->view->ncommunities=count($CommunitiesDao);
66+
$this->view->nusers=count($UsersDao);
67+
$this->view->json['search']['results']=$results;
68+
$this->view->json['search']['keyword'] = $keyword;
69+
$this->view->json['search']['noResults'] = $this->t('No result found.');
70+
$this->view->json['search']['moreResults'] = $this->t('Show more results.');
71+
}
72+
}//end indexAction
73+
74+
/**
75+
* Format search results
76+
* @param string $order
77+
* @param Array $items
78+
* @param Array $folders
79+
* @param Array $communities
80+
* @param Array $users
81+
* @return Array
82+
*/
83+
private function formatResults($order,$items,$folders,$communities,$users)
84+
{
85+
foreach ($users as $key=>$user)
86+
{
87+
$users[$key]->name=$user->getLastname();
88+
$users[$key]->date=$user->getCreation();
89+
}
90+
foreach ($communities as $key=>$community)
91+
{
92+
$communities[$key]->date=$community->getCreation();
93+
}
94+
$results=array_merge($folders, $items,$communities,$users);
95+
96+
switch ($order)
97+
{
98+
case 'name':
99+
$this->Component->Sortdao->field='name';
100+
$this->Component->Sortdao->order='asc';
101+
usort($results, array($this->Component->Sortdao,'sortByName'));
102+
break;
103+
case 'date':
104+
$this->Component->Sortdao->field='date';
105+
$this->Component->Sortdao->order='asc';
106+
usort($results, array($this->Component->Sortdao,'sortByDate'));
107+
break;
108+
case 'view':
109+
$this->Component->Sortdao->field='view';
110+
$this->Component->Sortdao->order='desc';
111+
usort($results, array($this->Component->Sortdao,'sortByNumber'));
112+
break;
113+
default:
114+
throw new Zend_Exception('Error order parameter');
115+
break;
116+
}
117+
$resultsArray=array();
118+
foreach ($results as $result)
119+
{
120+
$tmp=$result->_toArray();
121+
if($result instanceof UserDao)
122+
{
123+
$tmp['resultType']='user';
124+
$tmp['formattedDate']=$this->Component->Date->formatDate($result->getCreation());
125+
}
126+
if($result instanceof ItemDao)
127+
{
128+
$tmp['resultType']='item';
129+
$tmp['formattedDate']=$this->Component->Date->formatDate($result->getDate());
130+
}
131+
if($result instanceof CommunityDao)
132+
{
133+
$tmp['resultType']='community';
134+
$tmp['formattedDate']=$this->Component->Date->formatDate($result->getCreation());
135+
}
136+
if($result instanceof FolderDao)
137+
{
138+
$tmp['resultType']='folder';
139+
$tmp['formattedDate']=$this->Component->Date->formatDate($result->getDate());
140+
}
141+
unset($tmp['password']);
142+
unset($tmp['email']);
143+
$resultsArray[]=$tmp;
144+
}
145+
return $resultsArray;
146+
}//formatResults
147+
148+
/** advanced search Action */
149+
public function advancedAction()
150+
{
151+
$this->_helper->layout->disableLayout();
152+
}//advancedAction
51153

52154
/** search live Action */
53155
public function liveAction()
54156
{
55157
// This is necessary in order to avoid session lock and being able to run two
56158
// ajax requests simultaneously
57159
session_write_close();
160+
161+
$this->_helper->layout->disableLayout();
162+
$this->_helper->viewRenderer->setNoRender();
58163

59164
$search = $this->getRequest()->getParam('term');
60165

@@ -242,7 +347,6 @@ public function liveAction()
242347
}
243348

244349
echo ']';
245-
exit();
246350
}
247351

248352
} // end class

core/controllers/UserController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function userpageAction()
302302
{
303303
throw new Zend_Exception("Unable to find user");
304304
}
305-
305+
306306
$this->view->user=$userDao;
307307
$this->view->userCommunities=$this->User->getUserCommunities($userDao);
308308
$this->view->folders=array();
@@ -311,6 +311,10 @@ public function userpageAction()
311311
{
312312
$this->view->folders[]=$userDao->getPrivateFolder();
313313
}
314+
else
315+
{
316+
$this->User->plusOneView($userDao);
317+
}
314318
$this->view->feeds=$this->Feed->getFeedsByUser($this->userSession->Dao,$userDao);
315319

316320
$this->view->information=array();

core/controllers/components/SortdaoComponent.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ public function sortByName($a,$b)
5151
}
5252
}//end sortByDate
5353

54+
/** sort by number*/
55+
public function sortByNumber($a,$b)
56+
{
57+
if($this->field==''||!isset($a->{$this->field}))
58+
{
59+
throw new Zend_Exception("Error field.");
60+
}
61+
$a_n = strtolower($a->{$this->field}) ;
62+
$b_n = strtolower($b->{$this->field}) ;
63+
64+
if( $a_n == $b_n )
65+
return 0 ;
66+
67+
if($this->order=='asc')
68+
{
69+
return ($a_n < $b_n) ? -1 : 1;
70+
}
71+
else
72+
{
73+
return ($a_n < $b_n ) ? 1 : -1;
74+
}
75+
}//end sortByNumber
5476

5577
public function arrayUniqueDao($array, $keep_key_assoc = false)
5678
{

core/layouts/layout.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<input type="text" id="live_search" value="<?= $this->t('Jump to a data, folder...') ?>" autocomplete="off" autocorrect="off" autocapitalize="off" />
131131
<input type="hidden" id="live_search_value" value="init" />
132132
<div id="searchloading" style="display:none"></div>
133+
<a id="advancedSearchLink"><?php echo $this->t('Advanced search')?></a>
133134
</div>
134135
<div class="HeaderAction">
135136
<ul>

0 commit comments

Comments
 (0)