示例#1
0
 /**
  * @param  $linkName String name of a link field in the module's vardefs
  * @param  $bean SugarBean focus bean for this link (one half of a relationship)
  * @param  $linkDef Array Optional vardef for the link in case it can't be found in the passed in bean for the global dictionary
  * @return void
  *
  */
 function __construct($linkName, $bean, $linkDef = false)
 {
     $this->focus = $bean;
     //Try to load the link vardef from the beans field defs. Otherwise start searching
     if (empty($bean->field_defs) || empty($bean->field_defs[$linkName]) || empty($bean->field_defs[$linkName]['relationship'])) {
         if (empty($linkDef)) {
             //Assume $linkName is really relationship_name, and find the link name with the vardef manager
             $this->def = VardefManager::getLinkFieldForRelationship($bean->module_dir, $bean->object_name, $linkName);
         } else {
             $this->def = $linkDef;
         }
         //Check if multiple links were found for a given relationship
         if (is_array($this->def) && !isset($this->def['name'])) {
             //More than one link found, we need to figure out if we are currently on the LHS or RHS
             //default to lhs for now
             if (isset($this->def[0]['side']) && $this->def[0]['side'] == 'left') {
                 $this->def = $this->def[0];
             } else {
                 if (isset($this->def[1]['side']) && $this->def[1]['side'] == 'left') {
                     $this->def = $this->def[1];
                 } else {
                     $this->def = $this->def[0];
                 }
             }
         }
         if (empty($this->def['name'])) {
             $GLOBALS['log']->fatal("failed to find link for {$linkName}");
             return false;
         }
         $this->name = $this->def['name'];
     } else {
         //Linkdef was found in the bean (this is the normal expectation)
         $this->def = $bean->field_defs[$linkName];
         $this->name = $linkName;
     }
     //Instantiate the relationship for this link.
     $this->relationship = SugarRelationshipFactory::getInstance()->getRelationship($this->def['relationship']);
     // Fix to restore functionality from Link.php that needs to be rewritten but for now this will do.
     $this->relationship_fields = !empty($this->def['rel_fields']) ? $this->def['rel_fields'] : array();
     if (!$this->loadedSuccesfully()) {
         global $app_strings;
         $GLOBALS['log']->error(string_format($app_strings['ERR_DATABSE_RELATIONSHIP_QUERY'], array($this->name, $this->def['relationship'])));
     }
     //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($this->def) && is_array($this->def)) {
         if (isset($this->def['ignore_role'])) {
             if ($this->def['ignore_role']) {
                 $this->ignore_role_filter = true;
                 $this->add_distinct = true;
             }
         }
         if (!empty($this->def['primary_only'])) {
             $this->relationship->primaryOnly = true;
         }
     }
 }
 /**
  * The constructor
  * @param string $subpanelName
  * @param string $loadedModule - Accounts
  * @param string $client - base
  */
 public function __construct($subpanelName, $loadedModule, $client = 'base')
 {
     $GLOBALS['log']->debug(get_class($this) . "->__construct({$subpanelName} , {$loadedModule})");
     $this->mdc = new MetaDataConverter();
     $this->loadedModule = $loadedModule;
     $this->setViewClient($client);
     $linkName = $this->linkName = $this->getLinkName($subpanelName, $loadedModule);
     // get the link and the related module name as the module we need the subpanel from
     $bean = BeanFactory::getBean($loadedModule);
     // Get the linkdef, but make sure to tell VardefManager to use name instead by passing true
     $linkDef = VardefManager::getLinkFieldForRelationship($bean->module_dir, $bean->object_name, $subpanelName, true);
     if ($bean->load_relationship($linkName)) {
         $link = $bean->{$linkName};
     } else {
         $link = new Link2($linkName, $bean);
     }
     $this->_moduleName = $link->getRelatedModuleName();
     $this->bean = BeanFactory::getBean($this->_moduleName);
     $subpanelFixed = true;
     if (empty($this->bean)) {
         $subpanelFixed = $this->fixUpSubpanel();
     }
     if (empty($linkDef['name']) && (!$subpanelFixed && isModuleBWC($this->loadedModule))) {
         $GLOBALS['log']->error("Cannot find a link for {$subpanelName} on {$loadedModule}");
         return true;
     }
     // Handle validation up front that will throw exceptions
     if (empty($this->bean) && !$subpanelFixed) {
         throw new Exception("No valid parent bean found for {$this->linkName} on {$this->loadedModule}");
     }
     $this->setUpSubpanelViewDefFileInfo();
     include $this->loadedSubpanelFileName;
     // Prepare to load the history file. This will be available in cases when
     // a layout is restored.
     $this->historyPathname = 'custom/history/modules/' . $this->_moduleName . '/clients/' . $this->getViewClient() . '/views/' . $this->sidecarSubpanelName . '/' . self::HISTORYFILENAME;
     $this->_history = new History($this->historyPathname);
     if (file_exists($this->historyPathname)) {
         // load in the subpanelDefOverride from the history file
         $GLOBALS['log']->debug(get_class($this) . ": loading from history");
         require $this->historyPathname;
     }
     $this->_viewdefs = !empty($viewdefs) ? $this->getNewViewDefs($viewdefs) : array();
     $this->_fielddefs = $this->bean->field_defs;
     $this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
     $this->_language = '';
     // don't attempt to access the template_instance property if our subpanel represents a collection, as it won't be there - the sub-sub-panels get this value instead
     if (isset($this->_viewdefs['type']) && $this->_viewdefs['type'] != 'collection') {
         $this->_language = $this->bean->module_dir;
     }
     // Make sure the paneldefs are proper if there are any
     $this->_paneldefs = isset($this->_viewdefs['panels']) ? $this->_viewdefs['panels'] : array();
 }
