Ejemplo n.º 1
0
 function getData($objectType, $objectId, Search_Type_Factory_Interface $typeFactory, array $data = array())
 {
     if (isset($data['relations']) || isset($data['relation_types'])) {
         return array();
     }
     $relations = array();
     $types = array();
     $from = $this->relationlib->get_relations_from($objectType, $objectId);
     foreach ($from as $rel) {
         $relations[] = Search_Query_Relation::token($rel['relation'], $rel['type'], $rel['itemId']);
         $types[] = $rel['relation'];
     }
     $to = $this->relationlib->get_relations_to($objectType, $objectId);
     foreach ($to as $rel) {
         $relations[] = Search_Query_Relation::token($rel['relation'] . '.invert', $rel['type'], $rel['itemId']);
         $types[] = $rel['relation'] . '.invert';
     }
     //take the type array and get a count of each indiv. type
     $type_count = array_count_values($types);
     $rel_count = array();
     foreach ($type_count as $key => $val) {
         //instead of returning an assoc. array, format to "relation:count" format for input in index
         $rel_count[] = $key . ":" . $val;
     }
     return array('relations' => $typeFactory->multivalue($relations), 'relation_types' => $typeFactory->multivalue(array_unique($types)), 'relation_count' => $typeFactory->multivalue($rel_count));
 }
Ejemplo n.º 2
0
 function getData($objectType, $objectId, Search_Type_Factory_Interface $typeFactory, array $data = array())
 {
     $relations = array();
     $from = $this->relationlib->get_relations_from($objectType, $objectId);
     foreach ($from as $rel) {
         $relations[] = Search_Query_Relation::token($rel['relation'], $rel['type'], $rel['itemId']);
     }
     $to = $this->relationlib->get_relations_to($objectType, $objectId);
     foreach ($to as $rel) {
         $relations[] = Search_Query_Relation::token($rel['relation'] . '.invert', $rel['type'], $rel['itemId']);
     }
     return array('relations' => $typeFactory->multivalue($relations));
 }
Ejemplo n.º 3
0
 function visit(Search_Expr_Interface $expr, $results)
 {
     if ($expr instanceof Search_Expr_Token) {
         $relation = Search_Query_Relation::fromToken($expr);
         if (in_array($relation->getQualifier(), $this->invertable)) {
             $invert = $relation->getInvert();
             return new Search_Expr_Or(array($expr, new Search_Expr_Token($invert->getToken())));
         }
     }
     if ($expr instanceof Search_Expr_Or || $expr instanceof Search_Expr_And) {
         $class = get_class($expr);
         return new $class($results);
     } elseif ($expr instanceof Search_Expr_Not) {
         return new Search_Expr_Not($results[0]);
     }
     return $expr;
 }
Ejemplo n.º 4
0
 protected function populate($index)
 {
     $typeFactory = $index->getTypeFactory();
     $index->addDocument(array('object_type' => $typeFactory->identifier('wiki page'), 'object_id' => $typeFactory->identifier('HomePage'), 'title' => $typeFactory->sortable('HomePage'), 'language' => $typeFactory->identifier('en'), 'modification_date' => $typeFactory->timestamp(self::DOCUMENT_DATE), 'description' => $typeFactory->plaintext('a description for the page'), 'categories' => $typeFactory->multivalue(array(1, 2, 5, 6)), 'allowed_groups' => $typeFactory->multivalue(array('Project Lead', 'Editor', 'Admins')), 'contents' => $typeFactory->plaintext('a description for the page Hello world!'), 'relations' => $typeFactory->multivalue(array(Search_Query_Relation::token('tiki.content.link', 'wiki page', 'About'), Search_Query_Relation::token('tiki.content.link', 'wiki page', 'Contact'), Search_Query_Relation::token('tiki.content.link.invert', 'wiki page', 'Product'), Search_Query_Relation::token('tiki.user.favorite.invert', 'user', 'bob')))));
 }
