本文整理汇总了PHP中Entity::addReference方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::addReference方法的具体用法?PHP Entity::addReference怎么用?PHP Entity::addReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::addReference方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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!
//.........这里部分代码省略.........
示例2: parseRecipients
function parseRecipients($contribution)
{
$recipients = $this->getRecipients($contribution);
$this->printDebug(" Number of recipients " . count($recipients));
foreach ($recipients as $recipient) {
$candidate = $this->getCandidateInfo($recipient[0]);
$committee = $this->getCommitteeInfo($recipient[0]);
$committee_name = trim($committee[2]);
$committee_fec_id = trim($committee[1]);
//CHECK FOR EXISTING COMMITTEE
unset($current_committee);
$current_committee = EntityTable::getByExtensionQuery(array('Org', 'PoliticalFundraising'))->addWhere("org.name = ?", $committee_name)->fetchOne();
if ($current_committee) {
$this->printDebug(" Found Committee " . $committee_name . " (" . $committee_fec_id . ")");
} else {
//clear cache
Doctrine::getTable('ExtensionDefinition')->clear();
$current_committee = new Entity();
$current_committee->addExtension('Org');
$current_committee->addExtension('PoliticalFundraising');
$current_committee->name = LsLanguage::titleize($committee_name);
$current_committee->fec_id = $committee_fec_id;
$current_committee->save();
$current_committee->addReference($source = $this->fecCommitteeUrl . $committee_fec_id, $excerpt = null, $fields = array('name', 'fec_id'), $name = 'FEC Disclosure Report', $detail = null, $date = null, false);
$this->printDebug(" Adding new committee: " . $committee_name . " (" . $committee_fec_id . ")");
}
$this->committee = $current_committee;
$this->updateCommitteeDetails($current_committee);
$transactions = $this->getTransactions($recipient[0]);
//RECORD DONATIONS
$validate_existance_of_donation = true;
foreach ($transactions as $transaction) {
list($month, $day, $year) = explode('/', $transaction[1]);
$donation_amount = $transaction[2];
$donation_fec_id = $transaction[4];
$donation_date = $year . '-' . $month . '-' . $day;
if ($this->hasMeta($this->person->id, $donation_fec_id) && !$this->forceScaper) {
$this->printDebug("#{$donation_fec_id} Already scraped");
continue;
}
if ($validate_existance_of_donation) {
$donation_exists = FecFilingTable::getFecFiling($donation_fec_id);
$validate_existance_of_donation = false;
}
if (!$donation_exists) {
$this->printDebug(" Donation exists: FALSE ");
$this->printDebug(" Donation ({$donation_fec_id}): " . $donation_amount . " on " . $donation_date);
$this->printDebug(" Creating relationship between \"" . $this->person->name_first . " " . $this->person->name_last . "\" and \"" . $current_committee->name . "\"");
$filing = new FecFiling();
$filing->amount = $donation_amount;
$filing->fec_filing_id = $donation_fec_id;
$filing->start_date = $donation_date;
$filing->end_date = $donation_date;
$relationship = null;
if ($relationship = $this->person->getRelationshipsWithQuery($current_committee, RelationshipTable::DONATION_CATEGORY)->fetchOne()) {
$relationship->addFecFiling($filing);
} else {
$relationship = new Relationship();
$relationship->Entity1 = $this->person;
$relationship->Entity2 = $current_committee;
$relationship->setCategory('Donation');
$relationship->description1 = 'Campaign Contribution';
$relationship->is_current = 1;
$relationship->save();
$relationship->addFecFiling($filing);
$relationship->addReference($source = self::$fecImageUrl . $donation_fec_id, $excerpt = null, $fields = array('amount', 'start_date', 'end_date', 'description1'), $name = 'FEC Filing', $detail = null, $date = null);
$filing->save();
$relationship->addReference($source = $this->_url, $excerpt = null, $fields = array('amount', 'start_date', 'end_date', 'description1'), $name = 'FEC contribution search', $detail = null);
if ($this->_entity_reference == false) {
$this->person->addReference($source = $this->_url, $excerpt = null, $fields = null, $name = 'FEC contribution search');
$this->_entity_reference = true;
}
}
$this->saveMeta($this->person->id, $donation_fec_id, 1);
} else {
$this->printDebug(" Donation exists: TRUE");
break;
}
}
}
$this->printDebug("+ Adding Donation: COMPLETE\n");
}
示例3: 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;
}
示例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: processRow
protected function processRow($row)
{
foreach ($row as &$r) {
$r = trim($r);
}
$edit = array('Search Name' => $row['name'], 'Affiliation Name' => $row['affiliation1'], 'Similar Names' => array(), 'New Person' => null, 'Existing Person' => null, 'New Org' => null, 'Existing Org' => null, 'New Relationship' => null);
try {
$this->db->beginTransaction();
$person = null;
$search_person = PersonTable::parseFlatName($row['name']);
$similar = $search_person->getSimilarEntitiesQuery(true)->execute();
$matched_bio = false;
$similar_ids = array();
foreach ($similar as $s) {
$similar_ids[] = $s->id;
$sim_re = LsString::escapeStringForRegex($s->name_first);
$search_re = LsString::escapeStringForRegex($search_person->name_first);
if (preg_match('/^' . $sim_re . '/su', $search_person->name_first) == 0 && preg_match('/^' . $search_re . '/su', $s->name_first) == 0) {
continue;
}
$matched = false;
$affils = array();
$ct = 1;
$matched_affils = array();
$unmatched_affils = array();
while (isset($row['affiliation' . $ct]) && trim($row['affiliation' . $ct]) != '') {
$affil = trim($row['affiliation' . $ct]);
$org = $s->checkAffiliations(array($affil));
if ($org) {
$matched_affils[] = array($org, $affil);
$edit['Existing Org'] = $org->id;
break;
} else {
$unmatched_affils[] = $affil;
}
$ct++;
}
if (count($matched_affils)) {
$person = $s;
break;
//$ret[] = array('person' => $s, $matched_affils, $unmatched_affils);
} else {
/*$str = implode(' ', $unmatched_affils);
if (isset($row['bio']))
{
$str .= ' ' . $row['bio'];
}*/
$bio = $s->getExtendedBio();
foreach ($unmatched_affils as $affil) {
$affil = OrgTable::removeSuffixes($affil);
$this->printDebug($affil);
$this->printDebug($bio);
if (preg_match('/' . OrgTable::getNameRegex($affil) . '/su', $bio)) {
$matched_bio = true;
break;
}
}
if ($matched_bio) {
$person = $s;
break;
} else {
$this->printDebug(' ' . $s->name . ' failed');
}
}
}
$edit['Similar Names'] = array_slice($similar_ids, 0, 5);
$no_match = false;
if (!$person) {
if (isset($row['bio']) && trim($row['bio']) != '') {
$search_person->summary = $row['bio'];
}
$search_person->save();
$this->printDebug(' not found, new person saved: ' . $search_person->name);
$search_person->addReference($this->source_url, null, null, $this->source_name);
$no_match = true;
$edit['New Person'] = $search_person->id;
$person = $search_person;
} else {
if (isset($row['bio']) && trim($row['bio']) != '' && !$person->summary) {
$person->summary = $row['bio'];
$person->save();
}
$this->printDebug(' **person found: ' . $person->name);
$edit['Existing Person'] = $person->id;
}
if ($matched_bio || $no_match) {
$orgs = OrgTable::getOrgsWithSimilarNames($row['affiliation1'], true);
$max = -1;
$affiliated_org = null;
foreach ($orgs as $org) {
$this->printDebug(' found match: ' . $org->name);
$ct = $org->getRelatedEntitiesQuery('Person', RelationshipTable::POSITION_CATEGORY, null, null, null, false, 2)->count();
if ($ct > $max) {
$affiliated_org = $org;
$edit['Existing Org'] = $affiliated_org->id;
$max = $ct;
}
}
if (!$affiliated_org) {
$affiliated_org = new Entity();
//.........这里部分代码省略.........
示例6: Entity
$layerEntity = new Entity($database, "layer");
$layerEntity->setPresentation("title", "foto_filename");
$layerEntity->addField("title", VARCHAR, 50);
$layerEntity->addField("subtitle", VARCHAR, 50);
$layerEntity->addField("description", TEXT);
$layerEntity->addField("foto", FILE);
$layerEntity->addReference($bgEntity, "bg_id");
$layerEntity->addReference($pageEntity, "page_id");
$layerEntity->addField("position", POSITION);
$layerEntity->connect();
$msgEntity = new Entity($database, "message");
$msgEntity->setPresentation("title");
$msgEntity->addField("title", VARCHAR, 255);
$msgEntity->addField("description", TEXT);
$msgEntity->addField("position", POSITION);
$msgEntity->connect();
/* MODULISTICA + CATEGORIE MODULI */
$catModuleEntity = new Entity($database, "catmodule");
$catModuleEntity->setPresentation("name");
$catModuleEntity->addField("name", VARCHAR, 50);
$catModuleEntity->addField("position", POSITION);
$catModuleEntity->connect();
/* *** */
$moduleEntity = new Entity($database, "module", WITH_OWNER);
$moduleEntity->setPresentation("name");
$moduleEntity->addField("name", VARCHAR, 100);
$moduleEntity->addField("description", TEXT);
$moduleEntity->addField("position", POSITION);
$moduleEntity->addField("file", FILE);
$moduleEntity->addReference($catModuleEntity, "category");
$moduleEntity->connect();
示例7: import
//.........这里部分代码省略.........
} elseif ($this->year > 2004 && preg_match('/<blockquote class="spaced">(.*)<\\/blockquote>/ismU', $text, $match)) {
$summary = str_replace(array(' ', "\n"), array(' ', ' '), html_entity_decode(trim(strip_tags($match[1]))));
}
//get revenue
if ($this->year > 1995 && $this->year < 2000 && preg_match('/<td class="mainlisttxt">\\$([\\S]+) mil<sup>e?<\\/sup><\\/td>/ismU', $text, $match)) {
$this->printDebug($match[1]);
$revenue = str_replace(",", "", $match[1] . ",000,000");
} elseif ($this->year > 1999 && $this->year < 2005 && preg_match('/<td class="mainlisttxt" nowrap>([^<]+)<sup>e?<\\/sup><\\/td>/ismU', $text, $match)) {
$this->printDebug($match[1]);
$revenue = str_replace(",", "", $match[1] . ",000,000");
} elseif ($this->year > 2004 && preg_match('/<td class="highlight" nowrap="nowrap">\\$([\\S]+) bil.*<\\/td> <td class="highlight" nowrap="nowrap">[^<]+<\\/td> <td class="highlight" nowrap="nowrap">([^<]+)<\\/td>/ismU', $text, $match)) {
$revenue = 1000000000 * $match[1];
}
//get employees
if ($this->year > 1995 && $this->year < 2005 && preg_match('/mil<\\/td>.+<td class="mainlisttxt"( nowrap)?>(\\d[^<]+)<\\/td>.+<td class="mainlisttxt">[a-zA-Z]+<\\/td>/ismU', $text, $match)) {
$employees = str_replace(',', '', $match[2]);
} elseif ($this->year > 1999 && $this->year < 2005 && preg_match('/<sup>e?<\\/sup><\\/td> <td class="mainlisttxt"( nowrap)?>(\\d[^<]+)<sup>e?<\\/sup><\\/td> <td class="mainlisttxt">[a-zA-Z]+<\\/td>/ismU', $text, $match)) {
$employees = str_replace(',', '', $match[2]);
} elseif ($this->year > 2004 && preg_match('/<td class="highlight" nowrap="nowrap">([\\d,]+)<\\/td> <td class="highlight" nowrap="nowrap">[A-Z][a-z]{2,}<\\/td>/', $text, $match)) {
$employees = str_replace(',', '', $match[1]);
}
/*$this->printDebug( "URL: ". $url);
$this->printDebug( "Rank: " . $rank );
$this->printDebug( "Name: " . $name );
$this->printDebug( "Industry: " . $industryName );
$this->printDebug( "Street: " . $street1 );
$this->printDebug( "Street2: " . $street2 );
$this->printDebug( "City: " . $city );
$this->printDebug( "State: " . $state );
$this->printDebug( "Postal: " . $postal );
$this->printDebug( "Phone: " . $phone );
$this->printDebug( "Fax: " . $fax );
$this->printDebug( "Website: " . $website );
$this->printDebug( "CEO: " . $ceoName . " " . $ceoBirthYear);
$this->printDebug( "Summary: " . $summary );
$this->printDebug( "Revenue: " . $revenue );
$this->printDebug( "Employees: " . $employees );*/
$search_company_name = trim(implode(' ', array_diff(explode(' ', ucwords(strtolower($name))), array_merge(LsLanguage::$business, LsLanguage::$businessAbbreviations))));
//continue;
$this->printDebug("{$search_company_name} == {$name}");
if ($company = EntityTable::getByExtensionQuery(array('Org', 'PrivateCompany'))->addWhere("LOWER(REPLACE( org.name, '-' , '')) = ?", strtolower($name))->fetchOne()) {
$this->printDebug("Company exists");
$company->revenue = $revenue;
$company->save();
} else {
$this->printDebug("Creating new company {$name}");
Doctrine::getTable('ExtensionDefinition')->clear();
$company = new Entity();
$company->addExtension('Org');
$company->addExtension('Business');
$company->addExtension('PrivateCompany');
$company->name = LsLanguage::titleize($name);
$company->employees = strlen($employees) ? $employees : null;
$company->revenue = strlen($revenue) ? $revenue : null;
$company->website = strlen($website) ? $website : null;
$company->summary = strlen($summary) ? trim($summary) : null;
//add address
if ($phone) {
$company->addPhone($phone);
}
if ($fax) {
//$company->addPhone($fax);
}
if ($city && $state) {
$address = new Address();
$address->street1 = strlen($street1) ? $street1 : null;
$address->street2 = strlen($street2) ? $street2 : null;
$address->city = strlen($city) ? $city : null;
if ($state = AddressStateTable::retrieveByText($state)) {
$address->State = $state;
}
$address->postal = $postal;
$company->addAddress($address);
$address->save();
$address->addReference($source = $url, $excerpt = null, $fields = array('city', 'country_id', 'postal', 'state_id', 'street1'), $name = 'Forbes.com', $detail = null, $date = null);
}
}
/*$this->printDebug( "URL: ". $url);
$this->printDebug( "Rank: " . $rank );
$this->printDebug( "Name: " . $name );
$this->printDebug( "Industry: " . $industryName );
$this->printDebug( "Street: " . $street1 );
$this->printDebug( "Street2: " . $street2 );
$this->printDebug( "City: " . $city );
$this->printDebug( "State: " . $state );
$this->printDebug( "Postal: " . $postal );
$this->printDebug( "Phone: " . $phone );
$this->printDebug( "Fax: " . $fax );
$this->printDebug( "Website: " . $website );
$this->printDebug( "CEO: " . $ceoName . " " . $ceoBirthYear);
$this->printDebug( "Summary: " . $summary );
$this->printDebug( "Revenue: " . $revenue );
$this->printDebug( "Employees: " . $employees );*/
$company->save();
$company->addReference($source = $url, $excerpt = null, $fields = array('website', 'name', 'website', 'summary', 'revenue', 'employees'), $name = 'Forbes.com', $detail = null, $date = null);
$this->saveToList($company, $rank);
} else {
$this->printDebug("Couldn't get company: " . $url);
}
}
示例8: Entity
$luoghiEntity->addReference($fotoEntity, "id_foto");
$luoghiEntity->connect();
//ITINERARIO//
$itinerarioEntity = new Entity($database, "itinerario");
$itinerarioEntity->setPresentation("username_users");
$itinerarioEntity->addPrimaryKey("id", INT, 255);
$itinerarioEntity->addReference($usersEntity, "username_users");
$itinerarioEntity->addReference($luoghiEntity, "id_luoghi");
$itinerarioEntity->connect();
//RECENSIONI//
$recensioniEntity = new Entity($database, "recensioni");
$recensioniEntity->setPresentation("titolo");
$recensioniEntity->addPrimaryKey("id", INT, 255);
$recensioniEntity->addField("commento", VARCHAR, 255);
$recensioniEntity->addField("titolo", VARCHAR, 255);
$recensioniEntity->addReference($usersEntity, "username_users");
$recensioniEntity->addReference($luoghiEntity, "id_luoghi");
$recensioniEntity->connect();
//FOTO//
/*
$immaginiEntity = new Entity($database, "immagini");
$immaginiEntity->addPrimaryKey("id", INT, 255);
$immaginiEntity->addField("script", VARCHAR, 255);
$immaginiEntity->addField("id_galleria", INT, 255);
$immaginiEntity->connect();
//////////////////////////////////////////////////////////////////////FOTO E GALLERIA USATE DI LEARNPAD////////////////////////////////////
//GALLERIA//
$galleriaEntity = new Entity($database, "galleria");
$galleriaEntity->setPresentation("titolo");
$galleriaEntity->addPrimaryKey("id", INT, 255);
$galleriaEntity->addField("titolo", VARCHAR, 255);
示例9: executeAddBulk
//.........这里部分代码省略.........
$extensions_arr[] = $ext->name;
}
$this->matches = array();
if (isset($names) && count($names) > 0) {
for ($i = 0; $i < count($names); $i++) {
if (isset($names[$i]['name']) && trim($names[$i]['name']) != '') {
$name = $names[$i]['name'];
$name_terms = $name;
if ($this->default_type == 'Person') {
$name_parts = preg_split('/\\s+/', $name);
if (count($name_parts) > 1) {
$name_terms = PersonTable::nameSearch($name, true);
}
$terms = $name_terms;
$primary_ext = "Person";
} else {
if ($this->default_type == 'Org') {
$name_terms = OrgTable::nameSearch($name);
$terms = $name_terms;
$primary_ext = "Org";
} else {
$terms = $name_terms;
$primary_ext = null;
}
}
$pager = EntityTable::getSphinxPager($terms, $page = 1, $num = 20, $listIds = null, $aliases = true, $primary_ext);
$match = array('name' => $name);
$match['search_results'] = $pager->execute();
$match['blurb'] = isset($names[$i]['blurb']) ? $names[$i]['blurb'] : null;
$match['rank'] = isset($names[$i]['rank']) ? $names[$i]['rank'] : null;
$match['types'] = array();
if (isset($names[$i]['types'])) {
$types = explode(',', $names[$i]['types']);
$types = array_map('trim', $types);
foreach ($types as $type) {
if (in_array($type, $extensions_arr)) {
$match['types'][] = $type;
}
}
}
$this->matches[] = $match;
}
}
}
}
} else {
if ($request->hasParameter('ref_id')) {
$this->ref_id = $this->getRequestParameter('ref_id');
$entity_ids = array();
$default_type = $this->getRequestParameter('default_type');
for ($i = 0; $i < $this->getRequestParameter('count'); $i++) {
if ($entity_id = $request->getParameter('entity_' . $i)) {
$selected_entity_id = null;
if ($entity_id == 'new') {
$name = $request->getParameter('new_name_' . $i);
if ($default_type == 'Person') {
$new_entity = PersonTable::parseFlatName($name);
} else {
$new_entity = new Entity();
$new_entity->addExtension('Org');
$new_entity->name = trim($name);
}
if ($types = $request->getParameter('new_extensions_' . $i)) {
foreach ($types as $type) {
$new_entity->addExtension($type);
}
}
$new_entity->save();
$new_entity->blurb = $request->getParameter('new_blurb_' . $i);
$ref = Doctrine::getTable('Reference')->find($request->getParameter('ref_id'));
$new_entity->addReference($ref->source, null, null, $ref->name);
$new_entity->save();
$selected_entity_id = $new_entity->id;
} else {
if ($entity_id > 0) {
$selected_entity_id = $entity_id;
}
}
if ($selected_entity_id) {
$q = LsDoctrineQuery::create()->from('LsListEntity le')->where('le.list_id = ? AND le.entity_id = ?', array($this->list['id'], $selected_entity_id));
if (!$q->count()) {
$ls_list_entity = new LsListEntity();
$ls_list_entity->list_id = $this->list->id;
$ls_list_entity->entity_id = $selected_entity_id;
$ls_list_entity->rank = $request->getParameter('entity_' . $i . '_rank');
$ls_list_entity->save();
LsCache::clearEntityCacheById($selected_entity_id);
}
}
}
}
$this->clearCache($this->list);
$this->clearRailsCache($this->list->id);
$this->redirect($this->list->getInternalUrl());
} else {
$request->setError('name', 'The name you entered is invalid');
}
}
}
}
示例10: 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);
//.........这里部分代码省略.........
示例11: 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);
}
}
//.........这里部分代码省略.........
示例12: importCompany
private function importCompany($name, $ticker, $website, $address_raw, $telephone, $revenue, $url, $industry)
{
$corp = new Entity();
$corp->addExtension('Org');
$corp->addExtension('Business');
if ($ticker) {
$corp->addExtension('PublicCompany');
$corp->ticker = $ticker;
} else {
$corp->addExtension('PrivateCompany');
}
$corp->name = $name;
$corp->revenue = LsNumber::formatDollarAmountAsNumber($revenue, 1000000);
$corp->website = $website;
$modified = $corp->getAllModifiedFields();
if ($address = $corp->addAddress($address_raw)) {
$addressModified = $address->getAllModifiedFields();
}
if ($telephone) {
$phone = $corp->addPhone($telephone);
$phoneModified = $phone->getAllModifiedFields();
}
$corp->save();
$corp->addReference($url, null, $modified, 'Fortune Magazine Online');
if ($address) {
$address->addReference($url, null, $addressModified, 'Fortune Magazine Online');
}
if ($phone) {
$phone->addReference($url, null, $phoneModified, 'Fortune Magazine Online');
}
if ($industry) {
}
return $corp;
}
示例13: executeAddBulk
//.........这里部分代码省略.........
}
} else {
if ($page = $this->getRequestParameter('page')) {
$this->page = $page;
$this->num = $this->getRequestParameter('num', 50);
} else {
if ($request->isMethod('post') && $request->getParameter('commit') == 'Submit') {
$this->ref_id = $this->getRequestParameter('ref_id');
$entity_ids = array();
$relationship_category = $this->getRequestParameter('category_name');
$order = $this->getRequestParameter('order');
$default_type = $request->getParameter('default_type');
$default_ref = Doctrine::getTable('Reference')->find($request->getParameter('ref_id'));
for ($i = 0; $i < $this->getRequestParameter('count'); $i++) {
if ($entity_id = $request->getParameter('entity_' . $i)) {
$selected_entity_id = null;
$relParams = $request->getParameter("relationship_" . $i);
if ($relParams['ref_name']) {
$ref['source'] = $relParams['ref_source'];
$ref['name'] = $relParams['ref_name'];
}
if ($entity_id == 'new') {
$name = $request->getParameter('new_name_' . $i);
if ($default_type == 'Person') {
$new_entity = PersonTable::parseFlatName($name);
} else {
$new_entity = new Entity();
$new_entity->addExtension('Org');
$new_entity->name = trim($name);
}
$new_entity->save();
$new_entity->blurb = $request->getParameter('new_blurb_' . $i);
$new_entity->summary = $request->getParameter('new_summary_' . $i);
if (!$ref) {
$ref = $default_ref;
}
$new_entity->addReference($ref['source'], null, null, $ref['name']);
if ($types = $request->getParameter('new_extensions_' . $i)) {
foreach ($types as $type) {
$new_entity->addExtension($type);
}
}
$new_entity->save();
$selected_entity_id = $new_entity->id;
} else {
if ($entity_id > 0) {
$selected_entity_id = $entity_id;
LsCache::clearEntityCacheById($selected_entity_id);
}
}
if ($selected_entity_id) {
$startDate = $relParams['start_date'];
$endDate = $relParams['end_date'];
unset($relParams['start_date'], $relParams['end_date'], $relParams['ref_name'], $relParams['ref_url']);
$rel = new Relationship();
$rel->setCategory($relationship_category);
if ($order == '1') {
$rel->entity1_id = $this->entity['id'];
$rel->entity2_id = $selected_entity_id;
} else {
$rel->entity2_id = $this->entity['id'];
$rel->entity1_id = $selected_entity_id;
}
//only set dates if valid
if ($startDate && preg_match('#^\\d{4}-\\d{2}-\\d{2}$#', Dateable::convertForDb($startDate))) {
$rel->start_date = Dateable::convertForDb($startDate);
}
if ($endDate && preg_match('#^\\d{4}-\\d{2}-\\d{2}$#', Dateable::convertForDb($endDate))) {
$rel->end_date = Dateable::convertForDb($endDate);
}
$rel->fromArray($relParams, null, $hydrateCategory = true);
if ($request->hasParameter('add_method') && $request->getParameter('add_method') == 'db_search') {
$refs = EntityTable::getSummaryReferences($selected_entity_id);
if (count($refs)) {
$ref = $refs[0];
} else {
$refs = EntityTable::getAllReferencesById($selected_entity_id);
if (count($refs)) {
$ref = $refs[0];
}
}
}
if (!$ref) {
$ref = $default_ref;
}
$rel->saveWithRequiredReference(array('source' => $ref['source'], 'name' => $ref['name']));
$ref = null;
}
}
}
$this->clearCache($this->entity);
$this->redirect($this->entity->getInternalUrl());
} else {
if ($request->isMethod('post') && $request->getParameter('commit') == 'Cancel') {
$this->redirect($this->entity->getInternalUrl());
}
}
}
}
}