コード例 #1
0
 /**
  * [update description]
  * @return [type] [description]
  */
 public function update($id = null)
 {
     if (!$id) {
         $id = $this->auth_user_id;
     }
     //Validations
     $this->form_validation->set_rules('name', 'Name', 'required');
     $this->form_validation->set_rules('dob', 'Date of Birth', 'required');
     $this->form_validation->set_rules('skills[]', 'Skills', 'required');
     if (!$this->form_validation->run()) {
         $this->session->set_flashdata('error', validation_errors());
     } else {
         $profile = $this->doctrine->em->getRepository('Entity\\Profiles')->findOneBy(array('user' => $id));
         $actingUser = $this->doctrine->em->getReference('Entity\\Users', $this->auth_user_id);
         if (!$profile) {
             //Add a new profile for user
             $profile = new Entity\Profiles();
             $profile->setUser($actingUser);
         }
         $now = date_create(date('Y-m-d H:i:s'));
         $profile->setName(preg_replace('/\\_/', '', $this->input->post('name')));
         $profile->setDob(date_create(date('Y-m-d H:i:s', strtotime($this->input->post('dob')))));
         $profile->setContactNumber($this->input->post('contact'));
         $profile->setAddress($this->input->post('address'));
         $profile->setCreatedOn($now);
         $this->doctrine->em->persist($profile);
         //Add Skills
         if ($skills = $this->input->post("skills")) {
             foreach ($skills as $skill) {
                 if (!is_numeric($skill)) {
                     //Save new tags
                     $terms = new Entity\Terms();
                     $terms->setTitle($skill);
                     $terms->setStatus(1);
                     $terms->setDescription('');
                     $category = $this->doctrine->em->getReference('Entity\\Categories', 8);
                     $weight = $this->user_model->getMaxWeight($category->getId());
                     $terms->setWeight($weight + 1);
                     $terms->setCategory($category);
                     $terms->setCreatedBy($actingUser);
                     $terms->setCreatedOn(date_create(date('Y-m-d H:i:s')));
                     $this->doctrine->em->persist($terms);
                 } else {
                     $terms = $this->doctrine->em->getRepository('Entity\\Terms')->find($skill);
                 }
                 $exist = $this->doctrine->em->getRepository('Entity\\UserSkills')->findBy(array('term' => $terms->getId(), 'user' => $id));
                 if (!$exist) {
                     //Add Terms in user skills
                     $userSkills = new Entity\UserSkills();
                     $userSkills->setTerm($terms);
                     $userSkills->setUser($actingUser);
                     $this->doctrine->em->persist($userSkills);
                 }
             }
         }
         $this->doctrine->em->flush();
     }
     redirect('user/profile#profile');
 }
コード例 #2
0
 /**
  * [add_term description]
  * @param [type] $cid [description]
  */
 public function add_term($cid)
 {
     $category = $this->doctrine->em->getRepository('Entity\\Categories')->findOneBy(array('id' => $cid));
     //validations
     $this->form_validation->set_rules('title', 'Term name', 'trim|required');
     if (!$this->form_validation->run()) {
         $data['content'] = $this->load->view('admin/add_term', NULL, TRUE);
     } else {
         //Save Terms
         $terms = new Entity\Terms();
         $terms->setTitle($this->input->post('title'));
         $terms->setDescription($this->input->post('description'));
         $status = $this->input->post('status') ? $this->input->post('status') : '0';
         $terms->setStatus($status);
         //Get weights
         $dql = "SELECT MAX(t.weight) AS weight FROM Entity\\Terms t " . "WHERE t.category = ?1";
         $weight = $this->doctrine->em->createQuery($dql)->setParameter(1, $cid)->getSingleScalarResult();
         $terms->setWeight($weight + 1);
         $terms->setCategory($category);
         $createdBy = $this->doctrine->em->getReference('Entity\\Users', $this->auth_user_id);
         $terms->setCreatedBy($createdBy);
         $terms->setCreatedOn(date_create(date('Y-m-d H:i:s')));
         try {
             //save to database
             $this->doctrine->em->persist($terms);
             $this->doctrine->em->flush();
             $this->session->set_flashdata('success', 'Term has been successfully added.');
             redirect('admin/terms/' . $cid);
         } catch (Exception $err) {
             die($err->getMessage());
             $this->session->set_flashdata('warning', 'Some error occured while saving the values, please try again later.');
             redirect('admin/terms/' . $cid);
         }
     }
     $data['title'] = "Add Term";
     $view['title'] = $category->getTitle();
     $view['cid'] = $category->getId();
     $data['content'] = $this->load->view('admin/add_term', $view, TRUE);
     return $this->load->view('html', $data);
 }