function _invoice_get_variable in Invoice 7
Same name and namespace in other branches
- 6 invoice_helpers.inc \_invoice_get_variable()
Helper function to get template variables
10 calls to _invoice_get_variable()
- invoice_delete_item in ./
invoice_ajax.inc - Delete an invoice item
- invoice_form in ./
invoice_form.inc - Implements hook_form()
- invoice_invoices in ./
invoice.module - Overview of all invoices
- invoice_load in ./
invoice.module - Implements hook_load()
- invoice_save_item in ./
invoice_ajax.inc - Add an invoice item
File
- ./
invoice_helpers.inc, line 524 - Invoice module
Code
function _invoice_get_variable($template, $name, $default = NULL) {
// if $template is empty, check if a general/default value is available
if (empty($template)) {
return variable_get('invoice_' . $name, '');
}
static $templates = NULL;
// Get all template settings from the database only one time
if (!is_array($templates)) {
// Get template names available on disk
$template_names = _invoice_get_templates();
// Add templates to the database that exist on the disk but not in the database yet.
$database_template_names = array();
$result = db_query("SELECT name FROM {invoice_templates} WHERE name IN (:names)", array(
':names' => $template_names,
))
->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$database_template_names[] = $row['name'];
}
foreach ($template_names as $template_name) {
if (!in_array($template_name, $database_template_names)) {
// Add template
db_insert('invoice_templates')
->fields(array(
'name' => $template_name,
'locale' => '',
'date_format' => '',
'vat' => variable_get('invoice_vat', 0),
'pay_limit' => variable_get('invoice_pay_limit', 0),
'supplier_company_name' => '',
'supplier_street' => '',
'supplier_building_number' => '',
'supplier_zipcode' => '',
'supplier_city' => '',
'supplier_state' => '',
'supplier_country' => '',
'supplier_phone' => '',
'supplier_fax' => '',
'supplier_email' => '',
'supplier_web' => '',
'supplier_coc_number' => '',
'supplier_vat_number' => '',
'api_username' => '',
'display_column_vat' => variable_get('invoice_display_column_vat', 0),
'display_column_exunitcost' => variable_get('invoice_display_column_exunitcost', 1),
'display_column_incunitcost' => variable_get('invoice_display_column_incunitcost', 1),
'display_column_extotal' => variable_get('invoice_display_column_extotal', 1),
'display_column_inctotal' => variable_get('invoice_display_column_inctotal', 1),
))
->execute();
}
}
// Get all template settings
$templates = array();
$result = db_query("SELECT * FROM {invoice_templates} WHERE name IN (:names)", array(
':names' => $template_names,
))
->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$templates[$row['name']] = $row;
}
}
// Get template info that is stored in the database
$template = $templates[$template];
if (!empty($template[$name]) || is_numeric($template[$name])) {
return $template[$name];
}
else {
if (!is_null($default)) {
return $default;
}
else {
// if $default is not null, check if a general/default value is available
return variable_get('invoice_' . $name, '');
}
}
}