functions.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. function dDate($date=NULL, $format='d M Y', $default='N/A'){
  3. if(empty($format)) $format='d M Y';
  4. if(empty($date)) return $default;
  5. return date($format, strtotime($date));
  6. }
  7. function cn($object, $string, $if_false="N/A"){
  8. $properties=explode('.', $string);
  9. foreach($properties as $property){
  10. if(empty($object->$property)) return $if_false;
  11. else{
  12. $object=$object->$property;
  13. }
  14. }
  15. if(empty($object)) return $if_false;
  16. return $object;
  17. }
  18. function no_img($url='assets/img/placeholder.png'){
  19. return asset($url);
  20. }
  21. function model($name){
  22. return "\\App\\Models\\{$name}";
  23. }
  24. function default_avatar($path="assets/img/avatar-2-64.png"){
  25. return asset($path);
  26. }
  27. function nf($value, $decimal=2){
  28. if(empty($value)) $value=0.00;
  29. return number_format($value, $decimal);
  30. }
  31. function die_log($value){
  32. die(\Log::info($value));
  33. }
  34. function fDate($date, $format='d-m-Y'){
  35. if(empty($date)) return '';
  36. return \Carbon\Carbon::parse($date)->format($format);
  37. }
  38. // function auth_user(){
  39. // return \Auth::user();
  40. // }
  41. function auth_user($guard='teacher'){
  42. return \Auth::guard($guard)->user();
  43. }
  44. if(!function_exists('teacherRefNoGenerate')){
  45. function teacherRefNoGenerate(){
  46. $currentId = \DB::table('users')->where('user_type',2)->count();
  47. do{
  48. ++$currentId;
  49. $currentIdExist =\DB::table('users')->where('user_type',2)->where('id',$currentId)->exists();
  50. }while($currentIdExist);
  51. return date('y').intval(date('m')).str_pad($currentId, 3, "0", STR_PAD_LEFT).'R';
  52. }
  53. }
  54. if(!function_exists('studentRefNoGenerate')){
  55. function studentRefNoGenerate(){
  56. $currentId = \DB::table('student_proposals')->count();
  57. do{
  58. ++$currentId;
  59. $currentIdExist =\DB::table('student_proposals')->where('id',$currentId)->exists();
  60. }while($currentIdExist);
  61. return date('y').intval(date('m')).str_pad($currentId, 2, "0", STR_PAD_LEFT);
  62. }
  63. }
  64. if(!function_exists('proposalRefNoGenerate')){
  65. function proposalRefNoGenerate($student_id){
  66. $currentId = \DB::table('proposal')->where('student_id',$student_id)->count();
  67. do{
  68. ++$currentId;
  69. $currentIdExist =\DB::table('proposal')->where('id',$currentId)->exists();
  70. }while($currentIdExist);
  71. return str_pad($currentId, 3, "10", STR_PAD_LEFT);
  72. }
  73. }
  74. if(!function_exists('name_initials')){
  75. function name_initials($firstName,$lastName){
  76. return strtoupper(mb_substr($firstName, 0, 1) . mb_substr($lastName, 0, 1));
  77. }
  78. }
  79. if(!function_exists('student_proposal')){
  80. function student_proposal($std_id,$pro_id){
  81. $apply_checked = \App\StudentProposal::where('student_id',$std_id)->where('proposal_id',$pro_id)->exists();
  82. if($apply_checked){
  83. return FALSE;
  84. }
  85. return TRUE;
  86. }
  87. }
  88. if(!function_exists('profile_permission')){
  89. function profile_permission($std_id){
  90. $apply_checked = \App\StudentProposal::where('student_id',$std_id)->exists();
  91. if($apply_checked){
  92. return FALSE;
  93. }
  94. return TRUE;
  95. }
  96. }
  97. function local_tz(\App\User $user=NULL, $default='UTC'){
  98. if(empty($user)) $user=\Auth::user();
  99. if($user && $user->last_timezone){
  100. return $user->last_timezone;
  101. }
  102. return $default;
  103. }
  104. function utc_to_ltz($time_str, $format='d M Y g:i A', $tz=NULL){
  105. if(empty($tz)) $tz=local_tz();
  106. return \Carbon\Carbon::parse(
  107. $time_str
  108. )->setTimezone($tz)->format($format);
  109. }
  110. function lt_to_utc($time_str, $tz='Asia/Dhaka'){
  111. return \Carbon\Carbon::parse(
  112. $time_str, $tz
  113. )->setTimezone('UTC');
  114. }
  115. if(!function_exists('age_calculator')){
  116. function age_calculator($birthday=NULL){
  117. return \Carbon\Carbon::parse($birthday)->diff(\Carbon\Carbon::now())->format('%y years, %m months');
  118. }
  119. // %y years, %m months and %d days
  120. }
  121. if(!function_exists('work_experience')){
  122. function work_experience($start_date =NULL,$end_date =NULL){
  123. $start_date = new DateTime($start_date);
  124. $end_date = new DateTime($end_date);
  125. $interval = $start_date->diff($end_date);
  126. return $interval->format('%y years');
  127. }
  128. }
  129. if(!function_exists('diff_in_days')){
  130. function diff_in_days($sd, $ed){
  131. $c=new \Carbon\Carbon;
  132. if(is_string($sd)) $sd=$c->parse($sd);
  133. if(is_string($ed)) $ed=$c->parse($ed);
  134. return $sd->diffInDays($ed, FALSE);
  135. }
  136. }
  137. if(!function_exists('res_msg')){
  138. function res_msg(String $msg, Int $code=200, Array $data=NULL){
  139. return response(['msg'=>$msg, 'data'=>$data], $code);
  140. }
  141. }