示例#1
0
 public function executeRelationships($request)
 {
     if (!($ids = $request->getParameter('ids'))) {
         $this->returnStatusCode(400);
     }
     $ids = explode(',', $ids);
     $options = $this->getParams(array('details', 'cat_id'));
     $this->relationships = BatchApi::getRelationships($ids, $options);
     return 'Xml';
 }
示例#2
0
 public function executeFindConnections()
 {
     $request = $this->getRequest();
     if ($id2 = $request->getParameter('id2')) {
         if (!($this->entity2 = EntityApi::get($id2))) {
             $this->forward404();
         }
         $page = $this->page;
         $num = $request->getParameter('num', 10);
         $options = array('cat_ids' => $request->getParameter('cat_ids', '1'));
         //get all chains
         $chains = SearchApi::getEntitiesChains($this->entity['id'], $id2, $options);
         $offset = ($page - 1) * $num;
         $flat_chains = array();
         foreach ($chains as $degree => $ary) {
             foreach ($ary as $ids) {
                 $flat_chains[] = $ids;
             }
         }
         $page_chains = array_slice($flat_chains, $offset, $num);
         $full_chains = array();
         foreach ($page_chains as $ids) {
             $full = array();
             $chain = SearchApi::buildRelationshipChain($ids, explode(',', $options['cat_ids']));
             foreach ($chain as $id => $rels) {
                 $entity = EntityApi::get($id);
                 $entity['Relationships'] = count($rels) ? BatchApi::getRelationships($rels, array()) : array();
                 $full[] = $entity;
             }
             $full_chains[] = $full;
         }
         // foreach ($page_chains as $degree => $ary)
         // {
         //   foreach ($ary as $ids)
         //   {
         //     if ($count == $page)
         //     {
         //       $chain = SearchApi::buildRelationshipChain($ids, explode(',', $options['cat_ids']));
         //       break 2;
         //     }
         //     $count++;
         //   }
         // }
         // count total number of chains
         // $total = 0;
         // foreach ($chains as $degree => $ary)
         // {
         //   $total += count($ary);
         // }
         if ($total = count($flat_chains)) {
             $chainAry = array_fill(0, $total, null);
             array_splice($chainAry, $offset, $num, $full_chains);
             $this->chain_pager = new LsDoctrinePager($chainAry, $page, $num);
         }
         // get entities for chain
         // if ($chain)
         // {
         //   $this->entities = array();
         //   foreach ($chain as $id => $rels)
         //   {
         //     $entity = EntityApi::get($id);
         //     $entity['Relationships'] = count($rels) ? BatchApi::getRelationships($rels, array()) : array();
         //     $this->entities[] = $entity;
         //   }
         //   $chainAry = array_fill(0, $total, null);
         //   $chainAry[$page-1] = $this->entities;
         //   $this->chain_pager = new LsDoctrinePager($chainAry, $page, $num);
         // }
     } else {
         //form submission, display matching persons
         if ($request->hasParameter('q')) {
             $num = $request->getParameter('num', 10);
             $page = $request->getParameter('page', 1);
             if (!($terms = $request->getParameter('q'))) {
                 $this->entity_pager = new LsDoctrinePager(array(), $page, $num);
             } else {
                 switch (sfConfig::get('app_search_engine')) {
                     case 'sphinx':
                         $this->entity_pager = EntityTable::getSphinxPager($terms, $page, $num);
                         break;
                     case 'lucene':
                         $ary = EntityTable::getLuceneArray($terms, null);
                         $this->entity_pager = new LsDoctrinePager($ary, $page, $num);
                         break;
                     case 'mysql':
                     default:
                         $terms = explode(' ', $terms);
                         $q = EntityTable::getSimpleSearchQuery($terms);
                         $this->entity_pager = new Doctrine_Pager($q, $page, $num);
                         break;
                 }
             }
         }
     }
 }