Example #1
0
 public static function getAddRelatedEntitiesAndRelsForMap($entity_id, $num, $entity_ids, $rel_ids, $include_cats = array(), $exclude_cats = array())
 {
     if (!$entity_ids) {
         $entity_ids = array();
     }
     if (!$rel_ids) {
         $rel_ids = array();
     }
     if (!$include_cats) {
         $include_cats = array();
     }
     if (!$exclude_cats) {
         $exclude_cats = array();
     }
     $related_entities = EntityTable::getRelatedEntitiesForMap($entity_id, $num, $include_cats, $exclude_cats, $entity_ids);
     $new_entities = array();
     foreach ($related_entities as $entity) {
         if (!in_array($entity["id"], $entity_ids)) {
             $new_entities[] = $entity;
         }
     }
     if (count($new_entities) == 0) {
         return array("entities" => array(), "rels" => array());
     }
     $new_entity_ids = array_map(function ($e) {
         return $e['id'];
     }, $new_entities);
     $entity_ids = array_map(function ($id) {
         return (int) $id;
     }, array_merge($entity_ids, $new_entity_ids));
     $entity_ids = array_unique($entity_ids);
     // get all new rels
     $rels = self::getRelsForMapBetween($new_entity_ids, $entity_ids, $include_cats, $exclude_cats);
     $new_rels = array();
     foreach ($rels as $rel) {
         if (!in_array($rel["id"], $rel_ids)) {
             $new_rels[] = $rel;
         }
     }
     return array("entities" => $new_entities, "rels" => $new_rels);
 }