示例#3
0
 /**
  * @param  $linkName String name of a link field in the module's vardefs
  * @param  $bean SugarBean focus bean for this link (one half of a relationship)
  * @param  $linkDef Array Optional vardef for the link in case it can't be found in the passed in bean for the global dictionary
  * @return void
  *
  */
 function __construct($linkName, $bean, $linkDef = false)
 {
     $this->focus = $bean;
     //Try to load the link vardef from the beans field defs. Otherwise start searching
     if (empty($bean->field_defs) || empty($bean->field_defs[$linkName]) || empty($bean->field_defs[$linkName]['relationship'])) {
         if (empty($linkDef)) {
             //Assume $linkName is really relationship_name, and find the link name with the vardef manager
             $this->def = VardefManager::getLinkFieldForRelationship($bean->module_dir, $bean->object_name, $linkName);
         } else {
             $this->def = $linkDef;
         }
         //Check if multiple links were found for a given relationship
         if (is_array($this->def) && !isset($this->def['name'])) {
             //More than one link found, we need to figure out if we are currently on the LHS or RHS
             //default to lhs for now
             if (isset($this->def[0]['side']) && $this->def[0]['side'] == 'left') {
                 $this->def = $this->def[0];
             } else {
                 if (isset($this->def[1]['side']) && $this->def[1]['side'] == 'left') {
                     $this->def = $this->def[1];
                 } else {
                     $this->def = $this->def[0];
                 }
             }
         }
         if (empty($this->def['name'])) {
             $GLOBALS['log']->fatal("failed to find link for {$linkName}");
             return false;
         }
         $this->name = $this->def['name'];
     } else {
         //Linkdef was found in the bean (this is the normal expectation)
         $this->def = $bean->field_defs[$linkName];
         $this->name = $linkName;
     }
     //Instantiate the relationship for this link.
     $this->relationship = SugarRelationshipFactory::getInstance()->getRelationship($this->def['relationship']);
     if (!$this->loadedSuccesfully()) {
         $GLOBALS['log']->fatal("{$this->name} for {$this->def['relationship']} failed to load\n");
     }
     //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($this->def) && is_array($this->def)) {
         if (array_key_exists('ignore_role', $this->def)) {
             if ($this->def['ignore_role']) {
                 $this->ignore_role_filter = true;
                 $this->add_distinct = true;
             }
         }
     }
 }
