| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Campaigns\Blocks\CampaignComments\DataTransferObjects; |
| 4 |
|
| 5 |
use Give\Framework\Support\Contracts\Arrayable; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 4.0.0 |
| 9 |
*/ |
| 10 |
class BlockAttributes implements Arrayable |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public $blockId; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var int |
| 19 |
*/ |
| 20 |
public $campaignId; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var string |
| 24 |
*/ |
| 25 |
public $title; |
| 26 |
|
| 27 |
/** |
| 28 |
* @var bool |
| 29 |
*/ |
| 30 |
public $showAnonymous; |
| 31 |
|
| 32 |
/** |
| 33 |
* @var bool |
| 34 |
*/ |
| 35 |
public $showAvatar; |
| 36 |
|
| 37 |
/** |
| 38 |
* @var bool |
| 39 |
*/ |
| 40 |
public $showDate; |
| 41 |
|
| 42 |
/** |
| 43 |
* @var bool |
| 44 |
*/ |
| 45 |
public $showName; |
| 46 |
|
| 47 |
/** |
| 48 |
* @var int |
| 49 |
*/ |
| 50 |
public $commentLength; |
| 51 |
|
| 52 |
/** |
| 53 |
* @var string |
| 54 |
*/ |
| 55 |
public $readMoreText; |
| 56 |
|
| 57 |
/** |
| 58 |
* @var int |
| 59 |
*/ |
| 60 |
public $commentsPerPage; |
| 61 |
|
| 62 |
/** |
| 63 |
* @since 4.0.0 |
| 64 |
*/ |
| 65 |
public static function fromArray(array $array): BlockAttributes |
| 66 |
{ |
| 67 |
$self = new self(); |
| 68 |
|
| 69 |
$self->blockId = !empty($array['blockId']) ? (string)$array['blockId'] : null; |
| 70 |
$self->campaignId = !empty($array['campaignId']) ? (int)$array['campaignId'] : null; |
| 71 |
$self->title = !empty($array['title']) ? (string)$array['title'] : ''; |
| 72 |
$self->showAnonymous = !isset($array['showAnonymous']) || (bool)$array['showAnonymous']; |
| 73 |
$self->showAvatar = !isset($array['showAvatar']) || (bool)$array['showAvatar']; |
| 74 |
$self->showDate = !isset($array['showDate']) || (bool)$array['showDate']; |
| 75 |
$self->showName = !isset($array['showName']) || (bool)$array['showName']; |
| 76 |
$self->commentLength = isset($array['commentLength']) ? (int)$array['commentLength'] : 200; |
| 77 |
$self->readMoreText = !empty($array['readMoreText']) ? (string)$array['readMoreText'] : ''; |
| 78 |
$self->commentsPerPage = isset($array['commentsPerPage']) ? (int)$array['commentsPerPage'] : 3; |
| 79 |
|
| 80 |
return $self; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* @since 4.0.0 |
| 85 |
*/ |
| 86 |
public function toArray(): array |
| 87 |
{ |
| 88 |
return get_object_vars($this); |
| 89 |
} |
| 90 |
} |
| 91 |
|