Exemplo n.º 1
0
 public function executeAddEntity($request)
 {
     $this->checkList($request);
     $this->checkUser($this->list, 'admin');
     if ($request->hasParameter('q')) {
         $page = $request->getParameter('page', 1);
         $num = $request->getParameter('num', 10);
         if (!($terms = $request->getParameter('q'))) {
             $this->results_pager = new LsDoctrinePager(array(), $page, $num);
         } else {
             switch (sfConfig::get('app_search_engine')) {
                 case 'sphinx':
                     $this->results_pager = EntityTable::getSphinxPager($terms, $page, $num);
                     break;
                 case 'lucene':
                     $ary = EntityTable::getLuceneArray($terms, null);
                     $this->results_pager = new LsDoctrinePager($ary, $page, $num);
                     break;
                 case 'mysql':
                 default:
                     $terms = explode(' ', $terms);
                     $q = EntityTable::getSimpleSearchQuery($terms);
                     $this->results_pager = new Doctrine_Pager($q, $page, $num);
                     break;
             }
         }
     }
     if ($request->isMethod('post')) {
         $entity = Doctrine::getTable('Entity')->find($request->getParameter('entity_id'));
         $this->forward404Unless($entity);
         //if entity is already on the list, do nothing
         $q = LsDoctrineQuery::create()->from('LsListEntity le')->where('le.list_id = ? AND le.entity_id = ?', array($this->list['id'], $entity['id']));
         if (!$q->count()) {
             $listEntity = new LsListEntity();
             $listEntity->list_id = $this->list->id;
             $listEntity->entity_id = $entity->id;
             $listEntity->save();
             $this->clearCache($this->list);
             $this->clearRailsCache($this->list->id);
             LsCache::clearEntityCacheById($entity->id);
         }
         $this->redirect($this->list->getInternalUrl());
     }
 }
Exemplo n.º 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;
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public function executeAddRelationship($request)
 {
     $this->checkEntity($request, false, false);
     //for entity creation form, show network options if user's home network is not the US
     $homeNetworkId = sfGuardUserTable::getHomeNetworkId();
     $networkIds = array_unique(array(LsListTable::US_NETWORK_ID, $homeNetworkId));
     if (count($networkIds) > 1) {
         $this->networks = LsDoctrineQuery::create()->from('LsList l')->whereIn('l.id', $networkIds)->execute();
     }
     if ($request->isMethod('post')) {
         $primary = $request->getParameter('primary');
         $primary = $primary[0];
         $name = $request->getParameter('name');
         if (!$name) {
             $request->setError('name', 'You must enter a name');
         }
         if ($primary == 'Person') {
             $entity = PersonTable::parseFlatName($name);
             if ($name && !$entity->name_last) {
                 $request->setError('name', 'The name you entered is invalid');
             }
         } elseif ($primary == 'Org') {
             $entity = new Entity();
             $entity->addExtension('Org');
             $entity->name = $name;
         } else {
             $request->setError('primary', 'You must select a type');
         }
         if (!$request->hasErrors()) {
             //set blurb
             $entity->blurb = $request->getParameter('blurb');
             //add extensions
             $extensions = array();
             if ($request->getParameter('extensions')) {
                 $extensions = array_keys($request->getParameter('extensions'));
             }
             $allowedExtensions = ExtensionDefinitionTable::getNamesByParent($primary);
             $extensions = array_intersect($extensions, $allowedExtensions);
             foreach ($extensions as $extension) {
                 $entity->addExtension($extension);
             }
             //get networks to add entity to
             $networkIds = $request->getParameter('network_ids', array(sfGuardUserTable::getHomeNetworkId()));
             //save and redirect to edit page
             $entity->save(null, true, $networkIds);
             $this->redirect($this->entity->getInternalUrl('addRelationshipCategory', array('entity2_id' => $entity->id)));
         }
     }
     //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;
             }
         }
         $this->primary_exts = array('Person', 'Org');
         $this->tier2_defs = array();
         $this->tier3_defs = array();
         foreach ($this->primary_exts as $primaryExt) {
             $this->tier2_defs[$primaryExt] = ExtensionDefinitionTable::getByTier(2, $primaryExt);
             $this->tier3_defs[$primaryExt] = ExtensionDefinitionTable::getByTier(3, $primaryExt);
         }
     }
 }