+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\LicenceType;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * LicenceTypes Model
- *
- */
-class LicenceTypesTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('licence_types');
- $this->displayField('name');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->requirePresence('name', 'create')
- ->notEmpty('name');
-
- $validator
- ->allowEmpty('cd');
-
- return $validator;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\License;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * Licenses Model
- *
- * @property \Cake\ORM\Association\BelongsTo $LicenceTypes
- */
-class LicensesTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('licenses');
- $this->displayField('name');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->belongsTo('LicenceTypes', [
- 'foreignKey' => 'license_type_id',
- 'joinType' => 'INNER'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->requirePresence('name', 'create')
- ->notEmpty('name');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['license_type_id'], 'LicenceTypes'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\RawMetricsSoftware;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * RawMetricsSoftwares Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Softwares
- */
-class RawMetricsSoftwaresTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('raw_metrics_softwares');
- $this->displayField('name');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->belongsTo('Softwares', [
- 'foreignKey' => 'software_id'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->integer('id')
- ->allowEmpty('id', 'create');
-
- $validator
- ->allowEmpty('name');
-
- $validator
- ->integer('last_commit_age')
- ->requirePresence('last_commit_age', 'create')
- ->notEmpty('last_commit_age');
-
- $validator
- ->numeric('high_committer_percent')
- ->requirePresence('high_committer_percent', 'create')
- ->notEmpty('high_committer_percent');
-
- $validator
- ->integer('number_of_contributors')
- ->requirePresence('number_of_contributors', 'create')
- ->notEmpty('number_of_contributors');
-
- $validator
- ->integer('declared_users')
- ->allowEmpty('declared_users');
-
- $validator
- ->decimal('average_review_score')
- ->allowEmpty('average_review_score');
-
- $validator
- ->integer('screenshots')
- ->allowEmpty('screenshots');
-
- $validator
- ->integer('code_gouv_label')
- ->allowEmpty('code_gouv_label');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['software_id'], 'Softwares'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\RelationshipType;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * RelationshipTypes Model
- *
- * @property \Cake\ORM\Association\HasMany $Relationships
- */
-class RelationshipTypesTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('relationship_types');
- $this->displayField('name');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->hasMany('Relationships', [
- 'foreignKey' => 'relationship_type_id'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->allowEmpty('name')
- ->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
-
- $validator
- ->allowEmpty('cd')
- ->add('cd', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
-
- return $validator;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\RelationshipsSoftware;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * RelationshipsSoftwares Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Softwares
- * @property \Cake\ORM\Association\BelongsTo $Relationships
- * @property \Cake\ORM\Association\BelongsTo $Softwares
- * @property \Cake\ORM\Association\BelongsToMany $Users
- */
-class RelationshipsSoftwaresTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('relationships_softwares');
- $this->displayField('id');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->belongsTo('Softwares', [
- 'foreignKey' => 'software_id',
- 'joinType' => 'INNER'
- ]);
- $this->belongsTo('Relationships', [
- 'foreignKey' => 'relationship_id',
- 'joinType' => 'INNER'
- ]);
- $this->belongsTo('Softwares', [
- 'foreignKey' => 'recipient_id',
- 'joinType' => 'INNER'
- ]);
- $this->belongsToMany('Users', [
- 'foreignKey' => 'software_id',
- 'targetForeignKey' => 'user_id',
- 'joinTable' => 'relationships_softwares_users'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['software_id'], 'Softwares'));
- $rules->add($rules->existsIn(['relationship_id'], 'Relationships'));
- $rules->add($rules->existsIn(['recipient_id'], 'Softwares'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\RelationshipsSoftwaresUser;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * RelationshipsSoftwaresUsers Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Softwares
- * @property \Cake\ORM\Association\BelongsTo $Users
- * @property \Cake\ORM\Association\BelongsTo $Relationships
- */
-class RelationshipsSoftwaresUsersTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('relationships_softwares_users');
- $this->displayField('id');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->belongsTo('Softwares', [
- 'foreignKey' => 'software_id',
- 'joinType' => 'INNER'
- ]);
- $this->belongsTo('Users', [
- 'foreignKey' => 'user_id',
- 'joinType' => 'INNER'
- ]);
- $this->belongsTo('Relationships', [
- 'foreignKey' => 'relationship_id',
- 'joinType' => 'INNER'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['software_id'], 'Softwares'));
- $rules->add($rules->existsIn(['user_id'], 'Users'));
- $rules->add($rules->existsIn(['relationship_id'], 'Relationships'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\Relationship;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * Relationships Model
- *
- * @property \Cake\ORM\Association\BelongsTo $RelationshipTypes
- * @property \Cake\ORM\Association\BelongsToMany $Softwares
- * @property \Cake\ORM\Association\BelongsToMany $Users
- */
-class RelationshipsTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('relationships');
- $this->displayField('name');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
-
- $this->addBehavior('Translate', ['fields' => ['title', 'body']]);
-
- $this->belongsTo('RelationshipTypes', [
- 'foreignKey' => 'relationship_type_id'
- ]);
-
- $this->belongsToMany('Softwares', [
- 'foreignKey' => 'relationship_id',
- 'targetForeignKey' => 'software_id',
- 'joinTable' => 'relationships_softwares'
- ]);
- $this->belongsToMany('Users', [
- 'foreignKey' => 'relationship_id',
- 'targetForeignKey' => 'user_id',
- 'joinTable' => 'relationships_users'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->requirePresence('name', 'create')
- ->notEmpty('name');
-
- $validator
- ->allowEmpty('cd');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['relationship_type_id'], 'RelationshipTypes'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\RelationshipsUser;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * RelationshipsUsers Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Users
- * @property \Cake\ORM\Association\BelongsTo $Users
- * @property \Cake\ORM\Association\BelongsTo $Relationships
- */
-class RelationshipsUsersTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('relationships_users');
- $this->displayField('id');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->belongsTo('Users', [
- 'foreignKey' => 'user_id',
- 'joinType' => 'INNER'
- ]);
- $this->belongsTo('Users', [
- 'foreignKey' => 'recipient_id',
- 'joinType' => 'INNER'
- ]);
- $this->belongsTo('Relationships', [
- 'foreignKey' => 'relationship_id',
- 'joinType' => 'INNER'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['user_id'], 'Users'));
- $rules->add($rules->existsIn(['recipient_id'], 'Users'));
- $rules->add($rules->existsIn(['relationship_id'], 'Relationships'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\Review;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * Reviews Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Users
- * @property \Cake\ORM\Association\BelongsTo $Softwares
- */
-class ReviewsTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('reviews');
- $this->displayField('title');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->belongsTo('Users', [
- 'foreignKey' => 'user_id'
- ]);
- $this->belongsTo('Softwares', [
- 'foreignKey' => 'software_id'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->requirePresence('comment', 'create')
- ->notEmpty('comment');
-
- $validator
- ->requirePresence('title', 'create')
- ->notEmpty('title');
-
- $validator
- ->allowEmpty('evaluation');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['user_id'], 'Users'));
- $rules->add($rules->existsIn(['software_id'], 'Softwares'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\Screenshot;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * Screenshots Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Softwares
- */
-class ScreenshotsTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('screenshots');
- $this->displayField('name');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- //For upload file -> avatar
- $this->addBehavior('Josegonzalez/Upload.Upload', [
- 'photo' => [
- 'fields' => [
- 'dir' => 'url_directory',
- ],
- 'path' => 'files{DS}{model}',
- ],
- ]);
-
-
-
- $this->belongsTo('Softwares', [
- 'foreignKey' => 'software_id'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->allowEmpty('name');
-
-// $validator
-// ->requirePresence('photo', 'create')
-// ->notEmpty('photo');
-
- $validator
- ->allowEmpty('url_directory');
- $validator
- ->allowEmpty('photo');
-
- $validator->provider('upload',new \Josegonzalez\Upload\Validation\DefaultValidation());
-
-
- $validator->add('photo', 'fileBelowMaxSize', [
- 'rule' => ['isBelowMaxSize', 1000000],
- 'message' => 'This file is too large',
- 'provider' => 'upload'
- ]);
-
-
- //Check that the file is below the maximum height requirement (checked in pixels)
- $validator->add('photo', 'fileBelowMaxHeight', [
- 'rule' => ['isBelowMaxHeight', 1080],
- 'message' => 'This image should not be higher than 500px',
- 'provider' => 'upload'
- ]);
-
- $validator->add('photo','file',[
- 'rule' => ['mimeType', ['image/jpeg', 'image/png','image/gif','image/svg+xml']],
- 'message' => "This format is not allowed"
- ]);
-
-
- // Check that the file is below the maximum height requirement (checked in pixels)
- $validator->add('photo', 'fileAboveMinHeight', [
- 'rule' => ['isAboveMinHeight', 100],
- 'message' => 'This image should at least be 150px high',
- 'provider' => 'upload'
- ]);
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['software_id'], 'Softwares'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\SoftwaresStatistic;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * SoftwaresStatistics Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Softwares
- */
-class SoftwaresStatisticsTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('softwares_statistics');
- $this->displayField('id');
- $this->primaryKey('id');
-
- $this->belongsTo('Softwares', [
- 'foreignKey' => 'software_id'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->integer('id')
- ->allowEmpty('id', 'create');
-
- $validator
- ->integer('last_commit_age')
- ->allowEmpty('last_commit_age');
-
- $validator
- ->integer('project_age')
- ->allowEmpty('project_age');
-
- $validator
- ->integer('delta_commit_one_month')
- ->allowEmpty('delta_commit_one_month');
-
- $validator
- ->integer('delta_commit_one_year')
- ->allowEmpty('delta_commit_one_year');
-
- $validator
- ->integer('nb_contributors')
- ->allowEmpty('nb_contributors');
-
- $validator
- ->decimal('contributors_code_percent')
- ->allowEmpty('contributors_code_percent');
-
- $validator
- ->integer('declared_users')
- ->allowEmpty('declared_users');
-
- $validator
- ->decimal('average_review_score')
- ->allowEmpty('average_review_score');
-
- $validator
- ->integer('screenshots')
- ->allowEmpty('screenshots');
-
- $validator
- ->integer('codegouv_label')
- ->allowEmpty('codegouv_label');
-
- $validator
- ->decimal('score')
- ->allowEmpty('score');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->existsIn(['software_id'], 'Softwares'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\Software;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-use Search\Manager;
-/**
- * Softwares Model
- *
- * @property \Cake\ORM\Association\BelongsTo $Licenses
- * @property \Cake\ORM\Association\HasMany $RelationshipsSoftwaresUsers
- * @property \Cake\ORM\Association\HasMany $Reviews
- * @property \Cake\ORM\Association\HasMany $Screenshots
- * @property \Cake\ORM\Association\HasMany $SoftwaresStatistics
- * @property \Cake\ORM\Association\BelongsToMany $Relationships
- */
-class SoftwaresTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('softwares');
- $this->displayField('softwarename');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
- //For upload file -> avatar
- $this->addBehavior('Josegonzalez/Upload.Upload', [
- 'photo' => [
- 'fields' => [
- 'dir' => 'logo_directory',
- ],
- 'path' => 'files{DS}{model}{DS}{primaryKey}{DS}{field}{DS}avatar',
- ],
- ]);
-
- $this->belongsTo('Licenses', [
- 'foreignKey' => 'licence_id'
- ]);
- $this->hasOne('RawMetricsSoftwares', [
- 'foreignKey' => 'software_id'
- ]);
- $this->hasMany('RelationshipsSoftwaresUsers', [
- 'foreignKey' => 'software_id'
- ]);
- $this->hasMany('Reviews', [
- 'foreignKey' => 'software_id'
- ]);
- $this->hasMany('Screenshots', [
- 'foreignKey' => 'software_id'
- ]);
- $this->hasMany('SoftwaresStatistics', [
- 'foreignKey' => 'software_id'
- ]);
- $this->belongsToMany('Relationships', [
- 'foreignKey' => 'software_id',
- 'targetForeignKey' => 'relationship_id',
- 'joinTable' => 'relationships_softwares'
- ]);
-
-
-
- // #######################
- // ##### For search ######
- // #######################
-
- // Add the behaviour to your table
- $this->addBehavior('Search.Search');
-
- // Setup search filter using search manager
- $this->searchManager()
- ->value('id')
- // Here we will alias the 'q' query param to search the `Articles.title`
- // field and the `Articles.content` field, using a LIKE match, with `%`
- // both before and after.
- ->add('q', 'Search.Like', [
- 'before' => true,
- 'after' => true,
- 'mode' => 'or',
- 'comparison' => 'ILIKE',
- 'wildcardAny' => '*',
- 'wildcardOne' => '?',
- 'field' => [$this->aliasField('softwarename'), $this->aliasField('description')]
- ]);
-// ->add('foo', 'Search.Callback', [
-// 'callback' => function ($query, $args, $filter) {
-// // Modify $query as required
-// }
-// ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->allowEmpty('softwarename')
- ->add('softwarename', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
-
- $validator
- ->requirePresence('url_repository', 'create')
- ->notEmpty('url_repository')
- ->add('url_repository', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
-
- $validator
- ->allowEmpty('description');
-
- $validator
- ->allowEmpty('logo_directory');
-
- $validator
- ->allowEmpty('photo');
-
-
- $validator->add('photo','file',[
- 'rule' => ['mimeType', ['image/jpeg', 'image/png','image/gif','image/svg+xml']],
- 'message' => "This format is not allowed"
- ]);
-
-
- $validator->provider('uploadImage',new \Josegonzalez\Upload\Validation\ImageValidation());
-
- //Check that the file is below the maximum height requirement (checked in pixels)
- $validator->add('photo', 'fileBelowMaxHeight', [
- 'rule' => ['isBelowMaxHeight', 250],
- 'message' => 'This image should not be higher than 500px',
- 'provider' => 'uploadImage'
- ]);
-
-
- // Check that the file is Above the minimum height requirement (checked in pixels)
- $validator->add('photo', 'fileAboveMinHeight', [
- 'rule' => ['isAboveMinHeight', 100],
- 'message' => 'This image should at least be 150px high',
- 'provider' => 'uploadImage'
- ]);
-
-
-
- $validator->provider('upload',new \Josegonzalez\Upload\Validation\UploadValidation());
-
- $validator->add('photo', 'fileBelowMaxSize', [
- 'rule' => ['isBelowMaxSize', 1000000],
- 'message' => 'This file is too large',
- 'provider' => 'upload'
- ]);
-
-
-
-
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->isUnique(['softwarename']));
- $rules->add($rules->isUnique(['url_repository']));
- $rules->add($rules->existsIn(['licence_id'], 'Licenses'));
- return $rules;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\UserType;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * UserTypes Model
- *
- * @property \Cake\ORM\Association\HasMany $Users
- */
-class UserTypesTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('user_types');
- $this->displayField('name');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- $this->hasMany('Users', [
- 'foreignKey' => 'user_type_id'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->allowEmpty('name');
-
- $validator
- ->allowEmpty('cd');
-
- return $validator;
- }
-}
+++ /dev/null
-<?php
-namespace App\Model\Table;
-
-use App\Model\Entity\User;
-use Cake\ORM\Query;
-use Cake\ORM\RulesChecker;
-use Cake\ORM\Table;
-use Cake\Validation\Validator;
-
-/**
- * For authentification
- */
-use Cake\Auth\DefaultPasswordHasher;
-use Cake\Utility\Text;
-use Cake\Event\Event;
-
-/**
- * Users Model
- *
- * @property \Cake\ORM\Association\BelongsTo $UserTypes
- * @property \Cake\ORM\Association\HasMany $Reviews
- * @property \Cake\ORM\Association\BelongsToMany $RelationshipsSoftwares
- * @property \Cake\ORM\Association\BelongsToMany $Relationships
- */
-class UsersTable extends Table
-{
-
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
-
- $this->table('users');
- $this->displayField('username');
- $this->primaryKey('id');
-
- $this->addBehavior('Timestamp');
-
- //For upload file -> avatar
- $this->addBehavior('Josegonzalez/Upload.Upload', [
- 'photo' => [
- 'fields' => [
- 'dir' => 'logo_directory',
- ],
- 'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}{primaryKey}{DS}avatar',
- ],
- ]);
-
- $this->belongsTo('UserTypes', [
- 'foreignKey' => 'user_type_id',
- 'joinType' => 'INNER'
- ]);
- $this->hasMany('Reviews', [
- 'foreignKey' => 'user_id'
- ]);
- $this->belongsToMany('RelationshipsSoftwares', [
- 'foreignKey' => 'user_id',
- 'targetForeignKey' => 'relationship_id',
- 'joinTable' => 'relationships_softwares_users'
- ]);
- $this->belongsToMany('Relationships', [
- 'foreignKey' => 'user_id',
- 'targetForeignKey' => 'recipient_id',
- 'joinTable' => 'relationships_users'
- ]);
- }
-
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->allowEmpty('id', 'create');
-
- $validator
- ->allowEmpty('username');
-
- $validator
- ->allowEmpty('logo_directory');
-
- $validator
- ->allowEmpty('url');
-
- $validator
- ->allowEmpty('description');
-
- $validator
- ->requirePresence('role', 'create')
- ->notEmpty('role');
-
- $validator
- ->requirePresence('password', 'create')
- ->notEmpty('password');
-
- $validator
- ->add('email', 'valid', ['rule' => 'email'])
- ->allowEmpty('email');
-
- $validator
- ->allowEmpty('photo');
-
- return $validator;
- }
-
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->isUnique(['username']));
- $rules->add($rules->isUnique(['email']));
- $rules->add($rules->existsIn(['user_type_id'], 'UserTypes'));
- return $rules;
- }
-
-
- /**
- * Before save an user
- * @param \App\Controller\Api\V1\Event $event
- * @return boolean
- */
- public function beforeSave(Event $event)
- {
- $entity = $event->data['entity'];
-
- if ($entity->isNew()) {
- $hasher = new DefaultPasswordHasher();
-
- // Generate an API 'token'
- $entity->api_key_plain = sha1(Text::uuid());
-
- // Bcrypt the token so BasicAuthenticate can check
- // it during login.
- $entity->api_key = $hasher->hash($entity->api_key_plain);
- }
- return true;
- }
-}