FieldEntry
+ Inheritance diagram for FieldEntry:

Description

Represents a task's custom-field value.

Immutable:
When the entry belongs to a Change
See also
https://developers.asana.com/reference/custom-fields

Protected Properties

readonly string string $key
 The <resource_subtype>_value(s) data key. More...
 
const MAP
 
- Protected Properties inherited from Data
readonly Api Api $api
 
array array self[] AbstractEntity[] $data = []
 
array bool[] $diff = []
 
const MAP = []
 

Public Methods

 __construct (Change|FieldEntries $caller, array $data=[])
 
string __toString ()
 
CustomField getCustomField ()
 
magic null Date getDateValue ()
 
null string getDisplayValue ()
 Determines the human-readable value in a future-proof way. More...
 
magic null EnumOption getEnumValue ()
 For subtype enum More...
 
magic string getGid ()
 The custom field's GID. More...
 
magic EnumOption[] getMultiEnumValues ()
 For subtype multi_enum More...
 
magic null number getNumberValue ()
 For subtype number More...
 
magic User[] getPeopleValue ()
 For subtype people More...
 
null number string array Data Data[] getRawValue ()
 
magic string getResourceSubtype ()
 
magic null string getTextValue ()
 For subtype text More...
 
magic bool ofDate ()
 
magic bool ofEnum ()
 
magic bool ofMultiEnum ()
 
magic bool ofNumber ()
 
magic bool ofPeople ()
 
magic bool ofText ()
 
magic EnumOption[] selectMultiEnumValues (callable $filter)
 fn( EnumOption $option): bool More...
 
magic User[] selectPeopleValue (callable $filter)
 fn( User $user ): bool More...
 
$this setDateValue ($date)
 
$this setEnumValue ($value)
 
$this setMultiEnumValues (array $values)
 
magic $this setNumberValue (?number $number)
 
magic $this setPeopleValue (User[] $people)
 
magic $this setTextValue (?string $text)
 
$this setValue ($value)
 Calls the respective setter depending on the entry's type. More...
 
- Public Methods inherited from Data
mixed __call (string $method, array $args)
 Magic method handler. More...
 
 __construct (Api|self $caller, array $data=[])
 
array __serialize ()
 
void __unserialize (array $data)
 
bool isDiff ()
 Whether the instance has changes. More...
 
array jsonSerialize ()
 
bool offsetExists (mixed $offset)
 
mixed offsetGet (mixed $offset)
 
void offsetSet (mixed $offset, mixed $value)
 
void offsetUnset (mixed $offset)
 
array toArray (bool $diff=false)
 Dehydrated data. More...
 

Protected Methods

$this _set (string $field, $value)
 Values are immutable when the entry belongs to a Change. More...
 
void _setData (array $data)
 Strips Asana's redundant CustomField and EnumOption data. More...
 
- Protected Methods inherited from Data
mixed _get (string $field)
 Magic method: getField() More...
 
bool _has (string $field)
 Magic method: hasField() More...
 
_hydrate (string $class, $item)
 Sub-data factory that draws from the entity pool. More...
 
bool _is (string $field)
 Magic method: isField() More...
 
bool _of (string $resourceSubtype)
 Magic method: ofResourceSubtypeValue() More...
 
array _select (string|iterable $subject, callable $filter,... $args)
 Magic method: selectField(callable $filter) More...
 
void _setField (string $field, $value)
 Sets a value, hydrating if mapped, and clears the diff. More...
 

Properties

◆ $key

readonly string string $key
protected

The <resource_subtype>_value(s) data key.

◆ MAP

const MAP
protected
Initial value:
= [
'date_value' => Date::class,
'enum_value' => EnumOption::class,
'multi_enum_values' => [EnumOption::class],
'people_value' => [User::class]
]

Constructor

◆ __construct()

__construct ( Change|FieldEntries  $caller,
array  $data = [] 
)
Parameters
Change | FieldEntries$caller
array$data

Methods

◆ __toString()

string __toString ( )
Returns
string

◆ _set()

$this _set ( string  $field,
  $value 
)
protected

Values are immutable when the entry belongs to a Change.

Parameters
string$field
mixed$value
Returns
$this

Reimplemented from Data.

◆ _setData()

void _setData ( array  $data)
protected

Strips Asana's redundant CustomField and EnumOption data.

Parameters
array$data
Returns
void

Reimplemented from Data.

◆ getCustomField()

CustomField getCustomField ( )
Returns
CustomField

◆ getDateValue()

magic null Date getDateValue ( )
Returns
null|Date

◆ getDisplayValue()

null string getDisplayValue ( )

Determines the human-readable value in a future-proof way.

If a new value is set, and the entry is for a mapped type, the updated display value is returned.

When the entry is for an unknown type, this attempts to determine it, but may fall back on the upstream display_value, which won't be correct if the value was changed.

If you're getting incorrect display values for object-like entries, you should extend this class and add the new type/s to FieldEntry::MAP.

Returns
null|string

◆ getEnumValue()

magic null EnumOption getEnumValue ( )

For subtype enum

Returns
null|EnumOption

◆ getGid()

magic string getGid ( )

The custom field's GID.

Returns
string

◆ getMultiEnumValues()

magic EnumOption [] getMultiEnumValues ( )

For subtype multi_enum

Returns
EnumOption[]

◆ getNumberValue()

magic null number getNumberValue ( )

For subtype number

Returns
null|number

◆ getPeopleValue()

magic User [] getPeopleValue ( )

For subtype people

Returns
User[]

◆ getRawValue()

null number string array Data Data [] getRawValue ( )
final
Returns
null|number|string|array|Data|Data[]

◆ getResourceSubtype()

magic string getResourceSubtype ( )
Returns
string

◆ getTextValue()

magic null string getTextValue ( )

For subtype text

Returns
null|string

◆ ofDate()

magic bool ofDate ( )
Returns
bool

◆ ofEnum()

magic bool ofEnum ( )
Returns
bool

◆ ofMultiEnum()

magic bool ofMultiEnum ( )
Returns
bool

◆ ofNumber()

magic bool ofNumber ( )
Returns
bool

◆ ofPeople()

magic bool ofPeople ( )
Returns
bool

◆ ofText()

magic bool ofText ( )
Returns
bool

◆ selectMultiEnumValues()

magic EnumOption [] selectMultiEnumValues ( callable  $filter)

fn( EnumOption $option): bool

Returns
EnumOption[]

◆ selectPeopleValue()

magic User [] selectPeopleValue ( callable  $filter)

fn( User $user ): bool

Returns
User[]

◆ setDateValue()

$this setDateValue (   $date)
Parameters
null | string | DateTimeInterface | Date$date
Returns
$this

◆ setEnumValue()

$this setEnumValue (   $value)
Parameters
null | string | EnumOption$valueGID, name, or instance
Returns
$this

◆ setMultiEnumValues()

$this setMultiEnumValues ( array  $values)
Parameters
array<string|EnumOption>$values GIDs, names, or instances
Returns
$this

◆ setNumberValue()

magic $this setNumberValue ( ?number  $number)
Returns
$this

◆ setPeopleValue()

magic $this setPeopleValue ( User[]  $people)
Returns
$this

◆ setTextValue()

magic $this setTextValue ( ?string  $text)
Returns
$this

◆ setValue()

$this setValue (   $value)

Calls the respective setter depending on the entry's type.

Enum values can be set using EnumOption instances, names, or GIDs.

Dates can be set using Date instances, or date-like strings.

All other types must be set with their full representations.

Unmapped objects and object-lists can be given as associative arrays.

Parameters
mixed$value
Returns
$this