Ejemplo n.º 1
0
 /**
  * Mass loading of CExObjects
  *
  * @param self[] $list List of ExLinks
  *
  * @return void
  */
 static function massLoadExObjects(array $list)
 {
     $ex_object_id_by_ex_class = array();
     $ex_links_by_ex_class = array();
     foreach ($list as $_link) {
         $_ex_class_id = $_link->ex_class_id;
         $ex_object_id_by_ex_class[$_ex_class_id][] = $_link->ex_object_id;
         $ex_links_by_ex_class[$_ex_class_id][] = $_link;
     }
     foreach ($ex_object_id_by_ex_class as $_ex_class_id => $_ex_object_ids) {
         $_ex_object = new CExObject($_ex_class_id);
         $where = array("ex_object_id" => $_ex_object->getDS()->prepareIn($_ex_object_ids));
         $_ex_objects = $_ex_object->loadList($where);
         /** @var CExLink $_link */
         foreach ($ex_links_by_ex_class[$_ex_class_id] as $_link) {
             $_link->_ref_ex_object = $_ex_objects[$_link->ex_object_id];
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param CMbObject $object
  *
  * @return CExObject[][]
  */
 static function getExObjectsOf(CMbObject $object)
 {
     CExClassField::$_load_lite = true;
     CExObject::$_multiple_load = true;
     $group_id = CGroups::loadCurrent()->_id;
     $where = array("group_id = '{$group_id}' OR group_id IS NULL");
     if (empty(CExClass::$_list_cache)) {
         $ex_class = new CExClass();
         CExClass::$_list_cache = $ex_class->loadList($where, "name");
         if (!CExObject::$_locales_cache_enabled) {
             foreach (CExClass::$_list_cache as $_ex_class) {
                 foreach ($_ex_class->loadRefsGroups() as $_group) {
                     $_group->loadRefsFields();
                     foreach ($_group->_ref_fields as $_field) {
                         $_field->updateTranslation();
                     }
                 }
             }
         }
     }
     $ex_objects = array();
     $limit = 1;
     $ref_objects_cache = array();
     foreach (CExClass::$_list_cache as $_ex_class_id => $_ex_class) {
         $_ex_object = new CExObject($_ex_class_id);
         $where = array("(reference_class  = '{$object->_class}' AND reference_id  = '{$object->_id}') OR\n         (reference2_class = '{$object->_class}' AND reference2_id = '{$object->_id}') OR\n         (object_class     = '{$object->_class}' AND object_id     = '{$object->_id}')");
         $ljoin = array();
         /** @var CExObject[] $_ex_objects */
         $_ex_objects = $_ex_object->loadList($where, "{$_ex_object->_spec->key} DESC", $limit, null, $ljoin);
         foreach ($_ex_objects as $_ex) {
             $_ex->_ex_class_id = $_ex_class_id;
             $_ex->load();
             $guid = "{$_ex->object_class}-{$_ex->object_id}";
             if (!isset($ref_objects_cache[$guid])) {
                 $_ex->loadTargetObject()->loadComplete();
                 // to get the view
                 $ref_objects_cache[$guid] = $_ex->_ref_object;
             } else {
                 $_ex->_ref_object = $ref_objects_cache[$guid];
             }
             if ($_ex->additional_id) {
                 $_ex->loadRefAdditionalObject();
             }
             $ex_objects[$_ex_class_id][$_ex->_id] = $_ex;
         }
         if (isset($ex_objects[$_ex_class_id])) {
             krsort($ex_objects[$_ex_class_id]);
         }
     }
     ksort($ex_objects);
     return $ex_objects;
 }