forked from quaderno/quaderno-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquaderno_document.php
More file actions
59 lines (49 loc) · 1.93 KB
/
quaderno_document.php
File metadata and controls
59 lines (49 loc) · 1.93 KB
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
<?php
/* Interface that implements every Document
This is, invoices, expenses and estimates */
abstract class QuadernoDocument extends QuadernoModel {
protected $paymentsArray = array();
function __construct($newdata) {
parent::__construct($newdata);
if (isset($this->data['payments'])) {
foreach ($this->data['payments'] as $p) {
array_push($this->paymentsArray, new QuadernoPayment($p));
}
}
}
public function addContact($contact) {
$this->data["contact_id"] = $contact->id;
$this->data["contact_name"] = $contact->contact_name;
return isset($this->data["contact_id"]) && isset($this->data["contact_name"]);
}
public function addItem($item) {
$length = isset($this->data["items_attributes"]) ? count($this->data["items_attributes"]) : 0;
$this->data["items_attributes"][$length] = $item->getArray();
return count($this->data["items_attributes"]) == $length+1;
}
// Interface - only subclasses which implement original ones (i.e. without exec-)
// can call these methods
protected function execAddPayment($payment) {
$length = count($this->paymentsArray);
return array_push($this->paymentsArray, $payment) == $length+1;
}
protected function execGetPayments() {
return $this->paymentsArray;
}
protected function execRemovePayment($payment) {
$i = array_search($payment, $this->paymentsArray, true);
if ($i >= 0) $this->paymentsArray[$i]->markToDelete = true;
return ($i >= 0);
}
//// Deliver call for QuadernoDocument objects
// Deliver object to the contact email
// Returns true or false whether the request is accepted or not
protected function execDeliver() {
$return = false;
$response = QuadernoBase::deliver(static::$MODEL, $this->id);
if (QuadernoBase::responseIsValid($response)) $return = true;
elseif (isset($response['data']['errors'])) $this->errors = $response['data']['errors'];
return $return;
}
}
?>