* @return void
*/
public function index() {
-//
-
+//
+
//Redifine paginate for the use case
$this->paginate = [
//'fields' => ['Articles.id', 'Articles.created'],
$this->set('softwares', $this->paginate($this->Softwares));
$this->set('_serialize', ['softwares', 'pagination', 'paging']);
-//
+//
// $this->set('softwares', $this->paginate($software));
// $this->set('_serialize', ['softwares', 'pagination']);
if ($this->request->is('get') && $id != null) {
$software = $this->Softwares->get($id, [
- 'contain' => ['Licenses', 'Reviews', 'Screenshots', 'Relationships', 'SoftwaresStatistics', 'RawMetricsSoftwares'],
- ]);
- // Get the ID of the 'UserOf' relationship
- $relationshipsTable = TableRegistry::get('relationships');
- $relationshipsUserOf = $relationshipsTable->find('all')->select(['id'])->where(['relationships.cd = ' => 'UserOf'])->toArray();
- $relationshipsUserOfId = $relationshipsUserOf[0]->id;
-
- // Get all the userOf relationships
- $relationshipsSoftwareUsersTable = TableRegistry::get('relationships_softwares_users');
- $RelationshipsUsersOf = $relationshipsSoftwareUsersTable->find('all')
- ->where(['relationships_softwares_users.software_id = ' => $id])
- ->andWhere(['relationships_softwares_users.relationship_id = ' => $relationshipsUserOfId
- ]);
-
- //Get WorksWell With
- $worksWelleWith = $relationshipsTable->find('all')->select(['id'])->where(['relationships.cd = ' => 'WorksWellWith'])->toArray();
- $worksWelleWithId = $worksWelleWith[0]->id;
-
- $relationshipsSoftwareTable = TableRegistry::get('relationships_softwares');
- $RelationshipsWorksWellWith = $relationshipsSoftwareTable->find('all')->toArray();
-
- $RelationshipsWorksWellWith = $relationshipsSoftwareTable->find('all')
- ->where(['software_id = ' => $id])
- ->andWhere(['relationship_id = ' => $worksWelleWithId]);
-
- //Get Alternative to With
- $alternativeTo = $relationshipsTable->find('all')->select(['id'])->where(['relationships.cd = ' => 'AlternativeTo'])->toArray();
- $alternativeToId = $alternativeTo[0]->id;
-
- $relationshipsSoftwareTable = TableRegistry::get('relationships_softwares');
- $RelationshipsAlternativeTo = $relationshipsSoftwareTable->find('all')->toArray();
-
- $RelationshipsAlternativeTo = $relationshipsSoftwareTable->find('all')
- ->where(['software_id = ' => $id])
- ->andWhere(['relationship_id = ' => $alternativeToId]);
-
- //Get all backers for
- $RelationshipsBackerOf = $this->backersFor($id);
-
- //Get the creator of
- $RelationshipsCreatedBy = $this->createdBy($id);
-
-
-
- // Get the Id of the 'ServiceProvider' relationship.
- $relationshipsTable = TableRegistry::get('relationships');
- $relationshipsServicePorviders = $relationshipsTable->find('all')->select(['id'])->where(['relationships.cd = ' => 'ServicesProvider'])->toArray();
- $relationshipsServicePorvidersId = $relationshipsServicePorviders[0]->id;
- // Get all service providers relatios hip.
- // Get all the userOf relationships
- $relationshipsServicePorviders = $relationshipsSoftwareUsersTable->find('all')
- ->where(['relationships_softwares_users.software_id = ' => $id])
- ->andWhere(['relationships_softwares_users.relationship_id = ' => $relationshipsServicePorvidersId
+ 'contain' => [
+ 'Licenses',
+ 'Reviews',
+ 'Screenshots',
+ 'Userssoftwares',
+ 'Backerssoftwares',
+ 'Creatorssoftwares',
+ 'Contributorssoftwares',
+ 'Providerssoftwares',
+ 'workswellsoftwares',
+ 'alternativeto',
+ 'SoftwaresStatistics',
+ 'RawMetricsSoftwares'
+ ],
]);
- $this->set(compact('software', 'RelationshipsUsersOf', 'relationshipsServicePorviders', 'RawMetricsSoftwares', "RelationshipsWorksWellWith", "RelationshipsAlternativeTo","RelationshipsBackerOf","RelationshipsCreatedBy"));
- $this->set('_serialize', ['software', 'RelationshipsUsersOf', 'relationshipsServicePorviders', "RelationshipsWorksWellWith", "RelationshipsAlternativeTo","RelationshipsBackerOf","RelationshipsCreatedBy"]);
+ $this->set(compact('software'));
+ $this->set('_serialize', ['software']);
}
// no id specified => ALL software listed
if ($id == null && $this->request->is('get') && $this->response->type('json')) {
-// $softwares = $this->Softwares->find('all')
-// ->where(['Softwares.softwarename LIKE' => '%' . $this->request->query('name') . '%'])
-// ->orWhere(['Softwares.description LIKE' => '%' . $this->request->query('name') . '%'])
-// ->contain(['Licenses', 'Reviews', 'Screenshots', 'Relationships', 'SoftwaresStatistics', 'RawMetricsSoftwares'])
-// ;
-
- $softwares = $this->Softwares->find('search', ['search' => $this->request->query]);
-
+ $softwares = $this->Softwares
+ ->find('search', ['search' => $this->request->query])
+ ->contain([
+ 'SoftwaresStatistics',
+ ]);
$this->set('softwares', $this->paginate($softwares));
- $this->set('_serialize', ['softwares', 'pagination', 'paging']);
+ $this->set('_serialize', ['softwares','paging']);
}
}
$licenses = $this->Softwares->Licenses->find('list', ['limit' => 200]);
$this->set(compact('software', 'licenses'));
$this->set('_serialize', ['software']);
- //IF JSON
+ //IF JSON
} else if ($this->request->is(['patch', 'post', 'put']) && $this->request->is('json')) {
$software = $this->Softwares->patchEntity($software, $this->request->data);
if ($this->Softwares->save($software)) {
}
/**
- * 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
*/
/**
* Get all softwares matching with the name passed in parameter.
- * @param String $name
+ * @param String $name
*/
public function request($name = null) {
$this->set('softwares', $this->paginate($software));
$this->set('_serialize', ['softwares', 'pagination']);
}
-
-
+
+
/**
* Return all backers for a software thanks to his id.
- * @param Integer $id The software Id.
+ * @param Integer $id The software Id.
* @return type
*/
public function backersFor($id){
->where(['software_id = ' => $id])
->andWhere(['relationship_id = ' => $backerOfId]);
}
-
+
public function createdBy($id){
$relationshipsTable = TableRegistry::get('relationships');
//Get Backe by
->where(['software_id = ' => $id])
->andWhere(['relationship_id = ' => $backerOfId]);
}
-
+
/**
- * Fake function to get 4 projects
+ * Fake function to get 4 projects
*/
public function getProjectsById(){
//$softwaresIds = [27,15,9,23]; // softwares for tests
'contain' => ['Licenses', 'Reviews', 'Screenshots', 'Relationships', 'SoftwaresStatistics', 'RawMetricsSoftwares'],
]);
array_push($softwares, $software);
-
+
} catch (Exception $e){
$message = "Error";
$this->set('softwares', $softwares);
$this->set('_serialize', ['softwares', 'pagination']);
- }
+ }
}
-
+
$this->set('softwares', $softwares);
$this->set('_serialize', ['softwares', 'pagination']);
}
-
+
public function lastAdded(){
$this->paginate = [
'limit' => Configure::read('LIMIT_NUMBER_OF_SOFTWARES_HOME_PAGE'),
],
'contain' => ['Licenses', 'Reviews', 'Screenshots', 'Relationships', 'SoftwaresStatistics', 'RawMetricsSoftwares']
];
-
+
$this->set('softwares', $this->paginate($this->Softwares));
$this->set('_serialize', ['softwares', 'pagination', 'paging']);
}
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
-use Search\Manager;
+
/**
* Softwares Model
*
{
parent::initialize($config);
+ //----------------------------------------------------------------------
+ //-------------------------Logique BDD--------------------------
+ //----------------------------------------------------------------------
+
+
$this->table('softwares');
$this->displayField('softwarename');
$this->primaryKey('id');
'foreignKey' => 'licence_id'
]);
$this->hasMany('RawMetricsSoftwares', [
- 'foreignKey' => 'software_id'
+ 'foreignKey' => 'software_id',
+ 'strategy' => 'select',
+ 'conditions' => function (\Cake\Database\Expression\QueryExpression $exp, \Cake\ORM\Query $query) {
+ $query->last();
+ return [];
+ }
]);
$this->hasMany('RelationshipsSoftwaresUsers', [
'foreignKey' => 'software_id'
+ //----------------------------------------------------------------------
+ //-------------------------Logique applicative--------------------------
+ //----------------------------------------------------------------------
+
+ /**
+ *
+ */
+ $this->hasMany(
+ 'Userssoftwares',
+ [
+ 'className' => 'RelationshipsSoftwaresUsers',
+ 'foreignKey' => 'software_id',
+ 'targetForeignKey' => 'user_id',
+ 'joinTable' => 'relationships_softwares_users',
+ 'conditions' => [
+ 'relationship_id' => 7
+ ]
+ ]
+ );
+
+ /**
+ * Backed softwares
+ */
+ $this->hasMany(
+ 'Backerssoftwares',
+ [
+ 'className' => 'RelationshipsSoftwaresUsers',
+ 'foreignKey' => 'software_id',
+ 'targetForeignKey' => 'user_id',
+ 'joinTable' => 'relationships_softwares_users',
+ 'conditions' => [
+ 'relationship_id' => 8
+ ]
+ ]
+ );
+ $this->hasMany(
+ 'Creatorssoftwares',
+ [
+ 'className' => 'RelationshipsSoftwaresUsers',
+ 'foreignKey' => 'software_id',
+ 'targetForeignKey' => 'user_id',
+ 'joinTable' => 'relationships_softwares_users',
+ 'conditions' => [
+ 'relationship_id' => 3
+ ]
+ ]
+ );
+ /**
+ * Contributior to
+ */
+ $this->hasMany(
+ 'Contributorssoftwares',
+ [
+ 'className' => 'RelationshipsSoftwaresUsers',
+ 'foreignKey' => 'software_id',
+ 'targetForeignKey' => 'user_id',
+ 'joinTable' => 'relationships_softwares_users',
+ 'conditions' => [
+ 'relationship_id' => 3
+ ]
+ ]
+ );
+ /**
+ * Provider For
+ */
+ $this->hasMany(
+ 'Providerssoftwares',
+ [
+ 'className' => 'RelationshipsSoftwaresUsers',
+ 'foreignKey' => 'software_id',
+ 'targetForeignKey' => 'user_id',
+ 'joinTable' => 'relationships_softwares_users',
+ 'conditions' => [
+ 'relationship_id' => 3
+ ]
+ ]
+ );
+
+ /**
+ * Works Well with
+ */
+ $this->hasMany(
+ 'workswellsoftwares',
+ [
+ 'className' => 'RelationshipsSoftwares',
+ 'foreignKey' => 'software_id',
+ 'targetForeignKey' => 'recipient_id',
+ 'joinTable' => 'relationships_softwares',
+ 'conditions' => [
+ 'relationship_id' => 6
+ ]
+ ]
+ );
+
+ /**
+ * Alternative to
+ */
+ $this->hasMany(
+ 'alternativeto',
+ [
+ 'className' => 'RelationshipsSoftwares',
+ 'foreignKey' => 'software_id',
+ 'targetForeignKey' => 'recipient_id',
+ 'joinTable' => 'relationships_softwares',
+ 'conditions' => [
+ 'relationship_id' => 5
+ ]
+ ]
+ );
+
+
+
// #######################
// ##### For search ######
// #######################