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


PHP Reference::addFields方法代码示例

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


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

示例1: getGovtrackData

 public function getGovtrackData($member)
 {
     $modified = array();
     if (!$member->bioguide_id) {
         return null;
     }
     $gp = Doctrine::getTable('GovtrackPerson')->findOneByBioguideId($member->bioguide_id);
     if (!$gp) {
         return null;
     }
     //get birthday from govtrack
     if ($startDate = $gp->start_date) {
         $member->start_date = $startDate;
         $modified[] = 'start_date';
     }
     //get gender from govtrack
     switch ($gp->gender) {
         case 'F':
             $member->gender_id = GenderTable::FEMALE;
             $modified[] = 'gender_id';
             break;
         case 'M':
             $member->gender_id = GenderTable::MALE;
             $modified[] = 'gender_id';
             break;
     }
     //get website from govtrack
     if ($url = $gp->url) {
         $member->website = $url;
         $modified[] = 'website';
     }
     //get govtrack_id from govtrack
     $member->govtrack_id = $gp->govtrack_id;
     $modified[] = 'govtrack_id';
     $this->printDebug("Set govtrack_id: " . $member->govtrack_id);
     //get opensecrets_id from govtrack
     if ($os_id = $gp->os_id) {
         $member->crp_id = $os_id;
         $modified[] = 'crp_id';
         $this->printDebug("Set crp_id: " . $member->crp_id);
     }
     //get state and district
     if ($gp->State->name) {
         $state = $gp->State;
         if ($lsState = Doctrine::getTable('AddressState')->findOneByName($state->name)) {
             $this->printDebug('Added representative state: ' . $state->name);
             if ($federalDistrict = $gp->district) {
                 $district = LsQuery::getByModelAndFieldsQuery('PoliticalDistrict', array('state_id' => $lsState->id, 'federal_district' => $federalDistrict))->fetchOne();
                 if (!$district) {
                     $district = new PoliticalDistrict();
                     $district->State = $lsState;
                     $district->federal_district = $federalDistrict;
                     $district->save();
                 }
                 $member->ElectedDistrict[] = $district;
                 $this->printDebug('Added representative district: ' . $federalDistrict);
             }
         }
     }
     //create govtrack reference
     $ref = new Reference();
     $ref->source = $this->_govtrackUrlBase . $member->govtrack_id;
     $ref->name = 'GovTrack.us';
     $ref->addFields($modified);
     $this->_references['govtrack'] = $ref;
 }
开发者ID:silky,项目名称:littlesis,代码行数:66,代码来源:CongressMemberScraper.class.php

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

示例3: addReference

 public function addReference($source, $excerpt = null, $fields = null, $name = null, $detail = null, $date = null, $check_existing = true)
 {
     $object = $this->getInvoker();
     if (!$object->exists()) {
         throw new Exception("Can't add Reference to new object");
     }
     //make sure provided fields all exist
     if ($fields) {
         $entityFields = array_diff($object->getAllFields(), array('id'));
         if ($diff = array_diff((array) $fields, $entityFields)) {
             throw new Exception('Unknown fields: ' . implode(', ', $diff));
         }
     }
     //look for existing ref
     $ref = null;
     if ($check_existing == true) {
         $ref = $this->getReference($source, $detail);
     }
     if (!$ref) {
         $ref = new Reference();
         $ref->object_model = get_class($object);
         $ref->object_id = $object->id;
         $ref->source = $source;
         $ref->source_detail = $detail;
         $ref->publication_date = $date;
     }
     if (!$ref->name) {
         $ref->name = $name;
     }
     //add fields
     $ref->addFields($fields);
     //save ref and excerpt, if provided
     $db = Doctrine_Manager::connection();
     try {
         $db->beginTransaction();
         if ($excerpt) {
             $ref->addExcerpt($excerpt);
         }
         $ref->save();
         $db->commit();
     } catch (Exception $e) {
         $db->rollback();
         throw $e;
     }
     return $ref;
 }
开发者ID:silky,项目名称:littlesis,代码行数:46,代码来源:Referenceable.class.php


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