View source
<?php
class slickgrid_editors {
var $plugin;
var $field_name;
var $entity_type;
var $entities = array();
var $errors = array();
var $updated = array();
var $output;
var $field_id;
var $view_name;
var $display_id;
var $error_callback;
function __construct($plugin) {
$this->plugin = $plugin;
$this->entity_type = $_POST['entity_type'];
$this->entities = entity_load($this->entity_type, $_POST['entity_ids']);
$this->field_name = $_POST['field_name'];
$this->field_id = $_POST['field_id'];
$this->view = $_POST['view'];
$this->display_id = $_POST['display_id'];
if (function_exists($this->plugin['error'])) {
$this->error_callback = $this->plugin['error'];
}
}
function update() {
if (function_exists($this->plugin['process'])) {
$this->plugin['process']($this);
}
return $this
->get_result();
}
function set_error($id, $error, $op = 'validate') {
$this->errors[$id] = t('%title can not be edited: @error', array(
'%title' => $this->entities[$id]->title,
'@error' => $error,
));
unset($this->entities[$id]);
if (isset($this->error_callback)) {
call_user_func_array($this->error_callback, array(
$id,
$this->errors[$id],
$op,
));
}
}
function set_updated($id, $vid) {
$this->updated[$id] = array(
'vid' => $vid,
);
}
function get_result() {
if (count($this->updated)) {
$view = slickgrid_get_view($this->view, $this->display_id, array_keys($this->updated));
foreach ($view->result as $count => $row) {
if (isset($this->updated[$row->{$view->base_field}])) {
$this->updated[$row->{$view->base_field}]['value'] = $view
->render_field($this->field_id, $count);
}
}
}
drupal_get_messages();
if ($count_updated = count($this->updated)) {
drupal_set_message(format_plural($count_updated, 'One item was updated succesfully.', '@count items were updated succesfully.'));
}
if ($count_errors = count($this->errors)) {
$message = format_plural($count_errors, 'Update failed: there was an error', 'Update failed: There were @count errors.');
$message .= theme('item_list', array(
'items' => $this->errors,
));
drupal_set_message($message, 'error');
}
return array(
'errors' => $this->errors,
'updated' => $this->updated,
'field_id' => $this->field_id,
'op' => 'update',
);
}
}