当前位置: 首页>>代码示例>>PHP>>正文


PHP Relationship::setCategory方法代码示例

本文整理汇总了PHP中Relationship::setCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP Relationship::setCategory方法的具体用法?PHP Relationship::setCategory怎么用?PHP Relationship::setCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Relationship的用法示例。


在下文中一共展示了Relationship::setCategory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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";
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:52,代码来源:CongressIsAFamilyTask.class.php

示例2: execute

 protected function execute($arguments = array(), $options = array())
 {
     //set start time
     $time = microtime(true);
     //connect to raw database
     $this->init($arguments, $options);
     //find political candidates who don't have political party
     $sql = 'SELECT e.id,e.name,pc.crp_id FROM entity e LEFT JOIN political_candidate pc ON pc.entity_id = e.id LEFT JOIN person p on p.entity_id = e.id WHERE p.party_id IS NULL AND pc.crp_id IS NOT NULL AND pc.crp_id <> "" and e.is_deleted = 0 LIMIT ' . $options['limit'];
     $stmt = $this->db->execute($sql);
     $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($rows as $row) {
         echo 'processing ' . $row['name'] . " ::\n";
         $sql = 'SELECT name,party,candidate_id FROM os_candidate WHERE candidate_id = ?';
         $stmt = $this->rawDb->execute($sql, array($row['crp_id']));
         $matches = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $sql = 'select e.id from entity e limit 1';
         $stmt = $this->db->execute($sql);
         $stmt->fetchAll(PDO::FETCH_ASSOC);
         if (count($matches)) {
             $party_id = $this->processParty($matches[0]['party']);
             echo "\t match found: " . $matches[0]['name'] . ', with party ' . $party_id . "/" . $matches[0]['party'] . "\n";
             if ($party_id && !$options['test_mode']) {
                 $db = $this->databaseManager->getDatabase('main');
                 $this->db = Doctrine_Manager::connection($db->getParameter('dsn'), 'main');
                 $person = Doctrine::getTable('Person')->findOneByEntityId($row['id']);
                 if (!$person) {
                     die;
                 }
                 $person->party_id = $party_id;
                 $person->save();
                 echo "\t\t current political party saved as " . $person->party_id . "\n";
                 $q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? and r.entity2_id = ? and r.category_id = ?', array($row['id'], $party_id, 3));
                 if (!$q->fetchOne()) {
                     $r = new Relationship();
                     $r->entity1_id = $row['id'];
                     $r->entity2_id = $party_id;
                     $r->setCategory('Membership');
                     $r->is_current = true;
                     $r->save();
                     echo "\t\t party membership saved\n";
                 }
             }
         } else {
             echo "\t no matches found\n";
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:47,代码来源:CleanupPoliticalPartiesTask.class.php

示例3: execute

 public function execute()
 {
     if (!$this->safeToRun('uk-mp-candidates')) {
         $this->printDebug('Script already running');
         die;
     }
     // Get (or create) the UK local Network
     $uk = Doctrine::getTable('LsList')->findOneByName('United Kingdom');
     if (!$uk) {
         $uk = new LsList();
         $uk->name = 'United Kingdom';
         $uk->is_network = 1;
         $uk->description = 'People and organizations with significant influence on the policies of the United Kingdom';
         $uk->display_name = 'uk';
         $uk->save();
     }
     // Get the MP list
     $raw = $this->getMPs();
     // Add new MPs to the list
     foreach ($raw as $mp) {
         $this->printDebug(sprintf('Processing %s', $mp['name']));
         // Split name
         $entity = PersonTable::parseFlatName($mp['name']);
         $entity->blurb = 'Prospective Parliamentary Candidate for ' . $mp['constituency'];
         $q = TagTable::getByTripleQuery('yournextmp', 'url', $mp['url']);
         $r = $q->count();
         if ($r) {
             $this->printDebug('Already processed, skipping.');
             continue;
         }
         // Get political party
         $q = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('e.name = ?', $mp['party']);
         if (!($partyEntity = $q->fetchOne())) {
             $partyEntity = new Entity();
             $partyEntity->addExtension('Org');
             $partyEntity->addExtension('PoliticalParty');
             $partyEntity->name = $mp['party'];
             $partyEntity->blurb = 'UK Political Party';
             $partyEntity->save(null, true, array($uk->id));
             $this->printDebug("Created new political party: " . $mp['party']);
         }
         // Save entity to UK Network
         $entity->party_id = $partyEntity->id;
         $entity->save(null, true, array($uk->id));
         // Add party relationship
         $r = new Relationship();
         $r->entity1_id = $entity->id;
         $r->entity2_id = $partyEntity->id;
         $r->setCategory('Membership');
         $r->description1 = 'Prospective parliamentary candidate';
         $r->is_current = true;
         // $r->start_date = // Don't know where we can get this, and "now" seems kind of wrong
         $r->save();
         // Add YourNextMP triple
         $entity->addTagByTriple('yournextmp', 'url', $mp['url']);
         // Add references
         $ref = new Reference();
         $ref->addFields(array('name_first', 'name_last', 'name_middle'));
         // Don't need this
         $ref->source = $mp['url'];
         $ref->name = 'YourNextMP.com - ' . $entity['name'];
         $ref->object_model = 'Entity';
         $ref->object_id = $entity->getId();
         $ref->save();
         unset($ref);
         $ref = new Reference();
         $ref->addFields(array('name'));
         $ref->source = $mp['party_url'];
         $ref->name = 'YourNextMP.com - ' . $partyEntity['name'];
         $ref->object_model = 'Entity';
         $ref->object_id = $partyEntity->getId();
         $ref->save();
         unset($ref);
         $ref = new Reference();
         $ref->addFields(array('name'));
         $ref->source = $mp['url'];
         $ref->name = 'YourNextMP.com - ' . $entity['name'];
         $ref->object_model = 'Relationship';
         $ref->object_id = $r->getId();
         $ref->save();
         unset($ref);
         $r->free(true);
         unset($r);
         // Add image?
         if ($mp['image']) {
             if ($fileName = ImageTable::createFiles($mp['image'])) {
                 //insert image record
                 $image = new Image();
                 $image->filename = $fileName;
                 $image->title = $entity['name'];
                 $image->caption = 'From YourNextMP under CC-BY-SA license.';
                 $image->is_featured = true;
                 $image->is_free = true;
                 $image->url = $mp['image'];
                 $this->printDebug("Imported image: " . $image->filename);
             }
             $image->Entity = $entity;
             $image->save();
             if ($mp['image']) {
                 //save image source
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:UKMPCandidateScraper.class.php

示例4: getProfileData

 public function getProfileData($member)
 {
     //generate URL for member's profile
     $url = $this->_profileUrlBase . $member->bioguide_id;
     $this->_references['bioguide']->source = $url;
     $this->_references['bioguide']->name = 'Congressional Biographical Directory';
     if (!$this->browser->get($url)->responseIsError()) {
         $this->printDebug("Fetched member's profile page");
         $this->_bioPageText = $text = LsString::newlinesToSpaces($this->browser->getResponseText());
         //get bio
         if (preg_match('/, <\\/FONT>([^<]+)<\\/(TD|P)>/', $text, $bio)) {
             $bio = preg_replace('/\\n/', ' ', $bio[1]);
             $bio = ucfirst(trim(preg_replace('/\\s{2,}/', ' ', $bio)));
             $bio = LsHtml::replaceEntities($bio);
             $member->summary = $bio;
             $this->printDebug("Bio: " . $bio);
             if (preg_match('/\\b(a(\\s+\\p{L}+){2,8})\\;/isu', $bio, $match)) {
                 $blurb = 'US ' . preg_replace('/a\\s+/isu', '', $match[1]);
                 $member->blurb = $blurb;
                 $this->printDebug("Blurb: " . $blurb);
             }
         }
         //get senate term, if any
         if (preg_match('/Service:<\\/B><\\/FONT>([^<]+)<BR>/', $text, $term)) {
             $terms = preg_split('/,;/', $term[1]);
             foreach ($terms as $term) {
                 if (!($term = trim($term))) {
                     continue;
                 }
                 //create relationship
                 $rel = new Relationship();
                 $rel->Entity1 = $member;
                 $rel->entity2_id = $this->_senateEntityId;
                 $rel->setCategory('Membership');
                 $rel->description1 = 'Senator';
                 //break term into start and end
                 $years = explode('-', $term);
                 $start = trim($years[0]);
                 $rel->start_date = $start . '-00-00';
                 $this->printDebug("Senate term start: " . $start);
                 if (count($years) > 1 && trim($years[1])) {
                     $end = trim($years[1]);
                     $rel->end_date = $end . '-00-00';
                     $this->printDebug("Senate term end: " . $end);
                 }
                 $this->_senateRelationships[] = $rel;
                 $this->printDebug("Created relationship to US Senate");
             }
         }
         //get house terms
         preg_match_all('/\\((\\w+\\s+\\d{1,2},\\s+\\d{4})-(present|(\\w+\\s+\\d{1,2},\\s+\\d{4}))\\)/ismU', $text, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             if ($time = strtotime($match[1])) {
                 //create relationship
                 $rel = new Relationship();
                 $rel->Entity1 = $member;
                 $rel->entity2_id = $this->_houseEntityId;
                 $rel->setCategory('Membership');
                 $rel->start_date = date('Y-m-d', $time);
                 $rel->description1 = 'Representative';
                 $this->printDebug("Created relationship to US House of Reps");
                 $this->printDebug("House term start: " . $rel->start_date);
                 if ($match[2] != 'present' && ($time = strtotime($match[2]))) {
                     $rel->end_date = date('Y-m-d', $time);
                     $this->printDebug("House term end: " . $rel->end_date);
                 }
                 $this->_houseRelationships[] = $rel;
             }
         }
         //get photo url & name
         if (preg_match('/bioguide\\/photo\\/[A-Z]\\/([^"]+)/', $text, $photo)) {
             if ($photoUrl = $photo[0]) {
                 $this->_photoUrl = 'http://bioguide.congress.gov/' . $photoUrl;
                 $photoName = $photo[1];
                 $this->printDebug("Photo URL: " . $this->_photoUrl);
                 //get photo credit
                 if (preg_match('/<I>([^<]+)<\\/photo\\-credit>/', $text, $credit)) {
                     $credit = trim($credit[1]);
                     $this->printDebug("Photo credit: " . $credit);
                 } else {
                     $credit = null;
                 }
                 if ($fileName = ImageTable::createFiles($this->_photoUrl, $photoName)) {
                     //insert image record
                     $image = new Image();
                     $image->filename = $fileName;
                     $image->title = 'Congress Photo';
                     $image->caption = $credit ? $credit : 'From the Biographical Directory of the United States Congress';
                     $image->is_featured = true;
                     $image->is_free = true;
                     $image->url = $this->_photoUrl;
                     //save for later
                     $this->_image = $image;
                     $this->printDebug("Imported image: " . $image->filename);
                 }
             }
         }
     } else {
         //Error response (eg. 404, 500, etc)
         throw new Exception("Couldn't get " . $url);
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:CongressMemberScraper.class.php

示例5: 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;
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:54,代码来源:MassAddScraper.class.php

示例6: getOldRecord

 public function getOldRecord()
 {
     $old = new Relationship();
     if ($name = $this->getCategoryName()) {
         $old->setCategory($name);
     }
     $old->fromArray($this->getOldData(), null, true);
     return $old;
 }
开发者ID:silky,项目名称:littlesis,代码行数:9,代码来源:Relationship.class.php

示例7: 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;
         }
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:FedSpendingScraper.class.php

示例8: import


//.........这里部分代码省略.........
             $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!
             if (!$person->getRelationshipsWithQuery($current_school, RelationshipTable::EDUCATION_CATEGORY)->fetchOne()) {
                 $this->printDebug("  Creating Relation between " . $current_school->name . " and " . $person->name);
                 $education = new Relationship();
                 $education->Entity1 = $person;
                 $education->Entity2 = $current_school;
                 $education->setCategory('Education');
                 $education->description1 = $school['degree'];
                 $education->is_current = 1;
                 $education->save();
                 $education->addReference($source = $url, $excerpt = null, $fields = array('description1'), $name = 'Forbes.com', $detail = null, $date = null);
             }
         }
         $person->save();
         $person->addReference($source = $url, $excerpt = null, $fields = array('name_prefix', 'name_first', 'name_middle', 'name_last', 'name_suffix', 'name_nick', 'summary', 'net_worth', 'start_date'), $name = 'Forbes.com', $detail = null, $date = null);
         $this->saveToList($person, $rank);
         $this->attachImage($person, $imageUrl);
     } else {
         echo "Couldn't get person: " . $url . "\n";
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:Forbes400Scraper.class.php

示例9: processRow


//.........这里部分代码省略.........
     }
     $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
     if ($entity2) {
         if ($this->entity) {
             $relationship = new Relationship();
             if (isset($row['relationship_order']) && $row['relationship_order'] != '') {
                 if ($row['relationship_order'] == '1') {
                     $relationship->Entity1 = $this->entity;
                     $relationship->Entity2 = $entity2;
                 } else {
                     $relationship->Entity2 = $this->entity;
                     $relationship->Entity1 = $entity2;
                 }
             } else {
                 if ($relationship_category == 'Position' || $relationship_category == 'Education') {
                     if ($row['primary_type'] == 'Org') {
                         $relationship->Entity1 = $this->entity;
                         $relationship->Entity2 = $entity2;
                     } else {
                         $relationship->Entity1 = $entity2;
                         $relationship->Entity2 = $this->entity;
                     }
                 } else {
                     $relationship->Entity1 = $this->entity;
                     $relationship->Entity2 = $entity2;
                 }
             }
             $relationship->setCategory($relationship_category);
             $cols = array('description1', 'description2', 'start_date', 'end_date', 'goods', 'amount', 'is_board', 'is_executive', 'is_employee');
             foreach ($cols as $col) {
                 if (isset($row[$col]) && $row[$col] != '') {
                     try {
                         $relationship[$col] = $row[$col];
                     } catch (Exception $e) {
                         $this->printDebug("   could not set {$col} for relationship, skipping");
                     }
                 }
             }
             $q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? and r.entity2_id = ? and r.category_id = ? and r.id <> ?', array($relationship->entity1_id, $relationship->entity2_id, $relationship->category_id, $relationship->id))->fetchOne();
             if ($q) {
                 $this->printDebug('   (relationship already found, skipping...)');
                 return;
             }
             $relationship->save();
             $relationship->addReference($url, null, null, $url_name);
             $this->printDebug(" Relationship saved: {$relationship}\n");
         } else {
             if ($this->list) {
                 $q = LsDoctrineQuery::create()->from('LsListEntity le')->where('le.entity_id = ? and le.list_id = ?', array($entity2->id, $this->list->id))->fetchOne();
                 if ($q) {
                     $this->printDebug('   (already on list, skipping...)');
                     return;
                 }
                 $le = new LsListEntity();
                 $le->LsList = $this->list;
                 $le->Entity = $entity2;
                 var_dump($row);
                 if (isset($row['rank'])) {
                     echo $row['rank'];
                     $le->rank = $row['rank'];
                 }
                 $le->save();
             }
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:spreadsheetTask.class.php

示例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);
         }
         */
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:78,代码来源:PublicCompanyScraper.class.php

示例11: 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');
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:25,代码来源:PublicCompanyRosterScraper.class.php

示例12: createCampaignCommittee

 protected function createCampaignCommittee($entityId, $recipientId)
 {
     $sql = 'SELECT cycle, name, committee_id FROM os_committee WHERE recipient_id = ? AND committee_id <> recipient_id AND name IS NOT NULL';
     $stmt = $this->rawDb->execute($sql, array($recipientId));
     /*
     if (!count($committees = $stmt->fetchAll(PDO::FETCH_ASSOC)))
     {
       $sql = 'SELECT fec_id FROM os_candidate WHERE candidate_id = ?';
       $stmt = $this->rawDb->execute($sql, array($recipientId));
       
       if (count($fecIds = $stmt->fetchAll(PDO::FETCH_COLUMN)))
       {
         $sql = 'SELECT name, committee_id FROM os_committee WHERE candidate_id IN (\'' . implode('\',\'', $fecIds) . '\')';
         $stmt = $this->rawDb->execute($sql);
         $committees = $stmt->fetchAll(PDO::FETCH_ASSOC);
       }
     }
     */
     $committees = array();
     //group committees by committee_id, and get most recent name
     foreach ($stmt->fetchAll(PDO::FETCH_NUM) as $row) {
         list($cycle, $name, $committeeId) = $row;
         if (isset($committees[$committeeId])) {
             if ($cycle > $committees[$committeeId]['cycle']) {
                 $committees[$committeeId]['cycle'] = $cycle;
                 $committees[$committeeId]['name'] = $name;
             }
             $committees[$committeeId]['aliases'][] = $name;
         } else {
             $committees[$committeeId] = array('cycle' => $cycle, 'name' => $name, 'aliases' => array());
         }
     }
     foreach ($committees as $committeeId => $ary) {
         $name = $ary['name'];
         $aliases = array_unique($ary['aliases']);
         $sql = 'SELECT e.* FROM entity e LEFT JOIN political_fundraising p ON (p.entity_id = e.id) ' . 'WHERE p.fec_id = ? AND e.is_deleted = 0';
         $stmt = $this->db->execute($sql, array($committeeId));
         if ($entity = $stmt->fetch(PDO::FETCH_ASSOC)) {
             //check for an existing relationship
             $sql = 'SELECT COUNT(*) FROM relationship r ' . 'WHERE r.entity1_id = ? AND r.entity2_id = ? AND r.category_id = ? AND r.is_deleted = 0';
             $stmt = $this->db->execute($sql, array($entityId, $entity['id'], RelationshipTable::POSITION_CATEGORY));
             $createRel = $stmt->fetch(PDO::FETCH_COLUMN) ? false : true;
         } else {
             Doctrine_Manager::getInstance()->setCurrentConnection('main');
             //create new entity and relationship
             $entity = new Entity();
             $entity->addExtension('Org');
             $entity->addExtension('PoliticalFundraising');
             $entity->name = $name;
             $entity->fec_id = $committeeId;
             $entity->save();
             if ($this->debugMode) {
                 print "+ Created new entity for " . $name . " (" . $committeeId . ")\n";
             }
             $createRel = true;
         }
         if ($createRel) {
             Doctrine_Manager::getInstance()->setCurrentConnection('main');
             //create relationship
             $rel = new Relationship();
             $rel->setCategory('Position');
             $rel->entity1_id = $entityId;
             $rel->entity2_id = $entity['id'];
             $rel->description1 = 'Candidate';
             $rel->description2 = 'Political Fundraising Committee';
             $rel->is_executive = true;
             $rel->save();
             //create reference for the relationship
             $refName = 'FEC.gov - ' . $name;
             $refSource = $this->fecCommitteeBaseUrl . $committeeId;
             $sql = 'INSERT INTO reference (object_model, object_id, name, source) VALUES (?, ?, ?, ?)';
             $params = array('Relationship', $rel->id, $refName, $refSource);
             $stmt = $this->db->execute($sql, $params);
             if (!$stmt->rowCount()) {
                 throw new Exception("Couldn't insert Reference (" . implode(', ', $params) . ")");
             }
             if ($this->debugMode) {
                 print "+ Created position relationship between candidate (entity " . $entityId . ") and committee (entity " . $entity['id'] . ")\n";
             }
         }
         //create aliases if necessary
         $this->addAliasesToEntityById($entity['id'], $aliases);
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:84,代码来源:OsProcessMatchesTask.class.php

示例13: executeToolbar

 public function executeToolbar($request)
 {
     $this->checkToolbarCredentials(true);
     if ($request->isMethod('post')) {
         //if user wants to skip this relationship
         if ($request->getParameter('commit') == 'Skip') {
             $names = $this->getUser()->getAttribute('toolbar_names');
             array_shift($names);
             if (count($names)) {
                 $this->getUser()->setAttribute('toolbar_names', $names);
                 $this->redirect('relationship/toolbar');
             } else {
                 $entityId = $this->getUser()->getAttribute('toolbar_entity');
                 $entity = Doctrine::getTable('Entity')->find($entityId);
                 $this->getUser()->setAttribute('toolbar_names', null);
                 $this->getUser()->setAttribute('toolbar_ref', null);
                 $this->getUser()->setAttribute('toolbar_entity', null);
                 $this->getUser()->setAttribute('toolbar_defaults', null);
                 $this->redirect($entity->getInternalUrl());
             }
         }
         //if user wants to clear bulk queue
         if ($request->getParameter('commit') == 'Clear') {
             $entityId = $this->getUser()->getAttribute('toolbar_entity');
             $entity = Doctrine::getTable('Entity')->find($entityId);
             $this->getUser()->setAttribute('toolbar_names', null);
             $this->getUser()->setAttribute('toolbar_ref', null);
             $this->getUser()->setAttribute('toolbar_entity', null);
             $this->getUser()->setAttribute('toolbar_defaults', null);
             $this->redirect($entity->getInternalUrl());
         }
         $entity1Id = $request->getParameter('entity1_id');
         $entity2Id = $request->getParameter('entity2_id');
         $categoryName = $request->getParameter('category_name');
         $refSource = $request->getParameter('reference_source');
         $refName = $request->getParameter('reference_name');
         $categoryParams = $request->getParameter('relationship');
         $startDate = $categoryParams['start_date'];
         $endDate = $categoryParams['end_date'];
         unset($categoryParams['start_date'], $categoryParams['end_date']);
         if (!$entity1Id || !$entity2Id || !$categoryName || !$refSource || !$refName) {
             $this->forward('error', 'invalid');
         }
         if (!($entity1 = EntityApi::get($entity1Id))) {
             $this->forward('error', 'invalid');
         }
         if (!($entity2 = EntityApi::get($entity2Id))) {
             $this->forward('error', 'invalid');
         }
         $db = Doctrine_Manager::connection();
         $sql = 'SELECT name FROM relationship_category ' . 'WHERE (entity1_requirements IS NULL OR entity1_requirements = ?) ' . 'AND (entity2_requirements IS NULL OR entity2_requirements = ?)';
         $stmt = $db->execute($sql, array($entity1['primary_ext'], $entity2['primary_ext']));
         $validCategoryNames = $stmt->fetchAll(PDO::FETCH_COLUMN);
         if (!in_array($categoryName, $validCategoryNames)) {
             $request->setError('category', 'Invalid relationship; try changing the category or switching the entity order');
             //check session for bulk names
             if ($bulkEntityId = $this->getUser()->getAttribute('toolbar_entity')) {
                 if ($this->entity1 = Doctrine::getTable('Entity')->find($bulkEntityId)) {
                     if ($names = $this->getUser()->getAttribute('toolbar_names')) {
                         $this->entity2_name = array_shift($names);
                         if ($refId = $this->getUser()->getAttribute('toolbar_ref')) {
                             $this->ref = Doctrine::getTable('Reference')->find($refId);
                             $request->getParameterHolder()->set('title', $this->ref->name);
                             $request->getParameterHolder()->set('url', $this->ref->source);
                         }
                         if ($defaults = $this->getUser()->getAttribute('toolbar_defaults')) {
                             if (isset($defaults['category'])) {
                                 $this->category = $defaults['category'];
                             }
                         }
                     }
                 }
             }
             if ($createdId = $request->getParameter('created_id')) {
                 $this->created_rel = Doctrine::getTable('Relationship')->find($createdId);
             }
             return sfView::SUCCESS;
         }
         if (!preg_match('/^http(s?)\\:\\/\\/.{3,193}/i', $refSource)) {
             $this->forward('error', 'invalid');
         }
         //all's well, create relationship!
         $rel = new Relationship();
         $rel->setCategory($categoryName);
         $rel->entity1_id = $entity1['id'];
         $rel->entity2_id = $entity2['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($categoryParams, null, $hydrateCategory = true);
         $rel->save();
         //create reference
         $ref = new Reference();
         $ref->name = $refName;
         $ref->source = $refSource;
         $ref->object_id = $rel->id;
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:actions.class.php

示例14: 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;
 }
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:EducationScraper.class.php

示例15: parseResults


//.........这里部分代码省略.........
                         if (!$related_org && !$exists) {
                             $accept = $this->readline(" couldn't find org, should this one be created: {$name} (y or n) ");
                             while ($accept != 'y' && $accept != 'n' && $attempts < 5) {
                                 $accept = $this->readline(" couldn't find org, should this one be created: {$name} (y or n) ");
                                 $attempts++;
                             }
                             if ($accept == 'y') {
                                 $related_org = new Entity();
                                 $related_org->addExtension('Org');
                                 $related_org->name = preg_replace('/\\.(?!com)/i', '', $name);
                                 $extensions = $this->readline("  what extensions should this org get? (eg 'Business, LobbyingFirm, LawFirm') ");
                                 $extensions = preg_split('/\\,\\s*/isu', $extensions, -1, PREG_SPLIT_NO_EMPTY);
                                 try {
                                     foreach ($extensions as $extension) {
                                         $related_org->addExtension($extension);
                                     }
                                     $related_org->save();
                                     $related_org->addReference($this->url, null, null, $this->url_name);
                                 } catch (Exception $e) {
                                     $this->printDebug('   !!! problems with org creation, skipping');
                                     $related_org = null;
                                 }
                             }
                         }
                         if ($related_org) {
                             $q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? and r.entity2_id = ? and r.category_id = ?', array($entity->id, $related_org->id, 1))->fetchOne();
                             if ($q) {
                                 $this->printDebug('   (relationship already found, skipping...)');
                                 continue;
                             }
                             $relationship = new Relationship();
                             $relationship->Entity1 = $entity;
                             $relationship->Entity2 = $related_org;
                             $relationship->setCategory('Position');
                             $title = $this->readline("     Title for this position relationship? (<enter> to skip) ");
                             if (strlen($title) > 2) {
                                 $relationship->description1 = $title;
                             }
                             $current = strtolower($this->readline("      Is the relationship current? (y or n or <enter> to skip) "));
                             if (in_array($current, array('y', 'yes'))) {
                                 $relationship->is_current = 1;
                             } else {
                                 if (in_array($current, array('n', 'no'))) {
                                     $relationship->is_current = 0;
                                 }
                             }
                             $board = strtolower($this->readline("      Is the relationship a board position? (y or n or <enter> to skip) "));
                             if (in_array($board, array('y', 'yes'))) {
                                 $relationship->is_board = 1;
                             } else {
                                 if (in_array($board, array('n', 'no'))) {
                                     $relationship->is_board = 0;
                                 }
                             }
                             $relationship->save();
                             $relationship->addReference($this->url, null, null, $this->url_name);
                             $this->printDebug("     Relationship saved: {$relationship}");
                         }
                     }
                 }
             }
         }
     }
     if ($matched || $created) {
         if ($this->list) {
             $q = LsDoctrineQuery::create()->from('LsListEntity l')->where('l.entity_id = ? and l.list_id = ?', array($entity->id, $this->list->id))->fetchOne();
开发者ID:silky,项目名称:littlesis,代码行数:67,代码来源:ListScraper.class.php


注:本文中的Relationship::setCategory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。