当前位置: 首页>>代码示例>>PHP>>正文


PHP Relationship::retrieve_by_name方法代码示例

本文整理汇总了PHP中Relationship::retrieve_by_name方法的典型用法代码示例。如果您正苦于以下问题:PHP Relationship::retrieve_by_name方法的具体用法?PHP Relationship::retrieve_by_name怎么用?PHP Relationship::retrieve_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Relationship的用法示例。


在下文中一共展示了Relationship::retrieve_by_name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Link

 /**
  * @param string    $_rel_name   use this relationship key.
  * @param SugarBean $_bean       reference of the bean that instantiated this class.
  * @param array     $fieldDef    vardef entry for the field.
  * @param string    $_table_name optional, fetch from the bean's table name property.
  * @param string    $_key_name   optional, name of the primary key column for _table_name
  */
 public function Link($_rel_name, SugarBean &$_bean, $fieldDef, $_table_name = '', $_key_name = '')
 {
     global $dictionary;
     require_once DOCROOT . "modules/TableDictionary.php";
     Log::debug("Link Constructor, relationship name: [{$_rel_name}], Table name [{$_table_name}], Key name [{$_key_name}]");
     $this->_relationship_name = $_rel_name;
     $this->relationship_fields = !empty($fieldDef['rel_fields']) ? $fieldDef['rel_fields'] : [];
     $this->_bean =& $_bean;
     $this->_relationship = new Relationship();
     //$this->_relationship->retrieve_by_string_fields(array('relationship_name'=>$this->_relationship_name));
     $this->_relationship->retrieve_by_name($this->_relationship_name);
     $this->_db = DBManagerFactory::getInstance();
     // Following behavior is tied to a property(ignore_role) value in the vardef.
     // It alters the values of 2 properties, ignore_role_filter and add_distinct.
     // the property values can be altered again before any requests are made.
     if (!empty($fieldDef) && is_array($fieldDef)) {
         if (array_key_exists('ignore_role', $fieldDef)) {
             if ($fieldDef['ignore_role'] == true) {
                 $this->ignore_role_filter = true;
                 $this->add_distinct = true;
             }
         }
     }
     $this->_bean_table_name = !empty($_table_name) ? $_table_name : $_bean->getTableName();
     if (!empty($key_name)) {
         $this->_bean_key_name = $_key_name;
     } else {
         if ($this->_relationship->lhs_table != $this->_relationship->rhs_table) {
             if ($_bean->table_name == $this->_relationship->lhs_table) {
                 $this->_bean_key_name = $this->_relationship->lhs_key;
             }
             if ($_bean->table_name == $this->_relationship->rhs_table) {
                 $this->_bean_key_name = $this->_relationship->rhs_key;
             }
         }
     }
     if ($this->_relationship->lhs_table == $this->_relationship->rhs_table && isset($fieldDef['side']) && $fieldDef['side'] == 'right') {
         $this->_swap_sides = true;
     }
     if (!empty($fieldDef['rhs_key_override'])) {
         $this->_rhs_key_override = true;
     }
     if (!empty($fieldDef['bean_filter_field'])) {
         $this->_bean_filter_field = $fieldDef['bean_filter_field'];
     }
     //default to id if not set.
     if (empty($this->_bean_key_name)) {
         $this->_bean_key_name = 'id';
     }
     Log::debug("Link Constructor, _bean_table_name: [{$this->_bean_table_name}], _bean_key_name: [{$this->_bean_key_name}]");
     if (!empty($this->_relationship->id)) {
         Log::debug("Link Constructor, relationship record found.");
     } else {
         Log::debug("Link Constructor, No relationship record.");
     }
 }
开发者ID:butschster,项目名称:sugarcrm_dev,代码行数:63,代码来源:Link.php

示例2: testretrieve_by_name

 public function testretrieve_by_name()
 {
     //unset and reconnect Db to resolve mysqli fetch exeception
     global $db;
     unset($db->database);
     $db->checkConnection();
     $relationship = new Relationship();
     //test with invalid relationship
     $result = $relationship->retrieve_by_name('test_test');
     $this->assertEquals(false, $result);
     //test with invalid relationship
     unset($result);
     $result = $relationship->retrieve_by_name('roles_users');
     $this->assertEquals(null, $result);
     $this->assertEquals('Users', $relationship->rhs_module);
     $this->assertEquals('Roles', $relationship->lhs_module);
     $this->assertEquals('id', $relationship->rhs_key);
     $this->assertEquals('id', $relationship->lhs_key);
     $this->assertEquals('many-to-many', $relationship->relationship_type);
 }
开发者ID:sacredwebsite,项目名称:SuiteCRM,代码行数:20,代码来源:RelationshipTest.php

示例3: queryFilterone_of

 /**
  * Method returns part of where in style table_alias.id IN (...) because we can't join of relation
  *
  * @param array $layout_def definition of a field
  * @param bool $rename_columns unused
  * @return string SQL where part
  */
 public function queryFilterone_of($layout_def, $rename_columns = true)
 {
     $ids = array();
     if (isset($layout_def['link'])) {
         $relation = new Relationship();
         $relation->retrieve_by_name($layout_def['link']);
     }
     $module = isset($layout_def['custom_module']) ? $layout_def['custom_module'] : $layout_def['module'];
     $seed = BeanFactory::getBean($module);
     foreach ($layout_def['input_name0'] as $beanId) {
         if (!empty($relation->lhs_module) && !empty($relation->rhs_module) && $relation->lhs_module == $relation->rhs_module) {
             $filter = array('id');
         } else {
             $filter = array('id', $layout_def['name']);
         }
         $where = $layout_def['id_name'] . "='{$beanId}' ";
         $sql = $seed->create_new_list_query('', $where, $filter, array(), 0, '', false, $seed, true);
         $result = $this->reporter->db->query($sql);
         while ($row = $this->reporter->db->fetchByAssoc($result)) {
             $ids[] = $row['id'];
         }
     }
     $ids = array_unique($ids);
     $layout_def['name'] = 'id';
     return $this->_get_column_select($layout_def) . " IN ('" . implode("', '", $ids) . "')";
 }
