This repository was archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathActivity.php
More file actions
80 lines (72 loc) · 2.48 KB
/
Activity.php
File metadata and controls
80 lines (72 loc) · 2.48 KB
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
<?php
namespace YousafSaqib\ConstantContact\Components\Activities;
use YousafSaqib\ConstantContact\Components\Component;
/**
* Represents a single Activity in Constant Contact
*
* @package Components
* @subpackage Activities
* @author Constant Contact
*/
class Activity extends Component
{
public $id;
public $type;
public $status;
public $start_date;
public $finish_date;
public $file_name;
public $created_date;
public $error_count;
public $errors = array();
public $warnings = array();
public $contact_count;
/**
* Factory method to create an Activity object from an array
* @param array $props - associative array of initial properties to set
* @return Activity
*/
public static function create(array $props)
{
$activity = new Activity();
$activity->id = parent::getValue($props, "id");
$activity->type = parent::getValue($props, "type");
$activity->status = parent::getValue($props, "status");
$activity->start_date = parent::getValue($props, "start_date");
$activity->finish_date = parent::getValue($props, "finish_date");
$activity->created_date = parent::getValue($props, "created_date");
$activity->error_count = parent::getValue($props, "error_count");
$activity->contact_count = parent::getValue($props, "contact_count");
// set any errors that exist, otherwise destroy the property
if (array_key_exists('errors', $props)) {
foreach ($props['errors'] as $error) {
$activity->errors[] = ActivityError::create($error);
}
} else {
unset($activity->errors);
}
// set any warnings that exist, otherwise destroy the property
if (array_key_exists('warnings', $props)) {
foreach ($props['warnings'] as $error) {
$activity->warnings[] = ActivityError::create($error);
}
} else {
unset($activity->warnings);
}
// set the file name if exists
if (array_key_exists('file_name', $props)) {
$activity->file_name = $props['file_name'];
} else {
unset($activity->file_name);
}
return $activity;
}
/**
* Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
* @return string
*/
public function toJson()
{
return json_encode($this);
}
}