| @@ -32,8 +32,10 @@ | ||
| 32 | 32 | * @property string|null $code_error_trace Stack trace captured when last testing snippet code. |
| 33 | 33 | * @property int $revision Revision or version number of snippet. |
| 34 | 34 | * @property int $cloud_id The cloud ID of the snippet, if applicable. |
| 35 | 35 | * @property bool $is_cloud_owner Whether the user is the owner of the cloud snippet, if applicable. |
| 36 | + * @property int $created_by User ID of the snippet's original author. 0 if unknown. | |
| 37 | + * @property int $updated_by User ID of the last person to save the snippet. 0 if unknown. | |
| 36 | 38 | * |
| 37 | 39 | * @property-read int $last_active Timestamp of when the snippet was last active, if available. |
| 38 | 40 | * @property-read string $display_name The snippet name if it exists or a placeholder if it does not. |
| 39 | 41 | * @property-read string $tags_list The tags in string list format. |
| @@ -42,8 +44,9 @@ | ||
| 42 | 44 | * @property-read string $type The type of snippet. |
| 43 | 45 | * @property-read string $lang The language that the snippet code is written in. |
| 44 | 46 | * @property-read int $modified_timestamp The last modification date in Unix timestamp format. |
| 45 | 47 | * @property-read DateTime $modified_local The last modification date in the local timezone. |
| 48 | + * @property-read DateTime $modified_iso The last modification date in ISO 8601 format. | |
| 46 | 49 | * @property-read bool $is_pro Whether the snippet type is pro-only. |
| 47 | 50 | * @property-read string $cloud_id_owner Cloud ownership information as a single value, if applicable. |
| 48 | 51 | */ |
| 49 | 52 | class Snippet extends Model { |
| @@ -82,8 +85,10 @@ | ||
| 82 | 85 | 'code_error_trace' => null, |
| 83 | 86 | 'revision' => 1, |
| 84 | 87 | 'cloud_id' => 0, |
| 85 | 88 | 'is_cloud_owner' => false, |
| 89 | + 'created_by' => 0, | |
| 90 | + 'updated_by' => 0, | |
| 86 | 91 | ]; |
| 87 | 92 | |
| 88 | 93 | /** |
| 89 | 94 | * Field name aliases. |
| @@ -110,8 +115,10 @@ | ||
| 110 | 115 | case 'priority': |
| 111 | 116 | case 'condition_id': |
| 112 | 117 | case 'cloud_id': |
| 113 | 118 | case 'revision': |
| 119 | + case 'created_by': | |
| 120 | + case 'updated_by': | |
| 114 | 121 | return absint( $value ); |
| 115 | 122 | |
| 116 | 123 | case 'tags': |
| 117 | 124 | return code_snippets_build_tags_array( $value ); |
| @@ -460,8 +467,26 @@ | ||
| 460 | 467 | protected function get_modified_timestamp(): int { |
| 461 | 468 | $datetime = DateTime::createFromFormat( self::DATE_FORMAT, $this->modified, new DateTimeZone( 'UTC' ) ); |
| 462 | 469 | |
| 463 | 470 | return $datetime ? $datetime->getTimestamp() : 0; |
| 471 | + } | |
| 472 | + | |
| 473 | + /** | |
| 474 | + * Retrieve the modification date as an ISO 8601 string, including the UTC | |
| 475 | + * offset. | |
| 476 | + * | |
| 477 | + * `$modified` is stored as 'Y-m-d H:i:s' in UTC, which carries no offset, so | |
| 478 | + * anything parsing it — a browser, in particular — is free to read it as | |
| 479 | + * local time and land the snippet hours away from when it was really saved. | |
| 480 | + * This is the form to hand to clients. | |
| 481 | + * | |
| 482 | + * @return string|null ISO 8601 date, or null if no modification date is set. | |
| 483 | + * @noinspection PhpUnused | |
| 484 | + */ | |
| 485 | + protected function get_modified_iso(): ?string { | |
| 486 | + $timestamp = $this->get_modified_timestamp(); | |
| 487 | + | |
| 488 | + return $timestamp ? gmdate( 'c', $timestamp ) : null; | |
| 464 | 489 | } |
| 465 | 490 | |
| 466 | 491 | /** |
| 467 | 492 | * Retrieve the modification time in the local timezone. |