00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 class StatusCommandsController extends ControllerBase {
00011
00012
00013
00014 public function get_routes() {
00015 return array(
00016 new CommandsRoute('https://process_commands/{model:s}/{id:ui>}/status/{newstatus:s}', $this, 'status_cmd_handler'),
00017 );
00018 }
00019
00020 public function action_status_cmd_handler(PageData $page_data, $model, $id, $newstatus) {
00021 $dao = DB::create($model);
00022 if (empty($dao)) {
00023
00024 return CONTROLLER_NOT_FOUND;
00025 }
00026 $arr_id = explode(GYRO_COMMAND_ID_SEP, $id);
00027 foreach ($dao->get_table_keys() as $key => $field) {
00028 $dao->$key = array_shift($arr_id);
00029 }
00030
00031 if ($dao->find(IDataObject::AUTOFETCH) != 1) {
00032
00033 return CONTROLLER_NOT_FOUND;
00034 }
00035
00036 $cmd = CommandsFactory::create_command($dao, 'status', $newstatus);
00037 if (!$cmd->can_execute(false)) {
00038 return CONTROLLER_ACCESS_DENIED;
00039 }
00040
00041 $status = $cmd->execute();
00042 if ($status->is_ok()) {
00043 $status = new Message(tr('The status has been changed', 'status'));
00044 }
00045 History::go_to(0, $status);
00046 exit;
00047 }
00048 }