Skip to content

Instantly share code, notes, and snippets.

View mlewis-everley's full-sized avatar

Morven Lewis-Everley mlewis-everley

View GitHub Profile
@mlewis-everley
mlewis-everley / ControllerExtension.php
Created September 6, 2019 09:17
Controller Extension to add styled error pages
<?php
class ControllerExtension extends Extension {
private static $error_codes = array(
400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
@mlewis-everley
mlewis-everley / PermissableGridField.php
Last active November 21, 2022 02:58
Version of SilverStripe GridField that checks canView permissions before handing records over to components
<?php
namespace App\Forms\GridField;
use SilverStripe\ORM\SS_List;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridField_DataManipulator;
/**
* Custom gridfield that applies canView permissions to list before manipulation
@mlewis-everley
mlewis-everley / SingleSelectListBoxDropdownField.php
Created May 17, 2019 15:39
Custom dropdown field that pretends to submit an array (but only allows selection of one item)
<?php
namespace App\Forms;
use SilverStripe\Forms\DropdownField;
class SingleSelectListBoxDropdownField extends DropdownField
{
/**
* Force this field to appear as if it saves an array
@mlewis-everley
mlewis-everley / mammals.py
Last active March 21, 2019 16:22
Example function creation
import math
def CalculateDistance(Lat1, Lon1, Lat2, Lon2):
Lat1 = float(Lat1)
Lon1 = float(Lon1)
Lat2 = float(Lat2)
Lon2 = float(Lon2)
nDLat = (Lat1 - Lat2) * 0.017453293
nDLon = (Lon1 - Lon2) * 0.017453293
<?php
/**
* Helper class designed to reduce the vat rates on order items when a
* BookableProduct is added to cart.
*
*/
class VatReducer extends Object
{
@mlewis-everley
mlewis-everley / Payment_Controller.php
Created May 30, 2017 14:49
Omnipay Payment Controller
<?php
use SilverStripe\Omnipay\GatewayInfo;
use SilverStripe\Omnipay\GatewayFieldsFactory;
use SilverStripe\Omnipay\Service\ServiceFactory;
/**
* Summary Controller is responsible for displaying all order data before posting
* to the final payment gateway.
*