123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <?php
- function dDate($date=NULL, $format='d M Y', $default='N/A'){
- if(empty($format)) $format='d M Y';
- if(empty($date)) return $default;
- return date($format, strtotime($date));
- }
- function cn($object, $string, $if_false="N/A"){
- $properties=explode('.', $string);
- foreach($properties as $property){
- if(empty($object->$property)) return $if_false;
- else{
- $object=$object->$property;
- }
- }
- if(empty($object)) return $if_false;
- return $object;
- }
- function no_img($url='assets/img/placeholder.png'){
- return asset($url);
- }
- function model($name){
- return "\\App\\Models\\{$name}";
- }
- function default_avatar($path="assets/img/avatar-2-64.png"){
- return asset($path);
- }
- function nf($value, $decimal=2){
- if(empty($value)) $value=0.00;
- return number_format($value, $decimal);
- }
- function die_log($value){
- die(\Log::info($value));
- }
- function fDate($date, $format='d-m-Y'){
- if(empty($date)) return '';
- return \Carbon\Carbon::parse($date)->format($format);
- }
- // function auth_user(){
- // return \Auth::user();
- // }
- function auth_user($guard='teacher'){
- return \Auth::guard($guard)->user();
- }
- if(!function_exists('teacherRefNoGenerate')){
- function teacherRefNoGenerate(){
- $currentId = \DB::table('users')->where('user_type',2)->count();
- do{
- ++$currentId;
- $currentIdExist =\DB::table('users')->where('user_type',2)->where('id',$currentId)->exists();
- }while($currentIdExist);
- return date('y').intval(date('m')).str_pad($currentId, 3, "0", STR_PAD_LEFT).'R';
- }
- }
- if(!function_exists('studentRefNoGenerate')){
- function studentRefNoGenerate(){
- $currentId = \DB::table('student_proposals')->count();
- do{
- ++$currentId;
- $currentIdExist =\DB::table('student_proposals')->where('id',$currentId)->exists();
- }while($currentIdExist);
- return date('y').intval(date('m')).str_pad($currentId, 2, "0", STR_PAD_LEFT);
- }
- }
- if(!function_exists('proposalRefNoGenerate')){
- function proposalRefNoGenerate($student_id){
- $currentId = \DB::table('proposal')->where('student_id',$student_id)->count();
- do{
- ++$currentId;
- $currentIdExist =\DB::table('proposal')->where('id',$currentId)->exists();
- }while($currentIdExist);
- return str_pad($currentId, 3, "10", STR_PAD_LEFT);
- }
- }
- if(!function_exists('name_initials')){
- function name_initials($firstName,$lastName){
- return strtoupper(mb_substr($firstName, 0, 1) . mb_substr($lastName, 0, 1));
- }
- }
- if(!function_exists('student_proposal')){
- function student_proposal($std_id,$pro_id){
- $apply_checked = \App\StudentProposal::where('student_id',$std_id)->where('proposal_id',$pro_id)->exists();
- if($apply_checked){
- return FALSE;
- }
- return TRUE;
- }
- }
- if(!function_exists('profile_permission')){
- function profile_permission($std_id){
- $apply_checked = \App\StudentProposal::where('student_id',$std_id)->exists();
- if($apply_checked){
- return FALSE;
- }
- return TRUE;
- }
- }
- function local_tz($user=NULL, $default='UTC'){
- if(empty($user)) $user=\Auth::user();
- if($user && $user->last_logged_timezone){
- return $user->last_logged_timezone;
- }
- return $default;
- }
- function utc_to_ltz($time_str, $format='d M Y g:i A', $tz=NULL){
- if(empty($tz)) $tz=local_tz();
- return \Carbon\Carbon::parse(
- $time_str
- )->setTimezone($tz)->format($format);
- }
- function lt_to_utc($time_str, $tz='Asia/Dhaka'){
- return \Carbon\Carbon::parse(
- $time_str, $tz
- )->setTimezone('UTC');
- }
- if(!function_exists('age_calculator')){
- function age_calculator($birthday=NULL){
- return \Carbon\Carbon::parse($birthday)->diff(\Carbon\Carbon::now())->format('%y years, %m months');
- }
- // %y years, %m months and %d days
- }
- if(!function_exists('work_experience')){
- function work_experience($start_date =NULL,$end_date =NULL){
- $start_date = new DateTime($start_date);
- $end_date = new DateTime($end_date);
- $interval = $start_date->diff($end_date);
- return $interval->format('%y years');
- }
- }
- if(!function_exists('diff_in_days')){
- function diff_in_days($sd, $ed){
- $c=new \Carbon\Carbon;
- if(is_string($sd)) $sd=$c->parse($sd);
- if(is_string($ed)) $ed=$c->parse($ed);
- return $sd->diffInDays($ed, FALSE);
- }
- }
- if(!function_exists('res_msg')){
- function res_msg(String $msg, Int $code=200, Array $data=NULL){
- return response(['msg'=>$msg, 'data'=>$data], $code);
- }
- }
- function active($url, $active_class="active"){
- $current_url=url()->current();
- if(is_string($url) && $current_url==$url){
- return $active_class;
- }elseif(is_array($url) && in_array($current_url, $url)){
- return $active_class;
- }
- }
-
|