@@ -7,7 +7,7 @@ class SearchController extends AppController
7
7
{
8
8
public $ _models = array ('ItemKeyword ' , 'Item ' , 'Folder ' , 'User ' , 'Community ' , 'Group ' );
9
9
public $ _daos = array ('ItemKeyword ' , 'Item ' , 'Folder ' , 'User ' , 'Community ' );
10
- public $ _components = array ('Sortdao ' , 'Date ' , 'Utility ' );
10
+ public $ _components = array ('Sortdao ' , 'Date ' , 'Utility ' , ' Search ' );
11
11
12
12
/** Init Controller */
13
13
function init ()
@@ -38,20 +38,8 @@ public function indexAction()
38
38
{
39
39
$ order = 'view ' ;
40
40
}
41
- // Get the items corresponding to the search
42
- $ ItemsDao = $ this ->ItemKeyword ->getItemsFromSearch ($ keyword , $ this ->userSession ->Dao , 200 , false , $ order );
43
-
44
- // Search for the folders
45
- $ FoldersDao = $ this ->Folder ->getFoldersFromSearch ($ keyword , $ this ->userSession ->Dao , 15 , false , $ order );
46
-
47
- // Search for the communities
48
- $ CommunitiesDao = $ this ->Community ->getCommunitiesFromSearch ($ keyword , $ this ->userSession ->Dao , 15 , false , $ order );
49
-
50
- // Search for the users
51
- $ UsersDao = $ this ->User ->getUsersFromSearch ($ keyword , $ this ->userSession ->Dao , 15 , false , $ order );
52
-
53
- $ results = $ this ->_formatResults ($ order , $ ItemsDao , $ FoldersDao , $ CommunitiesDao , $ UsersDao );
54
41
42
+ $ results = $ this ->Component ->Search ->searchAll ($ this ->userSession ->Dao , $ keyword , $ order );
55
43
if (isset ($ ajax ))
56
44
{
57
45
$ this ->_helper ->layout ->disableLayout ();
@@ -60,90 +48,17 @@ public function indexAction()
60
48
}
61
49
else
62
50
{
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 ;
51
+ $ this ->view ->nitems = $ results [ ' nitems ' ] ;
52
+ $ this ->view ->nfolders = $ results [ ' nfolders ' ] ;
53
+ $ this ->view ->ncommunities = $ results [ ' ncommunities ' ] ;
54
+ $ this ->view ->nusers = $ results [ ' nusers ' ] ;
55
+ $ this ->view ->json ['search ' ]['results ' ] = $ results[ ' results ' ] ;
68
56
$ this ->view ->json ['search ' ]['keyword ' ] = $ keyword ;
69
57
$ this ->view ->json ['search ' ]['noResults ' ] = $ this ->t ('No result found. ' );
70
58
$ this ->view ->json ['search ' ]['moreResults ' ] = $ this ->t ('Show more results. ' );
71
59
}
72
60
}//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
61
+
147
62
148
63
149
64
/** search live Action */
0 commit comments