| 1 |
<?php |
| 2 |
|
| 3 |
namespace Code_Snippets\Model; |
| 4 |
|
| 5 |
/** |
| 6 |
* A connection between a local snippet and remote cloud snippet. |
| 7 |
* |
| 8 |
* @package Code_Snippets |
| 9 |
* |
| 10 |
* @property int $local_id ID of local snippet as stored in WordPress database, if applicable. |
| 11 |
* @property int $cloud_id ID of remote snippet on cloud platform, if applicable. |
| 12 |
* @property bool $is_owner Ownership status of remote snippet on cloud platform. |
| 13 |
* @property bool $in_codevault Whether the remote snippet is stored in the users' codevault. |
| 14 |
* @property bool $update_available If synchronised, whether there is an update available on the cloud platform. |
| 15 |
*/ |
| 16 |
class Cloud_Link extends Model { |
| 17 |
|
| 18 |
/** |
| 19 |
* List of default values provided for fields. |
| 20 |
* |
| 21 |
* @var array<string, mixed> |
| 22 |
*/ |
| 23 |
protected static array $default_values = [ |
| 24 |
'local_id' => 0, |
| 25 |
'cloud_id' => 0, |
| 26 |
'is_owner' => false, |
| 27 |
'in_codevault' => false, |
| 28 |
'update_available' => false, |
| 29 |
]; |
| 30 |
|
| 31 |
/** |
| 32 |
* Prepare a value before it is stored. |
| 33 |
* |
| 34 |
* @param mixed $value Value to prepare. |
| 35 |
* @param string $field Field name. |
| 36 |
* |
| 37 |
* @return mixed Value in the correct format. |
| 38 |
*/ |
| 39 |
protected function prepare_field( $value, string $field ) { |
| 40 |
switch ( $field ) { |
| 41 |
case 'local_id': |
| 42 |
case 'remote_id': |
| 43 |
return absint( $value ); |
| 44 |
|
| 45 |
case 'is_owner': |
| 46 |
case 'in_codevault': |
| 47 |
case 'update_available': |
| 48 |
return is_bool( $value ) ? $value : (bool) $value; |
| 49 |
|
| 50 |
default: |
| 51 |
return $value; |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|