<?php
namespace app\adminVue\controller;

use app\mobile\service\KeyTraining;

class V2Training extends V2Base
{
    protected function initialize()
    {
        parent::initialize();
        if((int)$this->actor['dpt']!==6&&(int)$this->actor['rightid']<99)$this->fail('仅HR或系统管理员可管理培训',403);
    }
    private function run($action)
    {
        try{$s=new KeyTraining();return json(['code'=>0,'msg'=>'成功','data'=>$action($s)]);}
        catch(\RuntimeException $e){$this->fail($e->getMessage());}
    }
    public function options(){return $this->run(function($s){return $s->options();});}
    public function employee(){return $this->run(function($s){return $s->employee($this->request->get('username'));});}
    public function templates(){return $this->run(function($s){return $s->templates($this->request->get('skill_id',0));});}
    public function savetemplate(){return $this->run(function($s){return ['id'=>$s->saveTemplate($this->request->post(),(int)$this->actor['id'])];});}
    public function sorttemplate(){return $this->run(function($s){$s->sortTemplate($this->request->post('id'),$this->request->post('sort'),(int)$this->actor['id']);return null;});}
    public function removetemplate(){return $this->run(function($s){$s->removeTemplate($this->request->post('id'),(int)$this->actor['id']);return null;});}
    public function registrations(){return $this->run(function($s){return $s->registrations($this->request->get());});}
    public function registration(){return $this->run(function($s){return $s->registrationDetail($this->request->get('id'));});}
    public function plans(){return $this->run(function($s){return $s->plans($this->request->get('page',1),$this->request->get('limit',15),$this->request->get('keyword',''));});}
    public function plan(){return $this->run(function($s){return $s->planDetail($this->request->get('id'));});}
    public function saveplan(){return $this->run(function($s){return ['id'=>$s->savePlan($this->request->post(),(int)$this->actor['id'])];});}
    public function publish(){return $this->run(function($s){$s->publish($this->request->post('id'),$this->request->post('version'),(int)$this->actor['id']);return null;});}
    public function course(){return $this->run(function($s){return $s->courseDetail($this->request->get('id'));});}
    public function makeup(){return $this->run(function($s){$s->confirmCourse($this->request->post('id'),$this->request->post('people'),(int)$this->actor['id'],true,$this->request->post('reason'));return null;});}
    public function release(){return $this->run(function($s){$s->release($this->request->post('id'),(int)$this->actor['id'],$this->request->post('reason'));return null;});}
    public function exam(){return $this->run(function($s){return ['id'=>$s->arrangeExam($this->request->post('id'),$this->request->post('exam_at'),(int)$this->actor['id'],$this->request->post('reason'),$this->request->post('exam_item_id',0))];});}
}

