public function __construct() { parent::__construct(); if (!(($id = $this->uri->rsegments(3, 0)) && (is_numeric($id) ? $this->tag = WorkTag::find_by_id($id) : ($this->tag = WorkTag::find_by_name(trim(urldecode($id))))))) { return redirect_message(array('works'), array('_flash_message' => '找不到該筆資料。')); } if (in_array($this->uri->rsegments(2, 0), array('edit', 'update', 'destroy', 'sort'))) { if (!(($id = $this->uri->rsegments(4, 0)) && ($this->work = Work::find_by_id($id)))) { return redirect_message(array('works', $this->tag->id, 'works'), array('_flash_message' => '找不到該筆資料。')); } } $this->add_js(resource_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'jquery.timeago.js'))->add_js(resource_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'locales', 'jquery.timeago.zh-TW.js')); }
public function __construct() { parent::__construct(); if (!(($id = $this->uri->rsegments(3, 0)) && ($this->tag = WorkTag::find_by_id($id)))) { return redirect_message(array('admin', 'work_tags'), array('_flash_message' => '找不到該筆資料。')); } if (in_array($this->uri->rsegments(2, 0), array('edit', 'update', 'destroy', 'sort'))) { if (!(($id = $this->uri->rsegments(4, 0)) && ($this->work = Work::find_by_id($id)))) { return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works'), array('_flash_message' => '找不到該筆資料。')); } } $this->add_param('class', 'work_tags')->add_tab('標籤列表', array('href' => base_url($this->tag->work_tag_id ? array('admin', 'work_tags', $this->tag->work_tag_id, 'tags') : array('admin', 'work_tags')), 'index' => 1))->add_tab('作品列表', array('href' => base_url('admin', 'works'), 'index' => 2))->add_tab('新增作品', array('href' => base_url('admin', 'work_tags', $this->tag->id, 'works', 'add'), 'index' => 3)); }
public function is_enabled($id = 0) { if (!($id && ($work = Work::find_by_id($id, array('select' => 'id, is_enabled, updated_at'))))) { return $this->output_json(array('status' => false, 'message' => '當案不存在,或者您的權限不夠喔!')); } $posts = OAInput::post(); if ($msg = $this->_validation_is_enabled_posts($posts)) { return $this->output_json(array('status' => false, 'message' => $msg, 'content' => Work::$enableNames[$work->is_enabled])); } if ($columns = array_intersect_key($posts, $work->table()->columns)) { foreach ($columns as $column => $value) { $work->{$column} = $value; } } $update = Work::transaction(function () use($work) { return $work->save(); }); if (!$update) { return $this->output_json(array('status' => false, 'message' => '更新失敗!', 'content' => Work::$enableNames[$work->is_enabled])); } $this->_clean_cell($work); return $this->output_json(array('status' => true, 'message' => '更新成功!', 'content' => Work::$enableNames[$work->is_enabled])); }