Skip to content

Instantly share code, notes, and snippets.

View oojacoboo's full-sized avatar

Jacob Thomason oojacoboo

View GitHub Profile
SELECT t.`id`, t.`reference_id`, t.`tenant_id`, t.`amount`,
(
SELECT SUM(t.`amount`)
FROM `transaction` t
) AS total
FROM `transaction` t
WHERE total > 0
GROUP BY t.`reference_id`;
/**
* The model behavior for the bathroom fan
*/
class Fan extends Courtesy {
//it is ok to leave it off if it's all fresh
protected $position = false;
/**
* If the can was used, fan should be on
SET @settingName = "feeMID", @companyId = 1;
SELECT COALESCE(company_setting.value, default_setting.value) AS value
FROM default_setting
LEFT JOIN company_setting
ON company_setting.default_setting_id
WHERE default_setting.name = @settingName
AND company_setting.company_id = @companyId
public function truncateTables($connection = null) {
if(!$connection)
$connection = $this->con;
$tables = $this->getTables();
foreach($tables as $table) {
//truncate data from this table
$sql = "DELETE FROM [" . $table . "]";
public function truncateTables($connection = null) {
if(!$connection)
$connection = $this->con;
$tables = $this->getTables();
foreach($tables as $table) {
//truncate data from this table
$sql = "DELETE FROM [" . $table . "]";
@oojacoboo
oojacoboo / actions.class.php
Created October 10, 2012 03:24
array_walk closure :P
/**
* Outputs a CSV file for download
* @param sfRequest $request
* @return string (.csv file)
*/
public function executeExportcsv(sfRequest $request) {
$companies = $this->getCompaniesData($request);
$outstream = fopen("php://output", "w");
/**
* Ensures that the value passed is in datetime format
* @param null $dateOrTime
* @param string $format
* @return null|string
*/
function ensureDateTime($dateOrTime = null, $format = "c") {
if(!$dateOrTime)
return null;
/**
* Ensures that the value passed is in datetime format
* @param null $dateOrTime
* @param string $format
* @param string $fallback
* @return null|string
*/
function ensureDateTime($dateOrTime = null, $format = "c", $fallback = null) {
if(!$dateOrTime && !$fallback)
return null;
@oojacoboo
oojacoboo / Globals.php
Created October 13, 2012 04:10
Make those dates work!
/**
* Checks a date/time string to verify it's a valid date/time
* Supports both Y-m-d and Y-m-d H:i:s
* @param $dateTime
* @return bool
*/
function isValidDateTime($dateTime) {
if(preg_match("/^(\d{4})-(\d{2})-(\d{2})( ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]))?$/", $dateTime, $matches)) {
if(checkdate($matches[2], $matches[3], $matches[1])) {
return true;
@oojacoboo
oojacoboo / Globals.php
Created October 13, 2012 04:14
Ensure those dates and times are working for you!
/**
* Checks a date/time string to verify it's a valid date/time
* Supports both Y-m-d and Y-m-d H:i:s
* @param $dateOrTime
* @return bool
*/
function isValidDateTime($dateOrTime) {
if(preg_match("/^(\d{4})-(\d{2})-(\d{2})( ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]))?$/", $dateOrTime, $matches)) {
if(checkdate($matches[2], $matches[3], $matches[1])) {
return true;