fixed mb issue on speaker serializer
Change-Id: I7fa612d664d0e320e2b667cc73cf35f6d211eaec
This commit is contained in:
parent
e97e25ea0f
commit
08680e5d46
@ -184,6 +184,11 @@ abstract class AbstractSerializer implements IModelSerializer
|
||||
$value = JsonUtils::toJsonFloat($value);
|
||||
}
|
||||
break;
|
||||
case 'json_obfuscated_email':
|
||||
{
|
||||
$value = JsonUtils::toObfuscatedEmail($value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$new_values[$mapping[0]] = $value;
|
||||
@ -210,7 +215,6 @@ abstract class AbstractSerializer implements IModelSerializer
|
||||
if(strlen($res) > 0) $res .= ',';
|
||||
$res .= explode('.', strtolower(trim($filtered_expand_elem)))[1];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
@ -32,6 +32,18 @@ abstract class JsonUtils
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return string
|
||||
*/
|
||||
public static function toObfuscatedEmail($value){
|
||||
$em = explode("@", $value);
|
||||
$name = implode(array_slice($em, 0, count($em) - 1), '@');
|
||||
$len = floor(mb_strlen($name) / 2);
|
||||
$obfuscated_email = mb_substr($name, 0, $len) . str_repeat('*', $len) . "@" . end($em);
|
||||
return $obfuscated_email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return bool
|
||||
|
@ -36,25 +36,10 @@ abstract class JsonController extends Controller
|
||||
return Response::json(array('message' => 'server error'), 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mixed
|
||||
* @return array|bool|null|string|string[]
|
||||
*/
|
||||
static function utf8ize($mixed) {
|
||||
if (is_array($mixed)) {
|
||||
foreach ($mixed as $key => $value) {
|
||||
$mixed[$key] = self::utf8ize($value);
|
||||
}
|
||||
} elseif (is_string($mixed)) {
|
||||
return mb_convert_encoding($mixed, "UTF-8", "UTF-8");
|
||||
}
|
||||
return $mixed;
|
||||
}
|
||||
|
||||
|
||||
protected function created($data = 'ok')
|
||||
{
|
||||
$res = Response::json(self::utf8ize($data), 201);
|
||||
$res = Response::json($data, 201);
|
||||
//jsonp
|
||||
if (Input::has('callback')) {
|
||||
$res->setCallback(Input::get('callback'));
|
||||
@ -65,7 +50,7 @@ abstract class JsonController extends Controller
|
||||
|
||||
protected function deleted($data = 'ok')
|
||||
{
|
||||
$res = Response::json(self::utf8ize($data), 204);
|
||||
$res = Response::json($data, 204);
|
||||
//jsonp
|
||||
if (Input::has('callback')) {
|
||||
$res->setCallback(Input::get('callback'));
|
||||
@ -76,7 +61,7 @@ abstract class JsonController extends Controller
|
||||
|
||||
protected function updated($data = 'ok', $has_content = true)
|
||||
{
|
||||
$res = Response::json(self::utf8ize($data), $has_content ? 201 : 204);
|
||||
$res = Response::json($data, $has_content ? 201 : 204);
|
||||
//jsonp
|
||||
if (Input::has('callback')) {
|
||||
$res->setCallback(Input::get('callback'));
|
||||
@ -91,7 +76,7 @@ abstract class JsonController extends Controller
|
||||
*/
|
||||
protected function ok($data = 'ok')
|
||||
{
|
||||
$res = Response::json(self::utf8ize($data), 200);
|
||||
$res = Response::json($data, 200);
|
||||
//jsonp
|
||||
if (Input::has('callback')) {
|
||||
$res->setCallback(Input::get('callback'));
|
||||
|
@ -33,26 +33,13 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
|
||||
'FundedTravel' => 'funded_travel:json_boolean',
|
||||
'WillingToTravel' => 'willing_to_travel:json_boolean',
|
||||
'WillingToPresentVideo' => 'willing_to_present_video:json_boolean',
|
||||
'Email' => 'email:json_obfuscated_email',
|
||||
];
|
||||
|
||||
protected static $allowed_relations = [
|
||||
'member',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
* @return null|string|string[]
|
||||
*/
|
||||
protected function getSpeakerEmail(PresentationSpeaker $speaker){
|
||||
$email = $speaker->getEmail();
|
||||
$em = explode("@", $email);
|
||||
$name = implode(array_slice($em, 0, count($em) - 1), '@');
|
||||
$len = floor(strlen($name) / 2);
|
||||
|
||||
$obfuscated_email = substr($name, 0, $len) . str_repeat('*', $len) . "@" . end($em);
|
||||
return $obfuscated_email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $expand
|
||||
* @param array $fields
|
||||
@ -68,7 +55,6 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
|
||||
if(!$speaker instanceof PresentationSpeaker) return [];
|
||||
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$values['email'] = $this->getSpeakerEmail($speaker);
|
||||
$summit_id = isset($params['summit_id'])? intval($params['summit_id']):null;
|
||||
$published = isset($params['published'])? intval($params['published']):true;
|
||||
if(!is_null($summit_id)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user