Created
July 6, 2015 08:09
-
-
Save avtaniket/a402aabeb476556b3529 to your computer and use it in GitHub Desktop.
Sugar 7 : Modify the Relationship Behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class OSTicketsForAccountsLink extends Link2 | |
{ | |
/** | |
* DB | |
* | |
* @var DBManager | |
*/ | |
protected $db; | |
public function __construct($linkName, $bean, $linkDef = false) | |
{ | |
$this->focus = $bean; | |
$this->name = $linkName; | |
$this->db = DBManagerFactory::getInstance(); | |
if (empty($linkDef)) { | |
$this->def = $bean->field_defs[$linkName]; | |
} else { | |
$this->def = $linkDef; | |
} | |
} | |
/** | |
* Returns false if no relationship was found for this link | |
* | |
* @return bool | |
*/ | |
public function loadedSuccesfully() | |
{ | |
// this link always loads successfully | |
return true; | |
} | |
/** | |
* @see Link2::getRelatedModuleName() | |
*/ | |
public function getRelatedModuleName() | |
{ | |
return 'OST__Tickets'; | |
} | |
/** | |
* | |
* @see Link2::buildJoinSugarQuery() | |
*/ | |
public function buildJoinSugarQuery($sugar_query, $options = array()) | |
{ | |
$joinParams = array('joinType' => isset($options['joinType']) ? $options['joinType'] : 'INNER'); | |
$jta = 'ost__tickets'; | |
if (!empty($options['joinTableAlias'])) { | |
$jta = $joinParams['alias'] = $options['joinTableAlias']; | |
} | |
$sugar_query->joinRaw($this->getCustomJoin($options), $joinParams); | |
return $sugar_query->join[$jta]; | |
} | |
/** | |
* Builds main join subpanel | |
* @param string $params | |
* @return string JOIN clause | |
*/ | |
protected function getCustomJoin($params = array()) | |
{ | |
$bean_id = $this->db->quoted($this->focus->id); | |
$sql = " INNER JOIN ost__tickets_contacts_c ON ost__tickets_contacts_c.ost__tickets_contactsost__tickets_idb = ost__tickets.id AND ost__tickets_contacts_c.deleted = '0' | |
INNER JOIN accounts_contacts ON accounts_contacts.contact_id = ost__tickets_contacts_c.ost__tickets_contactscontacts_ida AND accounts_contacts.deleted = '0' AND accounts_contacts.account_id = $bean_id "; | |
return $sql; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment