Oihana PHP

UpdateDateModel

Contract for models able to touch a single date property of a document.

An UpdateDateModel exposes a UpdateDateModel::updateDate() operation that stamps one date field of a document with the current date — by default the modified property (Schema::MODIFIED). It is the lightweight way to record a "last touched" timestamp without rewriting the rest of the document.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

updateDate()  : mixed
Updates a single date property in a document with the current date.

Methods

updateDate()

Updates a single date property in a document with the current date.

public updateDate([array<string|int, mixed> $init = [] ][, string $property = Schema::MODIFIED ]) : mixed

By default, it updates the modified property with the current timestamp.

Parameters
$init : array<string|int, mixed> = []

Operation options identifying the target document, typically a key/id, an explicit value to use instead of "now", optional binds and a return clause.

$property : string = Schema::MODIFIED

The document property to update (default: Schema::MODIFIED).

Tags
example
use oihana\models\interfaces\UpdateDateModel;
use org\schema\constants\Schema;

class UserModel implements UpdateDateModel
{
    public function updateDate( array $init = [] , string $property = Schema::MODIFIED ) : mixed
    {
        return $this->store->touch( $init[ 'key' ] ?? null, $property, date( 'c' ) ) ;
    }
}

$model = new UserModel() ;

$model->updateDate( [ 'key' => 'users/42' ] ) ;                       // stamps `modified`
$model->updateDate( [ 'key' => 'users/42' ], Schema::DATE_PUBLISHED ) ; // stamps another field
Return values
mixed

The updated document (or operation result), depending on the implementation.

On this page

Search results