Activity Global Grid Advanced Configuration
VIEW THE TITLE OF THE ENTITY TO WHICH THE WORK TASK IS ASSOCIATED
Some fields already present in the Work Activities may contain useful and convenient information to be displayed in the grid, in which, however, a brief configuration is required to make them actually usable.
In fact, we can see that if we want to view the contract or the contract line to which a work activity has been associated and we make the fields already available visible in the grid, some numbers will be displayed which will represent the ID of the relative entities.
To be able, for example, to view the name of the contract associated with a work activity, it is necessary first to go to the modification of the grid and make the Contract column visible.
It will then be necessary to click on the field just made visible and make a change on the type by setting it from Text to Options.
By pressing the </> key you can define custom PHP code for each column and change the printed value (Renderer) or change the options of a Field of type Options (Options).
In the Options field you will then need to enter the following custom code:
// retreive of the Contract collection
$contractCollection = Deep::getResourceModel('deep_contract/contract_collection');
// convert the collection into an associative array
// the key is the Contract Id and the value the Contract Name
$optionsArray = $contractCollection->toOptionHash();
return $optionsArray;
Similarly, to view the name of the contract line associated with a work activity it is necessary to make the Contract Line field visible, change its type in Options and within the Options field to define custom code insert the following code.
// retreive of the Contract Line collection
$lineCollection = Deep::getResourceModel('deep_contract/line_collection');
// convert the collection into an associative array
// the key is the Contract Line Id and the value the Contract Line Name
$optionsArray = $lineCollection->toOptionHash();
return $optionsArray;
At this point we may display the names of Contracts and Lines of Contracts that have been associated with the related work activities. We can also make these fields multifilterable and sortable.
MASS ACTION CONFIGURATION
It can often be helpful to set the same value to multiple tasks. In these cases, the use of mass actions is effective.
At the moment, the only massive action already prepared by the system in the grid of work activities is that for the (physical) elimination of one or more activities.
You can still configure a custom massive action by accessing the grid change. Below the Mass Action checkbox is the </> button that allows the opening of the custom PHP script area.
The following example shows the custom code that implements a massive custom action to enable or disable the visibility in the portal of one or more work activities.
The code must be inserted directly into the custom PHP script area.
// create the array for the option visibility
$visibilityArray = [0 => 'No', 1 => 'Yes'];
// initialize html component
$this->addMassActionItem('visibility', [
'label' => 'Visible to Frontend',
'additional' => array(
'visibility' => array(
'name' => 'visibility',
'type' => 'select',
'class' => 'required-entry',
'label' => 'Visible to Frontend',
'disable_js_select' => true,
'values' => $visibilityArray,
)
),
//callback is the method that contains the logic of the action
'callback' => function() {
/** @var Deep_Grid_Model_Grid_Massaction_Callback $this */
/** @var Mage_Core_Model_Resource_Db_Collection_Abstract $collection */
$collection = $this->getGrid()->getModelInstance()->getCollection();
//$this->getIds() returns the id of the selected activities
$collection->addFieldToFilter('entity_id', ['in' => $this->getIds()]);
// $collection contains the instances of the selected activities and we iterate on them
foreach($collection as $activity){
//$this->getValue() contains the id of the new option visibility, the selected one
//set the new activity visibility
$activity->setPortalVisibility($this->getValue());
//save the activity
$activity->save();
}
}
]);