Commit 7618d77b authored by Julie gauthier's avatar Julie gauthier

REFACTOR: replace request->query by getQueryParams()/getQuery()

It's done everywhere it's possible. But PagesController/search and
usersController/index need more serious refactoring as it doesn't suite
to immutable objects.
parent 04e10a16
......@@ -99,8 +99,10 @@ class PagesController extends AppController
$Softwares = TableRegistry::get("Softwares");
//TO SORT
if (isset($this->request->query["order"])) {
$sort = explode(".", $this->request->query["order"]);
if (! is_null($this->request->getQuery("order"))) {
$sort = explode(".", $this->request->getQuery("order"));
// Note JGauthier 2019-07-16: just discovered this horror. This is not the correct way to do this.
// TODO This should be fixed
$this->request->query["sort"] = $sort[0];
$this->request->query["direction"] = $sort[1];
}
......@@ -130,12 +132,14 @@ class PagesController extends AppController
$this->set('searchQuery', $searchQuery);
// keep spaces , uppercase and transiterate accent characters to non-accent characters.
// Note JGauthier 2019-07-16: just discovered this horror. This is not the correct way to do this.
// TODO This should be fixed
$this->request->query['search'] = strtoupper(Text::slug($searchQuery));
$softwares = $Softwares
->find(
'search',
[
'search' => $this->request->query,
'search' => $this->request->getQueryParams(),
"contain" => ["Reviews"],
]
)
......@@ -155,7 +159,7 @@ class PagesController extends AppController
->find(
'search',
[
'search' => $this->request->query,
'search' => $this->request->getQueryParams(),
'contain' => ['UserTypes'],
'order' => [
'Users.username' => Configure::read('ORDER')
......@@ -203,7 +207,7 @@ class PagesController extends AppController
// $this->set('direction',$this->request->getData('direction'));
//To populate SearchForm
$this->request->getData($this->request->query);
$this->request->getData($this->request->getQueryParams());
$this->set('softwares', $this->paginate($softwares));
$this->set('users', $this->paginate($this->Users));
......
......@@ -40,7 +40,7 @@ class RelationshipsSoftwaresUsersController extends AppController
'all',
[
'contain' => ["Users", "Relationships"],
'conditions' => ["Relationships.cd = " => $this->request->query['Relationships']],
'conditions' => ["Relationships.cd = " => $this->request->getQuery('Relationships')],
]
)
->distinct("user_id");
......
......@@ -109,8 +109,8 @@ class SoftwaresController extends AppController
// For sorting
if (null !== ($this->request->getData()) && null !== ($this->request->getData("order"))) {
$sort = explode(".", $this->request->getData("order"));
$this->request->query["sort"] = $sort[0];
$this->request->query["direction"] = $sort[1];
$sort[0] = $this->request->getQuery("sort");
$sort[1] = $this->request->getQuery("direction");
}
// For filtering
......@@ -309,7 +309,7 @@ class SoftwaresController extends AppController
// no id specified => ALL software listed
if ($id == null && $this->request->is('get') && $this->request->is('json')) {
$softwares = $this->Softwares
->find('search', ['search' => $this->request->query]);
->find('search', ['search' => $this->request->getQueryParams()]);
$this->set('softwares', $this->paginate($softwares));
$this->set('_serialize', ['softwares']);
......
......@@ -52,8 +52,8 @@ class TagsController extends AppController
if (null !== ($this->request->getData()) && null !== ($this->request->getData("order"))) {
$sort = explode(".", $this->request->getData("order"));
$this->request->query["sort"] = $sort[0];
$this->request->query["direction"] = $sort[1];
$sort[0] = $this->request->getQuery("sort");
$sort[1] = $this->request->getQuery("direction");
}
......
......@@ -142,10 +142,12 @@ class UsersController extends AppController
*/
public function index()
{
if (!empty($this->request->query)
&& isset($this->request->query["order"])
// Used to sort users in alphabetical order (increasing/decreasing) for the sorting function on the users page.
if (! is_null($this->request->getQuery("order"))
) {
$sort = explode(".", $this->request->query["order"]);
$sort = explode(".", $this->request->getQuery("order"));
// Note JGauthier 2019-07-16: just discovered this horror. This is not the correct way to do this.
// TODO This should be fixed
$this->request->query["sort"] = $sort[0];
$this->request->query["direction"] = $sort[1];
}
......@@ -160,13 +162,13 @@ class UsersController extends AppController
'created',
'modified',
],
'search' => $this->request->query,
'search' => $this->request->getQueryParams(),
'contain' => ['UserTypes'],
'order' =>
isset($this->request->query["sort"])
&& isset($this->request->query["direction"])
! is_null($this->request->getQuery("sort"))
&& ! is_null($this->request->getQuery("direction"))
?
['Users.' . $this->request->query["sort"] => $this->request->query["direction"]]
['Users.' . $this->request->getQuery("sort") => $this->request->getQuery("direction")]
:
['Users.username' => Configure::read('ORDER')]
,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment