Skip to content

Instantly share code, notes, and snippets.

View romaninsh's full-sized avatar
🚴‍♂️
Focusing

Romans Malinovskis romaninsh

🚴‍♂️
Focusing
View GitHub Profile
@romaninsh
romaninsh / notes.php
Created October 24, 2016 15:09
PHP Data Libraries
<?php
// This file contains comments that help you understand comparison
// criteria better: for "PHP Data Library comparison"
// http://socialcompare.com/en/comparison/php-data-access-libraries-orm-activerecord-persistence
// General Premise
// Data Access frameworks hide implementation detail of a specific database engine and allow you to work

Example - Invoice Totals

This is a full demonstration of a basic system designed with Agile Data and Audit extension. The purpose of this example implement functionality of "Invoices" and "Lines". Each Invoice contains of multiple Lines and additionally have a few auto-fields that are calculated automatically. I used implementation without SQL Expression to keep code cross-compatible with any persistence engine.

Setting up tables

There are 2 basic tables at play. Table invoice contains:

id ref total
@romaninsh
romaninsh / agile-data.php
Last active July 20, 2016 06:15
What you write and what query Agile Data builds you.
<?php
// uses https://github.com/atk4/data
$c = new smbo\Model_Payment_Transfer($db);
$c->getRef('transfer_document_id')
->addFields(['other_side'=>'total_gross', 'other_account_currency'=>'account_currency','other_account'=>'account']);
$c->addCondition($c->expr('abs([total_gross])!=abs([other_side])'));
$c->addCondition($c->expr('[account_currency]=[other_account_currency]'));
$c->onlyFields([
'system_id','system','id','doc_date','ref_no','account','other_account','total_gross','other_side',
@romaninsh
romaninsh / Model_File.php
Last active February 19, 2016 13:06
FileStore for ATK (version 2.0) draft - You will need https://github.com/blueimp/jQuery-File-Upload and tpyo/amazon-s3-php-class
<?php
class Model_File extends LF_Model {
public $table = 'file';
public $storage = null;
public $local_copy = null;
function init(){
@romaninsh
romaninsh / How to use on a page.php
Last active March 14, 2016 00:12
Model Union implementation in Agile Toolkit (draft version)
<?php
$tt->addTab('Debtor Report Level 1')->add('Grid')->setModel('Model_Report_Debtors',['contractor_id','amount','amount_sum'])->groupBy('contractor_id')
->owner->removeColumn('amount');//->addCondition('contractor_id','217716');
$tt->addTab('Debtor Report Drilldown on 217717 ')->add('Grid')->setModel('Model_Report_Debtors',['contractor_id','amount'])->addCondition('contractor_id','217717');
@romaninsh
romaninsh / Tabs.php
Created January 7, 2016 11:53
This is implementation of "Tabs" that also support icons in the tab
<?php
class Tabs extends View_Tabs_jUItabs {
function addTab($title,$name=null){
$container=$this->add('View_HtmlElement',$name);
$this->tab_template->set(array(
'url'=>'#'.$container->name,
'tab_id'=>$container->short_name,
@romaninsh
romaninsh / index.php
Created November 22, 2015 21:11
Cloud App School: Final look on your page/index.php.
<?php
class page_index extends Page {
public $title='Dashboard';
function init() {
parent::init();
$this->add('P')
<?php
class Controller_Storage_S3 extends Controller_Storage {
public $useSSL = true;
public $endpoint = 's3-eu-west-1.amazonaws.com';
function connect(){
return new S3(
$this->app->getConfig('amazon/s3/Access_Key_ID'),
$this->app->getConfig('amazon/s3/Secret_Access_Key'),
<?php
class Model_File extends LF_Model {
public $table = 'file';
public $storage = null;
public $local_copy = null;
function init(){
@romaninsh
romaninsh / gist:7835eef2c71c9ab4ee97
Created March 10, 2015 14:52
Password Strength Checker for Agile Toolkit 4.1
<?php
// Add into a field to perform password strength checking
class StrengthChecker extends HtmlElement {
public $default_text='use secure password';
function init(){
parent::init();
$this->set($this->default_text);
$this->addClass('password-checker');