/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/DocumentsTable.php (2761B)
setTable('documents');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Tree');
//$this->addBehavior('UploadFile');
$this->addBehavior('Josegonzalez/Upload.Upload', [
'file_path' => [
'path' => 'webroot{DS}uploads{DS}files{DS}{field-value:model}{DS}{field-value:foreign_uuid}{DS}',
'fields' => [
'dir' => 'upload_dir',
],
'nameCallback' => function ($table, $entity, $data, $field, $settings) {
$ext = pathinfo($data->getClientFilename(), PATHINFO_EXTENSION);
return uniqid() . '_' . rand(1, 9999) . '_' . date('Ymd_His') . '.' . $ext;
},
'keepFilesOnDelete' => false,
]
]);
$this->belongsTo('Causes', [
'foreignKey' => 'foreign_key'
]);
}
/**
* Default validation rules.
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmptyString('id', null, 'create');
$validator
->integer('foreign_key')
->requirePresence('foreign_key', 'create')
->notEmptyString('foreign_key');
$validator
->scalar('model')
->maxLength('model', 255)
->requirePresence('model', 'create')
->notEmptyString('model');
$validator->setProvider('upload', \Josegonzalez\Upload\Validation\UploadValidation::class);
$validator
->allowEmptyString('file_path')
->add('file_path', 'isBelowMaxSize', [
'rule' => ['isBelowMaxSize', 1024 * 1024 * 10],
'message' => __('Max 10MB'),
'provider' => 'upload'
])
->add('file_path', 'isAllowedType', [
'rule' => function ($value, $context) {
$allowed = ['application/pdf'];
return in_array($value->getClientMediaType(), $allowed) ? true : false;
},
'message' => __('Accepted formats: .pdf'),
]);
return $validator;
}
}