public function action_url($table_name) { // Find class name and metadata etc $class_name = \Admin::getClassForTable($table_name); if ($class_name === false) { return $this->show404(null, "type"); } // Import the data $this->import_result = \CMF\Utils\Importer::importUrl($class_name, \Input::post('import_url')); // If success, redirect back with message if (isset($this->import_result['success']) && $this->import_result['success']) { \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.messages.import_success'))); \Response::redirect("/admin/{$table_name}", 'location'); } // No success, damn! \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-danger'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.errors.actions.import'))); \Response::redirect_back("/admin/{$table_name}"); }
/** * Processes an action on the item from the $_actions array */ public function action_action($table_name, $id, $action_id) { // Find class name and metadata etc $class_name = \Admin::getClassForTable($table_name); \Admin::setCurrentClass($class_name); if ($class_name === false) { return $this->customPageOr404(array($table_name, $action_id), "type"); } // Load up the model with the Id $model = $class_name::find($id); if (is_null($model)) { \Response::redirect("/admin/{$table_name}", 'location'); } $actions = $class_name::actions(); if (!isset($actions[$action_id])) { return $this->customPageOr404(array($table_name, $action_id), "page"); } $action = $actions[$action_id]; $type = \Arr::get($action, 'type'); switch ($type) { case 'method': // Call a method on the model... $method = "action_" . \Arr::get($action, 'method', $action_id); $result = null; $error = null; try { $result = $model->{$method}($table_name); } catch (\Exception $e) { $error = $e->getMessage(); } if (!is_null($error)) { \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-danger'), 'msg' => $error)); } else { \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => $result)); } $redirect = \Input::referrer("/admin/{$table_name}/{$id}"); \Response::redirect($redirect, 'location'); break; default: return $this->customPageOr404(array($table_name, $action_id), "page"); break; } }
/** * Gets the options in JSON format for when populating a select2 box */ public function action_options($table_name) { $class_name = \Admin::getClassForTable($table_name); if ($class_name === false) { return $this->show404(null, "type"); } // Check and see if we need to filter the results... $filters = array(); $params = array(); $find = \Input::param('find', false); if ($find !== false) { $ids = explode(',', $find); $filters[] = 'id IN(?1)'; $params[] = $ids; } $options = $class_name::options($filters, array(), null, null, $params); // Get the options and put them in a format select2 would understand $output = array(); foreach ($options as $id => $option) { $output[] = array('id' => $id, 'text' => $option); } $this->headers = array("Content-Type: application/json"); return \Response::forge(json_encode($output), $this->status, $this->headers); }