| Version | Date | Notes | By |
|---|---|---|---|
| 0.1 | 2018-10-23 | Initial release | ROB |
This system is designed to group together all the actions a user has to perform throughout the various modules and alert the user of the need to perform them. As this is a relatively new system, this is implemented by adding the correct traits / contracts to the backend models that represent such actions. Then, a controller + frontend interface display this to the user.
This model must implement the IsActionContract and have the trait IsAction. The contract in particular will require certain actions be implemented:
/**
* Retrieves the name of the artifact of which this action is a part of
* (example plan actions should return the string (translated) 'Plan')
*
* @return mixed
*/
public function getOwningArtifactNameAttribute()
{
return trans('artifact.occurrence');
}
/**
* Retrieves the designation of the artifact of which this action is a part of
* (example plan actions should return the string code + name)
*
* @return mixed
*/
public function getOwningArtifactDesignationAttribute()
{
return $this->occurrence->code;
}
/**
* Retrieves the designation of the artifact of which this action is a part of
* (example plan actions should return the string code + name)
*
* @return mixed
*/
public function getActionDesignationAttribute()
{
return $this->number . ' - ' . $this->description;
}
/**
* Function that gets an array fit for feeding to the select function on a query builder. Use
* for providing users with action lists
*
* @return array Array of selectable
*/
public static function getActionDesignationSelect()
{
/*
This is required to be implemented as the results for all actions for all modules will be displayed through an sql union
*/
return [
't02_actions.id as unioned_action_id',
't02_actions.description as action_description',
't02_actions.occurrence_id as owning_artifact_id',
't02_actions.status_id',
't02_actions.action_type_id as action_type_id',
't02_actions.deadline as expected_end_date',
't02_actions.efficiency_analysis_deadline as actual_end_date',
\DB::raw('\'' . str_replace('\\','\\\\',self::class) . '\' as unioned_action_type') // this is for the acbin morph
];
}
/**
* Acts similar to Model::query() but adds whatever additional eloquent query operations are necessary
* to filter the result to just the actions the user is responsible for completing
*
* @param QueryBuilder|null - Pointer to a query builder, if not provided, assume fresh query from model
* @param int|string $user_id - User to find actions responsible for
*
* @return EloquentQueryBuilder - Query already with the conditions for finding the applicable actions applied
*/
public function scopeResponsible($query, $user_id)
{
return $query
->where('assign_to','=',$user_id);
}
/**
* gets an array with all the users / groups responsible for this action
*
* @return Collection - responsible users / groups
*/
public function getActionResponsiblesAttribute()
{
return collect([$this->assignedUser]);
}
/**
* gets the action type
*
* @return ActionType - Core model for action types
*/
public function getActionTypeAttribute()
{
return $this->type;
}
/**
* gets the expected end date for the attribute
*
* @return string
*/
public function getExpectedActionEndDateAttribute()
{
return $this->deadline;
}
/**
* gets the actual end date for the attribute
*
* @return string
*/
public function getActualActionEndDateAttribute()
{
return $this->efficiency_analysis_deadline;
}
/**
* Returns the name of the frontend route where this action may be resolved
* (combine with id in transformer and it just works)
*
* @return string - route name
*/
public function getFrontendRouteNameAttribute()
{
return 'occurrences.personal-area.my-actions.edit';
}