GravityKit\GravityBoard\Card
Class Card
Handles card creation, validation, and data management for GravityBoard.
Since: 1.0.0
Source: src/Card.php:27
Details
- Kind:
class - Namespace:
GravityKit\GravityBoard
Methods
| Method | Description |
|---|---|
__construct() | Card constructor. |
get_id() | Get card ID. |
get() | Get a data field value. |
set() | Set a data field value. |
get_title() | Get card title. |
set_title() | Set card title. |
get_description() | Get card description. |
set_description() | Set card description. |
get_label() | Get card label. |
set_label() | Set card label. |
get_position() | Get card position. |
set_position() | Set card position. |
get_due_date() | Get card due date. |
set_due_date() | Set card due date. |
get_due_date_timestamp() | Get card due date timestamp. |
set_due_date_timestamp() | Set card due date timestamp. |
get_lane() | Get card lane. |
set_lane() | Set card lane. |
to_array() | Convert card to array format. |
create_from_request() | Create a card from request data. |
get_lane_named_by_request() | The lane a request names through a card field mapped onto the lane field. |
get_entry_lane_id() | The lane an entry sits in on the board, as Helpers::get_lane_id_from_value() places it. |
get_next_position_in_lane() | The position a card added to a lane takes: one past the lane's highest stored position. |
update_from_request() | Update a card from request data. |
build_data_from_entry() | Build card data from entry. |
is_read_only_field() | Whether a Gravity Forms field is one the card API cannot write. |
writes_lane_field() | Whether a mapped card field would write the board's lane field. |
get_lane_field_keys() | The card field keys that would write the board's lane field. |
get_read_only_field_keys() | The mapped card field keys whose form field the card API cannot write. |
Method Reference
__construct()
public function __construct( string $id='', array $data=[], ?Lane $lane=null, array $feed=[], array $form=[] )
Card constructor.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$id | string | '' | The card ID. |
$data | array | [] | |
$lane | Lane | null | null | The card lane. |
$feed | FeedRow | array{} | [] | The feed data (optional, for operations). |
$form | array | [] |
Since: 1.0
Source: src/Card.php:178
get_id()
public function get_id(): string
Get card ID.
Returns
string
Since: 1.0
Source: src/Card.php:209
get()
public function get( string $key, $default_value=null )
Get a data field value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The data key. | |
$default_value | string | int | string[] | null | null | Returned when the key is unset. |
Returns
string|int|string[]|null
Since: 1.0
Source: src/Card.php:223
set()
public function set( string $key, $value ): void
Set a data field value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The data key. | |
$value | string | int | string[] | null | The value to set. |
Returns
void
Since: 1.0
Source: src/Card.php:235
get_title()
public function get_title(): string
Get card title.
Returns
string
Since: 1.0
Source: src/Card.php:246
set_title()
public function set_title( string $title ): void
Set card title.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$title | string | The card title. |
Returns
void
Since: 1.0
Source: src/Card.php:257
get_description()
public function get_description(): string
Get card description.
Returns
string
Since: 1.0
Source: src/Card.php:268
set_description()
public function set_description( string $description ): void
Set card description.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$description | string | The card description. |
Returns
void
Since: 1.0
Source: src/Card.php:279
get_label()
public function get_label(): string
Get card label.
Returns
string
Since: 1.0
Source: src/Card.php:290
set_label()
public function set_label( string $label ): void
Set card label.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$label | string | The card label. |
Returns
void
Since: 1.0
Source: src/Card.php:301
get_position()
public function get_position(): int
Get card position.
Returns
int
Since: 1.0
Source: src/Card.php:312
set_position()
public function set_position( int $position ): void
Set card position.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$position | int | The card position. |
Returns
void
Since: 1.0
Source: src/Card.php:323
get_due_date()
public function get_due_date(): string
Get card due date.
Returns
string
Since: 1.0
Source: src/Card.php:334
set_due_date()
public function set_due_date( string $due_date ): void
Set card due date.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$due_date | string | The card due date. |
Returns
void
Since: 1.0
Source: src/Card.php:345
get_due_date_timestamp()
public function get_due_date_timestamp(): ?int
Get card due date timestamp.
Returns
int|null
Since: 1.0
Source: src/Card.php:356
set_due_date_timestamp()
public function set_due_date_timestamp( ?int $timestamp ): void
Set card due date timestamp.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$timestamp | int | null | The card due date timestamp. |
Returns
void
Since: 1.0
Source: src/Card.php:367
get_lane()
public function get_lane(): ?Lane
Get card lane.
Returns
Lane|null
Since: 1.0
Source: src/Card.php:378
set_lane()
public function set_lane( ?Lane $lane ): void
Set card lane.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$lane | Lane | null | The card lane. |
Returns
void
Since: 1.0
Source: src/Card.php:389
to_array()
public function to_array(): array
Convert card to array format.
Returns
array<string,— string|int|string[]|null> The card:id,lane_value, and every key the card data holds.
Since: 1.0
Source: src/Card.php:400
create_from_request()
public static function create_from_request( WP_REST_Request $request, array $feed, int $lane_id, int $position )
Create a card from request data.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$request | WP_REST_Request | The REST request. | |
$feed | FeedRow | array{} | The feed data. | |
$lane_id | int | The lane ID. | |
$position | int | The position the editor sends (the lane's card count). The stored position is computed from the lane instead. |
Returns
array<string,— mixed>|WP_Error|ErrorCollection The new entry, asGFAPI::get_entry()returns it; a WP_Error on failure; an ErrorCollection on validation failure.
Since: 1.0
Source: src/Card.php:420
get_lane_named_by_request()
public static function get_lane_named_by_request( WP_REST_Request $request, array $feed, ?string $current_lane_id, bool $ignore_empty=false )
The lane a request names through a card field mapped onto the lane field.
The board can map a card field (usually Label) onto the form field that holds the lane, so
choosing its value chooses the lane. Values are matched to lanes the way the board places
cards, by Helpers::get_lane_id_from_value(). lane_field itself is never read from a request.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$request | WP_REST_Request | The REST request. | |
$feed | FeedRow | array{} | The feed. | |
$current_lane_id | string | null | The lane the card is already in; naming it is not a request. | |
$ignore_empty | bool | false | Whether an empty value means "no choice" rather than naming no lane. |
Returns
int| WP_Error |null— The lane ID; a WP_Error when a value names no lane or two fields name different lanes; null when the request names none.
Since: TBD
Source: src/Card.php:513
get_entry_lane_id()
public static function get_entry_lane_id( array $entry, array $feed ): ?string
The lane an entry sits in on the board, as Helpers::get_lane_id_from_value() places it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$entry | array | ||
$feed | FeedRow | array{} | The feed. |
Returns
string|null— The lane ID, or null when the value matches no lane.
Since: TBD
Source: src/Card.php:569
get_next_position_in_lane()
public static function get_next_position_in_lane( array $feed, string $lane_field_id, string $lane_value ): int
The position a card added to a lane takes: one past the lane's highest stored position.
Only active entries count. A card with no stored position sorts last on the board and has no number to go past.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$feed | FeedRow | array{} | The feed. | |
$lane_field_id | string | The lane field's ID. | |
$lane_value | string | The lane's choice value. |
Returns
int
Since: 1.5.0
Source: src/Card.php:595
update_from_request()
public static function update_from_request( WP_REST_Request $request, array $entry, array $feed )
Update a card from request data.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$request | WP_REST_Request | The REST request. | |
$entry | array | ||
$feed | FeedRow | array{} | The feed data. |
Returns
array{changes:— string[], updated_entry: array<string, mixed>|WP_Error}|WP_Error The card field keys written and the re-read entry, or a WP_Error on failure.
Since: 1.0
Source: src/Card.php:644
build_data_from_entry()
public static function build_data_from_entry( array $entry, array $feed ): array
Build card data from entry.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$entry | array | ||
$feed | FeedRow | array{} | The feed data. |
Returns
array<string,— mixed> The card:id,title,description,label,position,due_date,due_date_timestamp,lane_valueandchoice_field_values, plus every other mapped field under its own key and whatever the card/data filter adds.
Since: 1.0
Source: src/Card.php:711
is_read_only_field()
public static function is_read_only_field( $field )
Whether a Gravity Forms field is one the card API cannot write.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$field | \GF_Field | null | The field. |
Returns
bool
Since: 1.5.0
Source: src/Card.php:998
writes_lane_field()
public static function writes_lane_field( array $feed, string $field_key, $field_id ): bool
Whether a mapped card field would write the board's lane field.
The Label chooser offers select and radio and so does the Lane chooser, so a board
can map another card field onto the very field that holds the lane. Writing it moves the
card between lanes without gk/gravityboard/card/changed-lane firing or the lane
positions being handled, which only the move endpoint does.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$feed | FeedRow | array{} | The feed. | |
$field_key | string | The card field key. | |
$field_id | string | int | The form field ID the key is mapped to, or '' when unmapped. |
Returns
bool
Since: 1.5.0
Source: src/Card.php:1018
get_lane_field_keys()
public static function get_lane_field_keys( array $feed ): array
The card field keys that would write the board's lane field.
Always holds lane_field itself, plus any other card field the board maps onto the
same form field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$feed | FeedRow | array{} | The feed. |
Returns
string[]— Card field keys.
Since: 1.5.0
Source: src/Card.php:1040
get_read_only_field_keys()
public static function get_read_only_field_keys( array $feed, $form ): array
The mapped card field keys whose form field the card API cannot write.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$feed | FeedRow | array{} | The feed. | |
$form |
Returns
string[]— Card field keys.
Since: 1.5.0
Source: src/Card.php:1062