public function executeFedspendingFilings() { $page = $this->page ? $this->page : 1; $num = $this->num ? $this->num : 10; $q = RelationshipTable::getFedspendingFilingsByIdQuery($this->relationship['id']); $this->filing_pager = new LsDoctrinePager($q, $page, $num); }
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))); } }
public static function prepareRelData($rel) { sfLoader::loadHelpers(array("Asset", "Url")); try { $url = url_for(RelationshipTable::generateRoute($rel)); } catch (Exception $e) { $url = "http://littlesis.org/relationship/view/id/" . $rel['id']; } return array("id" => self::integerize($rel["id"]), "entity1_id" => self::integerize($rel["entity1_id"]), "entity2_id" => self::integerize($rel["entity2_id"]), "category_id" => self::integerize($rel["category_id"]), "category_ids" => (array) self::integerize($rel["category_ids"]), "is_current" => self::integerize($rel["is_current"]), "end_date" => @$rel["end_date"], "value" => 1, "label" => $rel["label"], "url" => $url, "x1" => @$rel["x1"], "y1" => @$rel["y1"], "fixed" => true); }
static function addUris($rel) { if ($rel['id']) { $rel['uri'] = RelationshipTable::getUri($rel); $rel['api_uri'] = self::getUri($rel['id']); } else { $rel['uri'] = null; $rel['api_uri'] = null; } return $rel; }
public function configure() { $choices = RelationshipTable::getDescriptionsByCategoryId(RelationshipTable::LOBBYING_CATEGORY); $this->setWidgets(array('start_date' => new sfWidgetFormInput(array(), array('size' => 10)), 'end_date' => new sfWidgetFormInput(array(), array('size' => 10)), 'description1' => new sfWidgetFormSelect(array('choices' => $choices)), 'description_new' => new sfWidgetFormInput(array(), array('size' => 30)), 'is_current' => new LsWidgetFormSelectRadio(array('is_ternary' => true)), 'amount' => new sfWidgetFormInput(array(), array('size' => 10)), 'notes' => new sfWidgetFormTextarea(array(), array('cols' => 50, 'rows' => 5)))); $this->setValidators(array('start_date' => new LsValidatorDate(array('required' => false)), 'end_date' => new LsValidatorDate(array('required' => false)), 'is_current' => new sfValidatorBoolean(array('required' => false)), 'description_new' => new sfValidatorString(array('max_length' => 200, 'required' => false)), 'amount' => new sfValidatorInteger(array('required' => false)))); $this->widgetSchema->setLabels(array('description1' => 'Type')); $this->widgetSchema->setHelps(array('start_date' => LsFormHelp::$dateHelp, 'end_date' => LsFormHelp::$dateHelp, 'is_current' => 'is this relationship ongoing?', 'amount' => LsFormHelp::$numberHelp, 'notes' => LsFormHelp::$notesHelp)); $this->widgetSchema->setNameFormat('relationship[%s]'); $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); $this->validatorSchema->setOption('allow_extra_fields', true); $this->validatorSchema->setOption('filter_extra_fields', false); }
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; }
public function getLobbyingRelationships() { if ($this->Relationship->Detail->description1 != 'Lobbying') { return null; } else { $q = RelationshipTable::getByCategoryQuery('Lobbying')->addWhere('lobbying.lda_filing_id = ?', $this->lda_filing_id)->execute(); if (count($q) > 0) { return $q; } else { return null; } } }
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); }
use_helper('LsNumber'); ?> <span class="text_big"> <?php slot('share_text'); echo entity_link($relationship['Entity1']); ?> <?php echo $current === NULL ? "is/was" : ($current == '1' ? "is" : "was"); ?> a member of <?php echo entity_link($relationship['Entity2']); end_slot(); echo get_slot('share_text'); slot('share_text', RelationshipTable::formatSentenceForShare(get_slot('share_text'))); ?> </span> <br /> <br /> <?php $data = array('Title' => $relationship['description1'], 'Start date' => Dateable::convertForDisplay($relationship['start_date']), 'End date' => Dateable::convertForDisplay($relationship['end_date']), 'Is current' => LsLogic::nullOrBoolean($relationship['is_current']), 'Dues' => readable_number($relationship['dues'], '$'), 'Notes' => $relationship['notes'] ? nl2br($relationship['notes']) : null); ?> <?php include_partial('global/section', array('title' => 'Details')); ?> <div class="padded">
echo entity_link($relationship['Entity2']); end_slot(); echo get_slot('share_text'); slot('share_text', RelationshipTable::formatSentenceForShare(get_slot('share_text'))); ?> </span> <br /> <br /> <?php $data = array('Start date' => Dateable::convertForDisplay($relationship['start_date']), 'End date' => Dateable::convertForDisplay($relationship['end_date']), 'Is current' => LsLogic::nullOrBoolean($relationship['is_current']), 'Amount' => $relationship['amount'], 'Notes' => $relationship['notes'] ? nl2br($relationship['notes']) : null); ?> <?php if ($relationship['filings'] && ($transactions = RelationshipTable::getTransactionsFromLobbyFilingByIdQuery($relationship['id'])->leftJoin('r.Entity1 e1')->leftJoin('r.Entity2 e2')->execute())) { ?> <?php $transactionAry = array(); ?> <?php foreach ($transactions as $transaction) { ?> <?php $client = $transaction->entity2_id == $relationship['entity1_id'] ? $transaction->Entity1 : $transaction->Entity2; ?> <?php $transactionAry[] = entity_link($client) . ' [' . link_to('see transaction', 'relationship/view?id=' . $transaction->id) . ']'; ?> <?php }
end_slot(); echo get_slot('share_text'); slot('share_text', RelationshipTable::formatSentenceForShare(get_slot('share_text'))); ?> </span> <br /> <br /> <?php $data = array(); ?> <?php if (!RelationshipTable::areSameDescriptions($relationship)) { ?> <?php if ($desc1 = $relationship['description1']) { ?> <?php $data[ucfirst($desc1)] = entity_link($relationship['Entity1']); ?> <?php } ?> <?php if ($desc2 = $relationship['description2']) { ?> <?php
<?php slot('header_text', RelationshipTable::getName($relationship)); slot('header_link', RelationshipTable::getInternalUrl($relationship)); slot('description_meta', RelationshipTable::generateMetaDescription($relationship)); ?> <?php if (!$relationship['is_deleted'] && isset($show_actions) && $show_actions) { ?> <?php slot('header_actions', array('edit' => array('url' => 'relationship/edit?id=' . $relationship['id'], 'credential' => 'editor'), 'flag' => array('url' => 'home/contact?type=flag'), 'remove' => array('url' => 'relationship/remove?id=' . $relationship['id'], 'options' => 'post=true confirm=Are you sure you want to remove this relationship?', 'credential' => 'deleter'), 'refresh' => array('url' => RelationshipTable::getInternalUrl($relationship, 'refresh', array('ref' => $sf_request->getUri())), 'credential' => 'admin'))); ?> <?php }
echo entity_link($related_entity); ?> • <?php $rels = array(); ?> <?php if (isset($related_entity['rel_ids'])) { ?> <?php $q = LsDoctrineQuery::create()->from('Relationship r')->whereIn('r.id', explode(',', $related_entity['rel_ids']))->orderBy('r.start_date DESC, r.end_date DESC')->setHydrationMode(Doctrine::HYDRATE_ARRAY); } elseif (isset($via_entity_ids)) { ?> <?php $q = RelationshipTable::getBetweenEntityAndGroupQuery($related_entity, $via_entity_ids, isset($category_ids) ? $category_ids : null, isset($order) ? $order : null); } else { ?> <?php $q = $profiled_entity->getRelationshipsWithQuery($related_entity, isset($category_ids) ? $category_ids : null, null, null, null, isset($order) ? $order : null); } ?> <?php foreach ($q->fetchArray() as $relationship) { ?> <?php $rels[] = trim(get_partial('relationship/oneliner', array('relationship' => $relationship, 'profiled_entity' => $profiled_entity, 'related_entity' => $related_entity))); ?> <?php die;
echo $related['name']; ?> </strong> <?php $descriptions = array(); ?> <?php foreach ($related['Relationships'] as $rel) { ?> <?php $description = $rel['entity1_id'] == $entity['id'] ? $rel['description2'] : $rel['description1']; ?> <?php if (!$description) { $description = RelationshipTable::getCategoryDefaultDescription($rel); } ?> <?php $descriptions[] = $description; ?> <?php } ?> <?php echo implode(', ', $descriptions); ?> <br /> <?php } ?>
if ($desc2 = $relationship['description2']) { ?> <?php $data[' ' . ucfirst($desc2)] = entity_link($relationship['Entity2']); ?> <?php } } ?> <?php $data = array_merge($data, array('Start date' => Dateable::convertForDisplay($relationship['start_date']), 'End date' => Dateable::convertForDisplay($relationship['end_date']), 'Is current' => LsLogic::nullOrBoolean($relationship['is_current']), 'Amount' => readable_number($relationship['amount'], '$'), 'Goods' => $relationship['goods'], 'Notes' => $relationship['notes'] ? nl2br($relationship['notes']) : null)); ?> <?php if ($relationship['filings'] && ($lobbyings = RelationshipTable::getLobbyingsFromLobbyFilingById($relationship['id']))) { ?> <?php $agencyAry = array(); ?> <?php foreach ($lobbyings as $lobbying) { ?> <?php if (in_array($lobbying->entity1_id, array($relationship['entity1_id'], $relationship['entity2_id']))) { ?> <?php $agency = $lobbying->Entity2; ?> <?php
] </div> <?php } ?> <?php if (@$created_rel) { ?> <div> Relationship created! <?php echo link_to($created_rel->getName(), RelationshipTable::getInternalUrl($created_rel), array('target' => '_new', 'absolute' => 1)); ?> </div> <br /> <?php } ?> <form action="<?php echo url_for('relationship/toolbar', 1); ?> " method="POST" onsubmit="return validateRelationship();"> <?php
public function executeRefresh($request) { $this->checkRelationship($request); LsCache::clearRelationshipCacheById($this->relationship['id']); $this->redirect($request->getParameter('ref', RelationshipTable::getInternalUrl($this->relationship))); }
public function getDisplayDescription($useDefault = true) { return RelationshipTable::getDisplayDescription($this, $useDefault); }
<?php echo RelationshipTable::getDisplayDescription($relationship, true); ?> <?php include_partial('relationship/onelinerdate', array('relationship' => $relationship));
slot('rightcol'); ?> <?php if ($sf_user->isAuthenticated() || !cache('rightcol', 86400)) { ?> <?php include_partial('global/modifications', array('object' => $relationship, 'more_uri' => RelationshipTable::getInternalUrl($relationship, 'modifications'))); ?> <?php include_component('reference', 'list', array('object' => $relationship, 'model' => 'Relationship', 'more_uri' => RelationshipTable::getInternalUrl($relationship, 'references'))); ?> <?php if (!$sf_user->isAuthenticated()) { ?> <?php cache_save(); ?> <?php } } ?> <br /> <?php include_component('note', 'recordSample', array('record' => $relationship, 'more_uri' => RelationshipTable::getInternalUrl($relationship, 'notes'), 'model' => 'Relationship', 'name' => 'this relationship')); ?> <?php end_slot();
</td> <td><?php echo user_link($object['User']); ?> </td> <td><?php echo ModificationTable::getType($object); ?> </td> <td> <strong> <?php if ($rel) { ?> <?php echo link_to(RelationshipTable::getName($rel), RelationshipTable::generateRoute($rel)); ?> <?php } else { ?> <?php echo link_to($object['object_name'], 'relationship/modifications?id=' . $object['object_id']); ?> <?php } ?> </strong> </td> </tr> <?php
} ?> <?php if (isset($existing_rels) && count($existing_rels)) { ?> <tr> <td> These relationships already existed: <br /> </td> <td style="float:left"> <?php foreach ($existing_rels as $rel) { ?> <?php echo link_to($rel->getName(), RelationshipTable::getInternalUrl($rel), array('target' => '_new')); ?> <br /> <?php } ?> </td> </tr> <?php } ?> </table> <?php } ?>
<?php slot('share_text'); echo entity_link($relationship['Entity1']); ?> <?php echo $current === NULL ? "is/was" : ($current == '1' ? "is" : "was"); ?> a student of <?php echo entity_link($relationship['Entity2']); end_slot(); echo get_slot('share_text'); slot('share_text', RelationshipTable::formatSentenceForShare(get_slot('share_text'))); ?> </span> <br /> <br /> <?php $data = array('Type' => $relationship['description1'], 'Start date' => Dateable::convertForDisplay($relationship['start_date']), 'End date' => Dateable::convertForDisplay($relationship['end_date']), 'Is current' => LsLogic::nullOrBoolean($relationship['is_current']), 'Degree' => RelationshipTable::getDegreeNameById($relationship['id']), 'Field' => $relationship['field'], 'Is dropout' => LsLogic::nullOrBoolean($relationship['is_dropout']), 'Notes' => $relationship['notes'] ? nl2br($relationship['notes']) : null); ?> <?php include_partial('global/section', array('title' => 'Details')); ?> <div class="padded"> <?php include_partial('global/datatable', array('data' => $data)); ?> </div>
protected function importGovernor($row) { $url = $this->_baseUrl . $row['url']; if (!$this->browser->get($url)->responseIsError()) { $text = $this->browser->getResponseText(); $text = LsHtml::replaceEntities($text); //preg_match('/>Family\:<\/b>([^<]*)<br/is',$text,$family_arr); $name = trim(str_ireplace('Gov.', '', $row['name'])); $this->printDebug(''); $this->printDebug($name . ':'); $governor = PersonTable::parseFlatName($name); $governor->addExtension('PoliticalCandidate'); $governor->addExtension('ElectedRepresentative'); $governor->is_state = 1; $similar = $governor->getSimilarEntitiesQuery(true)->execute(); foreach ($similar as $s) { $sim_re = LsString::escapeStringForRegex($s->name_first); $search_re = LsString::escapeStringForRegex($governor->name_first); if (preg_match('/^' . $sim_re . '/su', $governor->name_first) == 0 && preg_match('/^' . $search_re . '/su', $s->name_first) == 0) { continue; } $bio = $s->getExtendedBio(); if (preg_match('/\\bgovernor(ship)?\\b/isu', $bio)) { $governor = $s; $this->printDebug(' Found existing governor: ' . $s->name . ' ' . $s->id); break; } } $governor->save(); $this->printDebug($governor->id); if (!$governor->start_date && preg_match('/>Born\\:<\\/b>([^<]*)<br/is', $text, $birth_arr)) { $this->printDebug(' Birthdate: ' . $birth_arr[1]); $governor->start_date = trim($birth_arr[1]); } if (!$governor->birthplace && preg_match('/>Birth State\\:<\\/b>([^<]*)<br/is', $text, $birth_state_arr)) { $this->printDebug(' Birthplace: ' . trim($birth_state_arr[1])); $governor->birthplace = trim($birth_state_arr[1]); } //PARTY MEMBERSHIP if (preg_match('/>Party\\:<\\/b>([^<]*)<br/is', $text, $party_arr)) { $party_str = $party_arr[1]; $this->printDebug(' Party: ' . $party_str); if (stristr($party_str, 'Democrat')) { $party = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('name = ?', 'Democratic Party')->fetchOne(); } if (stristr($party_str, 'Republican')) { $party = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('name = ?', 'Republican Party')->fetchOne(); } if (isset($party) && $party && !$governor->party_id) { $governor->Party = $party; $governor->is_independent = false; $this->printDebug(' Added membership in ' . $party); } else { if (stristr($party_str, 'Independent')) { $governor->is_independent = true; } } } if (!$governor->summary && preg_match_all('/>([^<]{240,})/isu', $text, $bio_match)) { $str = ''; foreach ($bio_match[1] as $b) { if (!stristr($b, 'Javascript')) { $str .= "\n\n" . $b; } } $str = trim($str); if (strlen($str)) { $governor->summary = $str; } } $governor->save(); $governor->addReference($url, null, $governor->getAllModifiedFields(), 'Governors Association'); //SCHOOLS if (preg_match('/>School\\(s\\)\\:<\\/b>([^<]*)<br/is', $text, $school_arr)) { $school_names = explode(';', trim($school_arr[1])); if (count($school_names) == 1) { $school_names = explode(',', $school_names[0]); } foreach ($school_names as $school_name) { $school_name = trim($school_name); if (!($school = EntityTable::getByExtensionQuery('School')->leftJoin('e.Alias a')->addWhere('e.name = ? or a.name = ?', array($school_name, $school_name))->fetchOne())) { $school = new Entity(); $school->addExtension('Org'); $school->addExtension('School'); $school->name = $school_name; $school->save(); $this->printDebug(' Added School: ' . $school_name); } $q = RelationshipTable::getByCategoryQuery('Education')->addWhere('entity1_id = ? and entity2_id = ?', array($governor->id, $school->id))->fetchOne(); if (!$q) { $relationship = new Relationship(); $relationship->setCategory('Education'); $relationship->Entity1 = $governor; $relationship->Entity2 = $school; $relationship->is_current = 0; $relationship->save(); $relationship->addReference($url, null, $relationship->getAllModifiedFields(), 'Governors Association'); $this->printDebug(' Added education: ' . $relationship->name); } } } //GOVERNOR OFFICE AND POSITION $office_name = 'Office of the Governor of ' . $row['state']; if (!($office = EntityTable::getByExtensionQuery('GovernmentBody')->addWhere('name = ?', $office_name)->fetchOne())) { $office = new Entity(); $office->name = $office_name; $office->addExtension('Org'); $office->addExtension('GovernmentBody'); $state = Doctrine::getTable('AddressState')->findOneByName($row['state']); if ($state) { $office->state_id = $state->id; } $office->save(); $office->addReference($url, null, $office->getAllModifiedFields(), 'Governors Association'); $this->printDebug(' Added office: ' . $office->name); } $q = RelationshipTable::getByCategoryQuery('Position')->addWhere('entity1_id = ? and entity2_id = ? and description1 = ?', array($governor->id, $office->id, 'Governor'))->fetchOne(); if (!$q) { sort($row['years']); $i = 0; while ($i < count($row['years'])) { $governorship = new Relationship(); $governorship->setCategory('Position'); $governorship->Entity1 = $governor; $governorship->Entity2 = $office; $governorship->description1 = 'Governor'; $governorship->start_date = $row['years'][$i]; $i++; if (isset($row['years'][$i])) { $governorship->end_date = $row['years'][$i]; $governorship->is_current = 0; if (!$governor->blurb && !isset($row['years'][$i + 1])) { $governor->blurb = 'Former Governor of ' . $row['state']; } } else { $governorship->is_current = 1; if (!$governor->blurb) { $governor->blurb = 'Governor of ' . $row['state']; } } $governor->save(); $i++; $governorship->save(); $governorship->addReference($url, null, $governorship->getAllModifiedFields(), 'Governors Association'); $this->printDebug(' Added governorship: ' . $governorship->name); } } //SPOUSE if (preg_match('/>Spouse\\:<\\/b>(.*?)<br/is', $text, $spouse_arr)) { $spouse = trim(LsHtml::stripTags($spouse_arr[1])); $q = RelationshipTable::getByCategoryQuery('Family')->addWhere('entity1_id = ? or entity2_id = ?', array($governor->id, $governor->id))->fetchOne(); if (!$q && strlen($spouse)) { $spouse = PersonTable::parseFlatName($spouse); $spouse->save(); $this->printDebug(' Added spouse: ' . $spouse->name); $relationship = new Relationship(); $relationship->setCategory('Family'); $relationship->Entity1 = $spouse; $relationship->Entity2 = $governor; $relationship->description1 = 'Spouse'; $relationship->description2 = 'Spouse'; $relationship->save(); $relationship->addReference($url, null, $relationship->getAllModifiedFields(), 'Governors Association'); $this->printDebug(' Added spouse relationship: ' . $relationship->name); } } //ADDRESS --not working, malformed addresses /* if (preg_match('/>Address\:\s*<\/b>(.*?)<b>/is',$text,$address_arr)) { $address = trim(str_replace('<br/>',', ',$address_arr[1])); $this->printDebug($address); if ($governor->Address->count() == 0 && $a = $governor->addAddress($address)) { $this->printDebug(' Address: ' . $a); $governor->save(); } }*/ //PHONE NUMBER if (preg_match('/>Phone\\(s\\)\\:<\\/b>([^<]*)<br/is', $text, $phone_arr)) { $phone_number = trim($phone_arr[1]); if (!$governor->Phone->count()) { $phone = $governor->addPhone($phone_number); $this->printDebug(' Phone: ' . $phone); } } if (!$governor->Image->count() && preg_match('/<img .*?class\\="display" src\\="([^"]*)"/is', $text, $img_arr)) { $url = $img_arr[1]; try { $fileName = ImageTable::createFiles($url, $governor->name_first); } catch (Exception $e) { $fileName = null; } if ($fileName) { //insert image record $image = new Image(); $image->filename = $fileName; $image->entity_id = $governor->id; $image->title = $governor->name; $image->caption = 'From Governors Association website'; $image->is_featured = true; $image->is_free = false; $image->url = $url; $image->save(); $this->printDebug("Imported image: " . $image->filename); } } } }
private function importFiling($org, $lda_filing) { try { $this->printTimeSince(); $this->printDebug('Starting import...'); $excerpt = array(); //$time = microtime(1); $this->db->beginTransaction(); $date = null; $excerpt['Federal Filing Id'] = $lda_filing->federal_filing_id; $excerpt['Year'] = $lda_filing->year; $excerpt['Type'] = $lda_filing->LdaType->description; if (preg_match('/^[^T]*/su', $lda_filing->received, $match)) { $date = $match[0]; $date = str_replace('/', '-', $date); } $lda_registrant = Doctrine::getTable('LdaRegistrant')->find($lda_filing->registrant_id); $excerpt['Registrant'] = $lda_registrant->name; if ($lda_filing->client_id) { $lda_client = Doctrine::getTable('LdaClient')->find($lda_filing->client_id); $excerpt['Client'] = $lda_client->name; } else { $this->db->rollback(); return null; } $lobbying_entity = null; //DETERMINE (& CREATE) LOBBYING ENTITY //$this->printTimeSince(); //$this->printDebug('determine/create...'); if (strtolower(OrgTable::stripNamePunctuation($lda_client->name)) == strtolower(OrgTable::stripNamePunctuation($lda_registrant->name))) { $lobbying_entity = $org; $client_entity = null; if (!$lobbying_entity->lda_registrant_id) { $lobbying_entity->lda_registrant_id = $lda_registrant->federal_registrant_id; $lobbying_entity->save(); $lobbying_entity->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $lobbying_entity->getAllModifiedFields(), 'LDA Filing', null, $date, false); } else { if ($lobbying_entity->lda_registrant_id != $lda_registrant->federal_registrant_id) { $this->printDebug("LDA registrant ids did not match up for {$lobbying_entity->name} and {$lda_registrant->name} even though names matched {$lda_client->name}\n"); $this->db->rollback(); return null; } } $this->printDebug($lobbying_entity->name . ' noted (same as client ' . $lda_client->name . ')'); } else { $client_entity = $org; if ($lda_client->description) { $description = trim($lda_client->description); if ($description != '' && preg_match('/[\\/\\-]\\d+[\\/\\-]/isu', $description) == 0) { if (strlen($description) < 200) { if (!$org->blurb || $org->blurb == '') { $org->blurb = $description; } } else { if (!$org->summary || $org->summary == '') { $org->summary = $description; } } } } $org->save(); $this->printDebug($lda_client->name . ' is distinct from ' . $lda_registrant->name); } $lda_lobbyists = $lda_filing->LdaLobbyists; $excerpt['Lobbyists'] = array(); foreach ($lda_lobbyists as $lda_lobbyist) { $excerpt['Lobbyists'][] = $lda_lobbyist->name; } $excerpt['Lobbyists'] = implode('; ', $excerpt['Lobbyists']); if (!$lobbying_entity) { $lobbyist_name = null; if (count($lda_lobbyists)) { $lobbyist_parts = explode(',', $lda_lobbyists[0]->name); if (count($lobbyist_parts) > 1) { $lobbyist_last = trim($lobbyist_parts[0]); $arr = LsString::split($lobbyist_parts[1]); $lens = array_map('strlen', $arr); arsort($lens); $keys = array_keys($lens); $lobbyist_longest = $arr[$keys[0]]; $lobbyist_name = trim($lobbyist_parts[1]) . ' ' . trim($lobbyist_parts[0]); $existing_lobbyist_registrant = null; } else { $lobbyist_name = preg_replace('/^(Mr|MR|MS|Dr|DR|MRS|Mrs|Ms)\\b\\.?/su', '', $lda_lobbyists[0]->name); $arr = LsString::split(trim($lobbyist_name)); $arr = LsArray::strlenSort($arr); $lobbyist_last = array_pop($arr); if (count($arr)) { $lobbyist_longest = array_shift(LsArray::strlenSort($arr)); } else { $lobbyist_longest = ''; } } } //check to see if registrant and lobbyist are same if (count($lda_lobbyists) == 1 && (strtoupper($lda_lobbyists[0]->name) == strtoupper($lda_registrant->name) || $lobbyist_last && stripos($lda_registrant->name, $lobbyist_last) == strlen($lda_registrant->name) - strlen($lobbyist_last) && stristr($lda_registrant->name, $lobbyist_longest))) { $existing_lobbyist_registrant = EntityTable::getByExtensionQuery('Lobbyist')->addWhere('lobbyist.lda_registrant_id = ?', $lda_registrant->federal_registrant_id)->execute()->getFirst(); if ($existing_lobbyist_registrant) { $lobbying_entity = $existing_lobbyist_registrant; $this->printDebug('Existing lobbyist is lobbying entity: ' . $lobbying_entity->name); } else { $lobbyist = $this->prepLobbyistName($lda_lobbyists[0]->name); if ($lobbyist) { $lobbyist->lda_registrant_id = $lda_registrant->federal_registrant_id; $lobbyist->save(); $lobbyist->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $lobbyist->getAllModifiedFields(), 'LDA Filing', null, $date, false); $this->printDebug('New lobbyist/lobbying entity saved: ' . $lobbyist->name); $lobbying_entity = $lobbyist; } } } else { if ($existing_firm = EntityTable::getByExtensionQuery('Org')->addWhere('org.lda_registrant_id = ? ', $lda_registrant->federal_registrant_id)->execute()->getFirst()) { $modified = array(); $lobbying_entity = $existing_firm; if ($lda_registrant->description) { $description = trim($lda_registrant->description); if ($description != '' && preg_match('/[\\/\\-]\\d+[\\/\\-]/isu', $description) == 0) { if (strlen($description) < 200) { if (!$existing_firm->blurb || $existing_firm->blurb == '') { $existing_firm->blurb = $description; $modified[] = 'blurb'; } } else { if (!$existing_firm->summary || $existing_firm->summary == '') { $existing_firm->summary = $description; $modified[] = 'summary'; } } } } if ($lda_registrant->address && $lda_registrant->address != '' && count($existing_firm->Address) == 0) { if ($address = $existing_firm->addAddress($lda_registrant->address)) { $existing_firm->save(); $address->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $address->getAllModifiedFields(), 'LDA Filing', null, $date, false); } } $existing_firm->save(); if (count($modified)) { $existing_firm->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $modified, 'LDA Filing', null, $date, false); } $this->printDebug('Existing firm is lobbying entity: ' . $lobbying_entity->name); } else { $firm = new Entity(); $firm->addExtension('Org'); $firm->addExtension('Business'); $firm->addExtension('LobbyingFirm'); $firm->name = LsLanguage::titleize(OrgTable::stripNamePunctuation($lda_registrant->name), true); $firm->lda_registrant_id = $lda_registrant->federal_registrant_id; if ($lda_registrant->description) { $description = trim($lda_registrant->description); if ($description != '' && preg_match('/[\\/\\-]\\d+[\\/\\-]/isu', $description) == 0) { if (strlen($description) < 200) { $firm->blurb = $description; } else { $firm->summary = $description; } } } if ($lda_registrant->address && $lda_registrant->address != '') { if ($address = $firm->addAddress($lda_registrant->address)) { $firm->save(); $address->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $address->getAllModifiedFields(), 'LDA Filing', null, $date, false); } } $firm->save(); $this->printDebug('New lobbying firm/lobbying entity saved: ' . $firm->name); $firm->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $firm->getAllModifiedFields(), 'LDA Filing', null, $date, false); $lobbying_entity = $firm; } } } //PREP GOVT ENTITIES //$this->printTimeSince(); //$this->printDebug('gov entities...'); $lda_govts = $lda_filing->LdaGovts; //$this->printDebug('count of lda govs is ***** ' . count($lda_govts)); $govt_entities = array(); $excerpt['Government Bodies'] = array(); foreach ($lda_govts as $lda_govt) { $excerpt['Government Bodies'][] = $lda_govt->name; $name_arr = $this->prepGovtName($lda_govt->name); if (!$name_arr) { continue; } if ($govt_entity = EntityTable::findByAlias($lda_govt->name, $context = 'lda_government_body')) { $govt_entities[] = $govt_entity; //$this->printDebug('Existing govt entity: ' . $govt_entity->name); } else { if ($govt_entity = EntityTable::getByExtensionQuery(array('Org', 'GovernmentBody'))->addWhere('name = ?', array($name_arr[0]))->fetchOne()) { $govt_entities[] = $govt_entity; $alias = new Alias(); $alias->context = 'lda_government_body'; $alias->name = $lda_govt->name; $alias->entity_id = $govt_entity->id; $alias->save(); } else { $govt_entity = new Entity(); $govt_entity->addExtension('Org'); $govt_entity->addExtension('GovernmentBody'); $govt_entity->name = $name_arr[0]; $govt_entity->name_nick = $name_arr[1]; $govt_entity->is_federal = 1; $govt_entity->save(); $alias = new Alias(); $alias->context = 'lda_government_body'; $alias->name = $lda_govt->name; $alias->entity_id = $govt_entity->id; $alias->save(); $govt_entity->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $govt_entity->getAllModifiedFields(), 'LDA Filing', null, $date, false); $govt_entities[] = $govt_entity; } } } $excerpt['Government Bodies'] = implode('; ', $excerpt['Government Bodies']); $excerpt_str = ''; foreach ($excerpt as $k => $v) { $excerpt_str .= $k . ": "; $excerpt_str .= $v . "\n"; } $excerpt = trim($excerpt_str); $this->printDebug($excerpt); $relationships = array(); $lobbying_entity_extensions = $lobbying_entity->getExtensions(); //CREATE LOBBYIST POSITION RELATIONSHIPS //$this->printTimeSince(); //$this->printDebug('lobbyist positions...'); $category = Doctrine::getTable('RelationshipCategory')->findOneByName('Position'); if (!in_array('Lobbyist', $lobbying_entity_extensions)) { $firm_lobbyists = array(); if ($lobbying_entity->exists()) { $q = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.Relationship r ON (r.entity1_id = e.id)')->where('r.entity2_id = ? AND r.category_id = ?', array($lobbying_entity->id, RelationshipTable::POSITION_CATEGORY)); $firm_lobbyists = $q->execute(); } $lobbyists = array(); foreach ($lda_lobbyists as $lda_lobbyist) { $lobbyist = $this->prepLobbyistName($lda_lobbyist->name); if (!$lobbyist) { continue; } $existing_lobbyist = null; foreach ($firm_lobbyists as $fl) { if (PersonTable::areNameCompatible($fl, $lobbyist)) { $existing_lobbyist = $fl; break; } } //echo "before lobb save or rel save: "; //$this->printTimeSince(); if (!$existing_lobbyist) { $lobbyist->save(); $lobbyist->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $lobbyist->getAllModifiedFields(), 'LDA Filing', null, $date, false); //$this->printDebug('New lobbyist saved: ' . $lobbyist->name); $r = new Relationship(); $r->Entity1 = $lobbyist; $r->Entity2 = $lobbying_entity; $r->setCategory('Position'); $r->description1 = 'Lobbyist'; $r->is_employee = 1; $r->save(); $r->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $lobbyist->getAllModifiedFields(), 'LDA Filing', null, $date, false); //$this->printDebug('New position relationship saved: ' . $lobbying_entity->name . ' and ' . $lobbyist->name); $lobbyists[] = $lobbyist; } else { //$this->printDebug('Lobbyist exists: ' . $lobbyist->name . ' is same as ' . $existing_lobbyist->name); $lobbyists[] = $existing_lobbyist; } } } //PREP ISSUES //$this->printTimeSince(); //$this->printDebug('issues...'); $issues = array(); $lda_issues = Doctrine_Query::create()->from('LdaFilingIssue f')->leftJoin('f.LdaIssue i')->where('f.filing_id = ?', $lda_filing->id)->execute(); foreach ($lda_issues as $lda_issue) { $name = LsLanguage::nameize($lda_issue->LdaIssue->name); if (!($issue = Doctrine::getTable('LobbyIssue')->findOneByName($name))) { $issue = new LobbyIssue(); $issue->name = $name; $issue->save(); //$this->printDebug('Lobbying issue saved: ' . $issue->name); } $issues[] = array($issue, $lda_issue->specific_issue); } //CREATE LOBBY FILING //$this->printTimeSince(); //$this->printDebug('creating lobby filing:'); $lobby_filing = new LobbyFiling(); $lobby_filing->year = $lda_filing->year; $lobby_filing->amount = $lda_filing->amount; $lobby_filing->federal_filing_id = $lda_filing->federal_filing_id; $period = $lda_filing->LdaPeriod->description; $lobby_filing->start_date = $date; if ($paren = strpos($period, '(')) { $lobby_filing->period = trim(substr($period, 0, $paren)); } else { $lobby_filing->period = 'Undetermined'; } $lobby_filing->report_type = LsLanguage::nameize($lda_filing->LdaType->description); foreach ($issues as $issue) { $filing_issue = new LobbyFilingLobbyIssue(); $filing_issue->Issue = $issue[0]; $filing_issue->Filing = $lobby_filing; $filing_issue->specific_issue = $issue[1]; $filing_issue->save(); } if (in_array('Lobbyist', $lobbying_entity_extensions)) { $lobby_filing->Lobbyist[] = $lobbying_entity; //$this->printDebug('Lobbying entity lobbyist added to lobbying relationship: ' . $lobbying_entity->name); } else { foreach ($lobbyists as $lobbyist) { $lobby_filing->Lobbyist[] = $lobbyist; } } //var_dump($lobby_filing->toArray()); $lobby_filing->save(); //CREATE TRANSACTION RELATIONSHIP, IF ANY //$this->printTimeSince(); //$this->printDebug('starting transaction relationships:'); $transaction = null; if ($client_entity != null) { $transaction = RelationshipTable::getByCategoryQuery('Transaction')->addWhere('r.entity1_id = ?', $client_entity->id)->addWhere('r.entity2_id = ?', $lobbying_entity->id)->addWhere('transaction.is_lobbying = ?', 1)->fetchOne(); if ($transaction) { $transaction->updateDateRange($date, true); if ($lda_filing->amount && $lda_filing->amount != '') { if (!$transaction->amount || $transaction->amount == '') { $transaction->amount = $lda_filing->amount; } else { $transaction->amount += $lda_filing->amount; } } $transaction->filings++; $transaction->save(); $transaction->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $transaction->getAllModifiedFields(), 'LDA Filing', null, $date, false); } else { $transaction = new Relationship(); $transaction->Entity1 = $client_entity; $transaction->Entity2 = $lobbying_entity; $transaction->setCategory('Transaction'); $transaction->description1 = 'Lobbying Client'; $transaction->is_lobbying = 1; $transaction->filings = 1; $transaction->updateDateRange($date, true); if (in_array('Person', $lobbying_entity_extensions)) { $transaction->description2 = 'Hired Lobbyist'; } else { $transaction->description2 = 'Lobbying Firm'; } if ($lda_filing->amount && $lda_filing->amount != '') { $transaction->amount = $lda_filing->amount; } $transaction->save(); $transaction->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $transaction->getAllModifiedFields(), 'LDA Filing', null, $date, false); //$this->printDebug('New lobbying transaction saved between client ' . $client_entity->name . ' and lobbying firm ' . $lobbying_entity->name); } $relationships[] = $transaction; } //CREATE LOBBYING RELATIONSHIP //$this->printTimeSince(); //$this->printDebug('starting lobbying relationships:'); foreach ($govt_entities as $govt_entity) { $lobbying_relationship = RelationshipTable::getByCategoryQuery('Lobbying')->addWhere('r.entity1_id = ?', $lobbying_entity->id)->addWhere('r.entity2_id = ?', $govt_entity->id)->fetchOne(); if ($lobbying_relationship) { $lobbying_relationship->updateDateRange($date); $lobbying_relationship->filings++; $lobbying_relationship->save(); } else { $lobbying_relationship = new Relationship(); $lobbying_relationship->Entity1 = $lobbying_entity; $lobbying_relationship->Entity2 = $govt_entity; $lobbying_relationship->setCategory('Lobbying'); if ($transaction) { $lobbying_relationship->description1 = 'Lobbying (for client)'; } else { $lobbying_relationship->description1 = 'Direct Lobbying'; } $lobbying_relationship->description2 = $lobbying_relationship->description1; $lobbying_relationship->updateDateRange($date, true); $lobbying_relationship->filings = 1; $lobbying_relationship->save(); $lobbying_relationship->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $lobbying_relationship->getAllModifiedFields(), 'LDA Filing', null, $date, false); } $relationships[] = $lobbying_relationship; } foreach ($relationships as $relationship) { $lobby_filing->Relationship[] = $relationship; } $lobby_filing->save(); //$this->printTimeSince(); $this->printDebug("Import Completed\n"); $this->db->commit(); } catch (Exception $e) { $this->db->rollback(); throw $e; } }
<?php if ($description1 = $relationship['description1']) { ?> <?php echo $description1 == "Campaign Contribution" ? $relationship['filings'] . " contribution" . ($relationship['filings'] > 1 ? "s" : "") : $description1; } else { ?> <?php echo RelationshipTable::getCategoryDefaultDescription($relationship); } ?> <?php if ($amount = $relationship['amount']) { ?> ⋅ $<?php echo $amount; } ?> <?php include_partial('relationship/onelinerdate', array('relationship' => $relationship));
protected function execute($arguments = array(), $options = array()) { $this->init($arguments, $options); if ($this->testMode) { echo "TESTING -- no changes will be saved\n"; } $merge_modification = $this->getLastMerge(); if (!$merge_modification) { die; } $this->entity2_id = $merge_modification['object_id']; $this->entity1 = Doctrine::getTable('Entity')->find($this->entity1_id); $this->entity2 = Doctrine::getTable('Entity')->find($this->entity2_id); //GET ALL EXTENSIONS ADDED WITHIN A CERTAIN RANGE OF MODIFICATION TIME $sql = "SELECT m.* FROM extension_record er LEFT JOIN modification m on m.object_id = er.id AND m.object_model = ? WHERE er.entity_id = ? AND TIME_TO_SEC(TIMEDIFF(?,m.created_at)) < 100 and is_create = 1"; $stmt = $this->db->execute($sql, array('ExtensionRecord', $this->entity1_id, $merge_modification['created_at'])); $ext_mods = $stmt->fetchAll(PDO::FETCH_ASSOC); //REMOVE EXTENSIONS THAT WERE ADDED if (count($ext_mods)) { foreach ($ext_mods as $m) { $er = Doctrine::getTable("ExtensionRecord")->find($m['object_id']); $ed = Doctrine::getTable("ExtensionDefinition")->find($er['definition_id']); if ($ed) { $this->printDebug("removing " . $ed['name'] . " extension now"); if (!$this->testMode) { $this->entity1->removeExtension($ed['name']); $this->entity1->save(); } } } } //GET MODIFIED FIELDS $sql = "SELECT mf.* FROM modification_field mf LEFT JOIN modification m ON m.id = mf.modification_id WHERE m.object_model = ? AND m.object_id = ? AND TIME_TO_SEC(TIMEDIFF(?,m.created_at)) < 100"; $stmt = $this->db->execute($sql, array('Entity', $this->entity1_id, $merge_modification['created_at'])); $ent_mods = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($ent_mods as $ent_mod) { $this->printDebug("\tchange " . $ent_mod['field_name'] . ": " . $ent_mod['new_value'] . " back to " . $ent_mod['old_value'] . ""); } //UNDELETE ENTITY 2 $sql = "UPDATE entity e SET e.is_deleted = 0 WHERE e.id = ?"; if (!$this->testMode) { $stmt = $this->db->execute($sql, array($this->entity2_id)); } //GET ALL MODIFICATIONS THAT WE KNOW SOMETHING ABOUT $sql = "SELECT * FROM modification_field WHERE field_name like ? AND old_value = ? AND new_value = ?"; $stmt = $this->db->execute($sql, array('%_id%', $this->entity2_id, $this->entity1_id)); $all_mod_fields = $stmt->fetchAll(PDO::FETCH_ASSOC); $rels_updated = array(); foreach ($all_mod_fields as $mod_field) { $mod_id = $mod_field['modification_id']; $mod = Doctrine::getTable('Modification')->find($mod_id); if ($mod->object_model == 'Relationship') { //set merge to true or false? $rel = Doctrine::getTable("Relationship")->find($mod['object_id']); if ($rel) { if (strtotime($rel->updated_at) - strtotime($merge_modification['created_at']) > 100) { $rels_updated[] = $rel; } else { $prevName = RelationshipTable::getName($rel); $rel[$mod_field['field_name']] = $this->entity2_id; if (!$this->testMode) { $rel->save(); } $this->printDebug($prevName . " changed to " . RelationshipTable::getName($rel)); //UPDATE THE LINKS $links = Doctrine::getTable("Link")->findByRelationshipId($rel->id); foreach ($links as $l) { if ($l->entity1_id == $this->entity1_id) { $l->entity1_id = $this->entity2_id; } else { if ($l->entity2_id == $this->entity1_id) { $l->entity2_id = $this->entity2_id; } } if (!$this->testMode) { $l->save(); } $this->printDebug("link updated"); } } } else { $this->printDebug("\tNo relationship found"); } } else { $this->revertObject($mod->object_model, $mod['object_id'], $mod_field['field_name']); } } //GET ALL REFERENCES ON ENTITY 1 THAT SHOULD ACTUALLY BE FOR ENTITY 2 $sql = "SELECT * FROM reference WHERE object_id = ? AND object_model = ? AND TIME_TO_SEC(TIMEDIFF(?,updated_at)) < 100"; $stmt = $this->db->execute($sql, array($this->entity1_id, 'Entity', $merge_modification['created_at'])); $references = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($references as $ref) { if (!$this->testMode) { $ref['object_id'] = $this->entity2_id; } $this->printDebug("Reference " . $ref['id'] . " changed"); } foreach ($rels_updated as $rel) { $this->printDebug("updated after: " . RelationshipTable::getName($rel)); } }