示例#4
0
 /**
  * Find the link entry for a particular relationship and module.
  *
  * @param $module
  * @return array|bool
  */
 public function getLinkedDefForModuleByRelationship($module)
 {
     $results = VardefManager::getLinkFieldForRelationship($module, BeanFactory::getObjectName($module), $this->name);
     //Only a single link was found
     if (isset($results['name'])) {
         return $results;
     } else {
         if (is_array($results)) {
             $GLOBALS['log']->error("Warning: Multiple links found for relationship {$this->name} within module {$module}");
             return $this->getMostAppropriateLinkedDefinition($results);
         } else {
             return FALSE;
         }
     }
 }
 public function __construct($def)
 {
     global $dictionary;
     $this->def = $def;
     $this->name = $def['name'];
     $this->selfReferencing = $def['lhs_module'] == $def['rhs_module'];
     $lhsModule = $def['lhs_module'];
     $rhsModule = $def['rhs_module'];
     if ($this->selfReferencing) {
         $links = VardefManager::getLinkFieldForRelationship($lhsModule, BeanFactory::getObjectName($lhsModule), $this->name);
         if (empty($links)) {
             $GLOBALS['log']->fatal("No Links found for relationship {$this->name}");
         } else {
             if (!isset($links[0]) && !isset($links['name'])) {
                 $GLOBALS['log']->fatal("Bad link found for relationship {$this->name}");
             } else {
                 if (!isset($links[1]) && isset($links['name'])) {
                     $this->lhsLinkDef = $this->rhsLinkDef = $links;
                 } else {
                     if (!empty($links[0]) && !empty($links[1])) {
                         if (!empty($links[0]['side']) && $links[0]['side'] == "right" || !empty($links[0]['link_type']) && $links[0]['link_type'] == "one") {
                             //$links[0] is the RHS
                             $this->lhsLinkDef = $links[1];
                             $this->rhsLinkDef = $links[0];
                         } else {
                             //$links[0] is the LHS
                             $this->lhsLinkDef = $links[0];
                             $this->rhsLinkDef = $links[1];
                         }
                     }
                 }
             }
         }
     } else {
         $this->lhsLinkDef = VardefManager::getLinkFieldForRelationship($lhsModule, BeanFactory::getObjectName($lhsModule), $this->name);
         $this->rhsLinkDef = VardefManager::getLinkFieldForRelationship($rhsModule, BeanFactory::getObjectName($rhsModule), $this->name);
         if (!isset($this->lhsLinkDef['name']) && isset($this->lhsLinkDef[0])) {
             $this->lhsLinkDef = $this->lhsLinkDef[0];
         }
         if (!isset($this->rhsLinkDef['name']) && isset($this->rhsLinkDef[0])) {
             $this->rhsLinkDef = $this->rhsLinkDef[0];
         }
     }
     $this->lhsLink = $this->lhsLinkDef['name'];
     $this->rhsLink = $this->rhsLinkDef['name'];
 }
