• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

podio-community / podio-php / 5919248423

20 Aug 2023 07:35PM UTC coverage: 54.871% (+1.4%) from 53.497%
5919248423

Pull #242

github

daniel-sc
fix linter II
Pull Request #242: More fixes

181 of 181 new or added lines in 43 files covered. (100.0%)

1149 of 2094 relevant lines covered (54.87%)

34.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/models/PodioItem.php
1
<?php
2
/**
3
 * @see https://developers.podio.com/doc/items
4
 */
5
class PodioItem extends PodioObject
6
{
7
    public function __construct($attributes = array())
8
    {
9
        parent::__construct();
88✔
10

11
        # Basic item
12
        $this->property('item_id', 'integer', array('id' => true));
88✔
13
        $this->property('external_id', 'string');
88✔
14
        $this->property('title', 'string');
88✔
15
        $this->property('link', 'string');
88✔
16
        $this->property('rights', 'array');
88✔
17
        $this->property('created_on', 'datetime');
88✔
18
        $this->property('app_item_id_formatted', 'string');
88✔
19
        $this->property('app_item_id', 'integer');
88✔
20

21
        $this->has_one('created_by', 'ByLine');
88✔
22
        $this->has_one('created_via', 'Via');
88✔
23

24
        $this->has_one('initial_revision', 'ItemRevision');
88✔
25
        $this->has_one('current_revision', 'ItemRevision');
88✔
26
        $this->has_many('fields', 'ItemField');
88✔
27

28
        $this->property('like_count', 'integer');
88✔
29
        $this->property('is_liked', 'boolean');
88✔
30

31
        # Extra properties for full item
32
        $this->property('ratings', 'hash');
88✔
33
        $this->property('user_ratings', 'hash');
88✔
34
        $this->property('last_event_on', 'datetime');
88✔
35
        $this->property('participants', 'hash');
88✔
36
        $this->property('tags', 'array');
88✔
37
        $this->property('refs', 'array');
88✔
38
        $this->property('references', 'array');
88✔
39
        $this->property('linked_account_id', 'integer');
88✔
40
        $this->property('subscribed', 'boolean');
88✔
41
        $this->property('invite', 'hash');
88✔
42
        $this->property('votes', 'hash');
88✔
43

44
        $this->has_one('app', 'App');
88✔
45
        $this->has_one('ref', 'Reference');
88✔
46
        $this->has_one('reminder', 'Reminder');
88✔
47
        $this->has_one('recurrence', 'Recurrence');
88✔
48
        $this->has_one('linked_account_data', 'LinkedAccountData');
88✔
49
        $this->has_many('comments', 'Comment');
88✔
50
        $this->has_many('revisions', 'ItemRevision');
88✔
51
        $this->has_many('files', 'File', array('json_value' => 'file_id', 'json_target' => 'file_ids'));
88✔
52
        $this->has_many('tasks', 'Task');
88✔
53
        $this->has_many('shares', 'AppMarketShare');
88✔
54

55
        # When getting item collection
56
        $this->property('comment_count', 'integer');
88✔
57
        $this->property('file_count', 'integer');
88✔
58
        $this->property('task_count', 'integer');
88✔
59

60
        $this->init($attributes);
88✔
61
    }
62

63
    /**
64
     * Create or updates an item
65
     */
66
    public static function save(PodioClient $podio_client, PodioItem $item, $options = array())
67
    {
68
        $json_attributes = $item->as_json_without_readonly_fields();
4✔
69

70
        if ($item->id) {
4✔
71
            return self::update($podio_client, $item->id, $json_attributes, $options);
×
72
        } else {
73
            if ($item->app && $item->app->id) {
4✔
74
                $new = self::create($podio_client, $item->app->id, $json_attributes, $options);
×
75
                $item->item_id = $new->item_id;
×
76
                return $item;
×
77
            } else {
78
                throw new PodioMissingRelationshipError('{"error_description":"Item is missing relationship to app", "request": {}}', null, null);
4✔
79
            }
80
        }
81
    }
82

83
    /**
84
     * Return json representation without readonly fields. Used for saving items.
85
     */
86
    public function as_json_without_readonly_fields()
87
    {
88
        $readonly_fields = $this->fields->readonly_fields()->external_ids();
4✔
89
        $json_attributes = $this->as_json(false);
4✔
90
        foreach ($this->fields->readonly_fields()->external_ids() as $external_id) {
4✔
91
            if (isset($json_attributes['fields'][$external_id])) {
×
92
                unset($json_attributes['fields'][$external_id]);
×
93
            }
94
        }
95
        return $json_attributes;
4✔
96
    }
97

98
    /**
99
     * @see https://developers.podio.com/doc/items/get-item-22360
100
     */
101
    public static function get(PodioClient $podio_client, $item_id, $options = array())
102
    {
103
        $url = $podio_client->url_with_options("/item/{$item_id}", $options);
×
104
        return self::member($podio_client->get($url));
×
105
    }
106

107
    /**
108
     * @see https://developers.podio.com/doc/items/get-item-by-app-item-id-66506688
109
     */
110
    public static function get_by_app_item_id(PodioClient $podio_client, $app_id, $app_item_id)
111
    {
112
        return self::member($podio_client->get("/app/{$app_id}/item/{$app_item_id}"));
×
113
    }
114

115
    /**
116
     * @see https://developers.podio.com/doc/items/get-item-by-external-id-19556702
117
     */
118
    public static function get_by_external_id(PodioClient $podio_client, $app_id, $external_id)
119
    {
120
        return self::member($podio_client->get("/item/app/{$app_id}/external_id/{$external_id}"));
×
121
    }
122

123
    /**
124
     * @see https://developers.podio.com/doc/items/get-item-basic-61768
125
     */
126
    public static function get_basic(PodioClient $podio_client, $item_id, $attributes = array())
127
    {
128
        return self::member($podio_client->get("/item/{$item_id}/basic", $attributes));
×
129
    }
130

131
    /**
132
     * @see https://developers.podio.com/doc/items/filter-items-4496747
133
     */
134
    public static function filter(PodioClient $podio_client, $app_id, $attributes = array(), $options = array())
135
    {
136
        $url = $podio_client->url_with_options("/item/app/{$app_id}/filter/", $options);
×
137
        return self::collection($podio_client->post($url, $attributes ? $attributes : new StdClass()), "PodioItemCollection");
×
138
    }
139

140
    /**
141
     * @see https://developers.podio.com/doc/items/filter-items-by-view-4540284
142
     */
143
    public static function filter_by_view(PodioClient $podio_client, $app_id, $view_id, $attributes = array(), $options = array())
144
    {
145
        $url = $podio_client->url_with_options("/item/app/{$app_id}/filter/{$view_id}/", $options);
×
146
        return self::collection($podio_client->post($url, $attributes ? $attributes : new StdClass()), "PodioItemCollection");
×
147
    }
148

149
    /**
150
     * @see https://developers.podio.com/doc/items/delete-item-22364
151
     */
152
    public static function delete(PodioClient $podio_client, $item_id, $attributes = array(), $options = array())
153
    {
154
        $url = $podio_client->url_with_options("/item/{$item_id}", $options);
×
155
        return $podio_client->delete($url, $attributes);
×
156
    }
157

158
    /**
159
     * @see https://developers.podio.com/doc/items/bulk-delete-items-19406111
160
     */
161
    public static function bulk_delete(PodioClient $podio_client, $app_id, $attributes = array(), $options = array())
162
    {
163
        $url = $podio_client->url_with_options("/item/app/{$app_id}/delete", $options);
×
164
        return $podio_client->post($url, $attributes);
×
165
    }
166

167
    /**
168
     * @see https://developers.podio.com/doc/items/delete-item-reference-7302326
169
     */
170
    public static function delete_reference(PodioClient $podio_client, $item_id, $attributes = array())
171
    {
172
        return $podio_client->delete("/item/{$item_id}/ref", $attributes);
×
173
    }
174

175
    /**
176
     * @see https://developers.podio.com/doc/items/add-new-item-22362
177
     */
178
    public static function create(PodioClient $podio_client, $app_id, $attributes = array(), $options = array())
179
    {
180
        $url = $podio_client->url_with_options("/item/app/{$app_id}/", $options);
×
181
        return self::member($podio_client->post($url, $attributes));
×
182
    }
183

184
    /**
185
     * @see https://developers.podio.com/doc/items/clone-item-37722742
186
     */
187
    public static function duplicate(PodioClient $podio_client, $item_id, $options = array())
188
    {
189
        $url =  $podio_client->url_with_options("/item/{$item_id}/clone", $options);
×
190
        $body = $podio_client->post($url)->json_body();
×
191
        return $body['item_id'];
×
192
    }
193

194
    /**
195
     * @see https://developers.podio.com/doc/items/update-item-22363
196
     */
197
    public static function update(PodioClient $podio_client, $item_id, $attributes = array(), $options = array())
198
    {
199
        $url = $podio_client->url_with_options("/item/{$item_id}", $options);
×
200
        return $podio_client->put($url, $attributes)->json_body();
×
201
    }
202

203
    /**
204
     * @see https://developers.podio.com/doc/items/update-item-reference-7421495
205
     */
206
    public static function update_reference(PodioClient $podio_client, $item_id, $attributes = array())
207
    {
208
        return $podio_client->put("/item/{$item_id}/ref", $attributes)->json_body();
×
209
    }
210

211
    /**
212
     * @see https://developers.podio.com/doc/items/update-item-values-22366
213
     */
214
    public static function update_values(PodioClient $podio_client, $item_id, $attributes = array(), $options = array())
215
    {
216
        $url = $podio_client->url_with_options("/item/{$item_id}/value", $options);
×
217
        return $podio_client->put($url, $attributes)->json_body();
×
218
    }
219

220
    /**
221
     * @see https://developers.podio.com/doc/items/calculate-67633
222
     */
223
    public static function calculate(PodioClient $podio_client, $app_id, $attributes = array())
224
    {
225
        return $podio_client->post("/item/app/{$app_id}/calculate", $attributes)->json_body();
×
226
    }
227

228
    /**
229
     * @see https://developers.podio.com/doc/items/export-items-4235696
230
     */
231
    public static function export(PodioClient $podio_client, $app_id, $exporter, $attributes = array())
232
    {
233
        $body = $podio_client->post("/item/app/{$app_id}/export/{$exporter}", $attributes ? $attributes : new StdClass())->json_body();
×
234
        return $body['batch_id'];
×
235
    }
236

237
    /**
238
     * @see https://developers.podio.com/doc/items/get-items-as-xlsx-63233
239
     */
240
    public static function xlsx(PodioClient $podio_client, $app_id, $attributes = array())
241
    {
242
        return $podio_client->get("/item/app/{$app_id}/xlsx/", $attributes)->body;
×
243
    }
244

245
    /**
246
     * @see https://developers.podio.com/doc/items/find-items-by-field-and-title-22485
247
     */
248
    public static function search_field(PodioClient $podio_client, $field_id, $attributes = array())
249
    {
250
        return $podio_client->get("/item/field/{$field_id}/find", $attributes)->json_body();
×
251
    }
252

253
    /**
254
     * @see https://developers.podio.com/doc/items/get-item-count-34819997
255
     */
256
    public static function get_count(PodioClient $podio_client, $app_id, $view_id)
257
    {
258
        $attributes = empty($view_id) ? array() : array("view_id" => $view_id);
×
259
        $body = $podio_client->get("/item/app/{$app_id}/count", $attributes)->json_body();
×
260
        return $body['count'];
×
261
    }
262

263
    /**
264
     * @see https://developers.podio.com/doc/items/get-app-values-22455
265
     */
266
    public static function get_app_values(PodioClient $podio_client, $app_id)
267
    {
268
        return $podio_client->get("/item/app/{$app_id}/values")->json_body();
×
269
    }
270

271
    /**
272
     * @see https://developers.podio.com/doc/items/get-item-field-values-22368
273
     */
274
    public static function get_field_value(PodioClient $podio_client, $item_id, $field_id)
275
    {
276
        return $podio_client->get("/item/{$item_id}/value/{$field_id}")->json_body();
×
277
    }
278

279
    /**
280
     * @see https://developers.podio.com/doc/items/get-item-preview-for-field-reference-7529318
281
     */
282
    public static function get_basic_by_field(PodioClient $podio_client, $item_id, $field_id)
283
    {
284
        return self::member($podio_client->get("/item/{$item_id}/reference/{$field_id}/preview"));
×
285
    }
286

287
    /**
288
     * @see https://developers.podio.com/doc/items/get-item-references-22439
289
     */
290
    public static function get_references(PodioClient $podio_client, $item_id)
291
    {
292
        return $podio_client->get("/item/{$item_id}/reference/")->json_body();
×
293
    }
294

295
    /**
296
     * @see https://developers.podio.com/doc/items/get-meeting-url-14763260
297
     */
298
    public static function get_meeting_url(PodioClient $podio_client, $item_id)
299
    {
300
        $body = $podio_client->get("/item/{$item_id}/meeting/url")->json_body();
×
301
        return $body['url'];
×
302
    }
303

304
    /**
305
     * @see https://developers.podio.com/doc/items/get-item-preview-for-field-reference-7529318
306
     */
307
    public static function get_references_by_field(PodioClient $podio_client, $item_id, $field_id, $attributes = array())
308
    {
309
        return self::listing($podio_client->get("/item/{$item_id}/reference/field/{$field_id}", $attributes));
×
310
    }
311

312
    /**
313
     * @see https://developers.podio.com/doc/items/get-top-values-for-field-68334
314
     */
315
    public static function get_top_values_by_field(PodioClient $podio_client, $field_id, $attributes = array())
316
    {
317
        return self::listing($podio_client->get("/item/field/{$field_id}/top/", $attributes));
×
318
    }
319

320
    /**
321
     * @see https://developers.podio.com/doc/items/set-participation-7156154
322
     */
323
    public static function participation(PodioClient $podio_client, $item_id, $attributes = array())
324
    {
325
        return $podio_client->put("/item/{$item_id}/participation", $attributes)->json_body();
×
326
    }
327

328
    /**
329
     * @see https://developers.podio.com/doc/items/revert-to-revision-194362682
330
     */
331
    public static function revert_to_revision(PodioClient $podio_client, $item_id, $revision, $attributes = array())
332
    {
333
        return $podio_client->post("/item/{$item_id}/revision/{$revision}/revert_to", $attributes);
×
334
    }
335

336
    /**
337
     * @see https://developers.podio.com/doc/items/get-item-values-22365
338
     */
339
    public static function get_item_values(PodioClient $podio_client, $item_id)
340
    {
341
        return $podio_client->get("/item/{$item_id}/value")->json_body();
×
342
    }
343
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc