improve customer api & gui
This commit is contained in:
40
common/helpers/AppArrayHelper.php
Normal file
40
common/helpers/AppArrayHelper.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace common\helpers;
|
||||
|
||||
|
||||
class AppArrayHelper
|
||||
{
|
||||
|
||||
|
||||
public static function objectArrayToMap($array, $funcGetId, $funcGetValue){
|
||||
$result = [];
|
||||
|
||||
foreach ($array as $item ){
|
||||
$id = $funcGetId($item);
|
||||
$value = $funcGetValue($item);
|
||||
$result[$id] = $value;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map an array of object by object id
|
||||
* [obj1,obj2] => [obj1.id => obj1,obj2.id => obj2]
|
||||
* @param $array
|
||||
* @return array
|
||||
*/
|
||||
public static function objectArrayToMapById($array){
|
||||
return AppArrayHelper::objectArrayToMap(
|
||||
$array,
|
||||
function ($item){
|
||||
return $item->id;
|
||||
},
|
||||
function ($item){
|
||||
return $item;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
16
common/helpers/AppDateTimeHelper.php
Normal file
16
common/helpers/AppDateTimeHelper.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace common\helpers;
|
||||
|
||||
class AppDateTimeHelper
|
||||
{
|
||||
|
||||
public static function convertMySqlDatetimeToPhpInteger($dateString){
|
||||
if (!isset($dateString) || empty($dateString)){
|
||||
return null;
|
||||
}
|
||||
$unixTime = strtotime($dateString . " UTC");
|
||||
return $unixTime;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user