zalazdi

Untitled

Mar 8th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.49 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Entities\ApiKey;
  6. use App\Events\ApiKeyActionlog;
  7.  
  8. use Illuminate\Http\Request;
  9. use App\Http\Requests;
  10. use App\Services\ApiKeyService;
  11.  
  12. class ApiKeyController extends Controller
  13. {
  14.     protected $apiKey;
  15.  
  16.     public function __construct(ApiKeyService $apiKey)
  17.     {
  18.         parent::__construct();
  19.         $this->apiKey = $apiKey;
  20.     }
  21.  
  22.     /*
  23.      * ------------ GET ROUTES ------------
  24.      */
  25.  
  26.     public function index()
  27.     {
  28.         event(new ApiKeyActionlog('Wyświetlenie wszystkich kluczy API', []));
  29.  
  30.         return view('crm.apiKey.index', [
  31.             'apiKeys' => $this->apiKey->findAll(),
  32.         ]);
  33.     }
  34.  
  35.     public function active()
  36.     {
  37.         event(new ApiKeyActionlog('Wyświetlenie aktywnych kluczy API', []));
  38.  
  39.         return view('crm.apiKey.active', [
  40.             'apiKeys' => $this->apiKey->findActive(),
  41.         ]);
  42.     }
  43.  
  44.     public function archived()
  45.     {
  46.         event(new ApiKeyActionlog('Wyświetlenie zarchiwizowanych kluczy API', []));
  47.  
  48.         return view('crm.apiKey.archived', [
  49.             'apiKeys' => $this->apiKey->findArchived(),
  50.         ]);
  51.     }
  52.  
  53.     public function create(ApiKey $apiKey = null)
  54.     {
  55.         return view('crm.apiKey.create', [
  56.             'apiKeyForm' => $this->formBuilder->create('ApiKeyForm')
  57.         ]);
  58.     }
  59.  
  60.     /*
  61.      * ------------ POST ROUTES ------------
  62.      */
  63.  
  64.     public function store(Request $request)
  65.     {
  66.         $apiKey = $this->apiKey->create($request->all());
  67.         event(new ApiKeyActionlog('Utworzenie klucza API', ['actual' => $apiKey]));
  68.  
  69.         return $this->response(
  70.             redirect()->route('apiKey'),
  71.             'Klucz API został poprawnie dodany.',
  72.             'success',
  73.             ['apiKey' => $this->apiKey->findById($apiKey->id)]
  74.         );
  75.     }
  76.  
  77.     public function update(ApiKey $apiKey, Request $request)
  78.     {
  79.         $before = clone $apiKey;
  80.         $this->apiKey->update($apiKey, $request->all());
  81.         event(new ApiKeyActionlog('Aktualizacja klucza API', ['actual' => $apiKey, 'before' => $before]));
  82.  
  83.         return $this->response(
  84.             redirect()->route('apiKey'),
  85.             'Klucz API został poprawnie zaktualizowany w bazie danych.',
  86.             'success',
  87.             ['apiKey' => $apiKey]
  88.         );
  89.     }
  90.  
  91.     public function archive(ApiKey $apiKey)
  92.     {
  93.         $this->apiKey->archive($apiKey);
  94.         event(new ApiKeyActionlog('Archiwizacja klucza API', ['actual' => $apiKey]));
  95.  
  96.         return $this->response(
  97.             redirect()->back(),
  98.             'Ankieta została poprawnie zarchiwizowany.',
  99.             'success',
  100.             ['apiKey' => $apiKey]
  101.         );
  102.     }
  103.  
  104.     public function restore(ApiKey $apiKey)
  105.     {
  106.         $this->apiKey->restore($apiKey);
  107.         event(new ApiKeyActionlog('Przywrócenie klucza API', ['actual' => $apiKey]));
  108.  
  109.         return $this->response(
  110.             redirect()->back(),
  111.             'Klucz API został poprawnie przywrócony.',
  112.             'success',
  113.             ['apiKey' => $apiKey]
  114.         );
  115.     }
  116.  
  117.     public function delete(ApiKey $apiKey)
  118.     {
  119.         $this->apiKey->forceDelete($apiKey);
  120.         event(new ApiKeyActionlog('Usunięcie klucza API', ['actual' => $apiKey]));
  121.  
  122.         return $this->response(
  123.             redirect()->route('apiKey'),
  124.             "Trwale usunąłeś klucz {$apiKey->website} z bazy danych.",
  125.             'info',
  126.             ['apiKey' => $apiKey]
  127.         );
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment