functions.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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(){
  66. $currentId = \DB::table('proposal')->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. }