Ejemplo n.º 1
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;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function executeFindMember($request)
 {
     $this->checkList($request);
     $terms = explode(' ', $request->getParameter('member_search_terms'));
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 10);
     $q = EntityTable::getSimpleSearchQuery($terms)->leftJoin('e.LsListEntity listentity')->andWhere('listentity.list_id = ?', $this->list->id);
     $this->member_pager = new Doctrine_Pager($q, $page, $num);
 }
Ejemplo n.º 3
0
 public function executeFindEntity($request)
 {
     $this->entityField = $request->getParameter('entity_field');
     $this->forward404Unless($this->entityField);
     $terms = $request->getParameter(strtolower($this->entityField) . '_terms');
     $terms = preg_replace('/\\s{2,}/', ' ', $terms);
     $terms = explode(' ', $terms);
     //search for query that excludes the current Entity1
     $q = EntityTable::getSimpleSearchQuery($terms);
     $num = $request->getParameter('num', 10);
     $page = $request->getParameter('page', 1);
     $this->entity_pager = new LsDoctrinePager($q, $page, $num);
     return $this->renderPartial('relationship/entityresults');
 }
Ejemplo n.º 4
0
 public function executeFindOrg($request)
 {
     $terms = $request->getParameter('org_terms');
     $terms = preg_replace('/\\s{2,}/', ' ', $terms);
     $terms = explode(' ', $terms);
     //search for query that excludes the current Entity1
     $q = EntityTable::getSimpleSearchQuery($terms, array('Org'));
     $num = $request->getParameter('num', 10);
     $page = $request->getParameter('page', 1);
     $this->entity_pager = new LsDoctrinePager($q, $page, $num);
     return $this->renderPartial('operation/entityresults');
 }
Ejemplo n.º 5
0
 public function executeChangeParent($request)
 {
     $this->checkEntity($request, false, false);
     //form submission, display matching persons
     if ($request->hasParameter('parent_terms')) {
         $terms = $request->getParameter('parent_terms');
         $terms = preg_replace('/\\s{2,}/', ' ', $terms);
         $terms = explode(' ', $terms);
         //search for query that excludes the current Entity
         $q = EntityTable::getSimpleSearchQuery($terms, array('Org'))->addWhere('e.id <> ?', $this->entity->id);
         $num = $request->getParameter('num', 10);
         $page = $request->getParameter('page', 1);
         $this->entity_pager = new LsDoctrinePager($q, $page, $num);
     }
     if ($request->isMethod('post')) {
         if (!($parent = Doctrine::getTable('Entity')->findOneById($request->getParameter('parent_id')))) {
             $this->forward404();
         }
         $this->entity->parent_id = $parent->id;
         $this->entity->save();
         $this->clearCache($this->entity);
         $this->clearCache($parent);
         $this->redirect($this->entity->getInternalUrl('editHierarchy'));
     }
 }