add contraint , that everybody expect admin is limited to 3 days, Add card package
This commit is contained in:
@@ -5,6 +5,88 @@ namespace common\components;
|
||||
use \Yii;
|
||||
|
||||
class Helper {
|
||||
|
||||
public static function isStartDateToEarly($days_between){
|
||||
$days_visiblity = Helper::getReceptionVisibilityDays();
|
||||
// $days_between = $this->calcStartDaysSinceToday();
|
||||
return $days_between > $days_visiblity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $start the date string, format "datetime => "Y-m-d H:i", "date => "Y-m-d"
|
||||
* */
|
||||
public static function calcStartDatimeDaysSinceToday($start, $format = "datetime" ){
|
||||
$now = time();
|
||||
|
||||
if ( $format == "datetime"){
|
||||
$format = "Y-m-d H:i";
|
||||
}else if ( $format == "date") {
|
||||
$format = "Y-m-d";
|
||||
}else{
|
||||
//use format
|
||||
}
|
||||
|
||||
$d = \DateTime::createFromFormat( $format , $start)->getTimeStamp();
|
||||
$days_between = ceil(abs( $now - $d) / 86400 );
|
||||
|
||||
return $days_between;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Leellenőriz egy dátumot. Ha az aktuális felhasználó nem admin,
|
||||
* akkor a params[reception_visibility_days] napnál korábbi , vagy null
|
||||
* dátumot e params-ban megadott dátumra állítjuk
|
||||
*
|
||||
*
|
||||
* */
|
||||
public static function restrictIfNotAdminTheStartDate($query,$date, $fields = ['transfer.paid_at','transfer.created_at'], $format = 'datetime'){
|
||||
$result = null;
|
||||
|
||||
|
||||
$needFix = false;
|
||||
if ( !isset($date) || empty($date)){
|
||||
$needFix = true;
|
||||
}else {
|
||||
$days = Helper::calcStartDatimeDaysSinceToday($date,$format);
|
||||
if ( Helper::isStartDateToEarly($days)){
|
||||
$needFix = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $needFix == true ){
|
||||
$d = Helper::getReceptionVisibilityDays();
|
||||
|
||||
$time = date( "Y-m-d H:i:s", strtotime("today -$d day") );
|
||||
|
||||
$conditions = [];
|
||||
|
||||
foreach ($fields as $f ){
|
||||
$conditions[] = ['>=', $f, $time];
|
||||
}
|
||||
|
||||
|
||||
if ( count($conditions) > 1 ){
|
||||
$andWhereCond = [];
|
||||
$andWhereCond[0] = "or";
|
||||
$i = 1;
|
||||
foreach ($conditions as $c){
|
||||
$andWhereCond[$i] = $c;
|
||||
$i++;
|
||||
}
|
||||
}else if ( count($conditions) == 1 ){
|
||||
$andWhereCond = $conditions[0];
|
||||
}
|
||||
|
||||
// $start_date_condition = ['or',[ '>=', 'transfer.created_at', $time ] ,[ '>=', 'transfer.paid_at', $time] ];
|
||||
if ( isset($andWhereCond)){
|
||||
$query->andWhere( $andWhereCond );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getDateTimeString( ){
|
||||
|
||||
@@ -173,16 +255,27 @@ class Helper {
|
||||
public static function isUserCartVisibilityUser() {
|
||||
return \Yii::$app->params ['user_cart_item_visibility'] == 'user';
|
||||
}
|
||||
|
||||
public static function isCompanyMovar() {
|
||||
return \Yii::$app->params ['company'] == 'movar';
|
||||
}
|
||||
|
||||
public static function isProductVisibilityAccount() {
|
||||
return \Yii::$app->params ['product_visiblity'] == 'account';
|
||||
}
|
||||
|
||||
public static function isAccountStateClosePreloadMoney() {
|
||||
return \Yii::$app->params ['account_state_close_preload_money'] == true;
|
||||
}
|
||||
|
||||
public static function isAccountStateOpenSendMail() {
|
||||
return \Yii::$app->params ['mail_account_state_open'] == true;
|
||||
}
|
||||
|
||||
public static function isAccountStateCloseSendMail() {
|
||||
return \Yii::$app->params ['mail_account_state_close'] == true;
|
||||
}
|
||||
|
||||
public static function getReceptionVisibilityDays() {
|
||||
return \Yii::$app->params ['reception_visibility_days'] ;
|
||||
}
|
||||
@@ -237,5 +330,15 @@ class Helper {
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) {
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user