Ejemplo n.º 5
0
 function getData($objectType, $objectId, Search_Type_Factory_Interface $typeFactory, array $data = array())
 {
     global $prefs;
     if (isset($data['relations']) || isset($data['relation_types'])) {
         return array();
     }
     $relations = array();
     $relation_objects = array();
     $types = array();
     $relation_objects_to_index = array();
     if ($prefs['unified_engine'] == 'elastic') {
         // only index full objects in elasticsearch
         $relation_objects_to_index = array_map('trim', explode(',', $prefs['unified_relation_object_indexing']));
     }
     $from = $this->relationlib->get_relations_from($objectType, $objectId);
     foreach ($from as $rel) {
         $relations[] = Search_Query_Relation::token($rel['relation'], $rel['type'], $rel['itemId']);
         $types[] = $rel['relation'];
         if (in_array($rel['relation'], $relation_objects_to_index)) {
             $contentSource = $this->contentSources[$rel['type']];
             //new Search_ContentSource_TrackerItemSource();
             $data = $contentSource->getDocument($rel['itemId'], $typeFactory);
             $permissionSource = new Search_GlobalSource_PermissionSource(Perms::getInstance());
             $data = array_merge($data, $permissionSource->getData($rel['type'], $rel['itemId'], $typeFactory, $data));
             foreach ($data as &$item) {
                 if ($item instanceof Search_Type_Interface) {
                     $item = $item->getValue();
                 }
             }
             $data['relation'] = $rel['relation'];
             $relation_objects[] = $data;
         }
     }
     $to = $this->relationlib->get_relations_to($objectType, $objectId);
     foreach ($to as $rel) {
         $relations[] = Search_Query_Relation::token($rel['relation'] . '.invert', $rel['type'], $rel['itemId']);
         $rel_type = $rel['relation'] . '.invert';
         $types[] = $rel_type;
         if (in_array($rel_type, $relation_objects_to_index)) {
             $contentSource = $this->contentSources[$rel['type']];
             //new Search_ContentSource_TrackerItemSource();
             $data = $contentSource->getDocument($rel['itemId'], $typeFactory);
             $permissionSource = new Search_GlobalSource_PermissionSource(Perms::getInstance());
             $data = array_merge($data, $permissionSource->getData($rel['type'], $rel['itemId'], $typeFactory, $data));
             foreach ($data as &$item) {
                 if ($item instanceof Search_Type_Interface) {
                     $item = $item->getValue();
                 }
             }
             $data['relation'] = $rel['relation'];
             $relation_objects[] = $data;
         }
     }
     //take the type array and get a count of each indiv. type
     $type_count = array_count_values($types);
     $rel_count = array();
     foreach ($type_count as $key => $val) {
         //instead of returning an assoc. array, format to "relation:count" format for input in index
         $rel_count[] = $key . ":" . $val;
     }
     return array('relations' => $typeFactory->multivalue($relations), 'relation_objects' => $typeFactory->nested($relation_objects), 'relation_types' => $typeFactory->multivalue(array_unique($types)), 'relation_count' => $typeFactory->multivalue($rel_count));
 }
Ejemplo n.º 6
0
 protected function getUsers($itemId, $list)
 {
     $lib = TikiLib::lib('unifiedsearch');
     $query = $lib->buildQuery(['object_type' => 'user']);
     $complete = Search_Query_Relation::token('tiki.mustread.complete', 'trackeritem', $itemId);
     $relations = $query->getSubQuery('relations');
     foreach ($this->getAvailableActions() as $key => $label) {
         $token = Search_Query_Relation::token("tiki.mustread.{$key}", 'trackeritem', $itemId);
         $relations->filterRelation($token);
     }
     if ($list == 'sent') {
         // All, no additional filtering
     } elseif ($list == 'open') {
         $query->filterRelation($complete);
     } elseif ($list == 'unopen') {
         $query->filterRelation("NOT \"{$complete}\"");
     } else {
         return false;
     }
     return $query;
 }