protected function execute($arguments = array(), $options = array()) { if (!$this->safeToRun()) { print "Process already running!\n"; die; } $timer = sfTimerManager::getTimer('execute'); $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); //set up index $index = EntityTable::getLuceneIndex(); //delete deleted entities $q = LsDoctrineQuery::create()->from('Entity e')->where('e.is_deleted = ?', true)->setHydrationMode(Doctrine::HYDRATE_ARRAY); foreach ($q->execute() as $entity) { if ($hits = $index->find('key:' . $entity['id'])) { if ($options['debug_mode']) { printf("Deleting index for Entity %s\n", $entity['id']); } foreach ($hits as $hit) { $index->delete($hit->id); } } } printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage())); printf("Index size: %s\n", $index->count()); $timer->addTime(); printf("Run time: %s\n", $timer->getElapsedTime()); sfTimerManager::clearTimers(); }
protected function execute($arguments = array(), $options = array()) { $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true); $databaseManager = new sfDatabaseManager($configuration); $databaseManager->initialize($configuration); $this->db = Doctrine_Manager::connection(); if ($options['house_senate'] == 'house') { $sql = 'select e1.id,e2.id from entity e1 left join political_candidate pc on pc.entity_id = e1.id left join political_candidate pc2 on pc2.house_fec_id = pc.house_fec_id left join entity e2 on e2.id = pc2.entity_id where e1.is_deleted = 0 and e2.is_deleted = 0 and e1.id <> e2.id and pc.id is not null and pc2.id is not null and pc.id <> pc2.id and pc.house_fec_id is not null and pc.house_fec_id <> "" and e1.id < e2.id group by e1.id,e2.id'; } else { if ($options['house_senate'] == 'senate') { $sql = 'select e1.id,e2.id from entity e1 left join political_candidate pc on pc.entity_id = e1.id left join political_candidate pc2 on pc2.senate_fec_id = pc.senate_fec_id left join entity e2 on e2.id = pc2.entity_id where e1.is_deleted = 0 and e2.is_deleted = 0 and e1.id <> e2.id and pc.id is not null and pc2.id is not null and pc.id <> pc2.id and pc.senate_fec_id is not null and pc.senate_fec_id <> "" and e1.id < e2.id group by e1.id,e2.id'; } else { echo 'House or Senate not selected...ending script' . "\n"; die; } } $stmt = $this->db->execute($sql); $rows = $stmt->fetchAll(); foreach ($rows as $row) { $e1 = Doctrine::getTable('Entity')->find($row[0]); $e2 = Doctrine::getTable('Entity')->find($row[1]); $mergedEntity = EntityTable::mergeAll($e1, $e2); $e2->setMerge(true); $e2->clearRelated(); $e2->delete(); echo ' Successfully merged ' . $e2->name . "\n"; if ($options['test_mode']) { die; } } }
public function getEntitiesByExtension($extension = 'Person') { $q = EntityTable::getByExtensionQuery($extension); if ($this->limit) { $q->limit($this->limit); } return $q; }
public function setSelectObject(Doctrine_Record $object, $autoSelect = false, $contactInfo = false) { $this->_selectObject = $object; if ($object instanceof Relationship) { //when editing a Relationship, show all Relationship references //plus all references for Entity1 and Entity2 //plus 5 most recent references for Entity1's Relationships //plus 5 most recent references for Entity2's Relationships $refs = RelationshipTable::getReferencesForRelationship($object); } else { if ($object instanceof Entity && $contactInfo == true) { $refs = EntityTable::getContactReferencesById($object->id); } else { $refs = $object->getReferencesByFields(null, Doctrine::HYDRATE_ARRAY); if ($object instanceof Entity) { //when editing an Entity, show all Entity references //plus 10 most recent references for the Entity's Relationships $refs = array_merge($refs, EntityTable::getRecentRelationshipReferencesQuery($object, 10)->setHydrationMode(Doctrine::HYDRATE_ARRAY)->execute()); } } } $tmpRefs = array(); $uniqueRefs = array(); //consolidate references foreach ($refs as $ref) { if (!isset($tmpRefs[$ref['source']])) { $tmpRefs[$ref['source']] = array($ref['name']); $uniqueRefs[] = $ref; } else { if (!in_array($ref['name'], $tmpRefs[$ref['source']])) { $tmpRefs[$ref['source']][] = $ref['name']; $uniqueRefs[] = $ref; } } } $refs = $uniqueRefs; if (count($refs)) { //create choices array $choices = array('' => ''); foreach ($refs as $ref) { $choices[$ref['id']] = ReferenceTable::getDisplayName($ref); } //add select widget $widgets = array(); $widgets['existing_source'] = new sfWidgetFormSelect(array('choices' => $choices)); $widgets = array_merge($widgets, $this->getWidgetSchema()->getFields()); $this->setWidgets($widgets); if ($autoSelect && count($directRefs = $object->getReferencesByFields()->getData()) == 1) { $this->setDefault('existing_source', $directRefs[0]->id); } $this->widgetSchema->setLabels(array('source' => 'Source URL', 'name' => 'Display name', 'source_detail' => 'Location in source')); $this->widgetSchema->setHelps(array('source' => $this->_sourceHelp, 'name' => $this->_nameHelp, 'source_detail' => 'eg: Chapter 5, pp 75-80', 'publication_date' => LsFormHelp::$dateHelp, 'excerpt' => 'relevant section(s) of the source text')); $this->widgetSchema->setNameFormat('reference[%s]'); //make source validator optional $this->validatorSchema['existing_source'] = new sfValidatorChoice(array('choices' => array_keys($choices))); } }
protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); $entities = LsDoctrineQuery::create()->from('Entity e')->where('CHAR_LENGTH(e.name) = 100')->groupBy('e.name')->execute(); foreach ($entities as $e) { echo $e->id . ' :: ' . $e->name; echo "\n"; $duplicates = LsDoctrineQuery::create()->from('Entity e')->where('e.id != ? and e.name = ?', array($e->id, $e->name))->execute(); foreach ($duplicates as $e2) { $mergedEntity = EntityTable::mergeAll($e, $e2); $e2->setMerge(true); $e2->clearRelated(); $e2->delete(); echo ' Successfully merged ' . $e2->name . "\n"; } } /*$id = 0; $industry = LsDoctrineQuery::create() ->from('Industry i') ->where('id > ?',$id) ->fetchOne(); while ($industry) { $matches = LsDoctrineQuery::create() ->from('Industry i') ->where('i.name = ? and i.id != ?', array($industry->name,$industry->id)) ->execute(); echo $matches->count() . '...'; foreach($matches as $match) { $bis = LsDoctrineQuery::create() ->from('BusinessIndustry bi') ->where('bi.industry_id = ?', $match->id) ->execute(); foreach($bis as $b) { $b->industry_id = $industry->id; $b->save(); $match->delete(); } } $id = $industry->id; $industry = LsDoctrineQuery::create() ->from('Industry i') ->where('id > ?',$id) ->fetchOne(); } $images = LsQuery::getByModelAndFieldsQuery('Image',array('caption' => 'Array')); foreach($images as $image) { $image->caption = 'From the Biographical Directory of the United States Congress'; $image->save(); }*/ }
protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); $extensions1 = explode(',', $options['extensions1']); $extensions2 = explode(',', $options['extensions2']); $exact_first = $options['exact_first']; $start_id = $options['start_id']; $min_duplicates = $options['min_duplicates'] - 1; if (!in_array('Person', $extensions1) && !in_array('Person', $extensions2) && (!in_array('Org', $extensions1) && !in_array('Org', $extensions2))) { $this->printDebug('extension issues, exiting'); die; } $this->fileName = $options['file_name']; $entity = EntityTable::getByExtensionQuery($extensions1)->addWhere('e.id > ?', $start_id)->limit(1)->execute()->getFirst(); $ct = 0; $fh = fopen($this->fileName, 'a'); $been_done = array(); while ($entity) { $start_id = $entity->id; if (in_array('Person', $extensions1)) { $q = EntityTable::getByExtensionQuery($extensions2)->addWhere('person.name_last = ? and e.id <> ?', array($entity->name_last, $entity->id)); if (!$exact_first) { $q->addWhere('person.name_first like ?', substr($entity->name_first, 0, 1) . '%'); } else { $q->addWhere('person.name_first = ?', $entity->name_first); } if ($entity->name_middle) { $q->addWhere('person.name_middle like ? OR person.name_middle IS NULL', substr($entity->name_middle, 0, 1) . '%'); } } else { if (strlen($entity->name) > 8) { $q->addWhere('e.name like ?', '%' . $entity->name . '%'); } else { $q->addWhere('e.name = ?', $entity->name); } } if ($q->count() > $min_duplicates) { $matches = $q->execute(); $arr = array(); echo $entity->name . "\n"; foreach ($matches as $match) { $been_done[] = $match->id; $arr[] = $match->name; } $links = $entity->name . "\t"; $links .= implode("; ", $arr) . "\t"; $links .= 'http://littlesis.org/entity/view?id=' . $entity->id . "\n"; fwrite($fh, $links); } $entity = EntityTable::getByExtensionQuery($extensions1)->addWhere('e.id > ?', $start_id)->limit(1)->execute()->getFirst(); } fclose($fh); }
static function convertValueForDisplay($value, $field, $excerpt = 40) { if (is_null($value)) { return 'NULL'; } if (!($mod = self::loadModification($field))) { return $value; } $table = Doctrine::getTable($mod['object_model']); $columns = $table->getColumns(); if ($mod['object_model'] == 'Entity') { if (!array_key_exists($field['field_name'], $columns)) { if ($extensionName = EntityTable::getExtensionNameByFieldName($field['field_name'])) { $table = Doctrine::getTable($extensionName); } } } elseif ($mod['object_model'] == 'Relationship') { if (!array_key_exists($field['field_name'], $columns)) { $table = Doctrine::getTable(RelationshipTable::getCategoryNameByFieldName($field['field_name'])); } } if ($alias = self::getFieldNameAlias($field)) { $class = $table->getRelation($alias)->getClass(); if ($record = Doctrine::getTable($class)->find($value, Doctrine::HYDRATE_ARRAY)) { if ($class == 'Entity') { sfLoader::loadHelpers('Ls'); return entity_link($record, null); } elseif ($class == 'sfGuardUser') { sfLoader::loadHelpers('Ls'); return user_link($record); } return $record; } } if (in_array($field['field_name'], array('start_date', 'end_date'))) { return Dateable::convertForDisplay($value); } $def = $table->getColumnDefinition($field['field_name']); switch ($def['type']) { case 'integer': return (double) $value; break; case 'boolean': return $value ? 'yes' : 'no'; break; } if ($excerpt) { $short = LsString::excerpt($value, $excerpt); return $short == $value ? $value : '<span title="' . strip_tags($value) . '">' . $short . '</span>'; } return $value; }
protected function execute($arguments = array(), $options = array()) { $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true); $databaseManager = new sfDatabaseManager($configuration); $databaseManager->initialize($configuration); $q = EntityTable::getByExtensionQuery(array('Person', 'ElectedRepresentative'))->addWhere('summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ?', array('(daughter%', '(son%', '(father%', '(mother%', '(cousin%', '(husband%', '(wife%', '(brother%', '(sister%'))->orderBy('person.name_last'); $members = $q->execute(); foreach ($members as $member) { if (preg_match('/\\([^\\)]*\\)/isu', $member->summary, $match)) { echo $member->name . ":\n"; if (preg_match_all('/(brother|sister|daughter|mother|father|wife|husband|cousin)\\sof\\s+([^\\;\\)\\,]*)(\\;|\\)|\\,)/isu', $match[0], $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { echo "\t\t" . $m[1] . ' : of : ' . $m[2] . "\n"; $m[2] = str_replace('.', '', $m[2]); $parts = LsString::split($m[2]); $q = EntityTable::getByExtensionQuery(array('Person', 'ElectedRepresentative')); foreach ($parts as $part) { $q->addWhere('e.name like ?', '%' . $part . '%'); } $people = $q->execute(); $family = array(); foreach ($people as $person) { echo "\t\t\t\t" . $person->name . "\n"; if ($person->id != $member->id) { $family[] = $person; } } if (count($family) == 1) { $q = LsDoctrineQuery::create()->from('Relationship r')->where('(r.entity1_id = ? or r.entity2_id =?) and (r.entity1_id = ? or r.entity2_id = ?)', array($member->id, $member->id, $person->id, $person->id)); if (!$q->count()) { if ($description2 = FamilyTable::getDescription2($m[1], $family[0]->Gender->id)) { $relationship = new Relationship(); $relationship->setCategory('Family'); $relationship->Entity1 = $member; $relationship->Entity2 = $person; $relationship->description1 = $m[1]; $relationship->description2 = $description2; $relationship->save(); $ref = LsQuery::getByModelAndFieldsQuery('Reference', array('object_model' => 'Entity', 'object_id' => $member->id, 'name' => 'Congressional Biographical Directory'))->fetchOne(); if ($ref) { $relationship->addReference($ref->source, null, null, $ref->name, $ref->source_detail, $ref->publication_date); } echo "-------------------------------added relationship\n"; } } } } } echo "\n"; } } }
public function setOrgs($orgs = null) { if ($orgs) { $this->_orgs = $orgs; } else { array_unshift($this->_orgExtensions, 'Org'); $q = EntityTable::getByExtensionQuery($this->_orgExtensions)->addWhere('website is not NULL')->limit(100); if ($this->hasMeta($this->_metaName, $this->_metaPredicate)) { $start_id = $this->getMeta($this->_metaName, $this->_metaPredicate); $q->addWhere('e.id > ?', $start_id); } $this->_orgs = $q->execute(); } }
public function executeMenu() { $this->items = array(); if ($this->getUser()->isAuthenticated() && $this->getUser()->getGuardUser()) { $name = $this->getUser()->getGuardUser()->getProfile()->public_name; $network_name = LsListTable::getNameById(sfGuardUserTable::getHomeNetworkId()); $network_path = LsListTable::getDisplayNameById(sfGuardUserTable::getHomeNetworkId()); $this->items[$name]['highlighted'] = true; $this->items[$name]['url'] = 'home/notes'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Notes')] = 'home/notes'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Groups')] = 'home/groups'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Edits')] = 'home/modifications'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Maps')] = 'home/maps'; $this->items[$name]['items']['divider1'] = 'divider'; $this->items[$name]['items'][$network_name] = '@localHome?name=' . $network_path; $this->items[$name]['items']['divider2'] = 'divider'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Settings')] = 'home/settings'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Logout')] = '@sf_guard_signout'; //recent views if ($this->getUser()->getGuardUser()->getProfile()->enable_recent_views && ($entityIds = $this->getUser()->getAttribute('viewed_entity_ids'))) { $this->items[$this->getContext()->getI18N()->__('Recent')] = array('url' => null, 'highlighted' => true, 'items' => array()); //flip entity ids from user session $flippedEntityIds = array_flip($entityIds); $orderedEntities = array(); //get viewed entities from db $entities = LsDoctrineQuery::create()->from('Entity e')->whereIn('e.id', $entityIds)->setHydrationMode(Doctrine::HYDRATE_ARRAY)->execute(); //order entities foreach ($entities as $entity) { $orderedEntities[$flippedEntityIds[$entity['id']]] = $entity; } ksort($orderedEntities); foreach ($orderedEntities as $entity) { $this->items[$this->getContext()->getI18N()->__('Recent')]['items'][$entity['name']] = EntityTable::generateRoute($entity); } } } else { if (sfConfig::get('app_login_enabled')) { $this->items[$this->getContext()->getI18N()->__("Login")] = array('url' => '@sf_guard_signin'); $this->items[$this->getContext()->getI18N()->__("Sign Up")] = array('url' => '@join'); } } $this->items = array_merge($this->items, array($this->getContext()->getI18N()->__('Explore') => array('items' => array($this->getContext()->getI18N()->__('Maps') => '@maps', $this->getContext()->getI18N()->__('Lists') => 'list/list', $this->getContext()->getI18N()->__('Groups') => '@groups', $this->getContext()->getI18N()->__('Notes') => '@notes', $this->getContext()->getI18N()->__('Users') => '@users', $this->getContext()->getI18N()->__('Edits') => '@edits')), $this->getContext()->getI18N()->__('Add') => null, $this->getContext()->getI18N()->__('Help') => array('items' => array($this->getContext()->getI18n()->__('Search Help Pages') => '@help', $this->getContext()->getI18N()->__('Beginner') => '@beginnerhelp', $this->getContext()->getI18N()->__('Advanced') => '@advancedhelp')), $this->getContext()->getI18N()->__('About') => array('items' => array('LittleSis' => '@about', $this->getContext()->getI18N()->__('Features') => '@features', $this->getContext()->getI18N()->__('Our Team') => '@team', $this->getContext()->getI18N()->__('Blog') => 'http://blog.littlesis.org', $this->getContext()->getI18N()->__('Press') => '@press', $this->getContext()->getI18N()->__('Data API') => 'http://api.littlesis.org', $this->getContext()->getI18N()->__('Source Code') => 'https://github.com/littlesis-org/littlesis', $this->getContext()->getI18N()->__('Disclaimer') => '@disclaimer', $this->getContext()->getI18N()->__('Contact Us') => '@contact')))); if (!$this->getUser()->isAuthenticated()) { unset($this->items[$this->getContext()->getI18N()->__('About')]['items'][$this->getContext()->getI18N()->__('Blog')]); $this->items[$this->getContext()->getI18N()->__('Blog')] = array('url' => 'http://blog.littlesis.org'); } if ($this->getUser()->isAuthenticated()) { $this->items[$this->getContext()->getI18N()->__('Add')] = array('items' => array($this->getContext()->getI18N()->__('Person') => 'entity/addPerson', $this->getContext()->getI18N()->__('Organization') => 'entity/addOrg', $this->getContext()->getI18N()->__('List') => 'list/add')); } }
protected function execute($arguments = array(), $options = array()) { if (!$this->safeToRun()) { print "Process already running!\n"; die; } $timer = sfTimerManager::getTimer('execute'); //get index and optimize $index = EntityTable::getLuceneIndex(); $index->optimize(); printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage())); printf("Index size: %s\n", $index->count()); $timer->addTime(); printf("Run time: %s\n", $timer->getElapsedTime()); sfTimerManager::clearTimers(); }
protected function printFirst($options) { if (!$options['list_id']) { echo "you need a list id\r"; die; } $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); $db = Doctrine_Manager::connection(); //CREATE NEW PRIMARY ALIASES $q = Doctrine_Query::create()->from('Entity e')->leftJoin('e.LsListEntity le')->leftJoin('e.Person p')->where('le.list_id = ? and le.is_deleted = 0', $options['list_id'])->orderBy('le.created_at ASC'); $entities = $q->execute(); foreach ($entities as $e) { echo $e->name . "\t\t" . EntityTable::getUri($e) . '/editContact' . "\t" . EntityTable::getUri($e) . "\t\t\t\t\t\t\t" . $e->Person->name_last . "\t" . $e->id . "\n"; } }
public function convertValueForDisplay($value) { if (is_null($value)) { return '<span class="text_small">NULL</span>'; } if (!($record = $this->Modification->getObject(true))) { return $value; } $table = $record->getTable(); if ($record instanceof Entity) { $data = $record->getData(); if (!array_key_exists($this->field_name, $data)) { if ($extensionName = EntityTable::getExtensionNameByFieldName($this->field_name)) { $table = Doctrine::getTable($extensionName); } } } elseif ($record instanceof Relationship) { $data = $record->getData(); if (!array_key_exists($this->field_name, $data)) { $table = Doctrine::getTable(RelationshipTable::getCategoryNameByFieldName($this->field_name)); } } if ($alias = $this->getFieldNameAlias()) { $class = $table->getRelation($alias)->getClass(); if ($record = Doctrine::getTable($class)->find($value)) { if ($record instanceof Entity) { sfLoader::loadHelpers('Ls'); return entity_link($record, null); } return $record; } } if (in_array($this->field_name, array('start_date', 'end_date'))) { return Dateable::convertForDisplay($value); } $def = $table->getColumnDefinition($this->field_name); switch ($def['type']) { case 'integer': return (string) $value; break; case 'boolean': return $value ? 'yes' : 'no'; break; } return LsString::excerpt($value); }
function entity_link($entity, $class = 'text_big', $strong = true, $link_text = null, $htmlOptions = array()) { if (!$link_text) { $link_text = $entity['name']; } if (!isset($htmlOptions['title'])) { $htmlOptions['title'] = $entity['blurb'] ? $entity['blurb'] : 'view profile'; } $link = link_to($link_text, EntityTable::generateRoute($entity), $htmlOptions); if ($strong) { $strongTag = $class ? '<strong class="' . $class . '">' : '<strong>'; $link = $strongTag . $link . '</strong>'; } else { $link = '<span class= "' . $class . '">' . $link . '</span>'; } return $link; }
static function getOrgsWithSimilarNames($name, $strict = false) { $name = trim(OrgTable::removeSuffixes($name, $exclude = array('Bancorp'))); if (strlen($name) < 3) { return array(); } $terms = LsQuery::splitSearchPhrase($name); $q = EntityTable::getByExtensionQuery('Org')->leftJoin('e.Alias a'); $search_terms = array(); $e = array(); $a = array(); for ($i = 0; $i < count($terms); $i++) { $term = $terms[$i]; if (is_array($term)) { $e_temp = array(); $a_temp = array(); foreach ($term as $t) { $search_terms[] = $i == 0 ? $t . '%' : '%' . $t . '%'; $e_temp[] = 'e.name like ?'; $a_temp[] = 'a.name like ?'; } $e[] = '(' . implode(' or ', $e_temp) . ')'; $a[] = '(' . implode(' or ', $a_temp) . ')'; } else { $search_terms[] = $i == 0 ? $term . '%' : '%' . $term . '%'; $e[] = 'e.name like ?'; $a[] = 'a.name like ?'; } } $e = implode(' and ', $e); $a = implode(' and ', $a); $search_terms = array_merge($search_terms, $search_terms); $q->addWhere('(' . $e . ') or (' . $a . ')', $search_terms); $orgs = $q->execute(); $org_names = array(); $found_orgs = array(); foreach ($orgs as $org) { if ($org->hasSimilarName($name, $strict)) { $found_orgs[] = $org; $org_names[] = $org->name; } } $org_names = array_unique($org_names); return $found_orgs; }
protected function execute($arguments = array(), $options = array()) { if (!$options['list_id'] && !$options['entity_ids']) { echo "you need a list id or entity ids\r"; die; } $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); $db = Doctrine_Manager::connection(); //entity ids if ($options['entity_ids']) { $sql = 'SELECT p.name_first,p.name_last,e.blurb,GROUP_CONCAT(distinct(e2.name) separator "; ") as orgs, e.name, e.id FROM entity e LEFT JOIN person p on p.entity_id = e.id LEFT JOIN relationship r on r.entity1_id = e.id and r.category_id in (1,3) and (r.is_current = 1 or (r.is_current is null and r.end_date is null)) and r.is_deleted = 0 LEFT JOIN entity e2 on e2.id = r.entity2_id WHERE e.id in (' . $options['entity_ids'] . ') GROUP BY e.id'; $stmt = $db->execute($sql); } else { if ($options['list_id']) { $sql = 'SELECT p.name_first,p.name_last,e.blurb,GROUP_CONCAT(distinct(e2.name) separator "; ") as orgs, e.name, e.id FROM ls_list_entity le LEFT JOIN entity e ON e.id = le.entity_id LEFT JOIN person p on p.entity_id = e.id LEFT JOIN relationship r on r.entity1_id = e.id and r.category_id in (1,3) and (r.is_current = 1 or (r.is_current is null and r.end_date is null)) and r.is_deleted = 0 LEFT JOIN entity e2 on e2.id = r.entity2_id WHERE le.list_id = ? and le.is_deleted = 0 GROUP BY e.id'; $stmt = $db->execute($sql, array($options['list_id'])); } } $rows = $stmt->fetchAll(PDO::FETCH_CLASS); foreach ($rows as $row) { $row = (array) $row; $str1 = implode("\t", array_slice($row, 0, 3)); $str2 = implode("\t", array_slice($row, 3)); echo $str1 . "\t"; $e = Doctrine::getTable('Entity')->find($row['id']); echo EntityTable::getUri($e) . "\t"; echo $str2 . "\n"; } }
protected function execute($arguments = array(), $options = array()) { if (!$this->safeToRun()) { print "Process already running!\n"; die; } $timer = sfTimerManager::getTimer('execute'); $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); //get id of last-indexed entity $index = EntityTable::getLuceneIndex($options['index_file']); $index->setMergeFactor(200); $index->setMaxBufferedDocs(20); if ($count = $index->count()) { if (!($lastDoc = $index->getDocument($count - 1))) { throw new Exception("Can't find last document in index"); } $maxEntityId = $lastDoc->key; } else { $maxEntityId = 0; } //find non-deleted entities with greater IDs $q = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.Alias a')->where('e.id > ? AND e.is_deleted = ?', array($maxEntityId, false))->andWhere('a.context IS NULL')->offset($options['offset'])->limit($options['limit'])->orderBy('e.id ASC'); //index entities $optimize = 0; foreach ($q->fetchArray() as $entity) { if (EntityTable::updateLuceneIndex($entity, $index, $batchMode = true)) { if ($options['debug_mode']) { printf("Indexed entity with ID %s\n", $entity['id']); } } else { if ($options['debug_mode']) { printf("Skipped entity with ID %s\n", $entity['id']); } } } printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage())); printf("Index size: %s\n", $index->count()); $timer->addTime(); printf("Run time: %s\n", $timer->getElapsedTime()); sfTimerManager::clearTimers(); }
public function executeNameSearch($request) { $this->results = array(); if ($terms = $request->getParameter('name')) { $entities = array(); $page = $request->getParameter('page', 1); $num = $request->getParameter('num', 20); $result = EntityTable::getSphinxHits($terms, $page, $num); if ($result['total_found'] > 0 && isset($result['matches'])) { $ids = array_keys($result['matches']); $db = Doctrine_Manager::connection(); $sql = 'SELECT e.*, FIELD(e.id, ' . implode(',', $ids) . ') AS field ' . 'FROM entity e WHERE e.id IN (' . implode(',', $ids) . ') AND e.is_deleted = 0 ' . 'ORDER BY field'; $stmt = $db->execute($sql); $entities = $stmt->fetchAll(PDO::FETCH_ASSOC); } foreach ($entities as $entity) { $this->results[] = array('name' => $entity['name'], 'markup' => NoteTable::getRecordMarkup($entity, $entity['name'], 'entity')); } } }
public function executeOnePercentSearch($request) { $this->search_form = new OnePercentSearchForm(); if ($request->isMethod('post')) { $searchParams = $request->getParameter('onepercent'); $url = $searchParams['url']; $text = $searchParams['text']; $this->search_form->bind($searchParams); if (!$this->search_form->isValid()) { return; } if ($url) { $browser = new sfWebBrowser(); if (!$browser->get($url)->responseIsError()) { $text = $browser->getResponseText(); } } if ($text) { $html = stripos($text, "<html"); $entity_types = 'people'; $names = array(); if ($html !== false) { $names = LsTextAnalysis::getHtmlEntityNames($text, $entity_types); } else { $names = LsTextAnalysis::getTextEntityNames($text, $entity_types); } $this->matches = array(); foreach ($names as $name) { $name_terms = $name; $name_parts = preg_split('/\\s+/', $name); if (count($name_parts) > 1) { $name_terms = PersonTable::nameSearch($name); } $pager = EntityTable::getSphinxPager($terms, $page = 1, $num = 20, $listIds = null, $aliases = true, $primary_ext = "Person"); $match['name'] = $name; $match['search_results'] = $pager->execute(); $this->matches[] = $match; } } } }
public function import($school) { if (EntityTable::getByExtensionQuery('Org')->addWhere('LOWER(org.name) LIKE ?', '%' . strtolower($school->instnm) . "%")->fetchOne()) { $this->printDebug("School exists in database: " . $school->instnm); } else { $address = new Address(); $address->street1 = isset($school->addr) ? $school->addr : null; $address->street2 = isset($school->street2) ? $school->street2 : null; $address->city = $school->city; if ($state = AddressStateTable::retrieveByText($school->stabbr)) { $address->State = $state; } $address->postal = $school->zip; $aliases = explode("|", $school->ialias); $website = null; if (!preg_match('/^http\\:\\/\\//i', trim($school->webaddr))) { $website = "http://" . strtolower($school->webaddr); } $this->printDebug($website); $newschool = new Entity(); $newschool->addExtension('Org'); $newschool->addExtension('School'); $newschool->name = $school->instnm; $newschool->website = $website; $newschool->addAddress($address); $newschool->save(); foreach ($aliases as $alias) { try { $newalias = new Alias(); $newalias->Entity = $newschool; $newalias->name = $alias; $newalias->save(); } catch (Exception $e) { $this->printDebug("An alias exception. No biggie. It's most likely that the name already exists. so we ignore it and move on: " . $e); } } $this->printDebug("Adding new school: " . $school->instnm); } }
protected function merge($sql, $ask_user = true) { $stmt = $this->db->execute($sql); $rows = $stmt->fetchAll(); foreach ($rows as $row) { $e1 = Doctrine::getTable('Entity')->find($row[0]); $e2 = Doctrine::getTable('Entity')->find($row[1]); $response = 'y'; if ($ask_user) { $prompt = "\n\n*********\n\nDo you want to merge these entities?\n"; $prompt .= $this->getEntityString($e1) . "\n**********\n" . $this->getEntityString($e2); $response = $this->readline($prompt); } if ($response == 'y') { $mergedEntity = EntityTable::mergeAll($e1, $e2); $e2->setMerge(true); $e2->clearRelated(); $e2->delete(); echo ' Successfully merged ' . $e2->name . "\n"; } } }
public static function prepareEntityData($entity) { sfLoader::loadHelpers(array("Asset", "Url")); $primary_ext = @$entity["primary_ext"] ? $entity["primary_ext"] : (strpos($entity["url"], "person") === false ? "Org" : "Person"); $entity["primary_ext"] = $primary_ext; if (@$entity["image"] && strpos(@$entity["image"], "netmap") === false && strpos(@$entity["image"], "anon") === false) { $image_path = $entity["image"]; } elseif (@$entity["filename"]) { $image_path = image_path(ImageTable::getPath($entity['filename'], 'profile')); } else { $image_path = $primary_ext == "Person" ? image_path("system/netmap-person.png") : image_path("system/netmap-org.png"); } try { $url = url_for(EntityTable::generateRoute($entity)); } catch (Exception $e) { $url = 'http://littlesis.org/' . strtolower($primary_ext) . '/' . $entity['id'] . '/' . LsSlug::convertNameToSlug($entity['name']); } if (@$entity["blurb"]) { $description = $entity["blurb"]; } else { $description = @$entity["description"]; } return array("id" => self::integerize(@$entity["id"]), "name" => $entity["name"], "image" => $image_path, "url" => $url, "description" => $description, "x" => @$entity["x"], "y" => @$entity["y"], "fixed" => true); }
<?php if (isset($entity)) { $tabs = array('Connections Map' => array('url' => EntityTable::getInternalUrl($entity, "map"), 'actions' => array("map")), 'Interlocks Map' => array('url' => EntityTable::getInternalUrl($entity, 'interlocksMap'), 'actions' => array('interlocksMap')), 'Saved Maps' => array('url' => "map/list", 'actions' => array())); ?> <?php include_partial('global/tabs', array('tabs' => $tabs)); ?> <br /> <?php } ?> <div id="netmap"></div> <div id="netmap_controls"> <input id="netmap_prune" type="button" value="prune" /><br /> <input id="netmap_wheel" type="button" value="wheel" /><br /> <input id="netmap_grid" type="button" value="grid" /><br /> <input id="netmap_shuffle" type="button" value="shuffle" /><br /> <input id="netmap_short_force" type="button" value="force" /><br /> <input id="netmap_rezoom" type="button" value="rezoom" /><br /> <br /> Cats: <select multiple id="netmap_cat_ids" size="10"> <option value="1">Pos</option> <option value="2">Edu</option> <option value="3">Mem</option>
<tr> <td style="width: 30%; padding-bottom: 0.6em"> <?php echo entity_link($object, null); ?> </td> <td style="padding-bottom: 0.6em"> <?php //$people = LsDoctrineQuery::create()->from('Entity e')->andWhereIn('e.id', explode(',', $object['people_ids']))->fetchArray() ?> <?php $people = EntityTable::getMultipleById(explode(',', $object['people_ids'])); ?> <?php $people_links = array(); ?> <?php foreach ($people as $person) { ?> <?php $people_links[] = entity_link($person, null, false); ?> <?php } ?> <?php echo implode(', ', $people_links); ?> </td> </tr>
<?php include_partial('global/section', array('title' => 'Expert Tools')); ?> <div class="padded margin_bottom"> <?php echo link_to('network search', EntityTable::getInternalUrl($entity, 'networkSearch')); ?> <br> <?php echo link_to('find connections', EntityTable::getInternalUrl($entity, 'findConnections')); ?> <br> <?php if ($entity['primary_ext'] == 'Org') { ?> <?php echo link_to('match related donors', EntityTable::getInternalUrl($entity, 'matchRelated')); ?> <br> <?php } ?> <?php echo link_to('twitter accounts', '@railsEditTwitter?id=' . $entity['id']); ?> <br> </div>
echo link_to('search', 'http://google.com/images?q=' . urlencode($entity['name']), 'target=_blank'); ?> </td> <td> <?php echo entity_link($entity); ?> </td> <td> <?php if ($image = $entity['Image'][0]['filename']) { ?> <?php echo link_to(image_tag(ImageTable::getPath($image, 'profile'), array('alt' => '', 'style' => 'height: 80px; border: 0;')), EntityTable::getInternalUrl($entity)); ?> <?php } ?> </td> <td> <?php echo $entity['summary']; ?> </td> </tr> <?php $row++;
$addressLinks = array(); if ($entity['primary_ext'] == 'Org') { ?> <?php $addresses = Doctrine::getTable('Address')->findByEntityId($entity['id']); ?> <?php foreach ($addresses as $address) { ?> <?php $addressLinks[] = address_link($address); ?> <?php } } ?> <?php $categoryLinks = array(); $categories = OsEntity::getCategoriesForDisplay($entity['id']); foreach ($categories as $category) { ?> <?php $categoryLinks[] = category_link($category); } ?> <?php include_partial('global/datatable', array('data' => array('Aliases' => $aliases = EntityTable::getAliasNamesById($entity['id'], false), 'Networks' => $networkLinks, 'Industries' => $categoryLinks, 'Addresses' => $addressLinks), 'label_width' => '100px')); ?> </div>
<?php if (isset($match_pager)) { include_partial('global/section', array('title' => 'Search Results', 'pager' => $match_pager)); ?> <div class="padded"> <?php foreach ($match_pager->execute() as $match) { ?> <?php if ($match['id'] == $entity['id']) { ?> <?php continue; ?> <?php } ?> <?php include_partial('entity/oneliner', array('entity' => $match, 'merge_link' => true, 'actions' => array(array('name' => 'merge', 'url' => EntityTable::getInternalUrl($entity, 'merge', array('keep_id' => $match['id'])), 'options' => 'post=true confirm=Are you sure?')))); ?> <?php } ?> </div> <?php }
<?php foreach ($sections as $title => $ary) { ?> <?php if (isset($ary['pager'])) { ?> <?php if ($ary['pager']->getNumResults()) { ?> <?php include_partial('global/subsection', array('title' => $title, 'pager' => $ary['pager'], 'more' => EntityTable::getInternalUrl($entity, $ary['more_action']), 'pointer' => isset($ary['pointer']) ? $ary['pointer'] : null, 'actions' => isset($ary['actions']) ? $ary['actions'] : null)); ?> <div class="padded margin_bottom"> <?php foreach ($ary['pager']->execute() as $related_entity) { ?> <?php include_partial('entity/entitywithrelationships', array('related_entity' => $related_entity, 'relationships' => $related_entity['rels'], 'profiled_entity' => $entity)); } ?> </div> <br /> <?php }
private function getCandidatesQuery() { return EntityTable::getByExtensionQuery(array('Person', 'PoliticalCandidate')); }