/** * This function adds a favorite filter to the sugar query * * @param SugarQuery $q The whole SugarQuery object * @param SugarQuery_Builder_Where $where The Where part of the SugarQuery object * @param string $link Which module are you adding the favorite filter to. */ protected static function addFavoriteFilter(SugarQuery $q, SugarQuery_Builder_Where $where, $link, $joinType = 'LEFT') { $sfOptions = array('joinType' => $joinType, 'favorites' => true); if ($link == '' || $link == '_this') { $link_name = 'favorites'; } else { $joinTo = $q->join($link, array('joinType' => 'LEFT')); $sfOptions['joinTo'] = $joinTo; $sfOptions['joinModule'] = $q->getFromBean()->module_name; $link_name = "sf_" . $link; } $fjoin = $q->join($link_name, $sfOptions); $where->notNull($fjoin->joinName() . '.id'); }