+++ /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;
- }
-}