1: <?php
2: namespace Ctct\Components\Library;
3:
4: use Ctct\Components\Component;
5:
6: /**
7: * Represents a single File in a Constant Contact Library
8: *
9: * @package Components
10: * @subpackage Library
11: * @author Constant Contact
12: */
13: class File extends Component {
14: /**
15: * The ID of the file
16: * @var String
17: */
18: public $id;
19:
20: /**
21: * The name of the file
22: * @var String
23: */
24: public $name;
25:
26: /**
27: * The file's description
28: * @var String
29: */
30: public $description;
31:
32: /**
33: * The name of the folder that the file is in
34: * @var String
35: */
36: public $folder;
37:
38: /**
39: * The ID of the folder that the file is in
40: * @var String
41: */
42: public $folder_id;
43:
44: /**
45: * Is this file an image?
46: * @var Boolean
47: */
48: public $is_image;
49:
50: /**
51: * Type of the file, must be one of "JPG", "GIF", "PDF", "PNG", "DOC", "XLS", "PPT", "DOCX", "XLSX", "PPTX"
52: * @var String
53: */
54: public $type;
55:
56: /**
57: * File's height in pixels, if File is an image
58: * @var int
59: */
60: public $height;
61:
62: /**
63: * File's width in pixels, if File is an image
64: * @var int
65: */
66: public $width;
67:
68: /**
69: * File's size in bytes
70: * @var int
71: */
72: public $size;
73:
74: /**
75: * URL of the image hosted by Constant Contact
76: * @var String
77: */
78: public $url;
79:
80: /**
81: * Source of the image, must be one of "ALL", "MY_COMPUTER", "STOCK_IMAGE", "FACEBOOK", "INSTAGRAM", "SHUTTERSTOCK", "MOBILE"
82: * @var String
83: */
84: public $source;
85:
86: /**
87: * Status of the file, must be one of "ACTIVE", "PROCESSING", "UPLOADED", "VIRUS_FOUND", "FAILED", "DELETED"
88: * @var String
89: */
90: public $status;
91:
92: /**
93: * Thumbnail of the file, if File is an image
94: * @var Thumbnail
95: */
96: public $thumbnail;
97:
98: /**
99: * Date the file was created, in ISO-8601 format
100: * @var String
101: */
102: public $created_date;
103:
104: /**
105: * Date the file was last modified, in ISO-8601 format
106: * @var String
107: */
108: public $modified_date;
109:
110: /**
111: * The file's type. (PNG, JPEG, PDF, etc.)
112: * @var String
113: */
114: public $file_type;
115:
116: public static function create(array $props) {
117: $file = new File();
118:
119: $file->id = parent::getValue($props, "id");
120: $file->name = parent::getValue($props, "name");
121: $file->description = parent::getValue($props, "description");
122: $file->folder = parent::getValue($props, "folder");
123: $file->folder_id = parent::getValue($props, "folder_id");
124: $file->is_image = parent::getValue($props, "is_image");
125: $file->type = parent::getValue($props, "file_type");
126: $file->height = parent::getValue($props, "height");
127: $file->width = parent::getValue($props, "width");
128: $file->size = parent::getValue($props, "size");
129: $file->url = parent::getValue($props, "url");
130: $file->source = parent::getValue($props, "source");
131: $file->status = parent::getValue($props, "status");
132: if (array_key_exists("thumbnail", $props)) {
133: $file->thumbnail = Thumbnail::create($props['thumbnail']);
134: }
135: $file->created_date = parent::getValue($props, "created_date");
136: $file->modified_date = parent::getValue($props, "modified_date");
137: $file->file_type = parent::getValue($props, "file_type");
138:
139: return $file;
140: }
141:
142: /**
143: * Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
144: * @return String
145: */
146: public function toJson() {
147: unset($this->created_date);
148: unset($this->modified_date);
149: unset($this->status);
150: return json_encode($this);
151: }
152: }