Example #1
0
 /**
  * @param Request $request
  *
  * @return string
  * @throws NotFoundException
  * @throws \Exception
  */
 public function run(Request $request)
 {
     $repo = new StudyFieldRepository($this->db);
     $study_field = $repo->where('id', '=', $request->get('id'))->findSingle();
     if (!$study_field) {
         throw new NotFoundException('study field not found');
     }
     $repo = new PublicationRepository($this->db);
     $publications = $repo->where('study_field_id', '=', $request->get('id'))->order('date_published', 'DESC')->find();
     $view = new StudyFieldView($study_field, $publications);
     return $view->display();
 }
Example #2
0
 /**
  * @param       $id
  * @param array $data
  *
  * @return int
  */
 public function update($id, array $data)
 {
     /* Fetches the type */
     if (isset($data['type'])) {
         $repo = new TypeRepository($this->db);
         $type = $repo->where('name', '=', $data['type'])->findSingle();
         $data['type_id'] = $type->getId();
         unset($data['type']);
     }
     /* Fetches the study field */
     if (isset($data['study_field'])) {
         $repo = new StudyFieldRepository($this->db);
         $type = $repo->where('name', '=', $data['study_field'])->findSingle();
         $data['study_field_id'] = $type->getId();
         unset($data['study_field']);
     }
     /* If checkbox is unchecked, we do not get a value */
     if (!isset($data['foreign'])) {
         $data['foreign'] = 0;
     }
     $old_db = new OldDatabase();
     return $old_db->updateData('publications', array('id' => $id), $data);
 }