functions.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if(!function_exists('teacherRefNoGenerate')){
  42. function teacherRefNoGenerate(){
  43. $currentId = \DB::table('users')->where('user_type',2)->count();
  44. do{
  45. ++$currentId;
  46. $currentIdExist =\DB::table('users')->where('user_type',2)->where('id',$currentId)->exists();
  47. }while($currentIdExist);
  48. return date('y').intval(date('m')).'00'.$currentId.'R';
  49. }
  50. }
  51. if(!function_exists('name_initials')){
  52. function name_initials($firstName,$lastName){
  53. return strtoupper(mb_substr($firstName, 0, 1) . mb_substr($lastName, 0, 1));
  54. }
  55. }