Skip to content

Instantly share code, notes, and snippets.

View smalyshev's full-sized avatar

Stanislav Malyshev smalyshev

View GitHub Profile
@smalyshev
smalyshev / xhprof.php
Created January 27, 2011 19:28
xhprof with Sugar
View xhprof.php
<?php
if(mt_rand(0, 200) != 42) {
return;
}
if(!empty($_REQUEST['entryPoint']) && ($_REQUEST['entryPoint'] == 'getImage' || $_REQUEST['entryPoint'] == 'getYUIComboFile')) {
return;
}
xhprof_enable(XHPROF_FLAGS_LONGNAMES);
$xhprof_enabled = true;
include_once "xhprof_lib/utils/xhprof_lib.php";
View gist:807095
<?php
function getMetaData($session, $moduleName) {
return array('Contacts',
'fields' => array(...),
'links' => array(...),
'relationships' => array(...),
)
}
View gist:807102
<?php
'fields' => array(
'id' => array('type' => 'id'),
'name' => array('type' => 'varchar'),
'date_created' => array('type' => 'datetime'),
'assigned_to' => array('type' => 'assigned_user_id'),
'account_name' => array('type' => 'relate', 'link' => 'accounts'),
'account_id' => array('type' => 'relate', 'link' => 'accounts'),
'reports_to_id' => array('type' => 'id', 'link' => 'reports_to_link'),
'reports_to_name' => array('type' => 'relate', 'link' => 'reports_to_link'),
View gist:807109
<?php
'links' => array(
'accounts' => array('relationship' => 'accounts_contacts', 'module' => 'Accounts', 'type' => '1'),
'assigned_user' => array('relationship' => 'contacts_assigned_users', 'module' => 'Users', 'type' => '1'),
'reports_to_link' => array('relationship' => 'contact_direct_reports', 'module' => 'Contacts', 'type' => '1'),
'direct_reports' => array('relationship' => 'contact_direct_reports', 'module' => 'Contacts', 'type' => '*'),
'opportunities' => array('relationship' => 'contacts_opportunties', 'module' => 'Opportunities', 'type' => '*')
),
View gist:807115
<?php
'relationships' => array(
/* regular one-to-many */
'contact_direct_reports' => array(
'left' => array('module' => 'Contacts', 'link' => 'reports_to_link'),
'right' => array('module' => 'Contacts', 'link' => 'direct_reports'),
),
/* one-to-many with fields */
'accounts_contacts' => array(
'left' => array('module' => 'Accounts', 'id' = 'account_id', 'link' => 'contacts'),
View gist:807141
<?php
return array(
'Accounts',
array(
array(
'id'=>1,
'fields'=>array('date_modified'=>'2010-11-12 10:11:20', 'name'=>'bob',
'company'=>'abc', 'accounts' => '12345-6789-101213' ),
'status'=>array('code'=>0, 'description'=>'Success') ,
'acl'=>array('deleteable'=>false, 'writeable'=>true, 'readable'=>true))
View gist:807151
<?php
return array(
'Accounts',
array(
array('id'=>1, 'status'=>array('code'=>2, 'description'=>'Object Removed')),
)
);
View gist:807166
<?php
'fields' => array('id' => '1234', 'accounts' => '12345-678', 'accounts.contact_role' => 'Big Cheese')
View gist:807284
<?php
/* insert */
array('contact_id' => '12345', 'opportunity_id' => '3456', 'contact_role' => 'Big Cheese'),
/* update */
array('id' => '78910', 'contact_id' => '12345', 'opportunity_id' => '3456', 'contact_role' => 'Big Cheese'),
/* delete */
array('id' => '78910', 'deleted'=>1),
View gist:807307
<?php
return array(
array('id'=>1,
'fields'=>array('date_modified'=>'2010-11-12 10:11:20', 'name'=>'bob',
'company'=>'abc', 'accounts' => '12345-6789-101213' ),
'acl'=>array('deleteable'=>false, 'writeable'=>true, 'readable'=>true)),
)