Ejemplo n.º 1
0
 public function __construct($field, SugarQuery $query)
 {
     parent::__construct($field, $query);
 }
Ejemplo n.º 2
0
 public function __construct($field, SugarQuery $query, $direction = null)
 {
     $this->direction = $direction;
     parent::__construct($field, $query);
 }
Ejemplo n.º 3
0
 /**
  * Determine if the field needs a join to make the query succeed.  Return either the join table alias or false
  * @return bool| string
  * @throws SugarQueryException
  */
 public function getJoin()
 {
     $jta = false;
     if (!isset($this->def['source']) || $this->def['source'] == 'db') {
         return false;
     }
     if (isset($this->def['type']) && $this->def['type'] == 'relate' || isset($this->def['source']) && $this->def['source'] == 'non-db' && isset($this->def['link']) && $this->def['link'] !== true) {
         $params = array('joinType' => 'LEFT');
         if (!isset($this->def['link'])) {
             if (!isset($this->def['id_name']) || !isset($this->def['module'])) {
                 throw new SugarQueryException("No ID field Name or Module Name");
             }
             // we may need to put on our detective hat and see if we can
             // hunt down a relationship
             $farBean = BeanFactory::newBean($this->def['module']);
             // check if relate field refers some other field as id_name, otherwise we may get infinite recursion
             if ($this->def['id_name'] != $this->def['name'] && (!$this->query->getJoinAlias($farBean->table_name) || !$this->query->getJoinAlias($this->def['name']))) {
                 //Custom relate fields may have the id field on the custom table, need to check for that.
                 $idField = new SugarQuery_Builder_Field($this->def['id_name'], $this->query);
                 $idField->setupField($this->query);
                 $idField->checkCustomField();
                 if ($idField->custom) {
                     $this->custom = true;
                     $this->query->joinCustomTable($this->query->getFromBean());
                 }
                 //Now actually join the related table
                 $jta = $this->query->getJoinTableAlias($this->def['name']);
                 $join = $this->query->joinRaw(" LEFT JOIN {$farBean->table_name} {$jta} ON {$idField->table}.{$this->def['id_name']} = {$jta}.id ", array('alias' => $jta));
                 $join->bean = $farBean;
             }
         }
         if (!empty($this->def['link']) && !$this->query->getJoinAlias($this->def['link'])) {
             if ($this instanceof SugarQuery_Builder_Field_Select) {
                 $params['team_security'] = false;
             }
             if (isset($this->def['id_name']) && $this->def['id_name'] != $this->def['name']) {
                 //Custom relate fields may have the id field on the custom table, need to check for that.
                 $idField = new SugarQuery_Builder_Field_Select($this->def['id_name'], $this->query);
                 $idField->setupField($this->query);
                 $idField->checkCustomField();
                 if ($idField->custom) {
                     $this->custom = true;
                     $this->query->joinCustomTable($this->query->getFromBean());
                 }
             }
             $join = $this->query->join($this->def['link'], $params);
             $jta = $join->joinName();
         } elseif (!empty($this->def['link']) && $this->query->getJoinAlias($this->def['link'])) {
             $jta = $this->query->getJoinAlias($this->def['link']);
         }
         if (!empty($this->def['rname_link'])) {
             $jta = $this->query->getJoinAlias($this->def['link']);
             $this->query->rname_link = $jta;
             $this->table = !empty($this->query->join[$jta]->relationshipTableAlias) ? $this->query->join[$jta]->relationshipTableAlias : $jta;
         }
     }
     return $jta;
 }