-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension_attributes_model.php
executable file
·59 lines (51 loc) · 1.91 KB
/
extension_attributes_model.php
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
use CFPropertyList\CFPropertyList;
class Extension_attributes_model extends \Model
{
public function __construct($serial = '')
{
parent::__construct('id', 'extension_attributes'); // Primary key, tablename
$this->rs['id'] = '';
$this->rs['serial_number'] = $serial;
$this->rs['displayname'] = null;
$this->rs['result'] = null;
$this->rs['displayincategory'] = null;
$this->rs['datatype'] = null;
}
// ------------------------------------------------------------------------
/**
* Process data sent by postflight
*
* @param string data
*
**/
public function process($data)
{
// If data is empty, echo out error
if (! $data) {
echo ("Error Processing extension attributes: No data found");
} else {
// Delete previous entries
$this->deleteWhere('serial_number=?', $this->serial_number);
// Process incoming extension_attributes.plist
$parser = new CFPropertyList();
$parser->parse($data, CFPropertyList::FORMAT_XML);
$plist = $parser->toArray();
// Process each extension attribute
foreach ($plist as $single_ae) {
foreach (array('displayname', 'result', 'displayincategory', 'datatype') as $item) {
// If key does not exist in $single_ae, null it
if ( ! array_key_exists($item, $single_ae) || $single_ae[$item] == '') {
$this->$item = null;
// Set the db fields to be the same as those for the attribute
} else {
$this->$item = $single_ae[$item];
}
}
// Save the data, wash your hands
$this->id = '';
$this->save();
}
}
}
}