/** * Load Beans uses Link2 to take a SugarQuery object and add the joins needed to take a link and make the connection * * @param Linkname $join * @param $alias */ protected function loadBeans($join, $options) { $alias = !empty($options['alias']) ? $options['alias'] : $this->getJoinTableAlias($join); $joinType = !empty($options['joinType']) ? $options['joinType'] : 'INNER'; $team_security = isset($options['team_security']) ? $options['team_security'] : true; $ignoreRole = !empty($options['ignoreRole']) ? $options['ignoreRole'] : false; $bean = !empty($options['relatedJoin']) ? $this->join[$options['relatedJoin']]->bean : $this->from; if (is_array($bean)) { // the bean is the first element of the array $bean = reset($bean); } $bean->load_relationship($join); if (empty($bean->{$join})) { throw new SugarApiExceptionInvalidParameter("Invalid link {$join}"); } $bean->{$join}->buildJoinSugarQuery($this, array('joinTableAlias' => $alias, 'joinType' => $joinType, 'ignoreRole' => $ignoreRole)); $joined = BeanFactory::newBean($bean->{$join}->getRelatedModuleName()); if ($team_security === true) { $joined->addVisibilityQuery($this, array("table_alias" => $alias, 'as_condition' => true)); } if ($joined->hasCustomFields()) { $table_cstm = $joined->get_custom_table_name(); $alias_cstm = $this->db->getValidDBName($alias . '_cstm', false, 'alias'); $this->joinTable($table_cstm, array('alias' => $alias_cstm, 'joinType' => "LEFT", "linkingTable" => true))->on()->equalsField("{$alias_cstm}.id_c", "{$alias}.id"); } }
/** * Construct where clause from a list of name-value pairs. * @param array $fields_array Name/value pairs for column checks * @return string The WHERE clause */ function get_where($fields_array) { $where_clause = ""; foreach ($fields_array as $name => $value) { if (!empty($where_clause)) { $where_clause .= " AND "; } $name = $this->db->getValidDBName($name); $where_clause .= "{$name} = " . $this->db->quoted($value, false); } if (!empty($where_clause)) { return "WHERE {$where_clause} AND deleted=0"; } else { return "WHERE deleted=0"; } }
/** * Composes alias for related name field part * * @param string $field Current bean field * @param string $name_field Related bean field * * @return string */ public function getRelateAlias($field, $name_field) { $alias = sprintf('rel_%s_%s', $field, $name_field); $alias = $this->db->getValidDBName($alias, true, 'alias'); return $alias; }