Commit fc557395 by Zen-PC\Zen

Zen : update

parent 7b36c6e8
......@@ -8,73 +8,77 @@ use Cake\Http\Client;
class ProfilesController extends AppController
{
public function index()
{
public function index($id = 13112){
$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');
$http = new Client();
$response = $http->post($api_core_profile,$data,$options)->body();
$response = json_decode($response,'_full');#prr($response);
$Profiles = $response['result']['Data'];
$Profiles['UserProfiles']['organize_id'] = 10;
$Profiles['UserProfiles']['dept_id'] = 10;
#debug($Profiles);
$this->set(compact('Profiles'));
#$this->set('_serialize', ['Profiles']);
#---------------------------------------------------------------------------------------------------------------
$this->loadModel('MasterOrganizations');
@$MasterDepartmentEducations = $this->MasterOrganizations->find('all',
[
'conditions' => ['id' => $Profiles['UserProfiles'][0]['organize_id']],
$this->loadModel('Users');
$responseUserProfile = $this->Users->get($id, [
'contain' => []
]);
$username = $responseUserProfile['username'];
//********DropdownCountry********
$this->loadModel('MasterCountries');
$Country = $this->MasterCountries->find('list', [
'conditions' => [
'is_used' => true],
'keyField' => 'id',
'valueField' => 'org_name_th',
'order' => 'org_name_th asc'
]
);
if(!empty($MasterDepartmentEducations)) $MasterDepartmentEducations = $MasterDepartmentEducations->toArray();
$this->set(compact('MasterDepartmentEducations'));
//debug($MasterDepartmentEducations[0]['org_name_th']);
$this->loadModel('MasterDepartments');
@$MasterDepartments_v = $this->MasterDepartments->find('all',
[
'conditions' => ['id' => $Profiles['UserProfiles'][0]['dept_id']],
'valueField' => 'country_name_th'
]);
if(!empty($Country)) $Country = $Country->toArray();
//********DropdownProvince********
$this->loadModel('MasterProvinces');
$Province = $this->MasterProvinces->find('list', [
'conditions' => [
'is_used' => true],
'keyField' => 'id',
'valueField' => 'dept_name_th',
'order' => 'dept_name_th asc'
]
);
if(!empty($MasterDepartments_v)) $MasterDepartments_v = $MasterDepartments_v->toArray();
$this->set(compact('MasterDepartments_v'));
//debug($MasterDepartments_v);
$this->loadModel('MasterSections');
@$MasterSections_v = $this->MasterSections->find('all',
'valueField' => 'province_name_th'
]);
if(!empty($Province)) $Province = $Province->toArray();
$this->loadModel('UserPersonals');
$responseUserProfile = $this->UserPersonals->get($id, [
'contain' => []
]);
$res = $responseUserProfile['birthdate'];
$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']],
'keyField' => 'id',
'valueField' => 'section_name_th',
'order' => 'section_name_th asc'
'limit' => 1,
'conditions' => [
'user_id' => $data['Users']['user_id']
]
);
if(!empty($MasterSections_v)) $MasterSections_v = $MasterSections_v->toArray();
$this->set(compact('MasterSections_v'));
//debug($MasterSections_v);
]
)->toArray();
$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