Skip to content

Instantly share code, notes, and snippets.

View jaredhoyt's full-sized avatar

Jared Hoyt jaredhoyt

View GitHub Profile
@jaredhoyt
jaredhoyt / gist:658293
Created November 1, 2010 14:59
Pagination with sorting on deep associations
$this->paginate = array(
'limit' => 50,
'conditions' => $conditions,
'contain' => array(
'ExceptionWorkflowLog',
'Procedure(id,cpt,expected_amount,allowed_total,difference_amount)',
'Procedure.Claim(id,number)',
'Procedure.Claim.Group(abbr)'
)
);
<?php
class PaymentException extends AppModel {
var $actsAs = array('SoftDeletable');
var $belongsTo = array('Procedure');
var $hasMany = array(
'ExceptionWorkflowLog' => array(
'dependent' => true,
'order' => array('ExceptionWorkflowLog.created')
)
);
<?php
class FileTreeHelper extends AppHelper {
var $elements = array(
'tree' => '<ul class="tree">%s</ul>',
'folder' => '<li id="tree-folder_%d" class="folder open">
<div class="folder-name-wrap"><span class="icon">Sort</span><span class="folder-name">%s</span></div>
<div class="folder-contents"><ul class="folders">%s</ul><ul class="files">%s</ul></div></li>',
'file' => '<li id="tree-file_%d" class="file"><span class="icon">Sort</span><span class="file-name">%s</span></li>'
);
var $settings = array();
@jaredhoyt
jaredhoyt / gist:700524
Created November 15, 2010 16:14
Pagination deep relational sorting
# Controller -
<?php
$this->paginate = array(
'limit' => 50,
'contain' => array(
'ExceptionWorkflowLog',
'Procedure(id,cpt,expected_amount,allowed_total,difference_amount)',
'Procedure.Claim(id,number)',
'Procedure.Claim.Group(abbr)',
'Procedure.Payer(abbr)'
<?php
$this->PaymentException->bindModel(array(
'hasOne' => array(
'Claim' => array(
'foreignKey' => false,
'conditions' => array('Claim.id = Procedure.claim_id')
),
'Payer' => array(
'foreignKey' => false,
'conditions' => array('Payer.id = Procedure.payer_id')
load 'deploy' if respond_to?(:namespace)
# basics
set :branch, "master"
set :scm, "git"
set :deploy_via, :remote_cache
# ssh
set :user, "shared-user"
ssh_options[:forward_agent] = true
<?php
return $this->find('all', array(
'contain' => array(
'ExceptionWorkflowLog',
'Procedure(id,cpt,expected_amount,allowed_amount,difference_amount)',
'Procedure.Claim(id,number)',
'Procedure.Claim.Group(abbr)'
),
'conditions' => $conditions,
'order' => array('PaymentException.created', 'PaymentException.id')
@jaredhoyt
jaredhoyt / gist:765395
Created January 4, 2011 20:54
Custom find methods
<?php
class Page extends AppModel {
var $_findMethods = array(
'index' => true,
);
function _findRevision($state, $query, $results = array()) {
if ($state == 'before') {
if (empty($query['slug'])) {
@jaredhoyt
jaredhoyt / app_controller.php
Created January 6, 2011 16:32
Microsoft SQL datasource quoting issue
<?php
class AppController extends Controller {
function beforeFilter() {
$this->loadModel('ErpContract');
debug($this->ErpContract->find('first', array(
'fields' => array('No_', 'Change Order No_')
)));
}
}
<?php
function _findAccessible($state, $query, $results = array()) {
if ($state == 'before') {
if (isset($query[0]) && is_numeric($query[0])) {
$query['conditions'][$this->alias . '.id'] = $query[0];
}
$query['fields'] = $this->primaryKey;
$query['recursive'] = -1;
return $query;
} elseif ($state == 'after') {