Bulk operations - Jet\DataListing_Operation

Each operation on a data list is created by its own class, which inherits from the Jet\DataListing_Operation abstract class and implements the execution of the operation itself.

Example of a bulk operation to block users of the ManageAccess.Administrators.Users sample application module:

namespace JetApplicationModule\ManageAccess\Administrators\Users;

use 
Jet\DataListing_Operation;
use 
Jet\Logger;
use 
Jet\Tr;

use 
JetApplication\Auth_Administrator_User as User;

class 
Listing_Operation_Block extends DataListing_Operation
{
    public const 
KEY 'block';
    
    public function 
getKey(): string
    
{
        return static::
KEY;
    }
    
    public function 
getTitle(): string
    
{
        return 
Tr::_('Block filtered users');
    }
    
    public function 
perform(): void
    
{
        
$ids $this->listing->getAllIds();

        foreach(
$ids as $id) {
            
$user User::get$id );
            if(
                !
$user ||
                
$user->isBlocked()
            ) {
                continue;
            }
            
            
            
$user->block();
            
$user->save();
            
            
Logger::success(
                
event'admin_blocked',
                
event_message'Administrator '.$user->getUsername().' ('.$user->getId().') has been blocked',
                
context_object_id$user->getId(),
                
context_object_name$user->getUsername()
            );
        }
    }
}

Overview of methods

Method Meaning of
public setListing(
DataListing $listing
) : void
The list automatically sets the operation reference to itself when the operation is passed. This method is used for this purpose.
public getListing(
) : DataListing
Returns the instance of the data list to which the operation belongs.
public getKey(
) : string
Returns a unique key identifying the operation. It is recommended to implement as follows: class Listing_Operation_Block extends Listing_Operation
{
    public const 
KEY 'block';
    
    public function 
getKey(): string
    
{
        return static::
KEY;
    }
}
And the operation can then be handled as follows: $listing->operationListing_Operation_Block::KEY )->perform();
public getTitle(
) : string
Returns the generated and possibly already translated operation title.
public getIcon(
) : string
Can return the name of the operation icon. Optional.
abstract public perform(
) : void
Implementation of the operation.
Previous chapter
Exports - Jet\DataListing_Export
Next chapter
Configuration - SysConf_Jet_DataListing