示例#6
0
 /**
  * Create Sugar meetings from calendar events
  * @param SugarBean $parent related object to associate with meetings
  */
 function createSugarEvents($parent = NULL)
 {
     require_once 'modules/Meetings/Meeting.php';
     // if email description contains a meeting id that exists, don't create new meeting
     if (isset($parent) && !empty($parent->description)) {
         preg_match('/record=(.*)&gt/', $parent->description, $match);
         if (!empty($match[1])) {
             $meeting = new Meeting();
             $meeting->disable_row_level_security = true;
             $prev_meeting = $meeting->retrieve_by_string_fields(array("id" => $match[1]));
             if (isset($prev_meeting)) {
                 return;
             }
         }
     }
     foreach ($this->data['calendar'] as $calendar_key => $calendar_val) {
         foreach ($calendar_val->stack as $key => $val) {
             if (!$val instanceof vEvent) {
                 continue;
             }
             $meeting = BeanFactory::getBean('Meetings');
             // Hack - we don't care about this bean's permissions
             $meeting->disable_row_level_security = true;
             $prev_seq = 0;
             $prev_exists = false;
             $prev_meeting = $meeting->retrieve_by_string_fields(array("outlook_id" => $val->event->uid));
             if (isset($prev_meeting) && !empty($prev_meeting->id)) {
                 $prev_seq = (int) $prev_meeting->sequence;
                 $prev_exists = true;
             }
             if (isset($val->event->status) && $val->event->status == 'CANCELLED' && !$prev_exists) {
                 // can't cancel non-existing event, skip
                 continue;
             }
             if (!$prev_exists || $prev_exists && $val->event->sequence > $prev_seq) {
                 // insert if doesn't exist, otherwise overwrite it with newer data if current meeting's sequence is greater than prev. sequence
                 if ($parent) {
                     $meeting->assigned_user_id = $parent->assigned_user_id;
                     $meeting->team_set_id = $parent->team_set_id;
                     $meeting->team_id = $parent->team_id;
                     $meeting->parent_id = $parent->id;
                     $meeting->parent_type = $parent->module_dir;
                 }
                 $meeting->date_start = $val->event->date_start;
                 $meeting->date_end = $val->event->date_end;
                 $meeting->name = $val->event->name;
                 $meeting->date_entered = $val->event->date_created;
                 $meeting->date_modified = $val->event->date_modified;
                 $meeting->location = $val->event->location;
                 $dateDiff = strtotime($val->event->date_end) - strtotime($val->event->date_start);
                 $diffHours = floor($dateDiff / (60 * 60));
                 $diffMinutes = $dateDiff % (60 * 60) / (60 * 60) * 60;
                 $meeting->duration_hours = $diffHours;
                 $meeting->duration_minutes = $diffMinutes;
                 $meeting->outlook_id = $val->event->uid;
                 $meeting->sequence = $val->event->sequence;
                 if ($prev_exists && $val->event->status == 'CANCELLED') {
                     $meeting->deleted = 1;
                     $meeting->mark_deleted($meeting->id);
                     continue;
                 }
                 $meeting_id = $meeting->save();
                 // invite people
                 $emails = array();
                 foreach ($val->event->attendees as $attendee) {
                     if (!empty($attendee['email'])) {
                         $emails[] = "ea.email_address_caps=" . $meeting->db->quoted($this->cleanEmail($attendee['email']));
                     }
                 }
                 if (!empty($val->event->organizer) && !empty($val->event->organizer['email'])) {
                     $emails[] = "ea.email_address_caps=" . $meeting->db->quoted($this->cleanEmail($val->event->organizer['email']));
                 }
                 if (!empty($emails)) {
                     $query = join(" OR ", $emails);
                     $invitees = $meeting->db->query("SELECT eabr.bean_id, eabr.bean_module FROM email_addr_bean_rel eabr\n\t\t\t\t\t    JOIN email_addresses ea ON eabr.email_address_id=ea.id\n\t\t\t\t\t    WHERE eabr.deleted=0 AND ea.deleted=0 AND eabr.bean_module IN ('Users','Contacts','Leads') AND ({$query})\n\t\t\t\t\t    ");
                     $ids = array_flip($meeting->relationship_fields);
                     while ($inv = $meeting->db->fetchByAssoc($invitees)) {
                         $module = strtolower($inv['bean_module']);
                         $relname = "meetings_{$module}";
                         $linkfields = VardefManager::getLinkFieldForRelationship("Meetings", "Meeting", $relname);
                         $bean = BeanFactory::getBean($inv['bean_module']);
                         if (empty($bean)) {
                             $GLOBALS['log']->info("createSugarEvents: Don't know how to create bean {$inv['bean_module']}");
                             continue;
                         }
                         // Hack - we don't care about this bean's permissions
                         $bean->disable_row_level_security = true;
                         $bean->retrieve($inv["bean_id"]);
                         $linkname = $linkfields['name'];
                         $meeting->load_relationship($linkname);
                         if (empty($meeting->{$linkname})) {
                             $GLOBALS['log']->info("createSugarEvents: Unknown module {$module} with link {$linkname} encountered for id {$inv["bean_id"]}");
                             continue;
                         }
                         $GLOBALS['log']->info("Adding link for {$inv["bean_id"]} module {$module} relname {$relname} linkname {$linkname}");
                         $meeting->{$linkname}->add($bean);
                     }
                 }
             }
         }
     }
 }