Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SyncShortcutController | |
0.00% |
0 / 57 |
|
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 1 |
| sync | |
0.00% |
0 / 57 |
|
0.00% |
0 / 1 |
90 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\v1; |
| 4 | |
| 5 | use DateTime; |
| 6 | use Carbon\Carbon; |
| 7 | use App\Http\Models\Setting; |
| 8 | use Illuminate\Http\Request; |
| 9 | use App\Http\Models\Shortcut; |
| 10 | use App\Http\Models\Auth\User; |
| 11 | use Illuminate\Support\Facades\Log; |
| 12 | use App\Http\Controllers\Controller; |
| 13 | use Illuminate\Support\Facades\Cache; |
| 14 | use App\Http\Models\HubspotProperties; |
| 15 | use Illuminate\Support\Facades\Config; |
| 16 | use App\Http\Helpers\QueryBuilder\RomeoQueryBuilder; |
| 17 | use App\Http\Models\UserInfo; |
| 18 | |
| 19 | class SyncShortcutController extends Controller |
| 20 | { |
| 21 | public function sync(Request $request) |
| 22 | { |
| 23 | $userId = $request->user()->getKey(); |
| 24 | $browser_type = strtolower($request->header('Browser-type')); |
| 25 | |
| 26 | if ($request->header('Browser-type')) { |
| 27 | $browser_type = strtolower($request->header('Browser-type')); |
| 28 | } |
| 29 | |
| 30 | if ($request->header('browser-type')) { |
| 31 | $browser_type = strtolower($request->header('browser-type')); |
| 32 | } |
| 33 | |
| 34 | $userId = $request->user()->getKey(); |
| 35 | $userInfo = UserInfo::where('user_id', $userId)->first(); |
| 36 | |
| 37 | $searchArray = ['user_id' => $userId]; |
| 38 | $setting = Setting::where($searchArray)->first(); |
| 39 | if (!$setting) { |
| 40 | $data = [ |
| 41 | 'user_id' => $userId, |
| 42 | 'shortcut_timeout' => 5000, |
| 43 | 'shortcut_version' => 1.000, |
| 44 | 'blocked_domains' => [], |
| 45 | ]; |
| 46 | Setting::create($data); |
| 47 | $setting = Setting::where($searchArray)->first(); |
| 48 | } |
| 49 | |
| 50 | if ($setting['shortcut_timeout']) { |
| 51 | $syncMap['shortcut_timeout'] = 5000; |
| 52 | } else { |
| 53 | $syncMap['shortcut_timeout'] = 5000; |
| 54 | } |
| 55 | if ($setting['shortcut_version']) { |
| 56 | $syncMap['shortcut_version'] = $setting->shortcut_version; |
| 57 | } else { |
| 58 | $syncMap['shortcut_version'] = 1.000; |
| 59 | } |
| 60 | if ($setting['blocked_domains']) { |
| 61 | $syncMap['blocked_domains'] = $setting->blocked_domains; |
| 62 | } else { |
| 63 | $syncMap['blocked_domains'] = []; |
| 64 | } |
| 65 | |
| 66 | $browser = ucfirst($browser_type); |
| 67 | |
| 68 | if ($userInfo) { |
| 69 | $userInfo->signed_into_flymsg_extension = 'Yes'; |
| 70 | $userInfo->last_browser_used = $browser; |
| 71 | $userInfo->save(); |
| 72 | } |
| 73 | $queryBuilder = new RomeoQueryBuilder(new Shortcut, $request); |
| 74 | $result = $queryBuilder->build()->get(); |
| 75 | foreach ($result as $item) { |
| 76 | $string = str_replace('<p style="margin: 0; padding: 0; counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;"><span style="font-weight: 400;"> </span></p>', '<br>', $item->text); |
| 77 | $string = str_replace('<p style="margin: 0; padding: 0; counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;"> </p>', '<br>', $string); |
| 78 | $string = str_replace('<p style="margin: 0; padding: 0; counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;"> </p>', '<br>', $string); |
| 79 | $string = str_replace('<p style="margin: 0; padding: 0; counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9; background-color: #ffffff;"> </p>', '<br>', $string); |
| 80 | $string = str_replace('<p style="margin: 0; padding: 0; counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9; background-color: #ffffff;">', '', $string); |
| 81 | $string = str_replace('</p>', '<br>', $string); |
| 82 | |
| 83 | // Normal Extra Space. |
| 84 | // $string = str_replace('<div><span', '<span', $string); |
| 85 | // $string = str_replace('</span></div>', '</span>', $string); |
| 86 | |
| 87 | $syncMap['@' . $item->shortcut] = [ |
| 88 | 'id' => $item->id, |
| 89 | 'text' => $string, |
| 90 | 'html' => $item->html, |
| 91 | 'title' => $item->title, |
| 92 | 'shortcut' => $item->shortcut |
| 93 | ]; |
| 94 | } |
| 95 | $result = $syncMap; |
| 96 | // This works as a keys that control the extensions. |
| 97 | $counters = [ |
| 98 | 'Stop_linkedin_tutorial_done' => 0, |
| 99 | 'Stop_gmail_tutorial_done' => 0, |
| 100 | 'Stop_outlook_tutorial_done' => 0, |
| 101 | ]; |
| 102 | // Convert the counters data to JSON format |
| 103 | $result['counters'] = $counters; |
| 104 | |
| 105 | return response()->json($result); |
| 106 | } |
| 107 | } |