本文整理汇总了PHP中Relationship::addReference方法的典型用法代码示例。如果您正苦于以下问题:PHP Relationship::addReference方法的具体用法?PHP Relationship::addReference怎么用?PHP Relationship::addReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relationship
的用法示例。
在下文中一共展示了Relationship::addReference方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
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";
}
}
}
示例2: updateCommitteeDetails
private function updateCommitteeDetails(Entity $committee)
{
$this->printDebug(" Updating committee details: " . $this->fecCommitteeUrl . $committee->fec_id);
if (!$this->browser->get($this->fecCommitteeUrl . $committee->fec_id)->responseIsError()) {
$text = $this->browser->getResponseText();
if (preg_match('/Treasurer Name:<\\/B><\\/TD><TD>(.+)<\\/TD><\\/TR>/', $text, $treasurer_name)) {
//nothing
}
$committee_designation = null;
if (preg_match('/Committee Designation: <\\/B><\\/TD><TD>(\\w)/', $text, $committee_designation)) {
switch (trim($committee_designation[1])) {
case 'P':
$committee->addExtension('IndividualCampaignCommittee');
$committee_designation = "Principal Campaign Committee";
break;
case 'A':
$committee->addExtension('IndividualCampaignCommittee');
$committee_designation = "Authorized Campaign Committee";
break;
default:
$committee->addExtension('OtherCampaignCommittee');
$committee_designation = "Other Campaign Committee";
}
} else {
$committee->addExtension('OtherCampaignCommittee');
$committee_designation = "Other Campaign Committee";
}
if (preg_match('/Committee Type: <\\/B><\\/TD><TD WIDTH=300>([^<]+)<\\/TD><\\/TR>/', $text, $committee_type)) {
//var_dump($committee_type);
$type = null;
switch (trim($committee_type[1])) {
case 'PRESIDENTIAL':
$type = 'pres';
break;
case 'HOUSE':
$type = 'house';
break;
case 'SENATE':
$type = 'senate';
break;
}
}
if (preg_match('/Candidate State:<\\/B><\\/TD><TD>([^<]+)<\\/TD><\\/TR>/', $text, $candidate_state)) {
//var_dump($candidate_state);
if (trim($candidate_state[1]) != "Presidential Candidate") {
$committee->State = AddressStateTable::retrieveByText($candidate_state[1]);
}
}
if (preg_match_all('#cgi-bin/can_detail/([^"]+)?\\/">([^<]+)</A>#i', $text, $candidates, PREG_PATTERN_ORDER)) {
/*
* $candidates[1] = FEC ID
* $candidates[2] = NAME
*/
foreach ($candidates[1] as $key => $candidate_id) {
$candidate_name = $candidates[2][$key];
$found_candidate = null;
//look for candidate by their FEC IDs
$found_candidate = $this->getCandidatesQuery()->addWhere('politicalcandidate.senate_fec_id = ? OR politicalcandidate.house_fec_id = ? OR politicalcandidate.pres_fec_id = ?', array($candidate_id, $candidate_id, $candidate_id))->fetchOne();
$found_msg = $found_candidate ? " FOUND" : " NOT FOUND";
$this->printDebug(" + Looking for candidate by ID: " . $found_msg);
//next look for them by their names
$where_clause = null;
$p1 = null;
if (!$found_candidate) {
$p1 = PersonTable::parseCommaName($candidate_name);
$candidate_query = $this->getCandidatesQuery()->addWhere("person.name_first = ? AND person.name_last = ?", array($p1->name_first, $p1->name_last));
if (strlen($p1->name_middle)) {
$candidate_query = $candidate_query->addWhere('person.name_middle LIKE ?', "%" . $p1->name_middle);
}
$found_candidate = $candidate_query->fetchOne();
$found_msg = $found_candidate ? " FOUND" : " NOT FOUND";
$this->printDebug(" + Looking for candidate by name: " . $p1->name_first . " " . $p1->name_last . $found_msg . " ");
//candidate is not in database. we should add them
if (!$found_candidate) {
if (!$this->browser->get($this->fecCandidateUrl . $candidate_id)->responseIsError()) {
$text = $this->browser->getResponseText();
$office_sought_arr = $this->getOfficeSought($text);
if (!$office_sought_arr[1][0]) {
continue;
}
$office_sought = $office_sought_arr[1][0];
$found_candidate = PersonTable::parseCommaName($candidate_name);
$found_candidate->addExtension('PoliticalCandidate');
$found_candidate->is_federal = true;
$found_candidate->is_state = false;
$found_candidate->is_local = false;
$found_candidate->pres_fec_id = $office_sought == 'President' ? $candidate_id : null;
$found_candidate->senate_fec_id = $office_sought == 'Senate' ? $candidate_id : null;
$found_candidate->house_fec_id = $office_sought == 'House' ? $candidate_id : null;
$found_candidate->save();
$found_candidate->addReference($source = $this->fecCandidateUrl . $candidate_id, $excerpt = null, $fields = array('name_first', 'name_middle', 'name_last', 'name_prefix', 'name_suffix', 'pres_fec_id', 'senate_fec_id', 'house_fec_id'), $name = 'FEC Disclosure Report', $detail = null, $date = null, false);
$this->printDebug(" Adding new candidate: " . $p1->name_first . " " . $p1->name_middle . " " . $p1->name_last);
}
}
}
$q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? AND r.entity2_id = ? AND r.category_id = ? AND description1 = ?', array($committee->id, $found_candidate->id, RelationshipTable::DONATION_CATEGORY, $committee_designation));
if (!$q->count()) {
$relationship = new Relationship();
$relationship->Entity1 = $committee;
$relationship->Entity2 = $found_candidate;
//.........这里部分代码省略.........
示例3: import
protected function import($url)
{
$person = null;
$this->printDebug($url);
if (!$this->browser->get($url)->responseIsError()) {
$text = $this->browser->getResponseText();
$bio = null;
$name = null;
$netWorth = null;
$birthYear = null;
$schools = null;
$schools = null;
$imageUrl = null;
$rank = null;
//get name & rank
if ($this->year > 2005 && preg_match('/<b>#(\\d+) ([^<]+)<\\/b>/', $text, $match)) {
$name = trim($match[2]);
$rank = $match[1];
}
if ($this->year == 2005 && preg_match('/<h2>#(\\d+) ([^<]+)<\\/h2>/', $text, $match)) {
$name = trim($match[2]);
$rank = $match[1];
}
//get net worth
if (preg_match('/Net Worth<\\/span> <span class="red">\\$([\\S]+) billion/', $text, $match)) {
$netWorth = $match[1] * 1000000000;
}
//get birth year
if (preg_match('/>Age<\\/span> (\\d+)/', $text, $match)) {
$birthYear = date("Y") - $match[1] . "-00-00";
}
//get schools
if (preg_match('/Education<\\/span>(.*)<\\/td>/isU', $text, $match)) {
$schools = array();
$schoolParts = explode('<br>', $match[1]);
while ($schoolPart = current($schoolParts)) {
if (preg_match('/^([^,]+),\\s+<b>([^<]+)<\\/b>/is', trim($schoolPart), $match)) {
$schoolOrg = trim($match[1]);
if ($schoolOrg == 'High School') {
next($schoolParts);
continue;
}
$schoolDegree = trim($match[2]);
$schools[] = array('org' => $schoolOrg, 'degree' => $schoolDegree);
}
next($schoolParts);
}
}
if (preg_match('#<br>[\\n\\s]<br>(.+?)<br>[\\n\\s]<br>[\\n\\s]<img#isU', $text, $match)) {
$bio = strip_tags(trim($match[1]));
} else {
$wikipedia = new LsWikipedia();
if ($wikipedia->request($name)) {
$bio = $wikipedia->getIntroduction();
}
}
//get image
$regexp = '#([A-Z1-9]{4}).html#';
if (preg_match($regexp, $url, $match)) {
$imageFilename = $match[1] . ".jpg";
$imageUrl = $this->list_urls[$this->year]['img_src'] . $imageFilename;
}
//echo "Rank: " . $rank . "\n";
$this->printDebug("Rank: " . $rank);
$this->printDebug("Name: " . $name);
$this->printDebug("Image: " . $imageUrl);
$this->printDebug("Net worth: " . $netWorth);
$this->printDebug("Birth year: " . $birthYear);
$this->printDebug("Bio: " . $bio);
$person = $this->generatePerson($name, $bio);
$person_exists = $this->getBusinessPersonQuery()->addWhere("person.name_first = ? AND person.name_last = ?", array($person->name_first, $person->name_last))->fetchOne();
if ($person_exists != false) {
$this->printDebug('Person exists');
$person = $person_exists;
} else {
$this->printDebug('Saving new person');
}
//parse name and create person object
$person->addExtension('BusinessPerson');
$person->start_date = $person->start_date == null ? $birthYear : $person->start_date;
$person->summary = $person->summary == null ? $bio : $person->summary;
$person->net_worth = $person->net_worth == null ? $netWorth : $person->net_worth;
//go through schools person attended
foreach ($schools as $school) {
//does the current school exist?
$current_school = EntityTable::getByExtensionQuery('Org')->addWhere("org.name = ?", $school['org'])->fetchOne();
if ($current_school) {
$this->printDebug(" Found School " . $school['org']);
} else {
//clear cache
Doctrine::getTable('ExtensionDefinition')->clear();
$current_school = new Entity();
$current_school->addExtension('Org');
$current_school->addExtension('School');
$current_school->name = LsLanguage::titleize($school['org']);
$current_school->save();
$current_school->addReference($source = $url, $excerpt = null, $fields = array('name'), $name = 'Forbes.com', $detail = null, $date = null);
$this->printDebug(" Adding new school: " . $school['org']);
}
//if there is no relationship between person and school. connect them!
//.........这里部分代码省略.........
示例4: importGovernor
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);
}
}
//.........这里部分代码省略.........
示例5: import
//.........这里部分代码省略.........
}
}
if (isset($info_box['faculty']) && preg_match('/([\\d\\,]{2,})/isu', $info_box['faculty']['clean'], $match)) {
$new_school->faculty = LsNumber::clean($match[1]);
}
if (isset($info_box['type'])) {
if (stristr($info_box['type']['clean'], 'public')) {
$new_school->is_private = 0;
} else {
if (stristr($info_box['type']['clean'], 'private')) {
$new_school->is_private = 1;
}
}
}
if (isset($info_box['endowment'])) {
if (preg_match('/(\\$[\\d\\,\\.\\s]+)(million|billion)/isu', $info_box['endowment']['clean'], $match)) {
if (strtolower($match[2]) == 'billion') {
$factor = 1000000000;
} else {
$factor = 1000000;
}
$new_school->endowment = LsNumber::formatDollarAmountAsNumber($match[1], $factor);
}
}
if (isset($info_box['established'])) {
$year = null;
if ($date = LsDate::convertDate($info_box['established']['clean'])) {
$new_school->start_date = $date;
} else {
if (preg_match('/\\b(\\d\\d\\d\\d)\\b/isu', $info_box['established']['clean'], $match)) {
$new_school->start_date = $match[1];
}
}
}
$summary = trim($wikipedia->getIntroduction());
$summary = preg_replace('/\\n\\s*\\n/isu', '', $summary);
if (strlen($summary) > 10) {
$new_school->summary = $summary;
}
$new_school->save();
$new_school->addReference($source = $wikipedia->getUrl(), $excerpt = null, $fields = array('summary'), $name = 'Wikipedia');
} else {
$new_school->save();
}
$current_school = $new_school;
$this->printDebug('Adding new school');
}
$alias = new Alias();
$alias->name = $school->institution;
$alias->context = 'bw_school';
$alias->Entity = $current_school;
$alias->save();
}
//find degree
$degree = null;
if (!($degree = DegreeTable::getByText($school->degree))) {
$degree = DegreeTable::addDegree($school->degree);
$this->printDebug('Adding new degree');
}
//find relationship
$relationship = null;
$relationships = $person->getRelationshipsWithQuery($current_school, RelationshipTable::EDUCATION_CATEGORY)->execute();
foreach ($relationships as $existing_relationship) {
if ($existing_relationship->degree_id == $degree->id) {
$relationship = $existing_relationship;
break;
}
}
if ($relationship) {
$this->printDebug('Relationship between person and school exists');
} else {
$relationship = new Relationship();
$relationship->Entity1 = $person;
$relationship->Entity2 = $current_school;
$relationship->description1 = 'student';
$relationship->is_current = 0;
if ($school->year) {
$relationship->end_date = $school->year;
}
$relationship->setCategory('Education');
$this->printDebug('Creating new relationship between person and school');
}
//save
$relationship->save();
//add degree and reference
if ($relationship->degree_id == null) {
$reference_name = strstr($school->source, 'wikipedia') ? "Wikipedia" : "BusinessWeek";
$relationship->Degree = $degree;
$relationship->save();
$relationship->addReference($source = $school->source, $excerpt = null, $fields = array('degree_id'), $name = $reference_name, $detail = null, $date = null);
$this->printDebug('Adding degree and reference');
}
}
} else {
$this->printDebug('No organization matches');
return false;
}
}
return true;
}
示例6: processCongressMemberRow
//.........这里部分代码省略.........
if (!($partyEntity = $q->fetchOne())) {
$partyEntity = new Entity();
$partyEntity->addExtension('Org');
$partyEntity->addExtension('PoliticalParty');
$partyEntity->name = $partyName;
$partyEntity->save();
$this->printDebug("Created new political party: " . $partyName);
}
}
//create current party affiliation if session is member's most recent session
if ($member->exists()) {
$q = $member->getTripleTagsQuery('congress', 'session')->addWhere('tag.triple_value > ?', current($this->_sessions));
$setParty = $q->count() ? false : true;
} else {
$setParty = true;
}
if ($setParty) {
if ($partyName) {
$member->Party = $partyEntity;
$member->is_independent = false;
$this->printDebug("Set current political affiliation to " . $partyName);
} else {
$member->is_independent = true;
$member->party_id = null;
$this->printDebug("Set current political affiliation to Independent");
}
}
}
//save member
$modified = $member->getAllModifiedFields();
$member->save();
$this->printDebug("Saved member with entity ID: " . $member->id);
$this->addListMember($member);
//set member reference fields
$excludeFields = array();
foreach ($this->_references as $key => $ref) {
$ref->object_model = 'Entity';
$ref->object_id = $member->id;
if ($key != 'bioguide') {
$ref->save();
$excludeFields = array_merge($excludeFields, $ref->getFieldsArray());
}
}
$modified = array_diff($modified, $excludeFields);
$this->_references['bioguide']->addFields($modified);
$this->_references['bioguide']->save();
$this->printDebug("Saved member references");
//tag member with congress session
$member->addTagByTriple('congress', 'session', current($this->_sessions));
$this->printDebug("Added tag for session " . current($this->_sessions));
//save image, if any
if ($this->_image) {
$this->_image->Entity = $member;
$this->_image->save();
$this->printDebug("Saved member image");
if ($this->_photoUrl) {
//save image source
$this->_image->addReference($this->_photoUrl);
$this->printDebug("Saved image reference");
}
}
//create party membership relationships
if ($partyName) {
//if membership relationship with party doesn't exist, create it
$partyRel = LsQuery::getByModelAndFieldsQuery('Relationship', array('entity1_id' => $member->id, 'entity2_id' => $partyEntity->id, 'category_id' => RelationshipTable::MEMBERSHIP_CATEGORY))->fetchOne();
if (!$partyRel) {
$partyRel = new Relationship();
$partyRel->Entity1 = $member;
$partyRel->Entity2 = $partyEntity;
$partyRel->setCategory('Membership');
$modified = $partyRel->getAllModifiedFields();
$partyRel->save();
$partyRel->addReference($this->_profileUrlBase . $member->bioguide_id, null, $modified, 'Congressional Biographical Directory');
$this->printDebug("Created membership in political party: " . $partyName);
}
}
$senator = null;
//create senate relationships
foreach ($this->_senateRelationships as $rel) {
$modified = $rel->getAllModifiedFields();
$rel->save();
$rel->addReference($this->_profileUrlBase . $member->bioguide_id, null, $modified, 'Congressional Biographical Directory');
$this->printDebug("Saved Senate relationship");
}
//create house relationships
foreach ($this->_houseRelationships as $rel) {
$modified = $rel->getAllModifiedFields();
$rel->save();
$rel->addReference($this->_profileUrlBase . $member->bioguide_id, null, $modified, 'Congressional Biographical Directory');
$this->printDebug("Saved House relationship");
}
//save everything
if (!$this->testMode) {
$this->db->commit();
}
} catch (Exception $e) {
$this->db->rollback();
throw $e;
}
}
示例7: addRelationship
protected function addRelationship($org, $category_id, $description)
{
try {
$category = Doctrine::getTable('RelationshipCategory')->find($category_id);
if (!$category) {
$this->setError('No relationships added -- you must choose a category');
return false;
}
$this->db->beginTransaction();
foreach ($this->edits as &$edit) {
$person_id = $edit['New Person'] ? $edit['New Person'] : $edit['Existing Person'];
$person = Doctrine::getTable('Entity')->find($person_id);
$q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? and r.entity2_id = ?', array($person->id, $org->id))->fetchOne();
if ($q) {
unset($edit['Relationship']);
continue;
}
$rel = new Relationship();
$rel->Entity1 = $person;
$rel->Entity2 = $org;
$rel->setCategory($category);
$rel->is_current = 1;
if (isset($edit['Relationship']['start_date']) && preg_match('/\\d\\d\\d\\d/', $edit['Relationship']['start_date'])) {
$rel->start_date = $edit['Relationship']['start_date'];
}
if (isset($edit['Relationship']['end_date']) && preg_match('/\\d\\d\\d\\d/', $edit['Relationship']['end_date'])) {
$rel->end_date = $edit['Relationship']['end_date'];
}
if ($category->name == 'Position' && isset($edit['Relationship']['title'])) {
$rel->description1 = $edit['Relationship']['title'];
} else {
if ($description) {
$description == trim($description);
$rel->description1 = $description;
if ($description == 'Director' || $description == 'Trustee') {
$rel->is_board = 1;
$rel->is_employee = 0;
}
}
}
if (isset($edit['Relationship']['notes'])) {
$rel->notes = $edit['Relationship']['notes'];
}
$rel->save();
$rel->addReference($this->source_url, null, null, $this->source_name);
$this->printDebug($rel . ' saved');
unset($edit['Relationship']);
}
$this->db->commit();
} catch (Exception $e) {
$this->db->rollback();
throw $e;
}
}
示例8: importFiling
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);
//.........这里部分代码省略.........
示例9: parseResults
public function parseResults($match)
{
if (isset($match['bio'])) {
$bio_dirty = LsHtml::replaceEntities(LsString::spacesToSpace(LsHtml::stripTags($match['bio'], "; ")));
$bio_dirty = preg_replace('/(\\;\\s)+/is', '; ', $bio_dirty);
}
foreach ($match as $k => &$m) {
$m = LsHtml::replaceEntities(LsString::spacesToSpace(LsHtml::stripTags($m, " ")));
}
if (isset($match['name'])) {
$name = $match['name'];
$bio = '';
if (isset($match['bio'])) {
$bio = $match['bio'];
}
} else {
return;
}
$this->printDebug("_________________________\n\nname: " . $name . "\n");
$this->printDebug("bio: " . $bio . "\n");
$accept = strtolower($this->readline('Process this entity? (n to skip) '));
if ($accept == 'n' || $accept == 'no') {
return false;
}
if (!$this->org_org) {
if ($this->last_first) {
$entity = PersonTable::parseCommaName($name);
} else {
$entity = PersonTable::parseFlatName($name);
}
$similar_entities = PersonTable::getSimilarQuery2($entity)->execute();
} else {
$entity = new Entity();
$entity->addExtension('Org');
foreach ($this->org_extensions as $ext) {
$entity->addExtension($ext);
}
$entity->setEntityField('name', $name);
$name = trim($name);
$name = str_replace('.', '', $name);
$similar_entities = OrgTable::getSimilarQuery($entity)->execute();
}
$matched = false;
foreach ($similar_entities as $similar_entity) {
if ($similar_entity['primary_ext'] == 'Person') {
$this->printDebug(' POSSIBLE MATCH: ' . $similar_entity->name . ' (Orgs :: ' . $similar_entity->getRelatedOrgsSummary() . " Bio :: {$similar_entity->summary})");
} else {
$this->printDebug(' POSSIBLE MATCH: ' . $similar_entity->name . ' (Summary :: ' . $similar_entity->summary . ')');
}
$accept = $this->readline(' Is this the same entity? (y or n)');
$attempts = 1;
while ($accept != 'y' && $accept != 'n' && $attempts < 5) {
$accept = $this->readline(' Is this the same entity? (y or n) ');
$attempts++;
}
if ($accept == 'y') {
$entity = $similar_entity;
$matched = true;
$this->printDebug(' [accepted]');
//sleep(1);
break;
} else {
if ($accept == 'break') {
break;
}
}
}
$created = false;
if (!$matched) {
if ($entity->getPrimaryExtension() == 'Person') {
$this->printDebug(' New person: ' . $entity->name_first . ' ' . $entity->name_last);
} else {
$this->printDebug(' New org: ' . $entity->name);
}
$accept = $this->readline(' create this new entity? (y or n) ');
$attempts = 1;
while ($accept != 'y' && $accept != 'n' && $attempts < 5) {
$accept = $this->readline(' create this new entity? (y or n) ');
$attempts++;
}
if ($accept == 'y') {
if ($entity->getPrimaryExtension() == 'Person') {
$this->printDebug("\n Bio: {$bio} \n");
$accept = $this->readline(' Add this bio? (y or n) ');
$attempts = 1;
while ($accept != 'y' && $accept != 'n' && $attempts < 5) {
$accept = $this->readline(' add this bio? (y or n) ');
$attempts++;
}
if ($accept == 'y') {
$entity->summary = $bio;
}
}
$entity->save();
$entity->addReference($this->url, null, null, $this->url_name);
$created = true;
$this->printDebug(' ' . $entity->name . ' saved');
//sleep(1);
}
}
//.........这里部分代码省略.........
示例10: importRelationship
private function importRelationship($person, $position = null, $current = null, $is_board, $person_arr)
{
$q = LsDoctrineQuery::create()->from('Relationship r')->leftJoin('r.Position p')->where('r.entity1_id = ?', $person->id)->addWhere('r.entity2_id = ?', $this->entity->id)->addWhere('r.category_id = ?', RelationshipTable::POSITION_CATEGORY)->orderBy('r.id ASC');
if ($is_board) {
$q->addWhere('p.is_board = 1');
} else {
$q->addWhere('p.is_executive = 1');
//$q->addWhere('r.description1 = ?', $position)
// ->addWhere('p.id IS NOT NULL');
}
$count = $q->count();
if ($count == 0) {
//if relationship doesn't already exist, create it
$rel = new Relationship();
$rel->entity1_id = $person->id;
$rel->entity2_id = $this->entity->id;
$rel->setCategory('Position');
$rel->is_current = $current;
if ($is_board) {
$rel->is_board = 1;
$rel->is_executive = $position != 'Chairman' && $position != 'Director' ? 1 : 0;
$rel->description1 = null;
//better not to set description if is_board = 1
} else {
$rel->description1 = $position;
$rel->is_executive = 1;
$rel->is_board = 0;
}
if (!$this->testMode) {
$rel->save();
//save sources
$rel->addReference($person_arr['readableXmlUrl'], null, null, $this->entity->name . ' ' . $person_arr['formName'], null, $person_arr['date']);
if (isset($this->filing_url) && isset($this->filing_name)) {
$rel->addReference($this->filing_url, null, null, $this->entity->name . " " . $this->filing_name, null, $this->filing_date);
}
}
$this->printDebug("+ Relationship created: " . $rel->id . " (" . ($rel->is_board ? "Board Member" : $rel->description1) . ")");
} elseif ($count == 1) {
//this part might be redundant because importRoster() updates expired board memberships at the end?
if ($is_board) {
//if one relationship exists, expire if necessary
$rel = $q->fetchOne();
if ($current == false && $rel->is_current) {
$rel->is_current = false;
if (!$this->testMode) {
$rel->save();
}
$this->printDebug("Existing relationship no longer current: " . $rel->id . " (" . $rel->Entity1->name . ")");
}
}
} else {
//if mmultiple existing relationships found, do nothing
/*
$rel = $q->fetchOne();
if ($is_board)
{
//for board relationship...
//if existing rel was last updated by a bot, we update it
if (($current != $rel->is_current) && ($rel->last_user_id < 4))
{
$rel->is_current = $current;
$rel->addReference($this->filing_url, null, $fields= array('is_current'), $this->entity->name . " " . $this->filing_name, null, $this->filing_date);
$rel->save();
$this->printDebug("Board relationship updated: " . $rel);
}
}
else if ($current && !$rel->is_current && ($rel->last_user_id < 4))
{
$rel->is_current = $current;
$rel->addReference($this->filing_url, null, $fields= array('is_current'), $this->entity->name . " " . $this->filing_name, null, $this->filing_date);
$rel->save();
$this->printDebug("Exec relationship updated: " . $rel);
}
*/
}
}
示例11: processRow
public function processRow($row)
{
if (isset($row['url']) && $row['url'] != '' && isset($row['url_name']) && $row['url_name'] != '') {
$url = $row['url'];
$url_name = $row['url_name'];
} else {
$url = $this->url;
$url_name = $this->url_name;
}
foreach ($row as &$r) {
trim($r);
}
unset($r);
if ($this->entity) {
$required = array('entity_name', 'primary_type', 'relationship_category');
} else {
$required = array('entity_name', 'primary_type');
}
foreach ($required as $req) {
if (!isset($row[$req]) || $row[$req] == '') {
$this->printDebug('!!! > skipping row, ' . $req . ' not set');
return;
}
}
if ($row['primary_type'] != 'Person' && $row['primary_type'] != 'Org') {
$this->printDebug('!!! > primary type not properly set, skipping row...');
return;
}
if ($this->entity) {
$relationship_category = trim($row['relationship_category']);
$relationship_category_id = array_search($relationship_category, RelationshipCategoryTable::$categoryNames);
if (!$relationship_category_id) {
$this->printDebug('!!! > relationship type not properly set, skipping row...');
return;
}
}
$this->printDebug("processing: " . $row['entity_name'] . '......');
if ($row['primary_type'] == 'Person') {
$entity2 = PersonTable::parseFlatName($row['entity_name']);
$similar_entities = PersonTable::getSimilarQuery2($entity2)->execute();
} else {
$entity2 = new Entity();
$entity2->addExtension('Org');
$entity2->setEntityField('name', $row['entity_name']);
$similar_entities = OrgTable::getOrgsWithSimilarNames($entity2->name);
}
$matched = false;
foreach ($similar_entities as $similar_entity) {
if ($similar_entity['primary_ext'] == 'Person') {
$this->printDebug(' POSSIBLE MATCH: ' . $similar_entity->name . ' (Orgs :: ' . $similar_entity->getRelatedOrgsSummary() . " Bio :: {$similar_entity->summary})");
} else {
$this->printDebug(' POSSIBLE MATCH: ' . $similar_entity->name . ' (Summary :: ' . $similar_entity->summary . ')');
}
$accept = $this->readline(' Is this the same entity? (y or n or b to break)');
if ($accept == 'y') {
$entity2 = $similar_entity;
$matched = true;
$this->printDebug(' [accepted]');
break;
} else {
if ($accept == 'b') {
break;
}
}
}
$created = false;
if (!$matched) {
if ($entity2->getPrimaryExtension() == 'Person') {
$this->printDebug(' New person: ' . $entity2->name_first . ' ' . $entity2->name_last);
} else {
$this->printDebug(' New org: ' . $entity2->name);
}
$accept = $this->readline(' create this new entity? (y or n) ');
if ($accept == 'y') {
try {
$extensions = LsString::split($row['entity_extensions'], '\\s*\\,\\s*');
foreach ($extensions as $extension) {
$entity2->addExtension($extension);
}
$entity2->save();
$entity2->addReference($url, null, null, $url_name);
} catch (Exception $e) {
$this->printDebug(' !!! problems with extensions for this row');
}
$fields = array('summary', 'blurb', 'website');
foreach ($fields as $field) {
if (isset($row[$field])) {
$entity2[$field] = $row[$field];
}
}
$entity2->save();
$entity2->addReference($url, null, null, $url_name);
$created = true;
$this->printDebug(' ' . $entity2->name . ' saved');
//sleep(1);
} else {
$entity2 = null;
}
}
// create relationship
//.........这里部分代码省略.........
示例12: importRelationship
private function importRelationship($person, $corp, $position, $person_arr)
{
$r = new Relationship();
$r->entity1_id = $person->id;
$r->entity2_id = $corp->id;
$r->setCategory('Position');
$r->is_current = 1;
$r->description1 = $position;
$q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ?', $person->id)->addWhere('r.entity2_id = ?', $corp->id)->addWhere('r.category_id = ?', RelationshipTable::POSITION_CATEGORY)->addWhere('r.description1 = ?', $r->description1);
if ($q->count() == 0) {
//$r->relationship_id = $r->id;
if ($person_arr['isDirector'] == '1') {
$r->is_board = 1;
$r->is_executive = $position != 'Chairman' && $position != 'Director' ? 1 : 0;
} else {
$r->is_executive = 1;
$r->is_board = 0;
}
$r->save();
$r->addReference($person_arr['form4Url'], null, $fields = array('entity1_id', 'entity2_id', 'is_current', 'description1', 'description2', 'category_id', 'relationship_id', 'is_board', 'is_executive'), $corp->name . ' Form 4', null, $person_arr['date']);
$r->addReference($person_arr['proxyUrl'], null, $fields = array('entity1_id', 'entity2_id', 'is_current', 'description1', 'description2', 'category_id', 'relationship_id', 'is_board', 'is_executive'), $corp->name . ' proxy, ' . $person_arr['proxyYear']);
} else {
$this->printDebug('relationship exists');
}
}
示例13: getTransactionDetails
private function getTransactionDetails($org, $fedspending_id)
{
if (!$this->browser->get($this->fedSpendingSearchUrl, array('record_id' => $fedspending_id, 'datype' => 'X', 'detail' => '4'))->responseIsError()) {
$response_url = $this->browser->getUrlInfo();
$response_url_str = "http://" . $response_url['host'] . $response_url['path'] . "?" . $response_url['query'];
$this->printDebug("Transaction #{$fedspending_id} http://" . $response_url['host'] . $response_url['path'] . "?" . $response_url['query']);
$text = $this->browser->getResponseText();
$this->browser->setResponseText(iconv('ISO-8859-1', 'UTF-8', $this->browser->getResponseText()));
$xml = $this->browser->getResponseXml();
} else {
$this->printDebug("Couldn't get " . $this->fedSpendingSearchUrl);
return false;
}
$obligated_amount = $xml->xpath('/fedspendingSearchResults/data/record/amounts/obligatedAmount');
$maj_agency_cat = $xml->xpath('/fedspendingSearchResults/data/record/purchaser_information/maj_agency_cat');
$contracting_agency = $xml->xpath('/fedspendingSearchResults/data/record/purchaser_information/contractingOfficeAgencyID');
$psc_cat = $xml->xpath('/fedspendingSearchResults/data/record/product_or_service_information/psc_cat');
$signed_date = $xml->xpath('/fedspendingSearchResults/data/record/contract_information/signedDate');
$descriptionOfContractRequirement = $xml->xpath('/fedspendingSearchResults/data/record/contract_information/descriptionOfContractRequirement');
$current_completion_date = $xml->xpath('/fedspendingSearchResults/data/record/contract_information/currentCompletionDate');
$state_code = $xml->xpath('/fedspendingSearchResults/data/record/principal_place_of_performance/stateCode');
$place_of_performance_congressional_district = $xml->xpath('/fedspendingSearchResults/data/record/principal_place_of_performance/placeOfPerformanceCongressionalDistrict');
foreach ($obligated_amount as $key => $dont_use) {
$gov_name = $this->cleanGovtBodyName($maj_agency_cat[$key]);
$gov_agency = $this->getGovernmentBodyEntity($gov_name, $maj_agency_cat[$key]);
if ($gov_agency) {
//$this->printDebug("Found existing Government Agency" . $gov_agency->name);
} else {
$gov_name = $this->cleanGovtBodyName($maj_agency_cat[$key]);
$this->printDebug($gov_name);
$gov_agency = $this->addGovernmentBodyEntity($gov_name, $maj_agency_cat[$key]);
$this->printDebug("Creating new Government Agency: " . $gov_agency->name);
$gov_agency->addReference(self::$baseContractorUrl . $org->fedspending_id, null, array('name', 'parent_id'), 'FedSpending.org');
}
if (!$gov_agency) {
$this->printDebug("Error creating Government Agency");
return false;
}
$sub_agency_name = $this->cleanGovtBodyName($contracting_agency[$key]);
$sub_agency = $this->getGovernmentBodyEntity($sub_agency_name, $contracting_agency[$key]);
if ($sub_agency_name == $gov_agency->name) {
$sub_agency = $gov_agency;
}
if (!$sub_agency) {
$sub_agency = $this->addGovernmentBodyEntity($sub_agency_name, $contracting_agency[$key], $gov_agency->id);
$this->printDebug("Creating new sub-agency: " . $sub_agency->name);
$sub_agency->addReference(self::$baseContractorUrl . $org->fedspending_id, null, array('name', 'parent_id'), 'FedSpending.org');
}
if (!$sub_agency) {
$this->printDebug("Error creating Government Agency");
return false;
}
try {
$district = null;
$state = explode(': ', $state_code[$key]);
$federal_district = explode(': ', $place_of_performance_congressional_district[$key]);
$state = $state[0];
$federal_district = $federal_district[0];
$filing = new FedspendingFiling();
$filing->goods = $descriptionOfContractRequirement[$key];
$filing->amount = abs($obligated_amount[$key]);
if ($filing->amount < 1000) {
$this->printDebug('amount under $1000, rolling back');
return 'under_1000';
}
//$this->printDebug("state: " . $state . " and district: " . $federal_district);
if ($district = PoliticalDistrictTable::getFederalDistrict($state, $federal_district)) {
//$this->printDebug("found " . $district->id);
$filing->District = $district;
} elseif (trim($state) && trim($federal_district)) {
try {
$district = PoliticalDistrictTable::addFederalDistrict($state, $federal_district);
$this->printDebug("Adding District " . $state . " #" . $district->id);
$filing->District = $district;
} catch (Exception $e) {
throw $e;
}
}
$filing->fedspending_id = $fedspending_id;
$filing->start_date = LsDate::formatFromText($signed_date[$key]);
$filing->end_date = LsDate::formatFromText($current_completion_date[$key]);
$relationship = null;
if ($relationship = $org->getRelationshipsWithQuery($sub_agency, RelationshipTable::TRANSACTION_CATEGORY)->fetchOne()) {
$relationship->addFedspendingFiling($filing);
} else {
$relationship = new Relationship();
$relationship->Entity1 = $org;
$relationship->Entity2 = $sub_agency;
$relationship->setCategory('Transaction');
$relationship->description1 = 'Contractor';
$relationship->description2 = 'Client';
$relationship->save();
$relationship->addReference(self::$baseContractorUrl . $org->fedspending_id, null, array('start_date', 'end_date', 'amount', 'goods'), 'FedSpending.org');
$relationship->addFedspendingFiling($filing);
}
$filing->save();
return true;
} catch (Exception $e) {
throw $e;
}
//.........这里部分代码省略.........