Skip to content

Commit

Permalink
Merge pull request #4 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Add Money Helper
  • Loading branch information
nguyenanhung authored Feb 14, 2023
2 parents 8be9ff4 + f3ae77c commit d03737b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 81 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Trong trường hợp tích hợp gói này vào các framework, source khác ng
+ [Image Helper](#image-helper)
+ [IP Helper](#ip-helper)
+ [Meta Helper](#meta-helper)
+ [Money Helper](#money-helper)
+ [NanoID Helper](#nanoid-helper)
+ [Number Helper](#number-helper)
+ [Paging Helper](#paging-helper)
Expand Down Expand Up @@ -208,6 +209,10 @@ Các hàm này dùng debug

- [x] Helper Function: `setupMetaDnsPrefetch` - Hàm hỗ trợ gen ra 1 đoạn HTML Dns Prefetch tương tự `<link href='//data.nguyenanhung.com/' rel='dns-prefetch' />`

### Money Helper

- [x] Helper Function: `money_number_format` - format money currency will detect the current locale

### NanoID Helper

Helper này sử dụng gói `hidehalo/nanoid-php` để gen ra 1 mã random Id nhỏ, nhẹ và an toàn hơn nhiều so với UUID.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"nguyenanhung/html-helper": "^2.0 || ^1.0"
"nguyenanhung/html-helper": "^2.0 || ^1.0",
"nguyenanhung/basic-miscellaneous-helper": "^2.0 || ^1.0"
},
"require-dev": {
"nguyenanhung/image": "^3.0 || ^2.0 || ^1.0"
Expand Down Expand Up @@ -51,6 +52,7 @@
"helpers/image_helper.php",
"helpers/ip_helper.php",
"helpers/meta_helper.php",
"helpers/money_helper.php",
"helpers/nanoid_helper.php",
"helpers/number_helper.php",
"helpers/paging_helper.php",
Expand Down
2 changes: 1 addition & 1 deletion helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
function isEmpty($input = '')
{
if ($input === null || $input === false) {
if ($input === null || $input === false || $input === '') {
return true;
}
$isset = isset($input);
Expand Down
24 changes: 24 additions & 0 deletions helpers/money_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Project codeigniter-basic-helper
* Created by PhpStorm
* User: 713uk13m <[email protected]>
* Copyright: 713uk13m <[email protected]>
* Date: 15/02/2023
* Time: 00:40
*/
if (!function_exists('money_number_format')) {
function money_number_format($input, $showCents = true, $locale = null)
{
if (function_exists('numfmt_create') && function_exists('numfmt_format_currency') && function_exists('locale_get_default')) {
setlocale(LC_MONETARY, $locale ? : locale_get_default());
$numberOfDecimalPlaces = $showCents ? 2 : 0;
$formatter = numfmt_create('en_US', NumberFormatter::CURRENCY);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $numberOfDecimalPlaces);

return numfmt_format_currency($formatter, $input, trim(localeconv()['int_curr_symbol']));
}

return $input;
}
}
4 changes: 2 additions & 2 deletions src/BaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
class BaseHelper
{
const VERSION = '1.1.9.2';
const LAST_MODIFIED = '2023-02-14';
const VERSION = '1.2.0';
const LAST_MODIFIED = '2023-02-15';
const AUTHOR_NAME = 'Hung Nguyen';
const AUTHOR_EMAIL = '[email protected]';
const PROJECT_NAME = 'CodeIgniter - Basic Helper';
Expand Down
80 changes: 9 additions & 71 deletions src/ChartRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,84 +10,22 @@

namespace nguyenanhung\CodeIgniter\BasicHelper;

/**
* Class ChartRender
*
* @package nguyenanhung\CodeIgniter\BasicHelper
* @author 713uk13m <[email protected]>
* @copyright 713uk13m <[email protected]>
*/
use nguyenanhung\Libraries\Basic\Miscellaneous\Miscellaneous;

class ChartRender extends BaseHelper
{
/**
* Function get_data_chart
*
* @param $item_list
* @param $valueGet
* @param $total
*
* @return string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/11/2021 26:39
*/
public function get_data_chart($item_list, $valueGet, $total)
protected function misc()
{
$dataChart = '';
if (count($item_list) > 0) {
$dataChart .= '[';
foreach ($item_list as $key => $value) {
$dataChart .= '{' . '"country" : ' . '"' . $value->$valueGet . '", ';
$dataChart .= '"visits" : ' . $value->sl . ', ';
$dataChart .= '"color" : ' . '"#FF9E01"';
if ($key === count($item_list) - 1) {
$dataChart .= '}';
} else {
$dataChart .= '}, ';
}
}
if ($total) {
$dataChart .= ', {"country" : "Total", "visits" : ' . $total . ', "color" : "#0D52D1" }';
}
$dataChart .= ']';
} else {
$dataChart = '[]';
}
return new Miscellaneous();
}

return $dataChart;
public function get_data_chart($item_list, $valueGet, $total)
{
return $this->misc()->metronic_get_data_chart($item_list, $valueGet, $total);
}

/**
* Function get_data_chart_report
*
* @param $item_list
* @param $valueGet
*
* @return string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/11/2021 26:43
*/
public function get_data_chart_report($item_list, $valueGet)
{
$dataChart = '';
if (count($item_list) > 0) {
$dataChart .= '[';
foreach ($item_list as $key => $value) {
$dataChart .= '{' . '"country" : ' . '"' . date('d-m-Y', strtotime($value->date)) . '", ';
$dataChart .= '"visits" : ' . $value->$valueGet . ', ';
$dataChart .= '"color" : ' . '"#FF9E01"';
if ($key === count($item_list) - 1) {
$dataChart .= '}';
} else {
$dataChart .= '}, ';
}
}
$dataChart .= ']';
} else {
$dataChart = '[]';
}

return $dataChart;
return $this->misc()->metronic_get_data_chart_report($item_list, $valueGet);
}
}
12 changes: 6 additions & 6 deletions src/SimpleCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* @author 713uk13m <[email protected]>
* @copyright 713uk13m <[email protected]>
*/
class SimpleCurl extends BaseHelper
final class SimpleCurl extends BaseHelper
{
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36';
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36';
protected $url;
protected $data;
protected $followLocation;
Expand All @@ -36,21 +36,21 @@ class SimpleCurl extends BaseHelper
protected $json;
protected $post;
protected $postFields;
protected $referer = "";
protected $referer = "";
protected $session;
protected $webpage;
protected $headers;
protected $headerOut;
protected $includeHeader;
protected $noBody;
protected $status;
protected $isError = false;
protected $isError = false;
protected $error;
protected $binaryTransfer;
protected $userOptions;
protected $authentication = 0;
protected $authUsername = '';
protected $authPassword = '';
protected $authUsername = '';
protected $authPassword = '';

/**
* SimpleCurl constructor.
Expand Down

0 comments on commit d03737b

Please sign in to comment.