12 const REGEX_TAG =
'/^([ÄäÜüÖöß\sa-zA-Z0-9]+,)*[ÄäÜüÖöß\sa-zA-Z0-9]+$/';
18 const REGEX_DATE =
'/^(0[1-9]|[1-2][0-9]|3[0-1]).(0[1-9]|1[0-2]).(20\d{2})$/';
101 'document-subject' =>
'subject',
102 'document-tags' =>
'tags',
103 'document-price' =>
'price',
104 'document-recipient' =>
'recipient',
105 'document-company' =>
'company',
106 'document-date' =>
'date' 112 [
'document-subject'],
115 [
'document-recipient'],
116 [
'document-company'],
120 [
'document-subject', self::REGEX_STRING],
121 [
'document-recipient', self::REGEX_STRING],
122 [
'document-company', self::REGEX_STRING],
123 [
'document-tags', self::REGEX_TAG],
124 [
'document-price', self::REGEX_PRICE],
125 [
'document-date', self::REGEX_DATE]
131 'document-subject' =>
'Subject',
132 'document-tags' =>
'Tags',
133 'document-price' =>
'Price',
134 'document-recipient' =>
'Recipient',
135 'document-company' =>
'Company',
136 'document-date' =>
'Date' 145 $this->fullPath = $full_path;
151 $this->name = basename($this->fullPath);
153 $this->hash = hash_file(
"sha256", $full_path);
155 $this->identifier = base64_encode($full_path);
156 $this->url = $this->
getUrl($full_path);
164 $path = explode(
'/', $full_path);
166 array_walk($path,
function(&$part) {
167 $part = rawurlencode($part);
169 return implode(
'/', $path);
180 $this->oldFilename = $this->
parseAttribute(self::INDEX_OLD_FILENAME);
190 return get_object_vars($this);
200 return date_format(date_create($this->
parseAttribute(self::INDEX_DATE)),
'd.m.Y');
212 if ($this->rawAttributes == []) {
213 preg_match(
'/^(.*?) - (.*?) - (.*?) \((.*?)\) \(EUR(.*?)\) \[(.*?)\] -- (.*?)(?:.pdf)$/', $this->name, $this->rawAttributes);
216 if (!array_key_exists($attr, $this->rawAttributes)) {
220 return $this->rawAttributes[$attr];
231 $pdf =
new PDFInfo($full_path);
232 return (
int)$pdf->pages;
245 $bytes = filesize($full_path);
246 $size = array(
'B',
'kB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB');
247 $factor = floor((strlen($bytes) - 1) / 3);
248 return sprintf(
"%.{$decimals}f", $bytes / pow(1024, $factor)) .
' ' . @
$size[$factor];
257 public function fill(array $attributes)
260 $attributes = array_filter($attributes);
264 if (!empty($this->errors)) {
269 foreach ($this->fillable as $post_attribute => $obj_property) {
271 if (property_exists($this, $obj_property) && array_key_exists($post_attribute, $attributes)) {
274 $this->{$obj_property} = $this->{$mutator}($attributes[$post_attribute]);
276 $this->{$obj_property} = $attributes[$post_attribute];
292 return method_exists($this, $this->
mutatorFor($attribute));
304 return 'set' . ucfirst($attribute) .
'Attribute';
316 return \DateTime::createFromFormat(
"d.m.Y",
$date)->format(
'Ymd');
328 $dotless = str_replace(
".",
"",
$price);
330 if (strpos($dotless,
",") ===
false) {
331 return $dotless .
",00";
355 $format =
'%d - %s - %s (%s) (EUR%s) [%s] -- %s.pdf';
366 $dir = dirname($this->fullPath);
367 $new_fullpath = $dir . DIRECTORY_SEPARATOR . $filename;
368 rename($this->fullPath, $new_fullpath);
369 $this->fullPath = $new_fullpath;
375 $tags = explode(
',', $this->tags);
378 $trimmed = array_map(
'trim',
$tags);
381 $cleaned = array_diff($trimmed, [
'nt',
'ok']);
387 $this->tags = implode(
',', $cleaned);
393 $tags = explode(
',', $this->tags);
395 return in_array(
'ok',
$tags);
404 $validator =
new Validator($attributes);
407 $validator->rules($this->rules);
410 $validator->labels($this->labels);
413 if(!$validator->validate()) {
414 $this->errors = $validator->errors();
426 array_walk($paths,
function (&$path) {
432 array_walk($pdfs,
function (&$pdf) {
433 $pdf = (new \Paperyard\Models\Document($pdf))->
toArray();
439 private static function flatten(array $array) {
441 array_walk_recursive($array,
function($a) use (&$return) { $return[] = $a; });
getNumberOfPages($full_path)
validate(array $attributes)
humanFilesize($full_path, $decimals=2)
static findAll(array $paths)
setPriceAttribute($price)
static flatten(array $array)