Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
smart_core_connect
/
core-connect
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7b36c6e8
authored
May 14, 2018
by
Zen-PC\Zen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZEN : Update Data
parent
9765bb8e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
107 deletions
+139
-107
www/src/Controller/UserprofilesController.php
+57
-25
www/src/Model/Table/UserPersonalsTable.php
+47
-47
www/src/Model/Table/UserProfilesTable.php
+35
-35
No files found.
www/src/Controller/UserprofilesController.php
View file @
7b36c6e8
...
...
@@ -102,38 +102,70 @@ class UserProfilesController extends AppController {
//// debug($userProfiles);
// }
// exit;
// $data = $this->request->data;
// $UserPersonal = $this->UserProfiles->UserPersonals->find('first', [
// 'conditions' => [
// 'UserPersonals.user_id' => $data['Users']['user_id']
// ]
// ]);
// pr($UserPersonal);die;
if
(
$this
->
request
->
is
([
'patch'
,
'post'
,
'put'
]))
{
$data
=
$this
->
request
->
data
;
// debug($this->request->data);
// exit;
$data
=
$this
->
request
->
data
;
//pr($data);
list
(
$data
[
'UserPersonals'
][
'firstname_th'
],
$data
[
'UserPersonals'
][
'lastname_th'
])
=
explode
(
' '
,
$data
[
'UserPersonals'
][
'fullname'
]);
unset
(
$data
[
'UserPersonals'
][
'fullname'
]);
$data
[
'UserPersonals'
][
'birthdate'
]
=
''
;
$data
[
'UserPersonals'
][
'user_id'
]
=
$data
[
'Users'
][
'user_id'
];
$data
[
'UserPersonals'
][
'modified_by'
]
=
''
;
$data
[
'UserProfiles'
][
0
][
'user_id'
]
=
$data
[
'Users'
][
'user_id'
];
$data
[
'UserProfiles'
][
0
][
'user_type_id'
]
=
1
;
$data
[
'UserProfiles'
][
0
][
'modified_by'
]
=
''
;
$data
[
'UserProfiles'
][
1
][
'user_id'
]
=
$data
[
'Users'
][
'user_id'
];
$data
[
'UserProfiles'
][
1
][
'user_type_id'
]
=
2
;
$data
[
'UserProfiles'
][
1
][
'modified_by'
]
=
''
;
// pr($data);
$this
->
loadModel
(
'UserPersonals'
);
$userPersonals
=
$this
->
UserPersonals
->
find
(
'all'
,
[
'limit'
=>
1
,
'conditions'
=>
[
'user_id'
=>
$data
[
'Users'
][
'user_id'
]
]
]
)
->
toArray
();
// pr($userPersonals);
// pr($data['UserPersonals']);
// $userPersonals = $this->UserPersonals->newEntity();
$userPersonals
=
$this
->
UserPersonals
->
patchEntity
(
$userPersonals
[
0
],
$data
[
'UserPersonals'
]);
#prr($userPersonals);
list
(
$userPersonals
[
'firstname_th'
],
$userPersonals
[
'lastname_th'
])
=
explode
(
' '
,
$data
[
'UserPersonals'
][
'fullname'
]);
unset
(
$userPersonals
[
'fullname'
]);
$userPersonals
[
'birthdate'
]
=
'2000-01-01'
;
$userPersonals
[
'user_id'
]
=
$data
[
'Users'
][
'user_id'
];
$userPersonals
[
'modified_by'
]
=
''
;
// $userPersonals['modified'] = '2018-01-01 00:00:00';
// pr($userPersonals->toArray());die;
// debug($this->UserPersonals->save($userPersonals));die;
if
(
$this
->
UserPersonals
->
save
(
$userPersonals
))
{
//pr($userPersonals->toArray());die;
}
// $data['UserProfiles'][0]['user_id'] = $data['Users']['user_id'];
// $data['UserProfiles'][0]['user_type_id'] = 1;
// $data['UserProfiles'][0]['modified_by'] = '';
// $data['UserProfiles'][1]['user_id'] = $data['Users']['user_id'];
// $data['UserProfiles'][1]['user_type_id'] = 2;
// $data['UserProfiles'][1]['modified_by'] = '';
// debug($data);
// exit;
#$api_update_profile = 'http://connect06.pakgon.com/api/Connects/Profile/updateProfile';
$api_update_profile
=
Configure
::
read
(
'Config.apiCore.profile'
)
.
'/updateProfile'
;
$http
=
new
Client
();
//
$api_update_profile = Configure::read('Config.apiCore.profile') . '/updateProfile';
//
$http = new Client();
// $data = [];
$options
=
[
'headers'
=>
[
'Content-Type'
=>
'application/x-www-form-urlencoded'
,
#'Authorization' => $this->request->getHeaderLine('Authorization')
//'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1OTIzMCwidXNlcm5hbWUiOiJ0ZXN0dG9uZyIsImlwIjoiMTI3LjAuMC4xIn0.37hXRDEhiwjsgqR8mcgbhxnKtAof3tIDahL2P6DnQ4I'
'Authorization'
=>
'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1OTI4NywidXNlcm5hbWUiOiJOYW5hMiIsImlwIjoiOjoxIiwidG9waWMiOiJOYW5hMmI5OTQxMWE2NDExYTRhOTlhZmI5MWRhMjM3MTJjNDQ2In0.u3OdN5QzI_dvI9KfKYojjVXfcnvTcmHz9LM0XHXvwU8'
]
];
#
prr($options);
$response
=
$http
->
post
(
$api_update_profile
,
$data
,
$options
)
->
body
();
//
pr($response);
$response
=
json_decode
(
$response
,
'_full'
);
//
$options = ['headers' => [
//
'Content-Type' => 'application/x-www-form-urlencoded',
//
#'Authorization' => $this->request->getHeaderLine('Authorization')
//
//'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1OTIzMCwidXNlcm5hbWUiOiJ0ZXN0dG9uZyIsImlwIjoiMTI3LjAuMC4xIn0.37hXRDEhiwjsgqR8mcgbhxnKtAof3tIDahL2P6DnQ4I'
//
'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1OTI4NywidXNlcm5hbWUiOiJOYW5hMiIsImlwIjoiOjoxIiwidG9waWMiOiJOYW5hMmI5OTQxMWE2NDExYTRhOTlhZmI5MWRhMjM3MTJjNDQ2In0.u3OdN5QzI_dvI9KfKYojjVXfcnvTcmHz9LM0XHXvwU8'
//
]
//
];
//
prr($options);
//
$response = $http->post($api_update_profile, $data, $options)->body();
//
pr($response);
//
$response = json_decode($response, '_full');
// pr($response);
// die;
}
...
...
www/src/Model/Table/UserPersonalsTable.php
View file @
7b36c6e8
...
...
@@ -40,9 +40,9 @@ class UserPersonalsTable extends Table {
$this
->
addBehavior
(
'Timestamp'
);
$this
->
belongsTo
(
'MasterPrefixes'
,
[
'foreignKey'
=>
'master_prefix_id'
]);
//
$this->belongsTo('MasterPrefixes', [
//
'foreignKey' => 'master_prefix_id'
//
]);
$this
->
belongsTo
(
'Users'
,
[
'foreignKey'
=>
'user_id'
]);
...
...
@@ -55,63 +55,63 @@ class UserPersonalsTable extends Table {
* @return \Cake\Validation\Validator
*/
public
function
validationDefault
(
Validator
$validator
)
{
$validator
->
allowEmpty
(
'id'
,
'create'
);
//
$validator
//
->allowEmpty('id', 'create');
$validator
->
scalar
(
'person_card_no'
)
->
requirePresence
(
'person_card_no'
,
'create'
)
->
notEmpty
(
'person_card_no'
);
//
$validator
//
->scalar('person_card_no')
//
->requirePresence('person_card_no', 'create')
//
->notEmpty('person_card_no');
$validator
->
scalar
(
'firstname_th'
)
->
allowEmpty
(
'firstname_th'
);
//
$validator
//
->scalar('firstname_th')
//
->allowEmpty('firstname_th');
$validator
->
scalar
(
'lastname_th'
)
->
allowEmpty
(
'lastname_th'
);
//
$validator
//
->scalar('lastname_th')
//
->allowEmpty('lastname_th');
$validator
->
scalar
(
'firstname_en'
)
->
allowEmpty
(
'firstname_en'
);
//
$validator
//
->scalar('firstname_en')
//
->allowEmpty('firstname_en');
$validator
->
scalar
(
'lastname_en'
)
->
allowEmpty
(
'lastname_en'
);
//
$validator
//
->scalar('lastname_en')
//
->allowEmpty('lastname_en');
$validator
->
scalar
(
'gender'
)
->
allowEmpty
(
'gender'
);
//
$validator
//
->scalar('gender')
//
->allowEmpty('gender');
$validator
->
date
(
'birthdate'
)
->
allowEmpty
(
'birthdate'
);
//
$validator
//
->date('birthdate')
//
->allowEmpty('birthdate');
$validator
->
scalar
(
'moblie_no'
)
->
allowEmpty
(
'moblie_no'
);
//
$validator
//
->scalar('moblie_no')
//
->allowEmpty('moblie_no');
$validator
->
scalar
(
'phone_no'
)
->
allowEmpty
(
'phone_no'
);
//
$validator
//
->scalar('phone_no')
//
->allowEmpty('phone_no');
$validator
->
email
(
'email'
)
->
allowEmpty
(
'email'
);
//
$validator
//
->email('email')
//
->allowEmpty('email');
$validator
->
allowEmpty
(
'created_by'
);
//
$validator
//
->allowEmpty('created_by');
$validator
->
allowEmpty
(
'modified_by'
);
//
$validator
//
->allowEmpty('modified_by');
$validator
->
scalar
(
'blood_group'
)
->
allowEmpty
(
'blood_group'
);
//
$validator
//
->scalar('blood_group')
//
->allowEmpty('blood_group');
$validator
->
scalar
(
'address'
)
->
allowEmpty
(
'address'
);
//
$validator
//
->scalar('address')
//
->allowEmpty('address');
return
$validator
;
}
...
...
@@ -125,7 +125,7 @@ class UserPersonalsTable extends Table {
*/
public
function
buildRules
(
RulesChecker
$rules
)
{
$rules
->
add
(
$rules
->
isUnique
([
'email'
]));
$rules
->
add
(
$rules
->
existsIn
([
'master_prefix_id'
],
'MasterPrefixes'
));
//
$rules->add($rules->existsIn(['master_prefix_id'], 'MasterPrefixes'));
$rules
->
add
(
$rules
->
existsIn
([
'user_id'
],
'Users'
));
return
$rules
;
...
...
www/src/Model/Table/UserProfilesTable.php
View file @
7b36c6e8
...
...
@@ -79,52 +79,52 @@ class UserProfilesTable extends Table
*/
public
function
validationDefault
(
Validator
$validator
)
{
$validator
->
allowEmpty
(
'id'
,
'create'
);
//
$validator
//
->allowEmpty('id', 'create');
$validator
->
scalar
(
'card_code'
)
->
maxLength
(
'card_code'
,
20
)
->
allowEmpty
(
'card_code'
);
//
$validator
//
->scalar('card_code')
//
->maxLength('card_code', 20)
//
->allowEmpty('card_code');
$validator
->
scalar
(
'img_path'
)
->
maxLength
(
'img_path'
,
255
)
->
allowEmpty
(
'img_path'
);
//
$validator
//
->scalar('img_path')
//
->maxLength('img_path', 255)
//
->allowEmpty('img_path');
$validator
->
boolean
(
'is_used'
)
->
requirePresence
(
'is_used'
,
'create'
)
->
notEmpty
(
'is_used'
);
//
$validator
//
->boolean('is_used')
//
->requirePresence('is_used', 'create')
//
->notEmpty('is_used');
$validator
->
requirePresence
(
'created_by'
,
'create'
)
->
notEmpty
(
'created_by'
);
//
$validator
//
->requirePresence('created_by', 'create')
//
->notEmpty('created_by');
$validator
->
allowEmpty
(
'modified_by'
);
//
$validator
//
->allowEmpty('modified_by');
$validator
->
allowEmpty
(
'position_org'
);
//
$validator
//
->allowEmpty('position_org');
$validator
->
allowEmpty
(
'position_edu'
);
//
$validator
//
->allowEmpty('position_edu');
$validator
->
date
(
'enter_date'
)
->
allowEmpty
(
'enter_date'
);
//
$validator
//
->date('enter_date')
//
->allowEmpty('enter_date');
$validator
->
scalar
(
'address'
)
->
maxLength
(
'address'
,
255
)
->
allowEmpty
(
'address'
);
//
$validator
//
->scalar('address')
//
->maxLength('address', 255)
//
->allowEmpty('address');
$validator
->
scalar
(
'phone_no'
)
->
maxLength
(
'phone_no'
,
30
)
->
allowEmpty
(
'phone_no'
);
//
$validator
//
->scalar('phone_no')
//
->maxLength('phone_no', 30)
//
->allowEmpty('phone_no');
return
$validator
;
//
return $validator;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment