Definition at line 9 of file Document.php.
Paperyard\Models\Document::__construct |
( |
|
$full_path | ) |
|
- Parameters
-
Definition at line 142 of file Document.php.
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);
getNumberOfPages($full_path)
humanFilesize($full_path, $decimals=2)
Paperyard\Models\Document::confirm |
( |
| ) |
|
Definition at line 372 of file Document.php.
375 $tags = explode(
',', $this->tags);
378 $trimmed = array_map(
'trim',
$tags);
381 $cleaned = array_diff($trimmed, [
'nt',
'ok']);
387 $this->tags = implode(
',', $cleaned);
Paperyard\Models\Document::fill |
( |
array |
$attributes | ) |
|
Mass assignment.
- Parameters
-
- Returns
- array|bool
Definition at line 257 of file Document.php.
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];
validate(array $attributes)
static Paperyard\Models\Document::findAll |
( |
array |
$paths | ) |
|
|
static |
Returns document objects for all pdfs found in the paths provided.
- Parameters
-
array | $paths | Path to search in |
- Returns
- Document[]
Definition at line 424 of file Document.php.
426 array_walk($paths,
function (&$path) {
432 array_walk($pdfs,
function (&$pdf) {
433 $pdf = (new \Paperyard\Models\Document($pdf))->
toArray();
static flatten(array $array)
static Paperyard\Models\Document::flatten |
( |
array |
$array | ) |
|
|
staticprivate |
Definition at line 439 of file Document.php.
441 array_walk_recursive($array,
function($a) use (&$return) { $return[] = $a; });
Paperyard\Models\Document::getNumberOfPages |
( |
|
$full_path | ) |
|
|
private |
Uses pdfinfo to get the number of pages.
- Parameters
-
$full_path | string Absolute or relative path to pdf |
- Returns
- int number of pages
Definition at line 229 of file Document.php.
231 $pdf =
new PDFInfo($full_path);
232 return (
int)$pdf->pages;
Paperyard\Models\Document::getUrl |
( |
|
$full_path | ) |
|
|
private |
Definition at line 163 of file Document.php.
164 $path = explode(
'/', $full_path);
166 array_walk($path,
function(&$part) {
167 $part = rawurlencode($part);
169 return implode(
'/', $path);
Paperyard\Models\Document::hasMutator |
( |
|
$attribute | ) |
|
|
private |
Checks if mutator a method exists.
- Parameters
-
- Returns
- bool
Definition at line 290 of file Document.php.
292 return method_exists($this, $this->
mutatorFor($attribute));
Paperyard\Models\Document::humanFilesize |
( |
|
$full_path, |
|
|
|
$decimals = 2 |
|
) |
| |
|
private |
Converts bytes to a human readable format. Based on http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
- Parameters
-
string | $full_path | Path to file |
int | $decimals | decimal places |
- Returns
- string human readable filesize
Definition at line 243 of file Document.php.
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];
Paperyard\Models\Document::isConfirmed |
( |
| ) |
|
|
private |
Paperyard\Models\Document::mutatorFor |
( |
|
$attribute | ) |
|
|
private |
Creates mutator string for a given attribute name. Attribute will be converted to first letter uppercase.
- Parameters
-
- Returns
- string
Definition at line 302 of file Document.php.
304 return 'set' . ucfirst($attribute) .
'Attribute';
Paperyard\Models\Document::parseAttribute |
( |
|
$attr | ) |
|
|
private |
Capture and cache attributes with regular expression. Return on demand.
- Parameters
-
$attr | int index of capture group |
- Returns
- string attribute value
Definition at line 209 of file Document.php.
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];
Paperyard\Models\Document::parseDataFromFilename |
( |
| ) |
|
|
private |
Paperyard\Models\Document::parseDate |
( |
| ) |
|
|
private |
Gets raw date attribute and converts it to d.m.Y.
- Todo:
- date format customizable
- Returns
- false|string date or false on failure
Definition at line 199 of file Document.php.
200 return date_format(date_create($this->
parseAttribute(self::INDEX_DATE)),
'd.m.Y');
Paperyard\Models\Document::save |
( |
| ) |
|
Definition at line 353 of file Document.php.
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;
Paperyard\Models\Document::setDateAttribute |
( |
|
$date | ) |
|
|
private |
Mass assignment mutator. Converts date post (m.d.Y) to Ymd.
- Parameters
-
- Returns
- false|string
Definition at line 314 of file Document.php.
316 return \DateTime::createFromFormat(
"d.m.Y",
$date)->format(
'Ymd');
Paperyard\Models\Document::setPriceAttribute |
( |
|
$price | ) |
|
|
private |
Mass assignment mutator. Removes delimiter dot and adds double zero decimals if needed.
- Parameters
-
- Returns
- string
Definition at line 326 of file Document.php.
328 $dotless = str_replace(
".",
"",
$price);
330 if (strpos($dotless,
",") ===
false) {
331 return $dotless .
",00";
Paperyard\Models\Document::setTagsAttribute |
( |
|
$tags | ) |
|
|
private |
Mass assignment mutator. Checks for empty tags.
- Parameters
-
- Returns
- string
Definition at line 344 of file Document.php.
Paperyard\Models\Document::toArray |
( |
| ) |
|
Returns all important document information as an array.
- Returns
- array
Definition at line 188 of file Document.php.
190 return get_object_vars($this);
Paperyard\Models\Document::validate |
( |
array |
$attributes | ) |
|
|
private |
- Parameters
-
Definition at line 401 of file Document.php.
404 $validator =
new Validator($attributes);
407 $validator->rules($this->rules);
410 $validator->labels($this->labels);
413 if(!$validator->validate()) {
414 $this->errors = $validator->errors();
Paperyard\Models\Document::$company |
Paperyard\Models\Document::$date |
Paperyard\Models\Document::$documentType |
|
private |
Paperyard\Models\Document::$errors = [] |
|
private |
Paperyard\Models\Document::$fillable |
|
private |
Initial value:= [
'document-subject' => 'subject'
Definition at line 100 of file Document.php.
Paperyard\Models\Document::$fullPath |
|
private |
Paperyard\Models\Document::$hash |
Paperyard\Models\Document::$identifier |
Paperyard\Models\Document::$isConfirmed |
Paperyard\Models\Document::$labels |
|
private |
Initial value:= [
'document-subject' => 'Subject'
Definition at line 130 of file Document.php.
Paperyard\Models\Document::$name |
Paperyard\Models\Document::$oldFilename |
Paperyard\Models\Document::$pages |
Paperyard\Models\Document::$price |
Paperyard\Models\Document::$rawAttributes = [] |
|
private |
Paperyard\Models\Document::$recipient |
Paperyard\Models\Document::$rules |
|
private |
Initial value:= [
'optional' => [
['document-subject'],
['document-tags'],
['document-price'],
['document-recipient'],
['document-company'],
['document-date']
]
Definition at line 110 of file Document.php.
Paperyard\Models\Document::$size |
Paperyard\Models\Document::$subject |
Paperyard\Models\Document::$tags |
Paperyard\Models\Document::$url |
const Paperyard\Models\Document::INDEX_COMPANY = 2 |
INDEX_COMPANY date capture group index
Definition at line 28 of file Document.php.
const Paperyard\Models\Document::INDEX_DATE = 1 |
INDEX_DATE date capture group index
Definition at line 25 of file Document.php.
const Paperyard\Models\Document::INDEX_OLD_FILENAME = 7 |
INDEX_OLD_FILENAME date capture group index
Definition at line 43 of file Document.php.
const Paperyard\Models\Document::INDEX_PRICE = 5 |
INDEX_PRICE date capture group index
Definition at line 37 of file Document.php.
const Paperyard\Models\Document::INDEX_RECIPIENT = 4 |
INDEX_RECIPIENT date capture group index
Definition at line 34 of file Document.php.
const Paperyard\Models\Document::INDEX_SUBJECT = 3 |
INDEX_SUBJECT date capture group index
Definition at line 31 of file Document.php.
const Paperyard\Models\Document::INDEX_TAGS = 6 |
INDEX_TAGS date capture group index
Definition at line 40 of file Document.php.
const Paperyard\Models\Document::REGEX_DATE = '/^(0[1-9]|[1-2][0-9]|3[0-1]).(0[1-9]|1[0-2]).(20\d{2})$/' |
REGEX_DATE matches sqlite style dates (Ymd)
Definition at line 18 of file Document.php.
const Paperyard\Models\Document::REGEX_PRICE = '/^\d+(\.\d{3})*(,\d{2})?$/' |
REGEX_PRICE matches special price format
Definition at line 21 of file Document.php.
const Paperyard\Models\Document::REGEX_STRING = '/^[ÄäÜüÖöß\sa-zA-Z0-9]*$/' |
REGEX_STRING matches alphanum, special char and whitespace
Definition at line 15 of file Document.php.
const Paperyard\Models\Document::REGEX_TAG = '/^([ÄäÜüÖöß\sa-zA-Z0-9]+,)*[ÄäÜüÖöß\sa-zA-Z0-9]+$/' |
REGEX_TAG matches comma separated tags composed of alphanum, special char and whitespace
Definition at line 12 of file Document.php.
The documentation for this class was generated from the following file: