*/
class UsersController extends AppController
{
-
+
/**
* Index method
*
public function view($id = null)
{
$user = $this->Users->get($id, [
- 'contain' => ['UserTypes','RelationshipsSoftwares', 'Relationships', 'Reviews']
- // 'contain'=>['UserTypes','Reviews']
- ]);
-
-
-
- $creatorOfSoftwares = $this->getRelationsByUserId($id, 'CreatorOf');
- $userSoftwares = $this->getRelationsByUserId($id, 'UserOf');
- $backerSoftwares = $this->getRelationsByUserId($id, 'BackerOf');
- $contributorSoftwares = $this->getRelationsByUserId($id, 'ContributorOf');
- $providerForSoftwares = $this->getRelationsByUserId($id, 'ServicesProvider');
-
- $this->set(compact('user','creatorOfSoftwares','userSoftwares','backerSoftwares','contributorSoftwares','providerForSoftwares'));
-
- $this->set('_serialize', ['user','creatorOfSoftwares','userSoftwares','backerSoftwares','contributorSoftwares','providerForSoftwares','users']);
+ 'contain' => [
+ 'UserTypes',
+ 'Reviews',
+ 'Usedsoftwares' => [
+ 'Softwares' => [
+ 'fields' => [
+ 'id',
+ 'softwarename',
+ 'logo_directory',
+ 'photo',
+ 'description'
+ ]
+ ]
+ ],
+ "Backedsoftwares" =>[
+ 'Softwares' => [
+ 'fields' => [
+ 'id',
+ 'softwarename',
+ 'logo_directory',
+ 'photo',
+ 'description'
+ ]
+ ]
+ ],
+ "Createdsoftwares" =>[
+ 'Softwares' => [
+ 'fields' => [
+ 'id',
+ 'softwarename',
+ 'logo_directory',
+ 'photo',
+ 'description'
+ ]
+ ]
+ ],
+ "Contributionssoftwares" =>[
+ 'Softwares' => [
+ 'fields' => [
+ 'id',
+ 'softwarename',
+ 'logo_directory',
+ 'photo',
+ 'description'
+ ]
+ ]
+ ],
+ "Providerforsoftwares" =>[
+ 'Softwares' => [
+ 'fields' => [
+ 'id',
+ 'softwarename',
+ 'logo_directory',
+ 'photo',
+ 'description'
+ ]
+ ]
+ ],
+ ]
+ ]);
+ $this->set(compact('user'));
+ $this->set('_serialize', 'user');
}
- /**
- *
- * @param Integer $id reprensent the user id
- * @param String $typeOfRelation represent the name of the relation (filed => 'cd')
- * @return type
- */
- private function getRelationsByUserId($id,$typeOfRelation){
-
- $RelationshipsSoftwaresUsersTable = TableRegistry::get('relationships_softwares_users');
-
- if (!empty($this->Users->Relationships->find('all')
- ->select('id')
- ->where(['relationships.cd = ' => $typeOfRelation])
- ->toArray()) ){
- $relationId = $this->Users->Relationships->find('all')
- ->select('id')
- ->where(['relationships.cd = ' => $typeOfRelation])
- ->toArray()[0]->id;
-
- // Get the all relationships between an user and softwares
- $relations = $RelationshipsSoftwaresUsersTable->find('all')
- ->contain(['Relationships'])->where(["relationships_softwares_users.user_id = " =>$id])
- ->where(['relationships_softwares_users.relationship_id = '=> $relationId]);
- }
- return $relations ;
+ public function FindByType (){
+
+ $UserType = $this->request->params['pass'];
+
+ $this->paginate = [
+ 'finder' => [
+ 'ByType' => $UserType
+ ]
+ ];
+
+ $users = $this->paginate($this->Users);
+
+ $this->$this->set(compact('users'));
+ $this->set('_serialize', 'users');
}
-
public function getUsersByType(){
try {
$users = $this->Users->find("all")->contain(["UserTypes"])
'message' => "Success",
'users' => $this->paginate($users),
'_serialize' => ['message', 'users']
- ]);
+ ]);
}catch(Exception $e){
-
+
}
-
+
}
/**
// if is a json
if ($this->request->is('post') && $this->request->is('json')) {
$user = $this->Users->patchEntity($user, $this->request->data);
- if ($this->Users->save($user) ) {
+ if ($this->Users->save($user) ) {
$message = "success";
} else {
$message = "Error";
'message' => $message,
'user' => $user,
'_serialize' => ['message', 'user']
- ]);
+ ]);
// if is not a json
}else if ($this->request->is('post') && !$this->request->is('json')){
$user = $this->Users->patchEntity($user, $this->request->data);
$userTypes = $this->Users->UserTypes->find('list', ['limit' => 200]);
$this->set(compact('user', 'userTypes'/*, 'relationshipsSoftwares', 'relationships'*/));
$this->set('_serialize', ['user']);
- }
+ }
}
/**
if ($this->request->is(['patch', 'post', 'put']) && $this->request->is('json')) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
- $message = "success";
+ $message = "success";
} else {
$message = "Error";
}
'message' => $message,
'user' => $user,
'_serialize' => ['message', 'user']
- ]);
+ ]);
}
else if ($this->request->is(['patch', 'post', 'put']) && !$this->request->is('json')){
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
- $this->Flash->success(__('The user has been saved.'));
+ $this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
- }
+ }
$userTypes = $this->Users->UserTypes->find('list', ['limit' => 200]);
$this->set(compact('user', 'userTypes'/*, 'relationshipsSoftwares', 'relationships'*/));
}else {// Pour le template avant le poste des données.
$userTypes = $this->Users->UserTypes->find('list', ['limit' => 200]);
$this->set(compact('user', 'userTypes'/*, 'relationshipsSoftwares', 'relationships'*/));
- $this->set('_serialize', ['user']);
- }
+ $this->set('_serialize', ['user']);
+ }
}
-
- /**
- *
+
+ /**
+ *
*/
public function isAdministration (){
try {
$user = $this->Users->get($this->request->query["id"], [
'contain' => ['UserTypes',]
]);
-
+
$this->set([
'message' => "Success",
'user' => $user,
'_serialize' => ['message', 'user']
- ]);
+ ]);
}catch(Exception $e){
-
+
}
}
return $this->redirect(['action' => 'index']);
}
-
-
+
+
public function login()
- {
+ {
$message = "test";
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
$message ="Success";
-
+
}else {
$message = __("Bad Username or bad password");
}
'message' => $message,
'user' => $user,
'_serialize' => ['message', 'user']
- ]);
+ ]);
}else{
$this->set([
'message' => $message,
'_serialize' => ['message']
- ]);
+ ]);
}
-
+
}
public function logout()
{
return $this->redirect($this->Auth->logout());
}
-
+
/**
- * Manage all rights for the controllers' actions.
+ * Manage all rights for the controllers' actions.
* Returns true if the user can use the currrent action, FALSE otherwise.
* Returns true for add a project if the user is connected
- * Returns true for edit and delete action if the user is owner.
+ * Returns true for edit and delete action if the user is owner.
* @param Array $user
* @return boolean
*/
$this->Auth->allow();
return parent::isAuthorized($user);
}
-
-
+
+
public function initialize(){
-
-
+
+
parent::initialize();
-
+
$this->paginate = [
'limit' => Configure::read('LIMIT'),
'order' => [