1. Список говнокодов пользователя lemax

    Всего: 1

  2. PHP / Говнокод #19851

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    public function get($userId = null, $advense = false) {
            
            if ($userId === null) $userId = $this->currentId;
            
            $user = DB::table('users')
                    ->select(
                            '*',
                            DB::raw('IF(email IS NOT NULL AND email_confirm IS NULL, 1, 0) AS email_confirm'),
                            DB::raw('IF(phone IS NOT NULL AND phone_confirm IS NULL, 1, 0) AS phone_confirm'),
                            DB::raw('IF(birthday IS NOT NULL, TIMESTAMPDIFF(YEAR,birthday,CURDATE()), NULL) AS age'),
                            DB::raw('IF(phone IS NOT NULL AND phone_confirm IS NULL AND email IS NOT NULL AND email_confirm IS NULL AND (new_first_name IS NOT NULL OR new_last_name IS NOT NULL OR new_status_text IS NOT NULL OR new_image_url IS NOT NULL), 1, 0) AS on_moderate'))
                    ->where('id', $userId)->first();
            
            if ($user === null) throw new Exception ('User is not found', 404);
            unset($user->password);
            $user->locality           = Geo::get($user->locality_id);
            $rating = $this->rating($userId);
            $user->rating           = (float)$rating->avg;
            $user->rating_counter   = (int)$rating->cnt;
            $user->counters        = $this->getCounters($userId);
    
            
            $contact = $this->contacts->isMyContact($userId);
            if ($userId != $this->currentId) {
                $user->created = null;
                $user->updated = null;
                $user->birthday = null;
                $user->email_confirm = null;
                $user->phone_confirm = null;
                $user->subscribed = null;
                $user->organizations = null;
                $contact = $this->contacts->isMyContact($userId);
                // Если пользователь не контакт авторизованного, сотрем контактную информацию
                if ( $contact === null || $contact === 'declined') {
                    $user->phone = null;
                    $user->email = null;
                    $user->last_name = mb_substr($user->last_name, 0, 1, 'UTF-8');
                }
                
            } else {
                if($user->new_first_name !== null) {
                    $user->first_name = $user->new_first_name;
                }
                if($user->new_last_name !== null) {
                    $user->last_name = $user->new_last_name;
                }
                if($user->new_image_url !== null) {
                    $user->image_url = $user->new_image_url;
                }
                if($user->new_status_text !== null) {
                    $user->status_text = $user->new_status_text;
                }
                $user->organizations = Organizations\Organizations::getByUserId($userId);
                $user->is_followed     = null;
                $user->is_my_contact   = null;
                $user->has_my_contact  = null;
                $user->has_my_opinion  = null;
            }
            unset($user->new_status_text);
            unset($user->new_image_url);
            unset($user->new_last_name);
            unset($user->new_first_name);
            unset($user->reset_code);
    
            
            $user->is_followed     = $this->followers->isFollowed($userId);
            $user->is_my_contact   = $this->contacts->isMyContact($userId);
            $user->has_my_contact  = $this->contacts->hasMyContact($userId);
            return $user;
            
        }

    Тыдыдыдыдыыыц, laravel code О_О
    Что же тут вообще происходит?

    lemax, 20 Апреля 2016

    Комментарии (10)