/
AgenciaTransporte.php
112 lines (95 loc) · 2.79 KB
/
AgenciaTransporte.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* This file is part of FacturaScripts
* Copyright (C) 2015-2022 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FacturaScripts\Core\Model;
/**
* Merchandise transport agency.
*
* @author Carlos García Gómez <carlos@facturascripts.com>
* @author Artex Trading sa <jcuello@artextrading.com>
*/
class AgenciaTransporte extends Base\ModelClass
{
use Base\ModelTrait;
/**
* Contains True if is enabled.
*
* @var bool
*/
public $activo;
/**
* Primary key. Varchar(8).
*
* @var string
*/
public $codtrans;
/**
* Name of the agency.
*
* @var string
*/
public $nombre;
/**
* @var string
*/
public $telefono;
/**
* @var string
*/
public $web;
public function clear()
{
parent::clear();
$this->activo = true;
}
public static function primaryColumn(): string
{
return 'codtrans';
}
public static function tableName(): string
{
return 'agenciastrans';
}
public function test(): bool
{
if (!empty($this->codtrans) && 1 !== preg_match('/^[A-Z0-9_\+\.\-]{1,8}$/i', $this->codtrans)) {
$this->toolBox()->i18nLog()->error(
'invalid-alphanumeric-code',
['%value%' => $this->codtrans, '%column%' => 'codtrans', '%min%' => '1', '%max%' => '8']
);
return false;
}
$utils = $this->toolBox()->utils();
$this->nombre = $utils->noHtml($this->nombre);
$this->telefono = $utils->noHtml($this->telefono);
$this->web = $utils->noHtml($this->web);
// check if the web is a valid url
if (!empty($this->web) && false === self::toolBox()::utils()::isValidUrl($this->web)) {
self::toolBox()::i18nLog()->error('invalid-web');
return false;
}
return parent::test();
}
protected function saveInsert(array $values = []): bool
{
if (empty($this->codtrans)) {
$this->codtrans = (string)$this->newCode();
}
return parent::saveInsert($values);
}
}