/**
  * { delete }
  *
  * @param     
  * 1. id
  * 2. org_id
  * 3. input name
  * 4. input address
  * 5. input email
  * 6. input phone
  *
  * @return
  * 1. response
  * 
  * steps
  * 1. validate
  * 2. get data
  * 3. post to API
  * 4. return response
  */
 public function delete($org_id = null, $employee = null, $id = null)
 {
     //1. validate
     if (is_null($org_id)) {
         App::abort(403, 'Id Organisasi tidak ada');
     }
     //2. get data
     $APIEmployee = new APIEmployee();
     $data = $APIEmployee->getShow($org_id, $employee)['data'];
     foreach ($data['works'] as $key => $value) {
         if ($value['id'] == $id) {
             unset($data['works'][$key]);
         }
     }
     if (empty($data['works'])) {
         $data['works'] = null;
     }
     //3. post to API
     $APIEmployee = new APIEmployee();
     $result = $APIEmployee->postData($org_id, $data);
     //4. return response
     if ($result['status'] != 'success') {
         $this->errors = $result['message'];
     }
     $this->page_attributes->msg = "Data Pekerjaan Telah Dihapus";
     return $this->generateRedirectRoute('org.show', ['id' => $org_id]);
 }
示例#2
0
 /**
  * { postImport }
  *
  * @param     
  * 1. id
  * 2. org_id
  * 3. input name
  * 4. input address
  * 5. input email
  * 6. input phone
  *
  * @return
  * 1. response
  * 
  * steps
  * 1. get input
  * 2. post data
  * 3. return response
  */
 public function postImport()
 {
     //1. get input
     $input = Input::file('employee');
     if (!Input::hasFile('employee')) {
         $this->errors = 'TIdak ada data import';
     } else {
         $input = Excel::load($input)->toArray();
         $data = [];
         foreach ($input as $key => $value) {
             foreach ($value as $key2 => $value2) {
                 if (preg_match('/profile_/', $key2)) {
                     $data[$key]['profile'][str_replace('profile_', '', $key2)] = $value2;
                 } elseif (preg_match('/work_/', $key2)) {
                     $data[$key]['work'][str_replace('work_', '', $key2)] = $value2;
                 } elseif (preg_match('/relatives_/', $key2)) {
                     $real_data = str_replace('relatives_', '', $key2);
                     $index = explode('_content_', $real_data);
                     $title = str_replace($index[0] . '_content_', '', $real_data);
                     $data[$key]['relatives'][$index[0]][$title] = $value2;
                 } elseif (preg_match('/document_/', $key2)) {
                     $real_data = str_replace('document_', '', $key2);
                     $index = explode('_content_', $real_data);
                     $title = str_replace($index[0] . '_content_', '', $real_data);
                     $data[$key]['document'][$index[0]][$title] = $value2;
                 }
             }
         }
         //2. post data
         $APIEmployee = new APIEmployee();
         $result = $APIEmployee->postImportTemplate($data);
         //4. return response
         if ($result['status'] != 'success') {
             $this->errors = $result['message'];
         }
     }
     $this->page_attributes->msg = "Data Karyawan Telah Ditambahkan";
     return $this->generateRedirectRoute('org.index');
 }