Files
piratepoet/lib/Listing/BulkAction.php
Jonathan Labreuille 3c46a5b434 Optimized Bulk actions
- Updated SQL schema for every created_at column so that it has a default value
- Updated unit tests based on recent changes (new methods in SubscriberSegment model)
- Added check for HelpScout initialization code so that it doesn't throw errors
2016-05-27 14:15:46 +02:00

39 lines
918 B
PHP

<?php
namespace MailPoet\Listing;
if(!defined('ABSPATH')) exit;
class BulkAction {
private $listing = null;
private $action = null;
private $data = null;
private $model_class = null;
function __construct($model_class, $data) {
$this->action = $data['action'];
unset($data['action']);
$this->data = $data;
$this->model_class = $model_class;
$this->listing = new Handler(
$model_class,
$this->data['listing']
);
return $this;
}
function apply() {
$bulk_action_method = 'bulk'.ucfirst($this->action);
if(!method_exists($this->model_class, $bulk_action_method)) {
throw new Exception(
$this->model_class. ' has not method "'.$bulk_action_method.'"'
);
return false;
}
return call_user_func_array(
array($this->model_class, $bulk_action_method),
array($this->listing->getSelection(), $this->data)
);
}
}