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']);
#---------------------------------------------------------------------------------------------------------------
$this->loadModel('MasterOrganizations');
@$MasterDepartmentEducations = $this->MasterOrganizations->find('all',
[
'conditions' => ['id' => $Profiles['UserProfiles'][0]['organize_id']],
'keyField' => 'id', 'keyField' => 'id',
'valueField' => 'org_name_th', 'valueField' => 'country_name_th'
'order' => 'org_name_th asc' ]);
] if(!empty($Country)) $Country = $Country->toArray();
);
if(!empty($MasterDepartmentEducations)) $MasterDepartmentEducations = $MasterDepartmentEducations->toArray(); //********DropdownProvince********
$this->set(compact('MasterDepartmentEducations')); $this->loadModel('MasterProvinces');
//debug($MasterDepartmentEducations[0]['org_name_th']); $Province = $this->MasterProvinces->find('list', [
$this->loadModel('MasterDepartments'); 'conditions' => [
@$MasterDepartments_v = $this->MasterDepartments->find('all', 'is_used' => true],
[
'conditions' => ['id' => $Profiles['UserProfiles'][0]['dept_id']],
'keyField' => 'id', 'keyField' => 'id',
'valueField' => 'dept_name_th', 'valueField' => 'province_name_th'
'order' => 'dept_name_th asc' ]);
] if(!empty($Province)) $Province = $Province->toArray();
);
if(!empty($MasterDepartments_v)) $MasterDepartments_v = $MasterDepartments_v->toArray(); $this->loadModel('UserPersonals');
$this->set(compact('MasterDepartments_v')); $responseUserProfile = $this->UserPersonals->get($id, [
//debug($MasterDepartments_v); 'contain' => []
]);
$this->loadModel('MasterSections'); $res = $responseUserProfile['birthdate'];
@$MasterSections_v = $this->MasterSections->find('all', $dateNow = $res->i18nFormat('dd/MM/yyyy');
if ($this->request->is(['patch', 'post', 'put'])) {
$data = $this->request->data;
// pr($this->request->data);die;
$this->loadModel('UserPersonals');
$userPersonals = $this->UserPersonals->find('all',
[ [
'conditions' => ['id' => $Profiles['UserProfiles'][0]['section_id']], 'limit' => 1,
'keyField' => 'id', 'conditions' => [
'valueField' => 'section_name_th', 'user_id' => $data['Users']['user_id']
'order' => 'section_name_th asc'
] ]
); ]
if(!empty($MasterSections_v)) $MasterSections_v = $MasterSections_v->toArray(); )->toArray();
$this->set(compact('MasterSections_v'));
//debug($MasterSections_v); $birthdate = explode("/", $this->request->data['UserPersonals']['birthdate']);
$birthdate = $birthdate[2].'-'.$birthdate[1].'-'.$birthdate[0];
$userPersonals = $this->UserPersonals->patchEntity($userPersonals[0], $data['UserPersonals']);
$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