本文整理汇总了PHP中SugarBean::load_relationship方法的典型用法代码示例。如果您正苦于以下问题:PHP SugarBean::load_relationship方法的具体用法?PHP SugarBean::load_relationship怎么用?PHP SugarBean::load_relationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SugarBean
的用法示例。
在下文中一共展示了SugarBean::load_relationship方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isPortalOwner
/**
* Determines if a portal user "owns" a record
* @param SugarBean $bean
*/
protected function isPortalOwner(SugarBean $bean)
{
if (empty($bean->id) || $bean->new_with_id) {
// New record, they are the owner.
$bean->portal_owner = true;
}
// Cache portal owner on bean so that we aren't loading Contacts for each ACL check
// Performance Bug58133
if (!isset($bean->portal_owner)) {
switch ($bean->module_dir) {
case 'Contacts':
$bean->portal_owner = $bean->id == $_SESSION['contact_id'];
break;
// Cases & Bugs work the same way, so handily enough we can share the code.
// Cases & Bugs work the same way, so handily enough we can share the code.
case 'Cases':
case 'Bugs':
$bean->load_relationship('contacts');
$rows = $bean->contacts->query(array('where' => array('lhs_field' => 'id', 'operator' => '=', 'rhs_value' => $GLOBALS['db']->quote($_SESSION['contact_id']))));
$bean->portal_owner = count($rows) > 0;
break;
default:
// Unless we know how to find the "owner", they can't own it.
$bean->portal_owner = false;
}
}
return $bean->portal_owner;
}
示例2: get_merge_query
/**
* Create merge query depending on the modules being merged
* @param SugarBean $seed Object being queried
* @param string $merge_module Module being merged
* @param string $key ID of the record in module being merged
*/
function get_merge_query($seed, $merge_module, $key)
{
$selQuery = array('Contacts' => array('Accounts' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id AND (accounts_contacts.deleted is NULL or accounts_contacts.deleted=0)', 'Opportunities' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN opportunities_contacts ON contacts.id=opportunities_contacts.contact_id AND (opportunities_contacts.deleted is NULL or opportunities_contacts.deleted=0)', 'Cases' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN contacts_cases ON contacts.id=contacts_cases.contact_id AND (contacts_cases.deleted is NULL or contacts_cases.deleted=0)', 'Bugs' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN contacts_bugs ON contacts.id=contacts_bugs.contact_id AND (contacts_bugs.deleted is NULL or contacts_bugs.deleted=0)', 'Quotes' => 'SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts LEFT JOIN quotes_contacts ON contacts.id=quotes_contacts.contact_id AND (quotes_contacts.deleted is NULL or quotes_contacts.deleted=0)'), 'Opportunities' => array("Accounts" => 'SELECT opportunities.id, opportunities.name FROM opportunities LEFT JOIN accounts_opportunities ON opportunities.id = accounts_opportunities.opportunity_id AND (accounts_opportunities.deleted is NULL or accounts_opportunities.deleted=0)'), 'Accounts' => array("Opportunities" => 'SELECT accounts.id, accounts.name FROM accounts LEFT JOIN accounts_opportunities ON accounts.id = accounts_opportunities.account_id AND (accounts_opportunities.deleted is NULL or accounts_opportunities.deleted=0)'));
$whereQuery = array('Contacts' => array('Accounts' => 'accounts_contacts.contact_id = contacts.id AND accounts_contacts.account_id = ', 'Opportunities' => 'opportunities_contacts.contact_id = contacts.id AND opportunities_contacts.opportunity_id = ', 'Cases' => 'contacts_cases.contact_id = contacts.id AND contacts_cases.case_id = ', 'Bugs' => 'contacts_bugs.contact_id = contacts.id AND contacts_bugs.bug_id = ', 'Quotes' => 'quotes_contacts.contact_id = contacts.id AND quotes_contacts.quote_id = '), 'Opportunities' => array('Accounts' => 'accounts_opportunities.opportunity_id = opportunities.id AND accounts_opportunities.account_id = '), 'Accounts' => array('Opportunities' => 'accounts_opportunities.account_id = accounts.id AND accounts_opportunities.opportunity_id = '));
$relModule = $seed->module_dir;
$select = "";
if (!empty($selQuery[$relModule][$merge_module])) {
$select = $selQuery[$relModule][$merge_module];
} else {
$lowerRelModule = strtolower($relModule);
if ($seed->load_relationship($lowerRelModule)) {
$params = array('join_table_alias' => 'r1', 'join_table_link_alias' => 'r2', 'join_type' => 'LEFT JOIN');
$join = $seed->{$lowerRelModule}->getJoin($params);
$select = "SELECT {$seed->table_name}.* FROM {$seed->table_name} {$join}";
}
}
if (empty($select)) {
$select = "SELECT contacts.first_name, contacts.last_name, contacts.id, contacts.date_entered FROM contacts";
}
if (empty($whereQuery[$relModule][$merge_module])) {
$select .= " WHERE {$seed->table_name}.id = '{$seed->db->quote($key)}'";
} else {
$select .= " WHERE " . $whereQuery[$relModule][$merge_module] . "'{$seed->db->quote($key)}'";
}
$select .= " ORDER BY {$seed->table_name}.date_entered";
return $select;
}
示例3: add
/**
* @param SugarBean $lhs SugarBean left side bean to add to the relationship.
* @param SugarBean $rhs SugarBean right side bean to add to the relationship.
* @param array $additionalFields key=>value pairs of fields to save on the relationship
*
* @return bool true if successful
*/
public function add($lhs, $rhs, $additionalFields = [])
{
$lhsLinkName = $this->lhsLink;
//In a one to one, any existing links from both sides must be removed first.
//one2Many will take care of the right side, so we'll do the left.
$lhs->load_relationship($lhsLinkName);
$this->removeAll($lhs->{$lhsLinkName});
return parent::add($lhs, $rhs, $additionalFields);
}
示例4: getRelatedModuleName
/**
* Gets related module name from a rel link
* @param SugarBean $focus
* @return string
*/
protected function getRelatedModuleName($focus)
{
$relate_to = null;
if (!empty($_REQUEST['relate_to'])) {
$rel_link = $_REQUEST['relate_to'];
if (!$focus->load_relationship($rel_link)) {
//Try to find the link in this bean based on the relationship
foreach ($focus->field_defs as $key => $def) {
if (isset($def['type']) && $def['type'] == 'link' && isset($def['relationship']) && $def['relationship'] == $rel_link) {
$rel_link = $key;
if ($focus->load_relationship($rel_link)) {
break;
}
}
}
}
if ($focus->{$rel_link}) {
$relate_to = $focus->{$rel_link}->getRelatedModuleName();
}
}
return $relate_to;
}
示例5: getRelatedFields
/**
* This function is used to popluate an fields on the relationship from the request
*
* @param $api ServiceBase The API class of the request, used in cases where the API changes how security is applied
* @param $args array The arguments array passed in from the API
* @param $primaryBean SugarBean The near side of the link
* @param $linkName string What is the name of the link field that you want to get the related fields for
*
* @return array A list of the related fields pulled out of the $args array
*/
protected function getRelatedFields(ServiceBase $api, $args, SugarBean $primaryBean, $linkName, $seed = null)
{
$relatedData = array();
if (!empty($primaryBean->{$linkName}) || $primaryBean->load_relationship($linkName)) {
$otherLink = $primaryBean->{$linkName}->getLinkForOtherSide();
if ($seed instanceof SugarBean) {
foreach ($args as $field => $value) {
if (empty($seed->field_defs[$field]['rname_link']) || empty($seed->field_defs[$field]['link']) || $seed->field_defs[$field]['link'] != $otherLink) {
continue;
}
$relatedData[$seed->field_defs[$field]['rname_link']] = $value;
}
}
}
return $relatedData;
}
示例6: getLinkField
protected function getLinkField($fieldName)
{
if ((empty($this->context->{$fieldName}) || !is_a($this->context->{$fieldName}, "Link2")) && !$this->context->load_relationship($fieldName)) {
throw new Exception("Unable to load relationship {$fieldName}");
}
if (empty($this->context->{$fieldName})) {
throw new Exception("Relationship {$fieldName} was not set");
}
if (SugarBean::inOperation('delete')) {
// if we are in a delete operation, always re-fetch the relationships beans
// as one of the could have changed and we want the freshest set from the db
$this->context->{$fieldName}->beans = null;
$this->context->{$fieldName}->resetLoaded();
} elseif (isset($this->context->{$fieldName}->beans)) {
return $this->context->{$fieldName}->beans;
}
$beans = $this->context->{$fieldName}->getBeans();
return $beans;
}
示例7: array
function set_relationships(SugarBean $record, SugarBean $bean, $params = array())
{
$record_vardefs = $record->getFieldDefinitions();
require_once 'modules/Relationships/Relationship.php';
if (isset($params['rel'])) {
foreach ($params['rel'] as $key => $field) {
if ($field == '' || $params['rel_value'][$key] == '') {
continue;
}
switch ($params['rel_value_type'][$key]) {
case 'Field':
$data = $bean->field_defs[$params['rel_value'][$key]];
if ($data['type'] == 'relate' && isset($data['id_name'])) {
$params['rel_value'][$key] = $data['id_name'];
}
$rel_id = $bean->{$params}['rel_value'][$key];
break;
default:
$rel_id = $params['rel_value'][$key];
break;
}
$def = $record_vardefs[$field];
if ($def['type'] == 'link' && !empty($def['relationship'])) {
$record->load_relationship($field);
$record->{$field}->add($rel_id);
}
}
}
}
示例8: processRecord
/**
* Helper for processing record activities.
* @param SugarBean $bean
*/
public function processRecord(SugarBean $bean)
{
if ($bean->load_relationship('activities')) {
$bean->activities->add($this);
}
}
示例9: execute_special_logic
/**
* Executes logic specific for the field being updated
*
* @param string $field_name
* @param SugarBean $source_object
*/
function execute_special_logic($field_name, SugarBean $source_object)
{
if ($field_name === 'team_id') {
// when Team ID is updated, remove all previously associated teams
if ($source_object->load_relationship('teams')) {
$source_object->teams->replace(array(), array(), false);
}
$source_object->team_set_id = null;
}
if (SugarAutoLoader::requireWithCustom('modules/' . $source_object->module_dir . '/SaveOverload.php')) {
perform_save($source_object);
}
}
示例10: getEmailsFromParams
//.........这里部分代码省略.........
switch ($params['email'][$key][0]) {
case 'security_group':
if (file_exists('modules/SecurityGroups/SecurityGroup.php')) {
require_once 'modules/SecurityGroups/SecurityGroup.php';
$security_group = new SecurityGroup();
$security_group->retrieve($params['email'][$key][1]);
$users = $security_group->get_linked_beans('users', 'User');
$r_users = array();
if ($params['email'][$key][2] != '') {
require_once 'modules/ACLRoles/ACLRole.php';
$role = new ACLRole();
$role->retrieve($params['email'][$key][2]);
$role_users = $role->get_linked_beans('users', 'User');
foreach ($role_users as $role_user) {
$r_users[$role_user->id] = $role_user->name;
}
}
foreach ($users as $user_id => $user) {
if ($params['email'][$key][2] != '' && !isset($r_users[$user->id])) {
unset($users[$user_id]);
}
}
break;
}
//No Security Group module found - fall through.
//No Security Group module found - fall through.
case 'role':
require_once 'modules/ACLRoles/ACLRole.php';
$role = new ACLRole();
$role->retrieve($params['email'][$key][2]);
$users = $role->get_linked_beans('users', 'User');
break;
case 'all':
default:
global $db;
$sql = "SELECT id from users WHERE status='Active' AND portal_only=0 ";
$result = $db->query($sql);
while ($row = $db->fetchByAssoc($result)) {
$user = new User();
$user->retrieve($row['id']);
$users[$user->id] = $user;
}
break;
}
foreach ($users as $user) {
$user_email = $user->emailAddress->getPrimaryAddress($user);
if (trim($user_email) != '') {
$emails[$params['email_to_type'][$key]][] = $user_email;
$emails['template_override'][$user_email] = array('Users' => $user->id);
}
}
break;
case 'Related Field':
$emailTarget = $params['email'][$key];
$relatedFields = array_merge($bean->get_related_fields(), $bean->get_linked_fields());
$field = $relatedFields[$emailTarget];
if ($field['type'] == 'relate') {
$linkedBeans = array();
$idName = $field['id_name'];
$id = $bean->{$idName};
$linkedBeans[] = BeanFactory::getBean($field['module'], $id);
} else {
if ($field['type'] == 'link') {
$relField = $field['name'];
if (isset($field['module']) && $field['module'] != '') {
$rel_module = $field['module'];
} else {
if ($bean->load_relationship($relField)) {
$rel_module = $bean->{$relField}->getRelatedModuleName();
}
}
$linkedBeans = $bean->get_linked_beans($relField, $rel_module);
} else {
$linkedBeans = $bean->get_linked_beans($field['link'], $field['module']);
}
}
if ($linkedBeans) {
foreach ($linkedBeans as $linkedBean) {
$rel_email = $linkedBean->emailAddress->getPrimaryAddress($linkedBean);
if (trim($rel_email) != '') {
$emails[$params['email_to_type'][$key]][] = $rel_email;
$emails['template_override'][$rel_email] = array($linkedBean->module_dir => $linkedBean->id);
}
}
}
break;
case 'Record Email':
$recordEmail = $bean->emailAddress->getPrimaryAddress($bean);
if ($recordEmail == '' && isset($bean->email1)) {
$recordEmail = $bean->email1;
}
if (trim($recordEmail) != '') {
$emails[$params['email_to_type'][$key]][] = $recordEmail;
}
break;
}
}
}
return $emails;
}
示例11: array
function build_report_query_join($name, SugarBean $module, $type, $query = array())
{
if (!isset($query['join'][$name])) {
switch ($type) {
case 'custom':
$query['join'][$name] = 'LEFT JOIN ' . $module->get_custom_table_name() . ' ' . $name . ' ON ' . $module->table_name . '.id = ' . $name . '.id_c ';
break;
case 'relationship':
if ($module->load_relationship($name)) {
$params['join_type'] = 'LEFT JOIN';
$params['join_table_alias'] = $name;
$join = $module->{$name}->getJoin($params, true);
$query['join'][$name] = $join['join'];
$query['select'][] = $join['select'] . " AS '" . $name . "_id'";
}
break;
default:
break;
}
}
return $query;
}
示例12: build_sub_queries_for_union
/**
* @param array $subpanel_list
* @param array $subpanel_def
* @param SugarBean $parentbean
* @param string $order_by
*
* @return array
*/
protected static function build_sub_queries_for_union($subpanel_list, $subpanel_def, $parentbean, $order_by)
{
global $layout_edit_mode, $beanFiles, $beanList;
$subqueries = [];
foreach ($subpanel_list as $this_subpanel) {
if (!$this_subpanel->isDatasourceFunction() || $this_subpanel->isDatasourceFunction() && isset($this_subpanel->_instance_properties['generate_select']) && $this_subpanel->_instance_properties['generate_select'] == true) {
//the custom query function must return an array with
if ($this_subpanel->isDatasourceFunction()) {
$shortcut_function_name = $this_subpanel->get_data_source_name();
$parameters = $this_subpanel->get_function_parameters();
if (!empty($parameters)) {
//if the import file function is set, then import the file to call the custom function from
if (is_array($parameters) && isset($parameters['import_function_file'])) {
//this call may happen multiple times, so only require if function does not exist
if (!function_exists($shortcut_function_name)) {
require_once $parameters['import_function_file'];
}
//call function from required file
$query_array = $shortcut_function_name($parameters);
} else {
//call function from parent bean
$query_array = $parentbean->{$shortcut_function_name}($parameters);
}
} else {
$query_array = $parentbean->{$shortcut_function_name}();
}
} else {
$related_field_name = $this_subpanel->get_data_source_name();
if (!$parentbean->load_relationship($related_field_name)) {
unset($parentbean->{$related_field_name});
continue;
}
$query_array = $parentbean->{$related_field_name}->getSubpanelQuery([], true);
}
$table_where = preg_replace('/^\\s*WHERE/i', '', $this_subpanel->get_where());
$where_definition = preg_replace('/^\\s*WHERE/i', '', $query_array['where']);
if (!empty($table_where)) {
if (empty($where_definition)) {
$where_definition = $table_where;
} else {
$where_definition .= ' AND ' . $table_where;
}
}
$submodulename = $this_subpanel->_instance_properties['module'];
$submoduleclass = $beanList[$submodulename];
//require_once($beanFiles[$submoduleclass]);
/** @var SugarBean $submodule */
$submodule = new $submoduleclass();
$subwhere = $where_definition;
$list_fields = $this_subpanel->get_list_fields();
foreach ($list_fields as $list_key => $list_field) {
if (isset($list_field['usage']) && $list_field['usage'] == 'display_only') {
unset($list_fields[$list_key]);
}
}
if (!$subpanel_def->isCollection() && isset($list_fields[$order_by]) && isset($submodule->field_defs[$order_by]) && (!isset($submodule->field_defs[$order_by]['source']) || $submodule->field_defs[$order_by]['source'] == 'db')) {
$order_by = $submodule->table_name . '.' . $order_by;
}
$table_name = $this_subpanel->table_name;
$panel_name = $this_subpanel->name;
$params = [];
$params['distinct'] = $this_subpanel->distinct_query();
$params['joined_tables'] = $query_array['join_tables'];
$params['include_custom_fields'] = !$subpanel_def->isCollection();
$params['collection_list'] = $subpanel_def->get_inst_prop_value('collection_list');
// use single select in case when sorting by relate field
$singleSelect = $submodule->is_relate_field($order_by);
$subquery = $submodule->create_new_list_query('', $subwhere, $list_fields, $params, 0, '', true, $parentbean, $singleSelect);
$subquery['select'] = $subquery['select'] . " , '{$panel_name}' panel_name ";
$subquery['from'] = $subquery['from'] . $query_array['join'];
$subquery['query_array'] = $query_array;
$subquery['params'] = $params;
$subqueries[] = $subquery;
}
}
return $subqueries;
}
示例13: assignUserTeam
/**
* Assign user's private team to an email
* @param SugarBean $email Email object
* @param string $userid User ID
*/
static function assignUserTeam($email, $userid)
{
if (empty($userid)) {
return null;
}
$teamid = User::staticGetPrivateTeamID($userid);
if (empty($teamid)) {
return null;
}
if (empty($email->teams)) {
$email->load_relationship('teams');
}
$GLOBALS['log']->debug("Assigning {$email->id} to user {$userid} team {$teamid}");
$email->teams->add($teamid, array(), false);
return $teamid;
}
示例14: saveRecurring
/**
* @param SugarBean $parentBean
* @param array $repeatDateTimeArray
* @return array events saved
*/
protected function saveRecurring(SugarBean $parentBean, array $repeatDateTimeArray)
{
// Load the user relationship so the child events that are created will
// have the users added via bean->save (which has special auto-accept
// logic)
if ($parentBean->load_relationship('users')) {
$parentBean->users_arr = $parentBean->users->get();
}
return CalendarUtils::saveRecurring($parentBean, $repeatDateTimeArray);
}
示例15: processAfterCreateOperations
/**
* Process all after create operations:
* copy_rel_from - Copies relationships from a specified record. The relationship that should be copied is specified
* in the vardef.
*
* @param $args
* @param SugarBean $bean
*/
protected function processAfterCreateOperations($args, SugarBean $bean)
{
$this->requireArgs($args, array('module'));
global $dictionary;
$afterCreateKey = 'after_create';
$copyRelationshipsFromKey = 'copy_rel_from';
$module = $args['module'];
$objectName = BeanFactory::getObjectName($module);
if (array_key_exists($afterCreateKey, $args) && array_key_exists($copyRelationshipsFromKey, $args[$afterCreateKey]) && array_key_exists($afterCreateKey, $dictionary[$objectName]) && array_key_exists($copyRelationshipsFromKey, $dictionary[$objectName][$afterCreateKey])) {
$relationshipsToCopy = $dictionary[$objectName][$afterCreateKey][$copyRelationshipsFromKey];
$beanCopiedFrom = BeanFactory::getBean($module, $args[$afterCreateKey][$copyRelationshipsFromKey]);
foreach ($relationshipsToCopy as $linkName) {
$bean->load_relationship($linkName);
$beanCopiedFrom->load_relationship($linkName);
$beanCopiedFrom->{$linkName}->getBeans();
$bean->{$linkName}->add($beanCopiedFrom->{$linkName}->beans);
}
}
}