Commit fc557395 by Zen-PC\Zen

Zen : update

parent 7b36c6e8
...@@ -8,73 +8,77 @@ use Cake\Http\Client; ...@@ -8,73 +8,77 @@ use Cake\Http\Client;
class ProfilesController extends AppController class ProfilesController extends AppController
{ {
public function index() public function index($id = 13112){
{
$this->viewBuilder()->layout('blank'); $this->viewBuilder()->layout('blank');
/*******************************/
/*******************************/ /*******************************/
$http = new Client();
$data = [];
$options = ['headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => $this->request->getHeaderLine('Authorization')
#'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1OTI0OSwidXNlcm5hbWUiOiJ0ZXN0dGVzdCIsImlwIjoiMTE2LjU4LjIyNS4yNDgiLCIkdG9waWMiOiJ0ZXN0dGVzdDMzM2Y5MWI5ZjVlMTQzMjlmMWQ2ZTc2MzgwYjhiOWVhIn0.7KwfmevJ--tz0ta5f1O_eDxKSPAjWuAzLSRCNSeWg-g'
#'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1OTI4OCwidXNlcm5hbWUiOiJOYW5hMyIsImlwIjoiMTI3LjAuMC4xIiwiJHRvcGljIjoiTmFuYTNiODAwMjVlNWYyZTUxZDVkMmY0ZTM1Y2E4YWFkNmI1MSJ9.Up1oxsqxWASpOmj9UsAuHISlKArT2EE5NRM0bB2NLIE'
]
];
$api_core_profile = Configure::read('Config.apiCore.profile'); $this->loadModel('Users');
$http = new Client(); $responseUserProfile = $this->Users->get($id, [
$response = $http->post($api_core_profile,$data,$options)->body(); 'contain' => []
$response = json_decode($response,'_full');#prr($response); ]);
$username = $responseUserProfile['username'];
$Profiles = $response['result']['Data'];
$Profiles['UserProfiles']['organize_id'] = 10; //********DropdownCountry********
$Profiles['UserProfiles']['dept_id'] = 10; $this->loadModel('MasterCountries');
#debug($Profiles); $Country = $this->MasterCountries->find('list', [
'conditions' => [
$this->set(compact('Profiles')); 'is_used' => true],
#$this->set('_serialize', ['Profiles']); 'keyField' => 'id',
#--------------------------------------------------------------------------------------------------------------- 'valueField' => 'country_name_th'
$this->loadModel('MasterOrganizations'); ]);
@$MasterDepartmentEducations = $this->MasterOrganizations->find('all', if(!empty($Country)) $Country = $Country->toArray();
[
'conditions' => ['id' => $Profiles['UserProfiles'][0]['organize_id']], //********DropdownProvince********
'keyField' => 'id', $this->loadModel('MasterProvinces');
'valueField' => 'org_name_th', $Province = $this->MasterProvinces->find('list', [
'order' => 'org_name_th asc' 'conditions' => [
] 'is_used' => true],
); 'keyField' => 'id',
if(!empty($MasterDepartmentEducations)) $MasterDepartmentEducations = $MasterDepartmentEducations->toArray(); 'valueField' => 'province_name_th'
$this->set(compact('MasterDepartmentEducations')); ]);
//debug($MasterDepartmentEducations[0]['org_name_th']); if(!empty($Province)) $Province = $Province->toArray();
$this->loadModel('MasterDepartments');
@$MasterDepartments_v = $this->MasterDepartments->find('all', $this->loadModel('UserPersonals');
[ $responseUserProfile = $this->UserPersonals->get($id, [
'conditions' => ['id' => $Profiles['UserProfiles'][0]['dept_id']], 'contain' => []
'keyField' => 'id', ]);
'valueField' => 'dept_name_th', $res = $responseUserProfile['birthdate'];
'order' => 'dept_name_th asc' $dateNow = $res->i18nFormat('dd/MM/yyyy');
]
); if ($this->request->is(['patch', 'post', 'put'])) {
if(!empty($MasterDepartments_v)) $MasterDepartments_v = $MasterDepartments_v->toArray(); $data = $this->request->data;
$this->set(compact('MasterDepartments_v')); // pr($this->request->data);die;
//debug($MasterDepartments_v); $this->loadModel('UserPersonals');
$userPersonals = $this->UserPersonals->find('all',
$this->loadModel('MasterSections'); [
@$MasterSections_v = $this->MasterSections->find('all', 'limit' => 1,
[ 'conditions' => [
'conditions' => ['id' => $Profiles['UserProfiles'][0]['section_id']], 'user_id' => $data['Users']['user_id']
'keyField' => 'id', ]
'valueField' => 'section_name_th', ]
'order' => 'section_name_th asc' )->toArray();
]
); $birthdate = explode("/", $this->request->data['UserPersonals']['birthdate']);
if(!empty($MasterSections_v)) $MasterSections_v = $MasterSections_v->toArray(); $birthdate = $birthdate[2].'-'.$birthdate[1].'-'.$birthdate[0];
$this->set(compact('MasterSections_v')); $userPersonals = $this->UserPersonals->patchEntity($userPersonals[0], $data['UserPersonals']);
//debug($MasterSections_v); $userPersonals['firstname_th'] = $this->request->data['UserPersonals']['firstname_th'];
$userPersonals['lastname_th'] = $this->request->data['UserPersonals']['lastname_th'];
$userPersonals['birthdate'] = $birthdate;
$userPersonals['user_id'] = $data['Users']['user_id'];
$userPersonals['master_country_id'] = $this->request->data['master_country_id'];
$userPersonals['master_province_id'] = $this->request->data['master_province_id'];
$userPersonals['modified_by'] = '';
if ($this->UserPersonals->save($userPersonals)) {
$this->Flash->success(__('The article has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The article could not be saved. Please, try again.'));
}
$this->set(compact('userPersonals', 'responseUserProfile', 'dateNow', 'username', 'Country', 'Province'));
$this->set('_serialize', ['userPersonals', 'responseUserProfile', 'dateNow', 'username', 'Country', 'Province']);
} }
/*****************************************************************************/ /*****************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment