Ejemplo n.º 1
0
 /**
  * 記事の追加
  *
  * @param string $id
  * @throws NotFoundException
  */
 private function __add($id = null)
 {
     if (!$id) {
         throw new NotFoundException(__('不正なアクセス'));
     }
     // セレクトボックスを持つため
     $this->loadModel('Topic');
     // セレクトボックスは配列で1:値、2:画面表示で配列を持つ
     $this->set('seletopics', $this->Topic->find('list', array('fields' => array('id', 'topicname'))));
     // Topic_idへ記事を作成するトピックIDを選択
     $this->set('topic_id', $id);
     if ($this->request->is('post')) {
         // 			debug($this->request->data);
         // 			throw new NotFoundException();
         $this->Post->create();
         // throw Exceptino;
         // ポストのユーザIDへログイン中のユーザIDを持たせる
         $this->request->data['Post']['user_id'] = $this->Auth->user('id');
         // POSTされたデータは$this->request->dataに入ってる
         try {
             if ($this->Post->createWithAttachments($this->request->data)) {
                 //debug($this->Post->getLastInsertID());
                 // 通知処理
                 $RM = new ReadManagementsController();
                 $RM->createWithTeacherRM($this->Post->getLastInsertID(), 'Post', $this->Auth->user('id'));
                 $this->Session->setFlash(__('投稿が保存されました。'));
                 return $this->redirect(array('action' => 'lists', $id));
             }
             $this->Session->setFlash(__('投稿を追加できません。'));
         } catch (Exception $e) {
             $this->Session->setFlash($e->getMessage());
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * レポートの追加は生徒のみ行えるよ
  *
  * @return void
  * @param id これは所属する課題ID
  */
 public function add($id = null)
 {
     if (!$id) {
         throw new NotFoundException(__('課題エラー'));
     }
     // 課題の引数が間違えてる場合はダメ
     $this->loadModel('Assignment');
     if (!$this->Assignment->exists($id)) {
         throw new NotFoundException(__('課題エラー'));
     }
     if ($this->request->is('post')) {
         //  			debug($this->request->data);
         //  			throw new NotFoundException();
         //$this->Report->create ();
         if ($this->Report->createWithAttachments($this->request->data)) {
             // 通知処理
             $RM = new ReadManagementsController();
             $RM->createWithStudentRM($this->Report->getLastInsertID(), 'Report', $this->Auth->user('id'));
             $this->Session->setFlash(__('課題の提出を行いました。'));
             return $this->redirect(array('action' => 'index', $id));
         } else {
             $this->Session->setFlash(__('提出ができませんでした。再試行してください。'));
         }
     }
     $this->Assignment->recursive = 0;
     $this->set('assignment', $this->Assignment->find('first', array('conditions' => array('Assignment.id' => $id))));
 }