Skip to content

Instantly share code, notes, and snippets.

@chadhutchins
Created February 13, 2013 20:29
Show Gist options
  • Save chadhutchins/4947947 to your computer and use it in GitHub Desktop.
Save chadhutchins/4947947 to your computer and use it in GitHub Desktop.
<?php
$dictionary["Opportunity"]["fields"]["priority"] = array(
'required' => false,
'name' => 'priority',
'vname' => 'LBL_PRIORITY',
'type' => 'bool',
'audited' => 0,
'massupdate' => 0,
'source' => 'non-db',
'studio' => 'visible',
);
<?php
$beanList['Opportunities'] = 'SOCustomOpportunity';
$beanFiles['SOCustomOpportunity'] = 'custom/modules/Opportunities/SOCustomOpportunity.php';
$objectList['Opportunities'] = 'Opportunity';
<?php
$mod_strings['LBL_PRIORITY'] = 'Priority';
<?php
require_once('modules/Opportunities/Opportunity.php');
class SOCustomOpportunity extends Opportunity
{
function create_export_query(&$order_by=null, &$where=null, $relate_link_join='')
{
//custom code to intercept where clause, rebuild where clauses array, and replace
if(!empty($where) && preg_match('/^(?!opportunities\.id)\(\s*(.+)\s*\)/', $where,$matches))
{
$where_clauses = explode(' ) AND ( ', $matches[1]) ;
foreach($where_clauses as $key => $clause)
{
if(preg_match('/opportunities.priority/', $clause))
{
if(preg_match('/1/', $clause))
{
$where_clauses[$key] = "(opportunities.sales_stage='Negotiation/Review' AND (opportunities.next_step='' OR opportunities.next_step IS NULL))";
}
else
{
$where_clauses[$key] = "(!(opportunities.sales_stage='Negotiation/Review' AND (opportunities.next_step='' OR opportunities.next_step IS NULL))";
}
}
}
if (count($where_clauses) > 0)
{
$where = '('. implode(' ) AND ( ', $where_clauses) . ')';
}
}
// carry on with the create_custom_query method in modules/Opportunities/Opportunity.php
return parent::create_export_query($order_by, $where, $relate_link_join='');
}
}
<?php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.list.php');
class OpportunitiesViewList extends ViewList {
function processSearchForm()
{
if(isset($_REQUEST['query']))
{
// we have a query
if(!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel
$this->searchForm->populateFromArray($this->storeQuery->query);
}
else {
$this->searchForm->populateFromRequest();
}
$where_clauses = $this->searchForm->generateSearchWhere(true, $this->seed->module_dir);
// CUSTOM CODE BEGINS HERE
// CUSTOM CODE BEGINS HERE
// CUSTOM CODE BEGINS HERE
foreach($where_clauses as $key => $clause)
{
if(preg_match('/opportunities.priority/', $clause))
{
if(preg_match('/1/', $clause))
{
$where_clauses[$key] = "(opportunities.sales_stage='Negotiation/Review' AND (opportunities.next_step='' OR opportunities.next_step IS NULL))";
}
else
{
$where_clauses[$key] = "(!(opportunities.sales_stage='Negotiation/Review' AND (opportunities.next_step='' OR opportunities.next_step IS NULL))";
}
}
}
// CUSTOM CODE ENDS HERE
// CUSTOM CODE ENDS HERE
// CUSTOM CODE ENDS HERE
if (count($where_clauses) > 0 )$this->where = '('. implode(' ) AND ( ', $where_clauses) . ')';
$GLOBALS['log']->info("List View Where Clause: $this->where");
}
if($this->use_old_search){
switch($view) {
case 'basic_search':
$this->searchForm->setup();
$this->searchForm->displayBasic($this->headers);
break;
case 'advanced_search':
$this->searchForm->setup();
$this->searchForm->displayAdvanced($this->headers);
break;
case 'saved_views':
echo $this->searchForm->displaySavedViews($this->listViewDefs, $this->lv, $this->headers);
break;
}
}else{
echo $this->searchForm->display($this->headers);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment