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


PHP Relationship::save方法代码示例

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


在下文中一共展示了Relationship::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addFriend

/**
 * @param array
 * @return array|false
 */
function addFriend($props)
{
    $r = new Relationship($props);
    // $props = ['u_id1' => %num%, 'u_id2' => %num%, 'r_status' => %string%]
    $r->save();
    return $r->getProps(TRUE);
}
开发者ID:juggernautt,项目名称:dead-poets-society,代码行数:11,代码来源:businessLogic.php

示例2: addLobbyFilingToRelationship

 static function addLobbyFilingToRelationship(Relationship $relationship, LobbyFiling $filing)
 {
     $generatedAmount = self::getFecFilingAmountSumByRelationshipId($relationship->id) + $filing->amount;
     $relationship->amount = max($generatedAmount, $relationship->amount);
     $relationship->updateDateRange($filing->start_date);
     $relationship->filings = $this->getLobbyFilingsByRelationshipId($relationship->id)->count() + 1;
     $relationship->save();
     $filing->relationship_id = $relationship->id;
     $filing->save();
 }
开发者ID:silky,项目名称:littlesis,代码行数:10,代码来源:Lobbying.class.php

示例3: 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

示例4: addReference

 public function addReference(myModel $object)
 {
     if ($this->getRelationByObject($object)) {
         return $this;
     }
     $relation = new Relationship();
     $relation->save(['start_id' => $object->id, 'start_type' => get_class($object), 'end_id' => $this->id, 'end_type' => get_class($this), 'type' => get_class($this)]);
     if (property_exists($this, 'relationCount')) {
         $object->save(['relationCount' => $object->relationCount + 1]);
         $this->save(['relationCount' => $this->relationCount + 1]);
     }
     return $this;
 }
开发者ID:huoybb,项目名称:standard,代码行数:13,代码来源:RelationshipTrait.php

示例5: 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

示例6: approveRelationship

 private function approveRelationship($r)
 {
     if ($this->registry->getObject('authenticate')->isLoggedIn()) {
         require_once FRAMEWORK_PATH . 'models/relationship.php';
         $relationship = new Relationship($this->registry, $r, 0, 0, 0, 0);
         if ($relationship->getUserB() == $this->registry->getObject('authenticate')->getUser()->getUserID()) {
             // we can approve this!
             $relationship->approveRelationship();
             $relationship->save();
             $this->registry->errorPage('Relationship approved', 'Thank you for approving the relationship');
         } else {
             $this->registry->errorPage('Invalid request', 'You are not authorized to approve that request');
         }
     } else {
         $this->registry->errorPage('Please login', 'Please login to approve this connection');
     }
 }
开发者ID:simontakite,项目名称:cookbooks,代码行数:17,代码来源:controller.php

示例7: blockUser

 public function blockUser($user_block, $user_blocked)
 {
     $model = Relationship::model()->findByAttributes(array('user_id_1' => $user_block, 'user_id_2' => $user_blocked));
     if ($model) {
         return 1;
     } else {
         $rel = new Relationship();
         $rel->user_id_1 = $user_block;
         $rel->user_id_2 = $user_blocked;
         $rel->status = 1;
         $rel->created_at = time();
         $rel->updated_at = time();
         $rel->type = Yii::app()->params['USER_BLOCK'];
         if ($rel->save(FALSE)) {
             return 2;
         } else {
             return 0;
         }
     }
 }
开发者ID:huynt57,项目名称:image_chooser,代码行数:20,代码来源:User.php

示例8: scopeBlockRelationship

 public function scopeBlockRelationship($quest, $sender, $target)
 {
     //check if relationship already exists
     $results = DB::table('relationship')->select('*')->where('relationship_sender', '=', $target)->where('relationship_target', '=', $sender)->first();
     // if it's pending from someone requesting, then change to active
     if ($results) {
         Relationship::where('relationship_id', '=', $results->relationship_id)->update(array('relationship_status' => 'block'));
     }
     $relationship = new Relationship();
     $relationship->relationship_target = $target;
     $relationship->relationship_sender = $sender;
     $relationship->relationship_status = 'block';
     $relationship->save();
 }
开发者ID:jacobross85,项目名称:community,代码行数:14,代码来源:Relationship.php

示例9: 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

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

示例11: processCongressMemberRow

 public function processCongressMemberRow($row)
 {
     $this->_references['bioguide'] = new Reference();
     $this->printDebug("\nProcessing member with name " . $row->name . " and ID " . $row->id);
     try {
         //we have to begin the transaction here because matchInDatabase might merge Entities and save
         $this->db->beginTransaction();
         //check that congress member isn't a repeat
         $member = EntityTable::getByExtensionQuery('ElectedRepresentative')->addWhere('electedrepresentative.bioguide_id = ?', $row->id)->fetchOne();
         //if member hasn't been imported already as a member of congress,
         //create with all bio info and look for a match
         if (!$member) {
             $member = $this->importNewMember($row);
             $member = $this->matchInDatabase($member);
             /*
                     if(!$merged_member = $this->matchInDatabase($member))
                     {
                       $redundant_member = false;
                     }
                     else
                     {
                       $redundant_member = $member;
                       $member = $merged_member;
                     }  */
         } else {
             $this->printDebug("Member exists in database with entity ID: " . $member->id);
             //if member is tagged with this session, skip
             if (in_array($member->id, $this->_existingSessionMemberIds)) {
                 $this->db->rollback();
                 $this->printDebug("Member has already been tagged with session " . current($this->_sessions) . "; skipping");
                 return $member;
             }
             //update member's bio
             $this->updateBio($member);
             $this->printDebug("Updated member bio");
             //check if member is continuing from previous session
             $q = $member->getTripleTagsQuery('congress', 'session')->addWhere('tag.triple_value = ?', current($this->_sessions) - 1);
             if ($q->count()) {
                 $this->printDebug("Continuing member from previous session...");
                 //if member continuing, look for relationship with opposite chamber to end,
                 //in case the member's switched chambers
                 $oppositeChamberId = $row->type == 'Senator' ? $this->_houseEntityId : $this->_senateEntityId;
                 $q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? AND r.entity2_id = ?', array($member->id, $oppositeChamberId))->andWhere('r.category_id = ? AND r.end_date IS NULL', RelationshipTable::MEMBERSHIP_CATEGORY);
                 foreach ($q->execute() as $rel) {
                     $rel->end_date = $this->_sessionStartYear - 1 . '-00-00';
                     $rel->is_current = false;
                     $rel->save();
                     $this->printDebug("Ended relationship " . $rel->id . " with opposite chamber from previous session");
                 }
                 //if no current relationships with same chamber, create one
                 $thisChamberId = $row->type == 'Senator' ? $this->_senateEntityId : $this->_houseEntityId;
                 $q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? AND r.entity2_id = ?', array($member->id, $thisChamberId))->andWhere('r.category_id = ? AND r.end_date IS NULL', RelationshipTable::MEMBERSHIP_CATEGORY);
                 if (!$q->count()) {
                     $this->printDebug("No relationships with this chamber from previous session; creating new one...");
                     $r = new Relationship();
                     $r->entity1_id = $member->id;
                     $r->entity2_id = $row->type == 'Senator' ? $this->_senateEntityId : $this->_houseEntityId;
                     $r->setCategory('Membership');
                     $r->description1 = $row->type;
                     $r->start_date = $row->termStart . '-00-00';
                     $r->is_current = true;
                     if ($row->type = 'Senator') {
                         $this->_senateRelationships[] = $r;
                     } else {
                         $this->_houseRelationships[] = $r;
                     }
                 }
             } else {
                 $this->printDebug("Member not continuing from previous session; creating new relationship...");
                 //if member not continuing, add a new relationship for this session and chamber
                 $r = new Relationship();
                 $r->entity1_id = $member->id;
                 $r->entity2_id = $row->type == 'Senator' ? $this->_senateEntityId : $this->_houseEntityId;
                 $r->setCategory('Membership');
                 $r->description1 = $row->type;
                 $r->start_date = $row->termStart . '-00-00';
                 $r->is_current = true;
                 if ($row->type = 'Senator') {
                     $this->_senateRelationships[] = $r;
                 } else {
                     $this->_houseRelationships[] = $r;
                 }
             }
         }
         //set party name
         $partyName = null;
         $blurb = '';
         if ($party = $row->party) {
             if ($party == 'Democrat') {
                 $blurb .= $party . 'ic';
                 $partyName = 'Democratic Party';
             } elseif ($party == 'Independent') {
                 $blurb .= $party;
                 $partyName = null;
             } else {
                 $blurb .= $party;
                 $partyName = $party . ' Party';
             }
             //if party entity doesn't exist, create one
             if ($partyName) {
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:CongressMemberScraper.class.php

示例12: 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

示例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: 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

示例15: processRow

 public function processRow($row)
 {
     if (isset($row['url']) && $row['url'] != '' && isset($row['url_name']) && $row['url_name'] != '') {
         $url = $row['url'];
         $url_name = $row['url_name'];
     } else {
         $url = $this->url;
         $url_name = $this->url_name;
     }
     foreach ($row as &$r) {
         trim($r);
     }
     unset($r);
     if ($this->entity) {
         $required = array('entity_name', 'primary_type', 'relationship_category');
     } else {
         $required = array('entity_name', 'primary_type');
     }
     foreach ($required as $req) {
         if (!isset($row[$req]) || $row[$req] == '') {
             $this->printDebug('!!! > skipping row, ' . $req . ' not set');
             return;
         }
     }
     if ($row['primary_type'] != 'Person' && $row['primary_type'] != 'Org') {
         $this->printDebug('!!! > primary type not properly set, skipping row...');
         return;
     }
     if ($this->entity) {
         $relationship_category = trim($row['relationship_category']);
         $relationship_category_id = array_search($relationship_category, RelationshipCategoryTable::$categoryNames);
         if (!$relationship_category_id) {
             $this->printDebug('!!! > relationship type not properly set, skipping row...');
             return;
         }
     }
     $this->printDebug("processing: " . $row['entity_name'] . '......');
     if ($row['primary_type'] == 'Person') {
         $entity2 = PersonTable::parseFlatName($row['entity_name']);
         $similar_entities = PersonTable::getSimilarQuery2($entity2)->execute();
     } else {
         $entity2 = new Entity();
         $entity2->addExtension('Org');
         $entity2->setEntityField('name', $row['entity_name']);
         $similar_entities = OrgTable::getOrgsWithSimilarNames($entity2->name);
     }
     $matched = false;
     foreach ($similar_entities as $similar_entity) {
         if ($similar_entity['primary_ext'] == 'Person') {
             $this->printDebug('  POSSIBLE MATCH: ' . $similar_entity->name . ' (Orgs :: ' . $similar_entity->getRelatedOrgsSummary() . "  Bio :: {$similar_entity->summary})");
         } else {
             $this->printDebug('  POSSIBLE MATCH: ' . $similar_entity->name . ' (Summary :: ' . $similar_entity->summary . ')');
         }
         $accept = $this->readline('  Is this the same entity? (y or n or b to break)');
         if ($accept == 'y') {
             $entity2 = $similar_entity;
             $matched = true;
             $this->printDebug('             [accepted]');
             break;
         } else {
             if ($accept == 'b') {
                 break;
             }
         }
     }
     $created = false;
     if (!$matched) {
         if ($entity2->getPrimaryExtension() == 'Person') {
             $this->printDebug('  New person: ' . $entity2->name_first . ' ' . $entity2->name_last);
         } else {
             $this->printDebug('  New org: ' . $entity2->name);
         }
         $accept = $this->readline('    create this new entity? (y or n) ');
         if ($accept == 'y') {
             try {
                 $extensions = LsString::split($row['entity_extensions'], '\\s*\\,\\s*');
                 foreach ($extensions as $extension) {
                     $entity2->addExtension($extension);
                 }
                 $entity2->save();
                 $entity2->addReference($url, null, null, $url_name);
             } catch (Exception $e) {
                 $this->printDebug('   !!! problems with extensions for this row');
             }
             $fields = array('summary', 'blurb', 'website');
             foreach ($fields as $field) {
                 if (isset($row[$field])) {
                     $entity2[$field] = $row[$field];
                 }
             }
             $entity2->save();
             $entity2->addReference($url, null, null, $url_name);
             $created = true;
             $this->printDebug(' ' . $entity2->name . ' saved');
             //sleep(1);
         } else {
             $entity2 = null;
         }
     }
     // create relationship
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:spreadsheetTask.class.php


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