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; } } } } }
public function executeEntitiesChains($request) { $options = $this->getParams(array('cat_ids', 'page')); $id1 = $request->getParameter('id1'); $id2 = $request->getParameter('id2'); if (!isset($options['cat_ids'])) { $options['cat_ids'] = '1'; } $this->chains = SearchApi::getEntitiesChains($id1, $id2, $options); $this->chain = null; $page = isset($options['page']) ? $options['page'] : 1; $count = 1; foreach ($this->chains as $degree => $ary) { foreach ($ary as $ids) { if ($count == $page) { $this->chain = SearchApi::buildRelationshipChain($ids, $options['cat_ids']); break 2; } $count++; } } if ($this->chain) { $this->entities = array(); foreach ($this->chain as $id => $rels) { $this->entities[$id] = EntityApi::get($id); $this->entities[$id]['relationship_ids'] = implode(',', $rels); } } return 'Xml'; }