1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17:
18: class ClipitLA extends UBItem {
19: 20: 21:
22: const SUBTYPE = "ClipitLA";
23: public $status_code = 0;
24: public $metric_id = "";
25: public $context = array();
26: public $file_id = 0;
27: public $metric_received = false;
28:
29:
30: 31: 32: 33: 34:
35: protected function copy_from_elgg($elgg_object) {
36: parent::copy_from_elgg($elgg_object);
37: $this->status_code = (int)$elgg_object->get("status_code");
38: $this->metric_id = (string)$elgg_object->get("metric_id");
39: $this->file_id = (int)$elgg_object->get("file_id");
40: $this->metric_received = (bool)$elgg_object->get("metric_received");
41: $this->context = unserialize((string)$elgg_object->get("context"));
42: }
43:
44: 45: 46: 47: 48:
49: protected function copy_to_elgg($elgg_object) {
50: parent::copy_to_elgg($elgg_object);
51: $elgg_object->set("status_code", (int)$this->status_code);
52: $elgg_object->set("metric_id", (string)$this->metric_id);
53: $elgg_object->set("file_id", (int)$this->file_id);
54: $elgg_object->set("metric_received", (bool)$this->metric_received);
55: $elgg_object->set("context", (string)serialize($this->context));
56: }
57:
58: static function get_metric($metric_id, $context) {
59: if(!$la_metrics_class = (string)elgg_get_config("la_metrics_class")){
60: error_log("No metrics class!");
61: return null;
62: }
63:
64: $la_id = (int)$la_metrics_class::get_metric($metric_id, $context);
65: if(empty($la_id)){
66: error_log("No la_id");
67: return null;
68: }
69: return new static($la_id);
70: }
71:
72: static function save_metric($return_id, $data, $status_code) {
73: $prop_value_array["data"] = $data;
74: $la_file_id = ClipitFile::set_properties(null, $prop_value_array);
75: $prop_value_array = array();
76: $prop_value_array["file_id"] = $la_file_id;
77: $prop_value_array["status_code"] = (int)$status_code;
78: $prop_value_array["metric_received"] = true;
79: return static::set_properties($return_id, $prop_value_array);
80: }
81: }