Add php files
This commit is contained in:
278
modules/Relationships/Relationship.php
Executable file
278
modules/Relationships/Relationship.php
Executable file
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: TODO: To be written.
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
class Relationship extends SugarBean {
|
||||
|
||||
var $object_name='Relationship';
|
||||
var $module_dir = 'Relationships';
|
||||
var $new_schema = true;
|
||||
var $table_name = 'relationships';
|
||||
|
||||
var $id;
|
||||
var $relationship_name;
|
||||
var $lhs_module;
|
||||
var $lhs_table;
|
||||
var $lhs_key;
|
||||
var $rhs_module;
|
||||
var $rhs_table;
|
||||
var $rhs_key;
|
||||
var $join_table;
|
||||
var $join_key_lhs;
|
||||
var $join_key_rhs;
|
||||
var $relationship_type;
|
||||
var $relationship_role_column;
|
||||
var $relationship_role_column_value;
|
||||
var $reverse;
|
||||
|
||||
var $_self_referencing;
|
||||
|
||||
function Relationship() {
|
||||
parent::SugarBean();
|
||||
}
|
||||
|
||||
/*returns true if the relationship is self referencing. equality check is performed for both table and
|
||||
* key names.
|
||||
*/
|
||||
function is_self_referencing() {
|
||||
if (empty($this->_self_referencing)) {
|
||||
$this->_self_referencing=false;
|
||||
|
||||
//is it self referencing, both table and key name from lhs and rhs should be equal.
|
||||
if ($this->lhs_table == $this->rhs_table && $this->lhs_key == $this->rhs_key) {
|
||||
$this->_self_referencing=true;
|
||||
}
|
||||
}
|
||||
return $this->_self_referencing;
|
||||
}
|
||||
|
||||
/*returns true if a relationship with provided name exists*/
|
||||
function exists($relationship_name,&$db) {
|
||||
$query = "SELECT relationship_name FROM relationships WHERE deleted=0 AND relationship_name = '".$relationship_name."'";
|
||||
$result = $db->query($query,true," Error searching relationships table..");
|
||||
$row = $db->fetchByAssoc($result);
|
||||
if ($row != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function delete($relationship_name,&$db) {
|
||||
|
||||
$query = "UPDATE relationships SET deleted=1 WHERE deleted=0 AND relationship_name = '".$relationship_name."'";
|
||||
$result = $db->query($query,true," Error updating relationships table for ".$relationship_name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_other_module($relationship_name, $base_module, &$db){
|
||||
//give it the relationship_name and base module
|
||||
//it will return the module name on the other side of the relationship
|
||||
|
||||
$query = "SELECT relationship_name, rhs_module, lhs_module FROM relationships WHERE deleted=0 AND relationship_name = '".$relationship_name."'";
|
||||
$result = $db->query($query,true," Error searching relationships table..");
|
||||
$row = $db->fetchByAssoc($result);
|
||||
if ($row != null) {
|
||||
|
||||
if($row['rhs_module']==$base_module){
|
||||
return $row['lhs_module'];
|
||||
}
|
||||
if($row['lhs_module']==$base_module){
|
||||
return $row['rhs_module'];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
//end function get_other_module
|
||||
}
|
||||
|
||||
function retrieve_by_sides($lhs_module, $rhs_module, &$db){
|
||||
//give it the relationship_name and base module
|
||||
//it will return the module name on the other side of the relationship
|
||||
|
||||
$query = "SELECT * FROM relationships WHERE deleted=0 AND lhs_module = '".$lhs_module."' AND rhs_module = '".$rhs_module."'";
|
||||
$result = $db->query($query,true," Error searching relationships table..");
|
||||
$row = $db->fetchByAssoc($result);
|
||||
if ($row != null) {
|
||||
|
||||
return $row;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
//end function retrieve_by_sides
|
||||
}
|
||||
|
||||
function retrieve_by_modules($lhs_module, $rhs_module, &$db, $type =''){
|
||||
//give it the relationship_name and base module
|
||||
//it will return the module name on the other side of the relationship
|
||||
|
||||
$query = " SELECT * FROM relationships
|
||||
WHERE deleted=0
|
||||
AND (
|
||||
(lhs_module = '".$lhs_module."' AND rhs_module = '".$rhs_module."')
|
||||
OR
|
||||
(lhs_module = '".$rhs_module."' AND rhs_module = '".$lhs_module."')
|
||||
)
|
||||
";
|
||||
if(!empty($type)){
|
||||
$query .= " AND relationship_type='$type'";
|
||||
}
|
||||
$result = $db->query($query,true," Error searching relationships table..");
|
||||
$row = $db->fetchByAssoc($result);
|
||||
if ($row != null) {
|
||||
|
||||
return $row['relationship_name'];
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
//end function retrieve_by_sides
|
||||
}
|
||||
|
||||
|
||||
function retrieve_by_name($relationship_name) {
|
||||
|
||||
if (empty($GLOBALS['relationships'])) {
|
||||
$this->load_relationship_meta();
|
||||
}
|
||||
|
||||
// _ppd($GLOBALS['relationships']);
|
||||
|
||||
if (array_key_exists($relationship_name, $GLOBALS['relationships'])) {
|
||||
|
||||
foreach($GLOBALS['relationships'][$relationship_name] as $field=>$value)
|
||||
{
|
||||
$this->$field = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$GLOBALS['log']->fatal('Error fetching relationship from cache '.$relationship_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function load_relationship_meta() {
|
||||
if (!file_exists(Relationship::cache_file_dir().'/'.Relationship::cache_file_name_only())) {
|
||||
$this->build_relationship_cache();
|
||||
}
|
||||
include(Relationship::cache_file_dir().'/'.Relationship::cache_file_name_only());
|
||||
$GLOBALS['relationships']=$relationships;
|
||||
}
|
||||
|
||||
function build_relationship_cache() {
|
||||
$query="SELECT * from relationships where deleted=0";
|
||||
$result=$this->db->query($query);
|
||||
|
||||
while (($row=$this->db->fetchByAssoc($result))!=null) {
|
||||
$relationships[$row['relationship_name']] = $row;
|
||||
}
|
||||
|
||||
$rel_string='<?php ';
|
||||
$rel_string.='$relationships='.var_export($relationships,true);
|
||||
$rel_string.=' ?>';
|
||||
mkdir_recursive($this->cache_file_dir());
|
||||
$handle=sugar_fopen(Relationship::cache_file_dir().'/'.Relationship::cache_file_name_only(),'w');
|
||||
fwrite($handle,$rel_string);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
|
||||
function cache_file_dir() {
|
||||
|
||||
$file_dir="{$GLOBALS['sugar_config']['cache_dir']}modules/Relationships";
|
||||
|
||||
return $file_dir;
|
||||
}
|
||||
function cache_file_name_only() {
|
||||
return 'relationships.cache.php';
|
||||
}
|
||||
|
||||
function delete_cache() {
|
||||
$filename=Relationship::cache_file_dir().'/'.Relationship::cache_file_name_only();
|
||||
if (file_exists($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function trace_relationship_module($base_module, $rel_module1_name, $rel_module2_name=""){
|
||||
global $beanList;
|
||||
global $dictionary;
|
||||
|
||||
$temp_module = get_module_info($base_module);
|
||||
|
||||
$rel_attribute1_name = $temp_module->field_defs[strtolower($rel_module1_name)]['relationship'];
|
||||
$rel_module1 = $this->get_other_module($rel_attribute1_name, $base_module, $temp_module->db);
|
||||
$rel_module1_bean = get_module_info($rel_module1);
|
||||
|
||||
if($rel_module2_name!=""){
|
||||
if($rel_module2_name == 'ProjectTask'){
|
||||
$rel_module2_name = strtolower($rel_module2_name);
|
||||
}
|
||||
$rel_attribute2_name = $rel_module1_bean->field_defs[strtolower($rel_module2_name)]['relationship'];
|
||||
$rel_module2 = $this->get_other_module($rel_attribute2_name, $rel_module1_bean->module_dir, $rel_module1_bean->db);
|
||||
$rel_module2_bean = get_module_info($rel_module2);
|
||||
return $rel_module2_bean;
|
||||
|
||||
} else {
|
||||
//no rel_module2, so return rel_module2 bean
|
||||
return $rel_module1_bean;
|
||||
}
|
||||
|
||||
//end function trace_relationship_module
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
408
modules/Relationships/RelationshipHandler.php
Executable file
408
modules/Relationships/RelationshipHandler.php
Executable file
@@ -0,0 +1,408 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class RelationshipHandler extends Relationship {
|
||||
|
||||
var $db; //Database link by reference
|
||||
|
||||
var $base_module; //name of module
|
||||
var $base_bean; //actual object
|
||||
var $base_vardef_field; //base's vardef field name of relationship with rel1
|
||||
|
||||
var $rel1_module; //name of related module
|
||||
var $rel1_bean; //actual related object
|
||||
var $rel1_relationship_name; //Relationship name between base and rel1
|
||||
var $rel1_vardef_field; //rel1's vardef field name of relationship with rel2
|
||||
var $rel1_vardef_field_base; //rel1's vardef field name of relationship with base
|
||||
|
||||
var $rel2_module; //name of related related module
|
||||
var $rel2_bean; //actual related related object
|
||||
var $rel2_relationship_name; //Relationship name between rel1 and rel2
|
||||
var $rel2_vardef_field; //rel2's vardef field name of relationship with rel1
|
||||
|
||||
|
||||
var $base_array; //Info array
|
||||
var $rel1_array; //Info array
|
||||
var $rel2_array; //Info array
|
||||
|
||||
|
||||
/*
|
||||
|
||||
info arrays contain:
|
||||
|
||||
'slabel' -> singular module name in correct language
|
||||
'plabel' -> plural module name in correct language
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
///////////////////////////Setup and populate functions//////////////////////////////
|
||||
|
||||
function RelationshipHandler(& $db, $base_module=""){
|
||||
|
||||
$this->db = $db;
|
||||
$this->base_module = $base_module;
|
||||
|
||||
//end function RelationshipHandler
|
||||
}
|
||||
|
||||
function set_rel_vardef_fields($base_vardef_field, $rel1_vardef_field=""){
|
||||
|
||||
$this->base_vardef_field = $base_vardef_field;
|
||||
$this->rel1_vardef_field = $rel1_vardef_field;
|
||||
|
||||
//end function set_rel_vardef_fields
|
||||
}
|
||||
|
||||
|
||||
function set_rel_relationship_names($build_rel2=false){
|
||||
|
||||
$this->rel1_relationship_name = $this->base_bean->field_defs[$this->base_vardef_field]['relationship'];
|
||||
|
||||
if($build_rel2==true){
|
||||
$this->rel2_relationship_name = $this->rel1_bean->field_defs[$this->rel1_vardef_field]['relationship'];
|
||||
}
|
||||
|
||||
//end function set_rel_relationship_names
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////END Setup and populate functions/////////////////////
|
||||
|
||||
|
||||
/*
|
||||
set the build_rel2 to true if you want the rel2 info array as well
|
||||
This function will build all the relationship info it can based on values set in the setup functions
|
||||
When you use the info arrays (rel1_array) or (rel2_array), make sure you always check for empty values
|
||||
*/
|
||||
function build_info($build_rel2=false){
|
||||
if($this->base_bean == null){
|
||||
$this->base_bean = get_module_info($this->base_module);
|
||||
}
|
||||
|
||||
if(empty($this->rel1_bean)){
|
||||
$this->build_rel1_info();
|
||||
$this->rel1_module = $this->rel1_bean->module_dir;
|
||||
}
|
||||
|
||||
if($build_rel2==true && $this->rel2_bean==""){
|
||||
$this->build_rel2_info();
|
||||
$this->rel2_module = $this->rel2_bean->module_dir;
|
||||
}
|
||||
|
||||
//translate the module titles to the proper language
|
||||
$this->build_module_labels($build_rel2);
|
||||
|
||||
//end function build_info
|
||||
}
|
||||
|
||||
function build_rel1_info(){
|
||||
|
||||
$this->rel1_bean = $this->trace_relationship_module($this->base_module, $this->base_vardef_field);
|
||||
|
||||
//end function build_rel1_info
|
||||
}
|
||||
|
||||
function build_rel2_info(){
|
||||
|
||||
$this->rel2_bean = $this->trace_relationship_module($this->base_module, $this->base_vardef_field, $this->rel1_vardef_field);
|
||||
|
||||
//end function build_rel1_info
|
||||
}
|
||||
|
||||
/*
|
||||
Translates the module names to their singular and plural label and puts them in
|
||||
the info arrays. Does it for base, rel1, and rel2 if specified
|
||||
*/
|
||||
|
||||
function build_module_labels($build_rel2=false){
|
||||
global $app_list_strings;
|
||||
|
||||
///Base Module Labels
|
||||
if(!empty($app_list_strings['moduleList'][$this->base_bean->module_dir])){
|
||||
$this->base_array['plabel'] = $app_list_strings['moduleList'][$this->base_bean->module_dir];
|
||||
} else {
|
||||
$this->base_array['plabel'] = $this->base_bean->module_dir;
|
||||
}
|
||||
if(!empty($app_list_strings['moduleListSingular'][$this->base_bean->module_dir])){
|
||||
$this->base_array['slabel'] = $app_list_strings['moduleListSingular'][$this->base_bean->module_dir];
|
||||
} else {
|
||||
$this->base_array['slabel'] = $this->base_bean->object_name;
|
||||
}
|
||||
|
||||
///Rel1 Module Labels
|
||||
if(!empty($app_list_strings['moduleList'][$this->rel1_bean->module_dir])){
|
||||
$this->rel1_array['plabel'] = $app_list_strings['moduleList'][$this->rel1_bean->module_dir];
|
||||
} else {
|
||||
$this->rel1_array['plabel'] = $this->rel1_bean->module_dir;
|
||||
}
|
||||
|
||||
if(!empty($app_list_strings['moduleListSingular'][$this->rel1_bean->module_dir])){
|
||||
$this->rel1_array['slabel'] = $app_list_strings['moduleListSingular'][$this->rel1_bean->module_dir];
|
||||
} else {
|
||||
$this->rel1_array['slabel'] = $this->rel1_bean->object_name;
|
||||
}
|
||||
|
||||
|
||||
//Rel2 Module Labels
|
||||
if($build_rel2==true){
|
||||
|
||||
if(!empty($app_list_strings['moduleList'][$this->rel2_bean->module_dir])){
|
||||
$this->rel2_array['plabel'] = $app_list_strings['moduleList'][$this->rel2_bean->module_dir];
|
||||
} else {
|
||||
$this->rel2_array['plabel'] = $this->rel2_bean->module_dir;
|
||||
}
|
||||
if(!empty($app_list_strings['moduleListSingular'][$this->rel2_bean->module_dir])){
|
||||
$this->rel2_array['slabel'] = $app_list_strings['moduleListSingular'][$this->rel2_bean->module_dir];
|
||||
} else {
|
||||
$this->rel2_array['slabel'] = $this->rel2_bean->module_dir;
|
||||
}
|
||||
//end if build_rel2 is true
|
||||
}
|
||||
|
||||
//end function buld_module_lables
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function build_related_list($type="base"){
|
||||
//type can be base, rel1
|
||||
|
||||
$target_list = "";
|
||||
|
||||
if($type=="base"){
|
||||
$target_list = $this->base_bean->get_linked_beans($this->base_vardef_field, $this->rel1_bean->object_name);
|
||||
//Possibility exists that this is a new relationship, so capture via relationship fields
|
||||
if(empty($target_list)){
|
||||
$target_list = search_filter_rel_info($this->base_bean, $this->rel1_bean->module_dir, $this->base_vardef_field);
|
||||
//end if the target list is empty
|
||||
}
|
||||
}
|
||||
|
||||
if($type=="rel1"){
|
||||
$target_list = $this->rel1_bean->get_linked_beans($this->rel1_vardef_field, $this->rel2_bean->object_name);
|
||||
|
||||
//Possibility exists that this is a new relationship, so capture via relationship fields
|
||||
if(empty($target_list)){
|
||||
$target_list = search_filter_rel_info($this->rel1_bean, $this->rel2_bean->module_dir, $this->rel1_vardef_field);
|
||||
//end if the target list is empty
|
||||
}
|
||||
}
|
||||
|
||||
return $target_list;
|
||||
|
||||
//end function build_related_list
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///////BEGIN Functions to find relationships/////////////////////////////////
|
||||
|
||||
function get_relationship_information(& $target_bean, $get_upstream_rel_field_name = false){
|
||||
|
||||
$target_module_name = $target_bean->module_dir;
|
||||
$current_module_name = $this->base_module;
|
||||
|
||||
//Look for downstream connection
|
||||
$rel_array = $this->retrieve_by_sides($current_module_name, $target_module_name, $this->db);
|
||||
|
||||
|
||||
//Does a downstream relationship exist
|
||||
if($rel_array!=null){
|
||||
if($rel_array['relationship_type']=="many-to-many"){
|
||||
$target_bean->$rel_array['join_key_lhs'] = $this->base_bean->id;
|
||||
if($rel_array['relationship_role_column']!=""){
|
||||
$target_bean->$rel_array['relationship_role_column'] = $rel_array['relationship_role_column_value'];
|
||||
}
|
||||
//end if many-to-many
|
||||
}
|
||||
|
||||
if($rel_array['relationship_type']=="one-to-many"){
|
||||
$target_bean->$rel_array['rhs_key'] = $this->base_bean->id;
|
||||
if($rel_array['relationship_role_column']!=""){
|
||||
$target_bean->$rel_array['relationship_role_column'] = $rel_array['relationship_role_column_value'];
|
||||
}
|
||||
//end if one-to-many
|
||||
}
|
||||
|
||||
return;
|
||||
//end if downstream relationship exists
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Look for upstream connection
|
||||
$rel_array = $this->retrieve_by_sides($target_module_name, $current_module_name, $this->db);
|
||||
|
||||
//Does an upstream relationship exist
|
||||
if($rel_array!=null){
|
||||
if($rel_array['relationship_type']=="many-to-many"){
|
||||
$target_bean->$rel_array['join_key_rhs'] = $this->base_bean->id;
|
||||
if($rel_array['relationship_role_column']!=""){
|
||||
$target_bean->$rel_array['relationship_role_column'] = $rel_array['relationship_role_column_value'];
|
||||
}
|
||||
//end if many-to-many
|
||||
}
|
||||
|
||||
if($rel_array['relationship_type']=="one-to-many"){
|
||||
$this->$rel_array['rhs_key'] = $this->base_bean->id;
|
||||
if($rel_array['relationship_role_column']!=""){
|
||||
$this->$rel_array['relationship_role_column'] = $rel_array['relationship_role_column_value'];
|
||||
}
|
||||
//end if one-to-many
|
||||
}
|
||||
|
||||
|
||||
///Fill additional id field if necessary
|
||||
if(($id_name = $this->traverse_rel_meta($current_module_name, $target_bean, $rel_array['relationship_name'])) != null){
|
||||
$target_bean->$id_name = $this->base_bean->id;
|
||||
if($get_upstream_rel_field_name) {
|
||||
$target_bean->new_rel_relname = $id_name;
|
||||
$target_bean->new_rel_id = $this->base_bean->id;
|
||||
}
|
||||
}
|
||||
|
||||
//end if an upstream relationship exists
|
||||
}
|
||||
|
||||
//end function get_relationship_information
|
||||
}
|
||||
|
||||
function traverse_rel_meta($base_module, & $target_bean, $target_rel_name){
|
||||
$id_name = null;
|
||||
|
||||
//returns name of variable to store id in
|
||||
//if none exists, then returns null
|
||||
foreach($target_bean->field_defs as $field_array){
|
||||
|
||||
if(!empty($field_array['relationship']) && $field_array['relationship']==$target_rel_name){
|
||||
|
||||
$id_name = $this->get_id_name($target_bean, $field_array['name']);
|
||||
return $id_name;
|
||||
//end if rel name match
|
||||
}
|
||||
|
||||
//end foreach field def
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
//end function traverse_rel_meta
|
||||
}
|
||||
|
||||
|
||||
function get_id_name(& $target_bean, $field_name){
|
||||
|
||||
foreach($target_bean->relationship_fields as $target_id => $rel_name){
|
||||
|
||||
if($rel_name == $field_name){
|
||||
//relationship id found
|
||||
return $target_id;
|
||||
//end if match
|
||||
}
|
||||
//end foreach
|
||||
}
|
||||
|
||||
return null;
|
||||
//end function get_id_name
|
||||
}
|
||||
|
||||
///////////////////////////END functions to find relationships //////////////////////
|
||||
|
||||
|
||||
function process_by_rel_bean($rel1_module){
|
||||
|
||||
$this->rel1_relationship_name = $this->retrieve_by_modules($this->base_module, $rel1_module, $this->db);
|
||||
$this->rel1_module = $rel1_module;
|
||||
$this->rel1_bean = get_module_info($this->rel1_module);
|
||||
|
||||
//end function process_by_rel_bean
|
||||
}
|
||||
|
||||
|
||||
function get_rel1_vardef_field_base($field_defs){
|
||||
foreach($field_defs as $field_array){
|
||||
|
||||
if(!empty($field_array['relationship']) && $field_array['relationship']==$this->rel1_relationship_name){
|
||||
|
||||
$this->rel1_vardef_field_base = $field_array['name'];
|
||||
//end if rel name match
|
||||
}
|
||||
|
||||
//end foreach field def
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
//end get_rel1_vardef_field_base
|
||||
}
|
||||
|
||||
|
||||
function get_farthest_reach(){
|
||||
|
||||
if($this->rel1_vardef_field!=""){
|
||||
//the farthest reach is rel2
|
||||
$this->build_info(true);
|
||||
return $this->rel2_bean;
|
||||
}
|
||||
|
||||
//the farthest reach is rel1
|
||||
$this->build_info(false);
|
||||
return $this->rel1_bean;
|
||||
|
||||
//end function get_farthest_reach
|
||||
}
|
||||
|
||||
//end class RelationshipHandler
|
||||
}
|
||||
|
||||
?>
|
||||
80
modules/Relationships/field_arrays.php
Executable file
80
modules/Relationships/field_arrays.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: Contains field arrays that are used for caching
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
$fields_array['Relationship'] = array ('column_fields' => Array(
|
||||
'id',
|
||||
'relationship_name',
|
||||
'lhs_module',
|
||||
'lhs_table',
|
||||
'lhs_key',
|
||||
'rhs_module',
|
||||
'rhs_table',
|
||||
'rhs_key',
|
||||
'join_table',
|
||||
'join_key_lhs',
|
||||
'join_key_rhs',
|
||||
'relationship_type',
|
||||
'relationship_role_column',
|
||||
'relationship_role_column_value',
|
||||
'reverse',
|
||||
),
|
||||
'list_fields' => Array(
|
||||
'id',
|
||||
'relationship_name',
|
||||
'lhs_module',
|
||||
'lhs_table',
|
||||
'lhs_key',
|
||||
'rhs_module',
|
||||
'rhs_table',
|
||||
'rhs_key',
|
||||
'join_table',
|
||||
'join_key_lhs',
|
||||
'join_key_rhs',
|
||||
'relationship_type',
|
||||
'relationship_role_column',
|
||||
'relationship_role_column_value',
|
||||
'reverse',
|
||||
),
|
||||
'required_fields' => array("relationship_name"=>1),
|
||||
);
|
||||
?>
|
||||
64
modules/Relationships/language/en_us.lang.php
Executable file
64
modules/Relationships/language/en_us.lang.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: Defines the English language pack for the base application.
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
|
||||
$mod_strings = array (
|
||||
'LBL_ID' => 'Relationship Id',
|
||||
'LBL_RELATIONSHIP_NAME' => 'Relationship Name',
|
||||
'LBL_LHS_MODULE' => 'LHS Module Name',
|
||||
'LBL_LHS_TABLE' => 'LHS Table Name',
|
||||
'LBL_LHS_KEY' => 'LHS Key Name',
|
||||
'LBL_RHS_MODULE' => 'RHS Module Name',
|
||||
'LBL_RHS_TABLE' => 'RHS Table Name',
|
||||
'LBL_RHS_KEY' => 'RHS Key Name',
|
||||
'LBL_JOIN_TABLE' => 'Join Table Name',
|
||||
'LBL_JOIN_KEY_LHS' => 'Join Key LHS',
|
||||
'LBL_JOIN_KEY_RHS' => 'Join Key RHS',
|
||||
'LBL_RELATIONSHIP_TYPE' => 'Relationship Type',
|
||||
'LBL_RELATIONSHIP_ROLE_COLUMN' => 'Relationship Role Column Name',
|
||||
'LBL_RELATIONSHIP_ROLE_COLUMN_VALUE' => 'Relationship Role Column Value',
|
||||
'LBL_REVERSE' => 'Reverse' ,
|
||||
'LBL_DELETED' => 'Deleted',
|
||||
);
|
||||
|
||||
?>
|
||||
54
modules/Relationships/language/pl_pl.lang.php
Executable file
54
modules/Relationships/language/pl_pl.lang.php
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* The contents of this file are subject to the SugarCRM Public License Version
|
||||
* 1.1.3 ("License"); You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* All copies of the Covered Code must include on each user interface screen:
|
||||
* (i) the "Powered by SugarCRM" logo and
|
||||
* (ii) the SugarCRM copyright notice
|
||||
* in the same form as they appear in the distribution. See full license for
|
||||
* requirements.
|
||||
*
|
||||
* The Original Code is: SugarCRM Open Source
|
||||
* The Initial Developer of the Original Code is SugarCRM, Inc.
|
||||
* Portions created by SugarCRM are Copyright (C) 2004-2005 SugarCRM, Inc.;
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
********************************************************************************/
|
||||
|
||||
/*********************************************************************************
|
||||
* pl_pl.lang.php,v for SugarCRM 4.5.1-->>
|
||||
* Translator: Krzysztof Morawski
|
||||
* All Rights Reserved.
|
||||
* Any bugs report welcome: krzysiek<at>kmmgroup<dot>pl
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
$mod_strings = array (
|
||||
'LBL_ID' => 'ID Zależności',
|
||||
'LBL_RELATIONSHIP_NAME' => 'Nazwa zależności',
|
||||
'LBL_LHS_MODULE' => 'Nazwa modułu LHS',
|
||||
'LBL_LHS_TABLE' => 'Nazwa tabeli LHS',
|
||||
'LBL_LHS_KEY' => 'Nazwa klucza LHS',
|
||||
'LBL_RHS_MODULE' => 'Nazwa modułu RHS',
|
||||
'LBL_RHS_TABLE' => 'Nazwa tabeli RHS',
|
||||
'LBL_RHS_KEY' => 'Nazwa klucza RHS',
|
||||
'LBL_JOIN_TABLE' => 'Nazwa dołączanej tabeli',
|
||||
'LBL_JOIN_KEY_LHS' => 'Nazwa dołączanego klucza LHS',
|
||||
'LBL_JOIN_KEY_RHS' => 'Nazwa dołączanego klucza RHS',
|
||||
'LBL_RELATIONSHIP_TYPE' => 'Typ zależności',
|
||||
'LBL_RELATIONSHIP_ROLE_COLUMN' => 'Kolumna nazw ról zależności',
|
||||
'LBL_RELATIONSHIP_ROLE_COLUMN_VALUE' => 'Kolumna nazw wartości zależności',
|
||||
'LBL_REVERSE' => 'Odwrotnie' ,
|
||||
'LBL_DELETED' => 'Usunięte',
|
||||
);
|
||||
|
||||
?>
|
||||
172
modules/Relationships/vardefs.php
Executable file
172
modules/Relationships/vardefs.php
Executable file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
$dictionary['Relationship'] =
|
||||
|
||||
array('table' => 'relationships'
|
||||
,'fields' => array (
|
||||
'id' =>
|
||||
array (
|
||||
'name' => 'id',
|
||||
'vname' => 'LBL_ID',
|
||||
'type' => 'id',
|
||||
'required'=>true,
|
||||
),
|
||||
|
||||
'relationship_name' =>
|
||||
array (
|
||||
'name' => 'relationship_name',
|
||||
'vname' => 'LBL_RELATIONSHIP_NAME',
|
||||
'type' => 'varchar',
|
||||
'required'=>true,
|
||||
'len' => 150,
|
||||
'importable' => 'required',
|
||||
),
|
||||
'lhs_module' =>
|
||||
array (
|
||||
'name' => 'lhs_module',
|
||||
'vname' => 'LBL_LHS_MODULE',
|
||||
'type' => 'varchar',
|
||||
'required'=>true,
|
||||
'len' => 100
|
||||
),
|
||||
'lhs_table' =>
|
||||
array (
|
||||
'name' => 'lhs_table',
|
||||
'vname' => 'LBL_LHS_TABLE',
|
||||
'type' => 'varchar',
|
||||
'required'=>true,
|
||||
'len' => 64
|
||||
),
|
||||
'lhs_key' =>
|
||||
array (
|
||||
'name' => 'lhs_key',
|
||||
'vname' => 'LBL_LHS_KEY',
|
||||
'type' => 'varchar',
|
||||
'required'=>true,
|
||||
'len' => 64
|
||||
),
|
||||
'rhs_module' =>
|
||||
array (
|
||||
'name' => 'rhs_module',
|
||||
'vname' => 'LBL_RHS_MODULE',
|
||||
'type' => 'varchar',
|
||||
'required'=>true,
|
||||
'len' => 100
|
||||
),
|
||||
'rhs_table' =>
|
||||
array (
|
||||
'name' => 'rhs_table',
|
||||
'vname' => 'LBL_RHS_TABLE',
|
||||
'type' => 'varchar',
|
||||
'required'=>true,
|
||||
'len' => 64
|
||||
),
|
||||
'rhs_key' =>
|
||||
array (
|
||||
'name' => 'rhs_key',
|
||||
'vname' => 'LBL_RHS_KEY',
|
||||
'type' => 'varchar',
|
||||
'required'=>true,
|
||||
'len' => 64
|
||||
),
|
||||
'join_table' =>
|
||||
array (
|
||||
'name' => 'join_table',
|
||||
'vname' => 'LBL_JOIN_TABLE',
|
||||
'type' => 'varchar',
|
||||
'len' => 64
|
||||
),
|
||||
'join_key_lhs' =>
|
||||
array (
|
||||
'name' => 'join_key_lhs',
|
||||
'vname' => 'LBL_JOIN_KEY_LHS',
|
||||
'type' => 'varchar',
|
||||
'len' => 64
|
||||
),
|
||||
'join_key_rhs' =>
|
||||
array (
|
||||
'name' => 'join_key_rhs',
|
||||
'vname' => 'LBL_JOIN_KEY_RHS',
|
||||
'type' => 'varchar',
|
||||
'len' => 64
|
||||
),
|
||||
'relationship_type' =>
|
||||
array (
|
||||
'name' => 'relationship_type',
|
||||
'vname' => 'LBL_RELATIONSHIP_TYPE',
|
||||
'type' => 'varchar',
|
||||
'len' => 64
|
||||
),
|
||||
'relationship_role_column' =>
|
||||
array (
|
||||
'name' => 'relationship_role_column',
|
||||
'vname' => 'LBL_RELATIONSHIP_ROLE_COLUMN',
|
||||
'type' => 'varchar',
|
||||
'len' => 64
|
||||
),
|
||||
'relationship_role_column_value' =>
|
||||
array (
|
||||
'name' => 'relationship_role_column_value',
|
||||
'vname' => 'LBL_RELATIONSHIP_ROLE_COLUMN_VALUE',
|
||||
'type' => 'varchar',
|
||||
'len' => 50
|
||||
),
|
||||
'reverse' =>
|
||||
array (
|
||||
'name' => 'reverse',
|
||||
'vname' => 'LBL_REVERSE',
|
||||
'type' => 'bool',
|
||||
'default' => '0'
|
||||
),
|
||||
'deleted' =>
|
||||
array (
|
||||
'name' => 'deleted',
|
||||
'vname' => 'LBL_DELETED',
|
||||
'type' => 'bool',
|
||||
'reportable'=>false,
|
||||
'default' => '0'
|
||||
),
|
||||
|
||||
)
|
||||
, 'indices' => array (
|
||||
array('name' =>'relationshippk', 'type' =>'primary', 'fields'=>array('id')),
|
||||
array('name' =>'idx_rel_name', 'type' =>'index', 'fields'=>array('relationship_name')),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user