Skip to content

Commit

Permalink
Merge pull request #126 from sarapis/laravel-9
Browse files Browse the repository at this point in the history
Laravel 9
  • Loading branch information
d9it committed Mar 4, 2024
2 parents 2e03f1f + 43d8606 commit 25f1b0c
Show file tree
Hide file tree
Showing 111 changed files with 11,106 additions and 3,427 deletions.
72 changes: 41 additions & 31 deletions app/Functions/Airtable.php
@@ -1,6 +1,7 @@
<?php

namespace App\Functions;

use GuzzleHttp, Config, Auth;
use \DOMDocument, \SimpleXMLElement;

Expand All @@ -13,18 +14,20 @@
*/


class Airtable
class Airtable
{
const API_URL = "https://api.airtable.com/v0/";
const API_URL = "https://api.airtable.com/v0/";

private $_key;

private $_key;
private $_token;

private $_base;
public function __construct($config)

public function __construct($config)
{
if (is_array($config)) {
$this->setKey($config['api_key']);
$this->setAccessToken($config['access_token']);
$this->setBase($config['base']);
} else {
echo 'Error: __construct() - Configuration data is missing.';
Expand All @@ -36,11 +39,21 @@ public function setKey($key)
$this->_key = $key;
}

public function setAccessToken($token)
{
$this->_token = $token;
}

public function getKey()
{
return $this->_key;
}

public function getAccessToken()
{
return $this->_token;
}

public function setBase($base)
{
$this->_base = $base;
Expand All @@ -51,46 +64,43 @@ public function getBase()
return $this->_base;
}

public function getApiUrl($request){
$request = str_replace( ' ', '%20', $request );
$url = self::API_URL.$this->getBase().'/'.$request;
return $url;
public function getApiUrl($request)
{
$request = str_replace(' ', '%20', $request);
$url = self::API_URL . $this->getBase() . '/' . $request;
return $url;
}

function getContent($content_type,$params="",$relations=false)
function getContent($content_type, $params = "", $relations = false)
{
return new Request( $this, $content_type, $params, false, $relations );
}

function saveContent($content_type,$fields)
{

$fields = array('fields'=>$fields);
return new Request($this, $content_type, $params, false, $relations);
}

$request = new Request( $this, $content_type, $fields, true );
function saveContent($content_type, $fields)
{

return $request->getResponse();
$fields = array('fields' => $fields);

}
$request = new Request($this, $content_type, $fields, true);

function updateContent($content_type,$fields)
{
return $request->getResponse();
}

$fields = array('fields'=>$fields);
function updateContent($content_type, $fields)
{

$request = new Request( $this, $content_type, $fields, 'patch' );
$fields = array('fields' => $fields);

return $request->getResponse();
$request = new Request($this, $content_type, $fields, 'patch');

}
return $request->getResponse();
}

function deleteContent($content_type)
function deleteContent($content_type)
{

$request = new Request( $this, $content_type, [], 'delete' );
$request = new Request($this, $content_type, [], 'delete');

return $request->getResponse();

}

}
11 changes: 4 additions & 7 deletions app/Functions/Request.php
@@ -1,4 +1,5 @@
<?php

/**
* Created by PhpStorm.
* User: glali
Expand Down Expand Up @@ -52,14 +53,13 @@ public function __construct($airtable, $content_type, $data = [], $is_post = fal
$this->data = $data;
$this->is_post = $is_post;
$this->relations = $relations;

}

private function init()
{
$headers = array(
'Content-Type: application/json',
sprintf('Authorization: Bearer %s', $this->airtable->getKey()),
sprintf('Authorization: Bearer %s', $this->airtable->getAccessToken()),
);

$request = $this->content_type;
Expand Down Expand Up @@ -87,7 +87,6 @@ private function init()
}

$this->curl = $curl;

}

/**
Expand All @@ -101,7 +100,6 @@ public function getResponse()
$response_string = curl_exec($this->curl);

return new Response($this->airtable, $this, $response_string, $this->relations);

}

public function __set($key, $value)
Expand All @@ -121,8 +119,8 @@ public function offsetExists($offset)
public function offsetGet($offset)
{
return is_array($this->data) && isset($this->data[$offset])
? $this->data[$offset]
: null;
? $this->data[$offset]
: null;
}

public function offsetSet($offset, $value)
Expand All @@ -140,5 +138,4 @@ public function offsetUnset($offset)
unset($this->data[$offset]);
}
}

}
123 changes: 123 additions & 0 deletions app/Http/Controllers/backend/AddressTypeController.php
@@ -0,0 +1,123 @@
<?php

namespace App\Http\Controllers\backend;

use App\Http\Controllers\Controller;
use App\Model\AddressType;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class AddressTypeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$addressTypes = AddressType::cursor();
return view('backEnd.address_types.index', compact('addressTypes'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('backEnd.address_types.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'type' => 'required|unique:address_types,type'
]);
try {
DB::beginTransaction();
AddressType::create([
'type' => $request->type,
'created_by' => Auth::id()
]);
DB::commit();
return redirect()->to('address_types')->with('success', 'Address type created successfully');
} catch (\Throwable $th) {
DB::rollBack();

return redirect()->to('address_types')->with('error', $th->getMessage());
}
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$addressType = AddressType::whereId($id)->first();
return view('backEnd.address_types.edit', compact('addressType'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'type' => 'required|unique:address_types,id,' . $id
]);
try {
AddressType::whereId($id)->update([
'type' => $request->type
]);
DB::commit();
return redirect()->to('address_types')->with('success', 'Address type updated successfully');
} catch (\Throwable $th) {
DB::rollBack();
return redirect()->to('address_types')->with('error', $th->getMessage());
}
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
try {
AddressType::whereId($id)->delete();
return redirect()->to('address_types')->with('success', 'Address type Deleted successfully');
} catch (\Throwable $th) {
DB::rollBack();
return redirect()->to('address_types')->with('error', $th->getMessage());
}
}
}
22 changes: 22 additions & 0 deletions app/Http/Controllers/backend/CostOptionController.php
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers\backend;

use App\Http\Controllers\Controller;
use App\Services\CostOptionService;
use Illuminate\Http\Request;

class CostOptionController extends Controller
{
protected $costOptionService;

public function __construct(CostOptionService $costOptionService)
{
$this->costOptionService = $costOptionService;
}

public function airtable_v3($access_token, $base_url)
{
$this->costOptionService->import_airtable_v3($access_token, $base_url);
}
}
22 changes: 22 additions & 0 deletions app/Http/Controllers/backend/FundingController.php
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers\backend;

use App\Http\Controllers\Controller;
use App\Services\FundingService;
use Illuminate\Http\Request;

class FundingController extends Controller
{
protected $fundingService;

public function __construct(FundingService $fundingService)
{
$this->fundingService = $fundingService;
}

public function airtable_v3($access_token, $base_url)
{
$this->fundingService->import_airtable_v3($access_token, $base_url);
}
}
22 changes: 22 additions & 0 deletions app/Http/Controllers/backend/IdentifierController.php
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers\backend;

use App\Http\Controllers\Controller;
use App\Services\IdentifierService;
use Illuminate\Http\Request;

class IdentifierController extends Controller
{
protected $identifierService;

public function __construct(IdentifierService $identifierService)
{
$this->identifierService = $identifierService;
}

public function airtable_v3($access_token, $base_url)
{
$this->identifierService->import_airtable_v3($access_token, $base_url);
}
}

0 comments on commit 25f1b0c

Please sign in to comment.