-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkyNewsItem.php
1184 lines (1050 loc) · 28.3 KB
/
kyNewsItem.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Kayako NewsItem object.
* Known issues:
* - could not create NewsItem with PUBLIC and PRIVATE type (http://dev.kayako.com/browse/SWIFT-3108)
* - fields customemailsubject and fromname are ignored (http://dev.kayako.com/browse/SWIFT-3111)
* - field totalcomments is not updated by Kayako
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+NewsItem
* @since Kayako version 4.51.1891
* @package Object\News
*
* @noinspection PhpDocSignatureInspection
*/
class kyNewsItem extends kyCommentableBase
{
/**
* News type - Global.
* The news articles classified as Global are visible in both the client support center and the staff control panel.
*
* @var int
*/
const TYPE_GLOBAL = 1;
/**
* News type - Public.
* The news articles classified as Public are visible only in the client support center.
*
* @var int
*/
const TYPE_PUBLIC = 2;
/**
* News type - Private.
* The news article classified as Private are only visible in the staff control panel.
*
* @var int
*/
const TYPE_PRIVATE = 3;
/**
* News status - Draft.
*
* @var int
*/
const STATUS_DRAFT = 1;
/**
* News status - Published.
*
* @var int
*/
const STATUS_PUBLISHED = 2;
protected static $controller = '/News/NewsItem';
protected static $object_xml_name = 'newsitem';
protected static $comment_class = 'kyNewsComment';
/**
* News item identifier.
* @apiField
* @var int
*/
protected $id;
/**
* Creator (staff) identifier.
* @apiField required_create=true
* @var int
*/
protected $staff_id;
/**
* Creator (staff).
* @var kyStaff
*/
private $staff;
/**
* Editor (staff) identifier.
* @apiField required_update=true
* @var int
*/
protected $edited_staff_id;
/**
* Editor (staff).
* @var kyStaff
*/
private $edited_staff;
/**
* News item type.
* @apiField name=newstype
* @var int
*/
protected $type;
/**
* News item status.
* @apiField name=newsstatus
* @var int
*/
protected $status;
/**
* Author's fullname.
* @apiField
* @var string
*/
protected $author;
/**
* Author's email.
* @var string
*/
protected $author_email;
/**
* Name of email notification sender.
* @var string
*/
protected $from_name;
/**
* Address of email notification sender.
* @apiField
* @var string
*/
protected $email;
/**
* News item subject.
* @apiField
* @var string
*/
protected $subject;
/**
* Email subject.
* @apiField alias=customemailsubject
* @var string
*/
protected $email_subject;
/**
* Whether to send email.
* @apiField
* @var bool
*/
protected $send_email;
/**
* Whether to allow comments.
* @apiField
* @var bool
*/
protected $allow_comments;
/**
* Timestamp of when the news item was created.
* @apiField
* @var int
*/
protected $dateline;
/**
* Timestamp of when this news item will expire.
* @apiField
* @var int
*/
protected $expiry;
/**
* Whether this news item was downloaded (synchronised) from external RSS feed.
* @apiField
* @var bool
*/
protected $is_synced = false;
/**
* Total count of news item comments.
* @apiField
* @var int
*/
protected $total_comments = 0;
/**
* If this news item is visible to specific user groups only.
* @see kyNewsItem::$user_group_ids
* @apiField
* @var bool
*/
protected $user_visibility_custom = false;
/**
* User group identifiers this news item is visible to.
* @apiField name=usergroupidlist
* @var int[]
*/
protected $user_group_ids = array();
/**
* User groups this news item is visible to.
* @var kyUserGroup[]
*/
private $user_groups = null;
/**
* If this news item is visible to specific staff groups only.
* @see kyNewsItem::$staff_group_ids
* @apiField
* @var bool
*/
protected $staff_visibility_custom;
/**
* User group identifiers this news item is visible to.
* @apiField name=staffgroupidlist
* @var int[]
*/
protected $staff_group_ids = array();
/**
* User groups this news item is visible to.
* @var kyStaffGroup[]
*/
private $staff_groups = null;
/**
* News item contents.
* @apiField required=true
* @var string
*/
protected $contents;
/**
* Identifiers of news categories this news item belongs to.
* @apiField name=categories
* @var int[]
*/
protected $category_ids = array();
/**
* News categories this news item belongs to.
* @var kyNewsCategory[]
*/
private $categories = array();
protected function parseData($data)
{
$this->id = ky_assure_positive_int($data['id']);
$this->staff_id = ky_assure_positive_int($data['staffid']);
$this->type = ky_assure_positive_int($data['newstype']);
$this->status = ky_assure_positive_int($data['newsstatus']);
$this->author = ky_assure_string($data['author']);
$this->author_email = ky_assure_string($data['email']);
$this->subject = ky_assure_string($data['subject']);
$this->email_subject = ky_assure_string($data['emailsubject']);
$this->dateline = ky_assure_positive_int($data['dateline']);
$this->expiry = ky_assure_positive_int($data['expiry']);
$this->is_synced = ky_assure_bool($data['issynced']);
$this->total_comments = ky_assure_positive_int($data['totalcomments'], 0);
$this->allow_comments = ky_assure_bool($data['allowcomments']);
$this->contents = ky_assure_string($data['contents']);
$this->categories = array();
if (is_array($data['categories'])) {
if (is_string($data['categories'][0]['categoryid'])) {
$this->category_ids[] = ky_assure_positive_int($data['categories'][0]['categoryid']);
} else {
foreach ($data['categories'][0]['categoryid'] as $category_id) {
$this->category_ids[] = ky_assure_positive_int($category_id);
}
}
}
$this->user_visibility_custom = ky_assure_bool($data['uservisibilitycustom']);
$this->user_group_ids = array();
if ($this->user_visibility_custom && is_array($data['usergroupidlist'])) {
if (is_string($data['usergroupidlist'][0]['usergroupid'])) {
$this->user_group_ids[] = ky_assure_positive_int($data['usergroupidlist'][0]['usergroupid']);
} else {
foreach ($data['usergroupidlist'][0]['usergroupid'] as $user_group_id) {
$this->user_group_ids[] = ky_assure_positive_int($user_group_id);
}
}
}
$this->staff_visibility_custom = ky_assure_bool($data['staffvisibilitycustom']);
$this->staff_group_ids = array();
if ($this->staff_visibility_custom && is_array($data['staffgroupidlist'])) {
if (is_string($data['staffgroupidlist'][0]['staffgroupid'])) {
$this->staff_group_ids[] = ky_assure_positive_int($data['staffgroupidlist'][0]['staffgroupid']);
} else {
foreach ($data['staffgroupidlist'][0]['staffgroupid'] as $staff_group_id) {
$this->staff_group_ids[] = ky_assure_positive_int($staff_group_id);
}
}
}
}
public function buildData($create)
{
$this->checkRequiredAPIFields($create);
$data = array();
$this->buildDataString($data, 'subject', $this->subject);
$this->buildDataString($data, 'contents', $this->contents);
if ($create) {
$this->buildDataNumeric($data, 'staffid', $this->staff_id);
$this->buildDataNumeric($data, 'newstype', $this->type);
} else {
$this->buildDataNumeric($data, 'editedstaffid', $this->edited_staff_id);
}
$this->buildDataNumeric($data, 'newsstatus', $this->status);
$this->buildDataString($data, 'fromname', $this->from_name);
$this->buildDataString($data, 'email', $this->email);
$this->buildDataString($data, 'customemailsubject', $this->email_subject);
$this->buildDataBool($data, 'sendemail', $this->send_email);
$this->buildDataBool($data, 'allowcomments', $this->allow_comments);
$this->buildDataBool($data, 'uservisibilitycustom', $this->user_visibility_custom);
if ($this->user_visibility_custom) {
$this->buildDataList($data, 'usergroupidlist', $this->user_group_ids);
}
$this->buildDataBool($data, 'staffvisibilitycustom', $this->staff_visibility_custom);
if ($this->staff_visibility_custom) {
$this->buildDataList($data, 'staffgroupidlist', $this->staff_group_ids);
}
//watch out for http://dev.kayako.com/browse/SWIFT-3110 resolution
$data['expiry'] = date('m/d/Y', $this->expiry);
// $this->buildDataNumeric($data, 'expiry', $this->expiry);
$this->buildDataList($data, 'newscategoryidlist', $this->category_ids);
return $data;
}
public static function getAll()
{
if (func_num_args() == 0) {
$category = null;
} else {
list($category) = func_get_args();
}
if ($category instanceof kyNewsCategory) {
$category_id = $category->getId();
} else {
$category_id = $category;
}
if (!is_numeric($category)) {
return parent::getAll();
} else {
return parent::getAll(array('ListAll', $category_id));
}
}
public function toString()
{
return sprintf("%s (type: %s, status: %s, expiry: %s)", $this->getSubject(), $this->getType(), $this->getStatus(), $this->getExpiry());
}
public function getId($complete = false)
{
return $complete ? array($this->id) : $this->id;
}
/**
* Returns identifier of staff user, the creator of this news item.
*
* @return int
* @filterBy
* @orderBy
*/
public function getStaffId()
{
return $this->staff_id;
}
/**
* Sets identifier of staff user, the creator of this news item.
*
* @param int $staff_id Staff user identifier.
* @return kyNewsItem
*/
public function setStaffId($staff_id)
{
$this->staff_id = ky_assure_positive_int($staff_id);
$this->staff = null;
return $this;
}
/**
* Returns the staff user, the creator of this news item.
*
* @param bool $reload True to reload data from server. False to use the cached value (if present).
* @return kyStaff
*/
public function getStaff($reload = false)
{
if ($this->staff !== null && !$reload) {
return $this->staff;
}
if ($this->staff_id === null) {
return null;
}
$this->staff = kyStaff::get($this->staff_id);
return $this->staff;
}
/**
* Sets staff user, the creator of this news item.
*
* @param kyStaff $staff Staff user.
* @return kyNewsItem
*/
public function setStaff($staff)
{
$this->staff = ky_assure_object($staff, 'kyStaff');
$this->staff_id = $this->staff !== null ? $this->staff->getId() : null;
return $this;
}
/**
* Sets identifier of staff user, the editor of this news item update.
*
* @param int $staff_id Staff user identifier.
* @return kyNewsItem
*/
public function setEditedStaffId($staff_id)
{
$this->edited_staff_id = ky_assure_positive_int($staff_id);
$this->edited_staff = null;
return $this;
}
/**
* Sets staff user, the editor of this news item update.
*
* @param kyStaff $staff Staff user.
* @return kyNewsItem
*/
public function setEditedStaff($staff)
{
$this->edited_staff = ky_assure_object($staff, 'kyStaff');
$this->edited_staff_id = $this->edited_staff !== null ? $this->edited_staff->getId() : null;
return $this;
}
/**
* Returns type of the news item.
*
* @see kyNewsItem::TYPE constants.
*
* @return int
* @filterBy
* @orderBy
*/
public function getType()
{
return $this->type;
}
/**
* Sets type of the news item.
*
* @see kyNewsItem::TYPE constants.
* @see http://dev.kayako.com/browse/SWIFT-3108
*
* @param int $type Type of the news item.
* @return kyNewsItem
*/
public function setType($type)
{
$this->type = ky_assure_constant($type, $this, 'TYPE');
return $this;
}
/**
* Returns status of the news item.
*
* @see kyNewsItem::STATUS constants.
*
* @return int
* @filterBy
* @orderBy
*/
public function getStatus()
{
return $this->status;
}
/**
* Sets status of the news item.
*
* @see kyNewsItem::STATUS constants.
*
* @param int $status Status of the news item.
* @return kyNewsItem
*/
public function setStatus($status)
{
$this->status = ky_assure_constant($status, $this, 'STATUS');
return $this;
}
/**
* Returns full name of author.
*
* @return string
* @filterBy
* @orderBy
*/
public function getAuthor()
{
return $this->author;
}
/**
* Returns email of author.
*
* @return string
* @filterBy
* @orderBy
*/
public function getAuthorEmail()
{
return $this->author_email;
}
/**
* Sets name of notification email sender.
*
* @see http://dev.kayako.com/browse/SWIFT-3111
*
* @param string $from_name The From Name email header that will be used for the emails sent out to subscribers.
* @return kyNewsItem
*/
public function setFromName($from_name)
{
$this->from_name = ky_assure_string($from_name);
return $this;
}
/**
* Sets address of notification email sender.
*
* @param string $email The From Email address that will be used for the emails sent out to subscribers. Please note that this may be the address users reply back to (if they reply to the news article email).
* @return kyNewsItem
*/
public function setEmail($email)
{
$this->email = ky_assure_string($email);
return $this;
}
/**
* Returns subject of the news item.
*
* @return string
* @filterBy
* @orderBy
*/
public function getSubject()
{
return $this->subject;
}
/**
* Sets subject of the news item.
*
* @param string $subject Subject of the news item.
* @return kyNewsItem
*/
public function setSubject($subject)
{
$this->subject = ky_assure_string($subject);
return $this;
}
/**
* Returns subject of notification email.
*
* @return string
* @filterBy
* @orderBy
*/
public function getEmailSubject()
{
return $this->email_subject;
}
/**
* Sets subject of notification email.
*
* @see http://dev.kayako.com/browse/SWIFT-3111
*
* @param string $email_subject Subject for the mass email that will be send out to the subscribers for this news article. If no subject is specified, the subject of the news article will be used instead.
* @return kyNewsItem
*/
public function setEmailSubject($email_subject)
{
$this->email_subject = ky_assure_string($email_subject);
return $this;
}
/**
* Sets whether to send notification email to subscribers when creating or updating this news item.
*
* @param bool $send_email True to send notification email to subscribers when creating or updating this news item. False otherwise.
* @return kyNewsItem
*/
public function setSendEmail($send_email)
{
$this->send_email = ky_assure_bool($send_email);
return $this;
}
/**
* Returns whether clients are permitted to comment on this news item.
*
* @return bool
* @filterBy
* @orderBy
*/
public function getAllowComments()
{
return $this->allow_comments;
}
/**
* Sets whether clients are permitted to comment on this news item.
*
* @param bool $allow_comments True to allow clients to comment on this news item.
* @return kyNewsItem
*/
public function setAllowComments($allow_comments)
{
$this->allow_comments = ky_assure_bool($allow_comments);
return $this;
}
/**
* Returns date and time when the news item was created.
*
* @see http://www.php.net/manual/en/function.date.php
*
* @param string $format Output format of the date. If null the format set in client configuration is used.
* @return string
* @filterBy
* @orderBy
*/
public function getDateline($format = null)
{
if ($this->dateline == null) {
return null;
}
if ($format === null) {
$format = kyConfig::get()->getDatetimeFormat();
}
return date($format, $this->dateline);
}
/**
* Returns expiration date of the user or null when expiration is disabled.
*
* @see http://www.php.net/manual/en/function.date.php
*
* @param string $format Output format of the date. If null the format set in client configuration is used.
* @return string
* @filterBy
* @orderBy
*/
public function getExpiry($format = null)
{
if ($this->expiry == null) {
return null;
}
if ($format === null) {
$format = kyConfig::get()->getDatetimeFormat();
}
return date($format, $this->expiry);
}
/**
* Sets expiration date of the news item.
*
* @see http://www.php.net/manual/en/function.strtotime.php
*
* @param string|int|null $expiry Date and time when the news item will expire (timestamp or string format understood by PHP strtotime). Null to disable expiration.
* @return kyNewsItem
*/
public function setExpiry($expiry)
{
$this->expiry = is_numeric($expiry) || $expiry === null ? ky_assure_positive_int($expiry) : strtotime($expiry);
return $this;
}
/**
* Returns whether this news item is expired.
*
* @return bool
* @filterBy name=IsExpired
* @orderBy name=IsExpired
*/
public function IsExpired()
{
return $this->expiry > 0 && $this->expiry <= time();
}
/**
* Returns whether this news item was downloaded (synchronised) from external RSS feed.
*
* @return bool
* @filterBy
* @orderBy
*/
public function getIsSynced()
{
return $this->is_synced;
}
/**
* Returns total count of comments on this news item.
*
* @return int
* @filterBy
* @orderBy
*/
public function getTotalComments()
{
return $this->total_comments;
}
/**
* Returns true to indicate that visibility of this news item is restricted to particular user groups.
* Use getUserGroupIds to get their identifiers or getUserGroups to get the objects.
*
* @return bool
* @filterBy
*/
public function getUserVisibilityCustom()
{
return $this->user_visibility_custom;
}
/**
* Sets wheter to restrict visibility of this news item to particular user groups.
* Use setUserGroupIds to set these groups using identifiers or addUserGroup to set them using objects.
* Automatically clears user groups when set to false.
*
* @param bool $user_visibility_custom True to restrict visibility of this news item to particular user groups. False otherwise.
* @return kyNewsItem
*/
public function setUserVisibilityCustom($user_visibility_custom)
{
$this->user_visibility_custom = ky_assure_bool($user_visibility_custom);
if ($this->user_visibility_custom === false) {
$this->user_group_ids = array();
$this->user_groups = null;
}
return $this;
}
/**
* Returns identifiers of user groups that this news item will be visible to.
*
* @return array
* @filterBy name=UserGroupId
*/
public function getUserGroupIds()
{
return $this->user_group_ids;
}
/**
* Sets user groups (using their identifiers) that this news item will be visible to.
*
* @param int[] $user_group_ids Identifiers of user groups that this news item will be visible to.
* @return kyNewsItem
*/
public function setUserGroupIds($user_group_ids)
{
//normalization to array
if (!is_array($user_group_ids)) {
if (is_numeric($user_group_ids)) {
$user_group_ids = array($user_group_ids);
} else {
$user_group_ids = array();
}
}
//normalization to positive integer values
$this->user_group_ids = array();
foreach ($user_group_ids as $user_group_id) {
$user_group_id = ky_assure_positive_int($user_group_id);
if ($user_group_id === null) {
continue;
}
$this->user_group_ids[] = $user_group_id;
}
return $this;
}
/**
* Returns user groups that this news item will be visible to.
* Result is cached until the end of script.
*
* @param bool $reload True to reload data from server. False to use the cached value (if present).
* @return kyResultSet
*/
public function getUserGroups($reload = false)
{
foreach ($this->user_group_ids as $user_group_id) {
if (!is_array($this->user_groups) || !array_key_exists($user_group_id, $this->user_groups) || $reload) {
$this->user_groups[$user_group_id] = kyUserGroup::get($user_group_id);
}
}
return new kyResultSet(array_values($this->user_groups));
}
/**
* Returns whether this news item is visible to specified user group.
*
* @param kyUserGroup|int $user_group User group or its identifier.
* @param bool $check_expiration Whether to also check if news item is expired.
* @return bool
* @filterBy
*/
public function isVisibleToUserGroup($user_group, $check_expiration = true)
{
if ($this->type === self::TYPE_PRIVATE) {
return false;
}
if ($check_expiration === true && $this->isExpired()) {
return false;
}
if ($this->user_visibility_custom === false) {
return true;
}
if ($user_group instanceof kyUserGroup) {
$user_group_id = $user_group->getId();
} else {
$user_group_id = intval($user_group);
}
return in_array($user_group_id, $this->user_group_ids);
}
/**
* Add user group to the list of groups that this news item will be visible to.
* Automatically sets custom user visibility flag to True.
*
* @param kyUserGroup $user_group User group that this news item will be visible to.
* @param bool $clear Clear the list before adding.
* @return kyNewsItem
*/
public function addUserGroup(kyUserGroup $user_group, $clear = false)
{
if ($clear) {
$this->user_groups = array();
$this->user_group_ids = array();
}
if (!in_array($user_group->getId(), $this->user_group_ids)) {
$this->user_group_ids[] = $user_group->getId();
$this->user_visibility_custom = true;
}
return $this;
}
/**
* Returns true to indicate that visibility of this news item is restricted to particular staff groups.
* Use getStaffGroupIds to get their identifiers or getStaffGroups to get the objects.
*
* @return bool
* @filterBy
*/
public function getStaffVisibilityCustom()
{
return $this->staff_visibility_custom;
}
/**
* Sets wheter to restrict visibility of this news item to particular staff groups.
* Use setStaffGroupIds to set these groups using identifiers or addStaffGroup to set them using objects.
* Automatically clears staff groups when set to false.
*
* @param bool $staff_visibility_custom True to restrict visibility of this news item to particular staff groups. False otherwise.
* @return kyNewsItem
*/
public function setStaffVisibilityCustom($staff_visibility_custom)
{
$this->staff_visibility_custom = ky_assure_bool($staff_visibility_custom);
if ($this->staff_visibility_custom === false) {
$this->staff_group_ids = array();
$this->staff_groups = null;
}
return $this;
}
/**
* Returns identifiers of staff groups that this news item will be visible to.
*
* @return array
* @filterBy name=StaffGroupId
*/
public function getStaffGroupIds()
{
return $this->staff_group_ids;
}
/**
* Sets staff groups (using their identifiers) that this news item will be visible to.
*
* @param int[] $staff_group_ids Identifiers of staff groups that this news item will be visible to.
* @return kyNewsItem
*/
public function setStaffGroupIds($staff_group_ids)
{
//normalization to array
if (!is_array($staff_group_ids)) {
if (is_numeric($staff_group_ids)) {
$staff_group_ids = array($staff_group_ids);
} else {
$staff_group_ids = array();
}
}
//normalization to positive integer values
$this->staff_group_ids = array();
foreach ($staff_group_ids as $staff_group_id) {
$staff_group_id = ky_assure_positive_int($staff_group_id);
if ($staff_group_id === null) {
continue;
}
$this->staff_group_ids[] = $staff_group_id;
}
return $this;
}
/**
* Returns staff groups that this news item will be visible to.
* Result is cached until the end of script.
*
* @param bool $reload True to reload data from server. False to use the cached value (if present).
* @return kyResultSet
*/
public function getStaffGroups($reload = false)
{
foreach ($this->staff_group_ids as $staff_group_id) {
if (!is_array($this->staff_groups) || !array_key_exists($staff_group_id, $this->staff_groups) || $reload) {
$this->staff_groups[$staff_group_id] = kyStaffGroup::get($staff_group_id);
}
}
return new kyResultSet(array_values($this->staff_groups));
}
/**
* Returns whether this news item is visible to specified staff group.
*
* @param kyStaffGroup|int $staff_group Staff group or its identifier.
* @param bool $check_expiration Whether to also check if news item is expired.
* @return bool
* @filterBy
*/
public function isVisibleToStaffGroup($staff_group, $check_expiration = true)
{
if ($this->type === self::TYPE_PUBLIC) {
return false;
}
if ($check_expiration === true && $this->isExpired()) {
return false;
}