-
Notifications
You must be signed in to change notification settings - Fork 0
/
budgetsys.line.api.inc
146 lines (134 loc) · 4.34 KB
/
budgetsys.line.api.inc
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* @file
* The Budget System Line Item API class.
*/
class BudgetSystemLineAPI extends BudgetSystemAPI {
/**
* Loads the LIDs of all the budget lines in the database
*
* @return
* An array of all the LIDs in the system
*/
public function loadAllLineIDs() {
$query = db_query("SELECT bl.lid FROM {budgetsys_line} bl");
$result = $query->fetchCol();
return $result;
}
}
/**
* Budget line class.
*/
class BudgetsysLineClass extends Entity {
protected function defaultLabel() {
return $this->title;
}
protected function defaultUri() {
return array('path' => 'budget/line/' . $this->identifier());
}
}
class BudgetsysLineClassController extends EntityAPIController {
public function create(array $values = array()) {
global $user;
$values += array(
'title' => '',
'account_number' => '',
'oid' => '',
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
'uid' => $user->uid,
'revision table' => 'budgetsys_line_revision',
);
return parent::create($values);
}
function saveRevision($budget_line, $uid, $update = FALSE) {
// Hold on to the budget line's original creator_uid but swap
// in the revision's creator_uid for the momentary write.
$temp_uid = $budget_line->uid;
$budget_line->uid = $uid;
if ($update) {
drupal_write_record('budgetsys_line_revision', $budget_line, 'vid');
}
else {
drupal_write_record('budgetsys_line_revision', $budget_line);
}
// Reset the order's creator_uid to the original value.
$budget_line->uid = $temp_uid;
}
public function buildContent($entity, $view_mode = 'full', $langcode = NULL, $content = array()) {
$wrapper = entity_metadata_wrapper('budgetsys_line', $entity);
$content['author'] = array('#markup' => t('Created by: !author', array('!author' => $wrapper->uid->name->value(array('sanitize' => TRUE)))));
// Make Description and Status themed like default fields.
$content['description'] = array(
'#theme' => 'field',
'#weight' => 0,
'#title' =>t('Description'),
'#access' => TRUE,
'#label_display' => 'above',
'#view_mode' => 'full',
'#language' => LANGUAGE_NONE,
'#field_name' => 'field_fake_description',
'#field_type' => 'text',
'#entity_type' => 'budgetsys_line',
'#bundle' => $entity->type,
'#items' => array(array('value' => $entity->description)),
'#formatter' => 'text_default',
0 => array('#markup' => check_plain($entity->description))
);
return parent::buildContent($entity, $view_mode, $langcode, $content);
}
public function queryValueType($account) {
// Select the budget value id from the budget value table where the account number = $account and the type = $type
$query = db_query("SELECT t.value_type FROM {budgetsys_line} l INNER JOIN {budgetsys_line_type} t ON l.type=t.type WHERE account_number = :account", array(
':account' => $account,
));
$result = $query->fetchField();
return $result;
}
}
/**
* Budget Line Type class.
*/
class LineItemType extends Entity {
public $type;
public $label;
public $weight = 0;
public function __construct($values = array()) {
parent::__construct($values, 'budgetsys_line_type');
}
function isLocked() {
return isset($this->status) && empty($this->is_new) && (($this->status & ENTITY_IN_CODE) || ($this->status & ENTITY_FIXED));
}
}
class LineItemTypeController extends EntityAPIControllerExportable {
public function create(array $values = array()) {
$values += array(
'label' => '',
'description' => '',
);
return parent::create($values);
}
/**
* Save Budget Line Type.
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
parent::save($entity, $transaction);
// Rebuild menu registry. We do not call menu_rebuild directly, but set
// variable that indicates rebuild in the end.
// @see _http://drupal.org/node/1399618
variable_set('menu_rebuild_needed', TRUE);
}
}
/**
* UI controller for Budget Line Type.
*/
class LineItemTypeUIController extends EntityDefaultUIController {
/**
* Overrides hook_menu() defaults.
*/
public function hook_menu() {
$items = parent::hook_menu();
$items[$this->path]['description'] = 'Manage Budget Line types.';
return $items;
}
}