main
This commit is contained in:
Executable
+260
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: AraNote
|
||||
* Date: 29/04/2018
|
||||
* Time: 04:38 PM
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait Selector
|
||||
{
|
||||
static $formatJ = 'Y/n/j-H:i';
|
||||
static $formatBJ = 'Y/n/j';
|
||||
static $SELECT_CUJ = [
|
||||
'created_at as caj',
|
||||
'updated_at as uaj',
|
||||
];
|
||||
|
||||
public static $DATE_FORMAT = 'Y/m/d - h:i';
|
||||
public static $BIRTHDAY_FORMAT = 'Y/m/d';
|
||||
static $SELECT_CAJ = 'created_at as caj';
|
||||
static $SELECT_DAJ = 'date_at as daj';
|
||||
static $SELECT_VAJ = 'vision_at as vaj';
|
||||
static $SELECT_EAJ = 'end_at as eaj';
|
||||
static $SELECT_SAJ = 'start_at as saj';
|
||||
static $SELECT_BIRTH_DAY_J = 'birth_date as bdj';
|
||||
static $SELECT_MARRIAGE_DATE_J = 'marriage_date as mdj';
|
||||
static $SELECT_STS_STR = 'sts as sts_str';
|
||||
static $SELECT_TYPE_STR = 'type as type_str';
|
||||
static $SELECT_USER_TYPE_STR = 'user_type as user_type_str';
|
||||
static $SELECT_GENDER_STR = 'gender as gender_str';
|
||||
static $SELECT_TYPE_SEND_STR = 'type_send as type_send_str';
|
||||
static $SELECT_PAYMENT_TYPE_STR = 'payment_type as payment_type_str';
|
||||
|
||||
public static $MAP_COLUMNS = [
|
||||
'caj' => "created_at",
|
||||
'daj' => 'date_at',
|
||||
'eaj' => 'end_at',
|
||||
'saj' => 'start_at',
|
||||
'bdj' => 'birth_date',
|
||||
'mdj' => 'marriage_date',
|
||||
'vaj' => 'vision_at',
|
||||
'type_str' => "type",
|
||||
'user_type_str' => "user_type",
|
||||
'sts_str' => "sts",
|
||||
'gender_str' => "gender",
|
||||
'type_send_str' => "type_send",
|
||||
'payment_type_str' => "payment_type",
|
||||
];
|
||||
//created_at
|
||||
public function getCreatedAtJAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return null;
|
||||
return Verta::instance($value)->format(self::$DATE_FORMAT);
|
||||
}
|
||||
public function getCajAttribute($value)
|
||||
{
|
||||
return $this->convertDate($value);
|
||||
}
|
||||
|
||||
// ------------------start_at----------------------------------
|
||||
public function getStartAtJAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return null;
|
||||
return Verta::instance($value)->format(self::$DATE_FORMAT);
|
||||
}
|
||||
public function getSajAttribute($value)
|
||||
{
|
||||
return $this->convertDate($value);
|
||||
}
|
||||
|
||||
// ----------------------date_at--------------------------------
|
||||
public function getDateJAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return null;
|
||||
return Verta::instance($value)->format(self::$BIRTHDAY_FORMAT);
|
||||
}
|
||||
public function getdajAttribute($value)
|
||||
{
|
||||
return $this->convertDateB($value);
|
||||
}
|
||||
|
||||
// ----------------------birthday_at----------------------------------
|
||||
public function getBirthDateJAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return null;
|
||||
return Verta::instance($value)->format(self::$BIRTHDAY_FORMAT);
|
||||
}
|
||||
public function getBdjAttribute($value)
|
||||
{
|
||||
return $this->convertDateB($value);
|
||||
}
|
||||
|
||||
// ----------------------marriage_date----------------------------------
|
||||
public function getMarriageDateJAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return null;
|
||||
return Verta::instance($value)->format(self::$BIRTHDAY_FORMAT);
|
||||
}
|
||||
public function getMdjAttribute($value)
|
||||
{
|
||||
return $this->convertDateB($value);
|
||||
}
|
||||
// -------------------vision_at---------------------------------------
|
||||
public function getVisionAtJAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return null;
|
||||
return Verta::instance($value)->format(self::$DATE_FORMAT);
|
||||
}
|
||||
public function getVajAttribute($value)
|
||||
{
|
||||
return $this->convertDate($value);
|
||||
}
|
||||
|
||||
// --------------------------end_at-------------------------------------------
|
||||
public function getEndAtJAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return null;
|
||||
return Verta::instance($value)->format(self::$DATE_FORMAT);
|
||||
}
|
||||
public function getEajAttribute($value)
|
||||
{
|
||||
return $this->convertDate($value);
|
||||
}
|
||||
|
||||
// -------------------------type_str----------------------------------------
|
||||
public function getTypeStrAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return $value;
|
||||
|
||||
return Arr::get(self::$TYPES, $value, 'تعریف نشده');
|
||||
}
|
||||
static function GetTypes($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
return Arr::get(self::$TYPES, $value, 'بدون مقدار');
|
||||
}
|
||||
|
||||
// -------------------------payment_type_str----------------------------------------
|
||||
public function getPaymentTypeStrAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return $value;
|
||||
|
||||
return Arr::get(self::$PAYMENT_TYPE, $value, 'تعریف نشده');
|
||||
}
|
||||
static function GetPaymentTypes($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
return Arr::get(self::$PAYMENT_TYPE, $value, 'بدون مقدار');
|
||||
}
|
||||
|
||||
// ----------------------------user_type_str-------------------------------
|
||||
public function getUserTypeStrAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return $value;
|
||||
$cnt = Cnt::select('value')->findOrFail($value)->pluck('value')->toArray();
|
||||
|
||||
return Arr::get($cnt, $value, 'تعریف نشده');
|
||||
}
|
||||
static function GetUserType($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
return Arr::get(config('userType'), $value, 'بدون مقدار');
|
||||
}
|
||||
|
||||
// -------------------------------sts_str-----------------------------
|
||||
static function GetSts($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
return Arr::get(self::$STS, $value, 'بدون مقدار');
|
||||
}
|
||||
public function getStsStrAttribute($value)
|
||||
{
|
||||
return self::GetSts($value);
|
||||
}
|
||||
// -------------------------gender_str----------------------------------------
|
||||
public function getGenderStrAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return $value;
|
||||
|
||||
return Arr::get(self::$GENDER, $value, 'تعریف نشده');
|
||||
}
|
||||
static function GetGender($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
return Arr::get(self::$GENDER, $value, 'بدون مقدار');
|
||||
}
|
||||
//---------------------type_send str--------------------------------------
|
||||
public function getTypeSendStrAttribute($value)
|
||||
{
|
||||
if (is_null($value)) return $value;
|
||||
|
||||
return Arr::get(self::$TYPE_SEND, $value, 'تعریف نشده');
|
||||
}
|
||||
static function GetTypeSend($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
return Arr::get(self::$TYPE_SEND, $value, 'بدون مقدار');
|
||||
}
|
||||
|
||||
|
||||
|
||||
static function selectWithjDate()
|
||||
{
|
||||
return array_merge(['*'], self::$SELECT_CUJ);
|
||||
}
|
||||
protected function convertDate($value, $format = NULL, $farsi = TRUE)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return NULL;
|
||||
}
|
||||
if (is_null($format)) {
|
||||
$format = self::$formatJ;
|
||||
}
|
||||
return Verta::instance($value)->format($format, $farsi);
|
||||
}
|
||||
protected function convertDateB($value, $format = NULL, $farsi = TRUE)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return NULL;
|
||||
}
|
||||
if (is_null($format)) {
|
||||
$format = self::$formatBJ;
|
||||
}
|
||||
return Verta::instance($value)->format($format, $farsi);
|
||||
}
|
||||
|
||||
|
||||
public function convertColumns($key){
|
||||
|
||||
return Arr::get(self::$MAP_COLUMNS , $key , $key);
|
||||
}
|
||||
|
||||
// public function getUserTypeStrAttribute(){
|
||||
// if (is_null($this->attributes['user_type'])) return null;
|
||||
// return Arr::get(config('userType') , $this->attributes['user_type'] , 'تعریف نشده');
|
||||
// }
|
||||
|
||||
|
||||
public static function deleteUrl($src){
|
||||
return substr($src,strlen(\request()->root())+1,strlen($src));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user