开发者ID:MexinaD,项目名称:SuiteCRM,代码行数:33,代码来源:SugarWidgetFieldrelate.php

示例4: setup

 function setup()
 {
     if (!class_exists('Relationship')) {
     }
     $rel = new Relationship();
     if (!empty($this->vardef['relationship'])) {
         $rel->retrieve_by_name($this->vardef['relationship']);
     }
     if ($rel->relationship_type == 'many-to-many') {
         if ($rel->lhs_module == $this->module_dir) {
             $this->related_module = $rel->rhs_module;
             $module_dir = $rel->lhs_module;
         } else {
             if ($rel->rhs_module == $this->module_dir) {
                 $this->related_module = $rel->lhs_module;
                 $module_dir = $rel->rhs_module;
             } else {
                 die("this field has no relationships mapped with this module");
             }
         }
         if ($module_dir != $this->module_dir) {
             die('These modules do not match : ' . $this->module_dir . ' and ' . $module_dir);
         }
         if (isset($GLOBALS['beanList'][$this->module_dir])) {
             $class = $GLOBALS['beanList'][$this->module_dir];
             if (file_exists($GLOBALS['beanFiles'][$class])) {
                 $this->bean = loadBean($this->module_dir);
                 $this->bean->retrieve($_REQUEST['bean_id']);
                 if ($this->bean->load_relationship($this->vardef['name'])) {
                     $this->retrieve_values();
                 } else {
                     die('failed to load the relationship');
                 }
             } else {
                 die('class file do not exist');
             }
         } else {
             die($this->module_dir . ' is not in the beanList.');
         }
     } else {
         die("the relationship is not a many-to-many");
     }
 }
开发者ID:netconstructor,项目名称:sugarcrm_dev,代码行数:43,代码来源:ViewSugarFieldCollection.php

示例5: queryFilterone_of

 /**
  * Method returns part of where in style table_alias.id IN (...) because we can't join of relation
  *
  * @param array $layout_def definition of a field
  * @param bool $rename_columns unused
  * @return string SQL where part
  */
 public function queryFilterone_of($layout_def, $rename_columns = true)
 {
     $ids = array();
     $relation = new Relationship();
     $relation->retrieve_by_name($layout_def['link']);
     global $beanList;
     $beanClass = $beanList[$relation->lhs_module];
     $seed = new $beanClass();
     foreach ($layout_def['input_name0'] as $beanId) {
         $seed->retrieve($beanId);
         $link = new Link2($layout_def['link'], $seed);
         $sql = $link->getQuery();
         $result = $this->reporter->db->query($sql);
         while ($row = $this->reporter->db->fetchByAssoc($result)) {
             $ids[] = $row['id'];
         }
     }
     $ids = array_unique($ids);
     $layout_def['name'] = 'id';
     return $this->_get_column_select($layout_def) . " IN ('" . implode("', '", $ids) . "')";
 }
开发者ID:sunmo,项目名称:snowlotus,代码行数:28,代码来源:SugarWidgetFieldrelate.php

示例6: getModuleRelationships

 /**
  * Get relationships for a specific module
  *
  * @param string $module SugarCRM Module's name
  * @param string $type   Could be either 'all' or 'one'. One will give only the rels as "fields"
  *
  * @throws \InvalidArgumentException
  *
  * @return array List of relationships
  */
 public function getModuleRelationships($module, $type = 'all')
 {
     // Check in cache
     if (isset($this->moduleRels[$module][$type])) {
         $this->getLogger()->debug($this->logPrefix . 'Got rels for this module in cache');
         return $this->moduleRels[$module][$type];
     }
     $sugarBean = $this->getBean($module);
     $data = array();
     $rels = $sugarBean->get_linked_fields();
     // removing the "right side" of a relationship
     foreach ($rels as $props) {
         $relName = $props['relationship'];
         $relationship = new \Relationship();
         $relationship->retrieve_by_name($relName);
         // Id is empty: fake relationship, especially for users
         if (empty($relationship->id)) {
             continue;
         }
         // Just rename the relationship if I ask only the beans directly related
         if ($type == 'one' && (array_key_exists('side', $props) && $props['side'] == 'right' || array_key_exists('link_type', $props) && $props['link_type'] == 'one')) {
             $relName = $props['name'];
         }
         // I am in a many to One, ignore other
         if ($type == 'one' && $relName == $relationship->relationship_name) {
             continue;
         }
         // Write data
         $data[$relName] = array('relationship_name' => $relName, 'lhs_key' => $relationship->lhs_key, 'lhs_module' => $relationship->lhs_module, 'relationship_type' => $relationship->relationship_type, 'rhs_module' => $relationship->rhs_module, 'rhs_key' => $relationship->rhs_key, 'join_table' => $relationship->join_table, 'join_key_lhs' => $relationship->join_key_lhs, 'join_key_rhs' => $relationship->join_key_rhs);
     }
     // sort it
     ksort($data);
     // cache it
     $this->moduleRels[$module][$type] = $data;
     return $data;
 }
开发者ID:inetprocess,项目名称:libsugarcrm,代码行数:46,代码来源:Bean.php


注:本文中的Relationship::retrieve_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。