1: <?php
2: namespace Ctct\Components\Activities;
3:
4: use Ctct\Components\Component;
5: use Ctct\Components\Activities\ActivityError;
6:
7: 8: 9: 10: 11: 12: 13:
14: class Activity extends Component
15: {
16: public $id;
17: public $type;
18: public $status;
19: public $start_date;
20: public $finish_date;
21: public $file_name;
22: public $created_date;
23: public $error_count;
24: public $errors = array();
25: public $warnings = array();
26: public $contact_count;
27:
28: 29: 30: 31: 32:
33: public static function create(array $props)
34: {
35: $activity = new Activity();
36: $activity->id = parent::getValue($props, "id");
37: $activity->type = parent::getValue($props, "type");
38: $activity->status = parent::getValue($props, "status");
39: $activity->start_date = parent::getValue($props, "start_date");
40: $activity->finish_date = parent::getValue($props, "finish_date");
41: $activity->created_date = parent::getValue($props, "created_date");
42: $activity->error_count = parent::getValue($props, "error_count");
43: $activity->contact_count = parent::getValue($props, "contact_count");
44:
45:
46: if (array_key_exists('errors', $props)) {
47: foreach ($props['errors'] as $error) {
48: $activity->errors[] = ActivityError::create($error);
49: }
50: } else {
51: unset($activity->errors);
52: }
53:
54:
55: if (array_key_exists('warnings', $props)) {
56: foreach ($props['warnings'] as $error) {
57: $activity->warnings[] = ActivityError::create($error);
58: }
59: } else {
60: unset($activity->warnings);
61: }
62:
63:
64: if (array_key_exists('file_name', $props)) {
65: $activity->file_name = $props['file_name'];
66: } else {
67: unset($activity->file_name);
68: }
69:
70: return $activity;
71: }
72:
73: 74: 75: 76:
77: public function toJson()
78: {
79: return json_encode($this);
80: }
81: }
82: