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


PHP Reference::save方法代码示例

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


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

示例1: addReference

 /**
  * adds a reference track from an object to another if that reference does not already exist
  * expects objects or arrays in the form array(id, 'ModelName')
  */
 public static function addReference($mFromObject, $mToObject)
 {
     if ($mFromObject instanceof BaseObject && $mFromObject->isNew()) {
         self::$aUnsavedReferences[] = array($mFromObject, $mToObject);
         return;
     }
     self::prepareObjectArgument($mFromObject);
     self::prepareObjectArgument($mToObject);
     if (self::referenceExists($mFromObject, $mToObject)) {
         return;
     }
     $oReference = new Reference();
     $oReference->setFromId($mFromObject[0]);
     $oReference->setFromModelName($mFromObject[1]);
     $oReference->setToId($mToObject[0]);
     $oReference->setToModelName($mToObject[1]);
     try {
         $oReference->save();
     } catch (PropelException $ex) {
         if ($ex->getCause() instanceof NotPermittedException) {
             //Silently discard NotPermittedException because the FromObject won’t be saved either
         } else {
             throw $ex;
         }
     }
 }
开发者ID:rapila,项目名称:cms-base,代码行数:30,代码来源:ReferencePeer.php

示例2: setList

 private function setList()
 {
     $name = 'Fortune 1000 (' . $this->year . ')';
     $list = Doctrine_Query::create()->from('LsList L')->where('L.name = ?', $name)->fetchOne();
     //if thlis year's fortune list doesn't already exist, create it
     if (!$list) {
         try {
             $this->db->beginTransaction();
             $list = new LsList();
             $list->name = $name;
             $list->description = "Fortune Magazine's list of the 1000 US companies with the largest published revenue figures.";
             $list->is_ranked = 1;
             $list->save();
             $this->list = $list;
             $ref = new Reference();
             $ref->object_model = 'LsList';
             $ref->object_id = $list->id;
             $ref->fields = 'name, description, is_ranked';
             $ref->source = 'http://money.cnn.com/magazines/fortune/fortune500/' . $this->year . '/full_list/';
             $ref->name = 'Fortune Magazine Online';
             $ref->save();
             if (!$this->testMode) {
                 $this->db->commit();
             }
         } catch (Exception $e) {
             $this->db->rollback();
             throw $e;
         }
     } else {
         $this->list = $list;
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:32,代码来源:Fortune1000Scraper.class.php

示例3: actionAdd

 public function actionAdd()
 {
     $model = new Reference();
     if (!isset(Yii::app()->user->storeID)) {
         $this->redirect(array('site/index'));
     }
     $this->pageTitle = 'Add Configs';
     $model->s_store_id = Yii::app()->user->storeID;
     if (isset($_POST['Reference'])) {
         $flagSave = false;
         $model->attributes = $_POST['Reference'];
         $model->i_flag_sync = 1;
         $model->i_flag_deleted = 0;
         $model->i_disable = 0;
         if (count($model->errors) == 0) {
             if ($model->save()) {
                 $this->redirect(array('index'));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:hson91,项目名称:posnail,代码行数:22,代码来源:ConfigsController.php

示例4: foreach

 function other_info($employee_id = '')
 {
     $data['page_name'] = '<b>Personal Data Sheet</b>';
     $data['section_name'] = '<b>Personal Information</b>';
     $data['focus_field'] = 'skill';
     $data['msg'] = '';
     $e = new Employee_m();
     $data['employee'] = $e->get_by_id($employee_id);
     if (Input::get('op')) {
         // OTHER INFORMATION=========================
         $skills = Input::get('skill');
         $recognition = Input::get('recognition');
         $membership_organization = Input::get('membership_organization');
         $o = new Other_info();
         $o->get_by_employee_id($employee_id);
         $o->delete_all();
         $i = 0;
         foreach ($skills as $skill) {
             $o = new Other_info();
             $o->employee_id = $employee_id;
             $o->special_skills = $skills[$i];
             $o->recognition = $recognition[$i];
             $o->membership_organization = $membership_organization[$i];
             $o->save();
             $i++;
         }
         // QUESTIONS=======================================
         $questions = Input::get('q');
         $answer = Input::get('q');
         $details = Input::get('details');
         $q = new Question();
         $q->get_by_employee_id($employee_id);
         // Delete Questions
         $q->delete_all();
         $i = 0;
         $count = 0;
         foreach ($questions as $question) {
             $count += 1;
             $q = new Question();
             $q->employee_id = $employee_id;
             $q->question_no = $count;
             $q->answer = $answer[$i];
             $q->details = $details[$i];
             $q->save();
             $i++;
         }
         // REFERENCE
         $names = Input::get('ref_name');
         $address = Input::get('ref_address');
         $no = Input::get('ref_tel');
         $r = new Reference();
         $r->get_by_employee_id($employee_id);
         $r->delete_all();
         $i = 0;
         foreach ($names as $name) {
             $r = new Reference();
             $r->employee_id = $employee_id;
             $r->name = $names[$i];
             $r->address = $address[$i];
             $r->tel_no = $no[$i];
             $r->ctc_no = Input::get('ctc_no');
             $r->issue_at = Input::get('issue_at');
             $r->issue_on = Input::get('issue_on');
             $r->save();
             $i++;
         }
         $data['msg'] = 'Other Information has been saved!';
     }
     // Other information============================================
     $o = new Other_info();
     $data['infos'] = $o->get_by_employee_id($employee_id);
     // Question ====================================================
     $q = new Question();
     $data['question_options'] = array('0' => 'No', '1' => 'Yes');
     $data['question1'] = $q->get_question($employee_id, 1);
     $data['question2'] = $q->get_question($employee_id, 2);
     $data['question3'] = $q->get_question($employee_id, 3);
     $data['question4'] = $q->get_question($employee_id, 4);
     $data['question5'] = $q->get_question($employee_id, 5);
     $data['question6'] = $q->get_question($employee_id, 6);
     $data['question7'] = $q->get_question($employee_id, 7);
     $data['question8'] = $q->get_question($employee_id, 8);
     $data['question9'] = $q->get_question($employee_id, 9);
     $data['question10'] = $q->get_question($employee_id, 10);
     // References=================================================
     $r = new Reference();
     $data['references'] = $r->get_by_employee_id($employee_id);
     $data['selected'] = $e->office_id;
     //Use for office listbox
     $data['options'] = $this->options->office_options();
     $data['employee_id'] = $employee_id;
     $data['main_content'] = 'other_info';
     return View::make('includes/template', $data);
 }
开发者ID:billyriantono,项目名称:ihrmis,代码行数:94,代码来源:pds2.php

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

示例6: importAddresses

 public function importAddresses($id)
 {
     $entity = Doctrine::getTable('Entity')->find($id);
     if (!$entity) {
         return false;
     }
     $this->printDebug("\nImporting addresses for entity " . $id . ": " . $entity->name);
     $addresses = array();
     //get all the transactions
     $sql = 'SELECT cycle, transaction_id FROM os_entity_transaction WHERE entity_id = ? AND is_verified = 1 AND cycle > ?';
     $stmt = $this->db->execute($sql, array($id, $this->after_cycle));
     $trans = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $this->printDebug("Found " . count($trans) . " transactions...");
     $unique_address_parts = array();
     $unique_addresses = array();
     foreach ($trans as $tran) {
         $sql = 'SELECT street, city, state, zip, fec_id, date FROM os_donation WHERE cycle = ? AND row_id = ? ' . 'AND street IS NOT NULL AND zip IS NOT NULL AND state IS NOT NULL GROUP BY street, city, state, zip';
         $stmt = $this->rawDb->execute($sql, array($tran['cycle'], $tran['transaction_id']));
         if (!($address = $stmt->fetch(PDO::FETCH_ASSOC))) {
             $this->printDebug("Couldn't find complete address for donation " . $tran['cycle'] . "-" . $tran['transaction_id'] . "; skipping...");
             continue;
         }
         $addr2 = array_map(function ($a) {
             return strtolower($a);
         }, array_slice($address, 0, 4));
         if (preg_match("/\\d+ +(.*?) +/is", $addr2['street'], $str)) {
             $addr2['street'] = $str[0];
         }
         if (!in_array($addr2, $unique_addresses2)) {
             $unique_addresses2[] = $addr2;
             $unique_addresses[] = $address;
         }
     }
     foreach ($unique_addresses as $address) {
         //get state id
         $sql = 'SELECT id FROM address_state WHERE abbreviation = ?';
         $stmt = $this->db->execute($sql, array($address['state']));
         if (!($stateId = $stmt->fetch(PDO::FETCH_COLUMN))) {
             $this->printDebug("Couldn't parse address: " . $str . "; skipping...");
             continue;
         }
         $str = $address['street'] . ', ' . $address['city'] . ', ' . $address['state'] . ' ' . $address['zip'];
         $a = AddressTable::parseV3($str);
         $this->ct++;
         $a->entity_id = $id;
         //only save if zips match
         if ($a->postal && trim($a->postal) != '' && $a->postal != $address['zip']) {
             $this->printDebug("Zips don't match, " . $a->postal . " / " . $address['zip'] . ", {$str} ; skipping...");
             continue;
         }
         //only save if longitude and latitude and street and state are set
         if ($a->longitude && $a->latitude && $a->street1 && $a->state_id) {
             //make sure it's not a duplicate
             $sql = 'SELECT COUNT(id) FROM address WHERE entity_id = ? AND ((longitude = ? AND latitude = ?) OR street1 = ?) AND is_deleted = 0';
             $stmt = $this->db->execute($sql, array($id, $a->longitude, $a->latitude, $a->street1));
             if ($stmt->fetch(PDO::FETCH_COLUMN)) {
                 $this->printDebug("Duplicate address: " . $a->getOneLiner() . "; skipping...");
                 continue;
             } else {
                 $a->save();
                 $this->printDebug("+ Imported address: " . $a->getOneLiner());
                 if ($address['fec_id']) {
                     $ref = new Reference();
                     $ref->object_model = 'Address';
                     $ref->object_id = $a->id;
                     $ref->source = 'http://images.nictusa.com/cgi-bin/fecimg/?' . $address['fec_id'];
                     $ref->name = 'FEC Filing ' . $address['fec_id'];
                     if ($address['date']) {
                         $ref->publication_date = $address['date'];
                     }
                     $ref->save();
                     $this->printDebug("  (with reference)");
                 }
             }
         } else {
             $this->printDebug("\tCouldn't parse address: " . $str . "; skipping...(" . $a->longitude . " " . $a->latitude . " " . $a->street1 . " " . $a->state_id . ")");
             continue;
         }
     }
     if (count($trans)) {
         $this->saveMeta($id, 'matched');
     } else {
         $this->saveMeta($id, 'no matches');
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:85,代码来源:OsImportAddressesTask.class.php

示例7: executeAddBulk

 public function executeAddBulk($request)
 {
     $this->checkList($request, false, false);
     $this->reference_form = new ReferenceForm();
     $this->reference_form->setSelectObject($this->list);
     $this->csv_form = new CsvUploadForm();
     if ($request->isMethod('post')) {
         $commit = $request->getParameter('commit');
         if ($commit == 'Cancel') {
             $this->redirect(LsListTable::getInternalUrl($this->list));
         }
         // IF REFERENCE INFO AND FILE HAVE BEEN SUBMITTED, LOAD DATA IN
         if ($request->hasParameter('reference') && $request->hasParameter('csv')) {
             $csvParams = $request->getParameter('csv');
             $filePath = $request->getFilePath('csv[file]');
             $this->csv_form->bind($csvParams, $request->getFiles('csv'));
             $refParams = $request->getParameter('reference');
             $this->reference_form->bind($refParams);
             if ($this->reference_form->isValid()) {
                 if ($spreadsheetArr = LsSpreadsheet::parse($filePath)) {
                     $names = $spreadsheetArr['rows'];
                     if (!in_array('name', $spreadsheetArr['headers'])) {
                         $request->setError('csv', 'The file you uploaded could not be parsed properly because there is no "name" column.');
                         return;
                     }
                 } else {
                     $request->setError('csv', 'The file you uploaded could not be parsed properly.');
                     return;
                 }
                 if ($this->ref_id = $refParams['existing_source']) {
                     $ref = Doctrine::getTable('Reference')->find($this->ref_id);
                     $url = $ref->source;
                 } else {
                     $ref = new Reference();
                     $ref->object_model = 'LsList';
                     $ref->object_id = $this->list->id;
                     $ref->source = $refParams['source'];
                     $ref->name = $refParams['name'];
                     $ref->source_detail = $refParams['source_detail'];
                     $ref->publication_date = $refParams['publication_date'];
                     $ref->save();
                     $this->ref_id = $ref->id;
                 }
                 $this->default_type = $request->getParameter('default_type');
                 if (!$this->default_type) {
                     $request->setError('csv', 'You need to choose a default type.');
                     return;
                 }
                 $this->extensions = ExtensionDefinitionTable::getByTier(2, $this->default_type);
                 $extensions_arr = array();
                 foreach ($this->extensions as $ext) {
                     $extensions_arr[] = $ext->name;
                 }
                 $this->matches = array();
                 if (isset($names) && count($names) > 0) {
                     for ($i = 0; $i < count($names); $i++) {
                         if (isset($names[$i]['name']) && trim($names[$i]['name']) != '') {
                             $name = $names[$i]['name'];
                             $name_terms = $name;
                             if ($this->default_type == 'Person') {
                                 $name_parts = preg_split('/\\s+/', $name);
                                 if (count($name_parts) > 1) {
                                     $name_terms = PersonTable::nameSearch($name, true);
                                 }
                                 $terms = $name_terms;
                                 $primary_ext = "Person";
                             } else {
                                 if ($this->default_type == 'Org') {
                                     $name_terms = OrgTable::nameSearch($name);
                                     $terms = $name_terms;
                                     $primary_ext = "Org";
                                 } else {
                                     $terms = $name_terms;
                                     $primary_ext = null;
                                 }
                             }
                             $pager = EntityTable::getSphinxPager($terms, $page = 1, $num = 20, $listIds = null, $aliases = true, $primary_ext);
                             $match = array('name' => $name);
                             $match['search_results'] = $pager->execute();
                             $match['blurb'] = isset($names[$i]['blurb']) ? $names[$i]['blurb'] : null;
                             $match['rank'] = isset($names[$i]['rank']) ? $names[$i]['rank'] : null;
                             $match['types'] = array();
                             if (isset($names[$i]['types'])) {
                                 $types = explode(',', $names[$i]['types']);
                                 $types = array_map('trim', $types);
                                 foreach ($types as $type) {
                                     if (in_array($type, $extensions_arr)) {
                                         $match['types'][] = $type;
                                     }
                                 }
                             }
                             $this->matches[] = $match;
                         }
                     }
                 }
             }
         } else {
             if ($request->hasParameter('ref_id')) {
                 $this->ref_id = $this->getRequestParameter('ref_id');
                 $entity_ids = array();
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:actions.class.php

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

示例9: setList

 protected function setList($title, $description, $fields = 'name, description, is_ranked')
 {
     $count = count($this->urls);
     $end = $this->end ? $this->end : $count;
     reset($this->urls);
     if (!$this->year) {
         throw new Exception('ForbesScraper:setYear has to be called before ForbesScraper:setList');
     }
     $this->list_name = $title . " ({$this->year})";
     //'Forbes Largest Private Companies (' . $this->year . ')';
     $list = Doctrine_Query::create()->from('LsList L')->where('L.name = ?', $this->list_name)->fetchOne();
     //if thlis year's fortune list doesn't already exist, create it
     if (!$list) {
         try {
             $list = new LsList();
             $list->name = $this->list_name;
             $list->description = $description;
             //"Fortune Magazine's list of large US private companies";
             $list->is_ranked = 1;
             $list->save();
             $this->list = $list;
             $ref = new Reference();
             $ref->object_model = 'LsList';
             $ref->object_id = $list->id;
             $ref->fields = $fields;
             $ref->source = $this->list_urls[$this->year]['source_url'];
             $ref->save();
         } catch (Exception $e) {
             $this->db->rollback();
             throw $e;
         }
     } else {
         $this->list = $list;
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:35,代码来源:ForbesScraper.class.php

示例10: processEntity


//.........这里部分代码省略.........
                 continue;
             }
             //create committee entity and position relationship between it and the candidate, if necessary
             //DISABLED, FOR NOW
             //$this->createCampaignCommittee($recipientEntity['id'], $recipientId);
             if ($this->debugMode) {
                 print "Updating donation relationship with " . $recipientEntity['name'] . "...\n";
             }
             //see if there's already a relationship
             Doctrine_Manager::getInstance()->setCurrentConnection('main');
             $q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? AND r.entity2_id = ? AND r.category_id = ?', array($id, $recipientEntity['id'], RelationshipTable::DONATION_CATEGORY));
             $rel = $q->fetchOne();
             //create relationship if there's not already one
             if (!$rel) {
                 //but if there aren't any new donations, then we skip this recipient
                 //THIS SHOULD NOT TYPICALLY HAPPEN, BECAUSE NO NEW DONATIONS MEANS
                 //THERE ARE OLD DONATIONS TO REMOVE, WHICH MEANS THERE SHOULD BE
                 //EXISTING RELATIONSHIPS... they may have been deleted
                 if (!count($donations['new'])) {
                     if ($this->debugMode) {
                         print "* No relationships found, and no new donations to process, so skipping it...\n";
                     }
                     continue;
                 }
                 if ($this->debugMode) {
                     print "+ Creating new donation relationship\n";
                 }
                 $rel = new Relationship();
                 $rel->entity1_id = $id;
                 $rel->entity2_id = $recipientEntity['id'];
                 $rel->setCategory('Donation');
                 $rel->description1 = 'Campaign Contribution';
                 $rel->description2 = 'Campaign Contribution';
                 $rel->save();
             }
             //add new filings and references to the relationship
             foreach ($donations['new'] as $donation) {
                 $filing = new FecFiling();
                 $filing->relationship_id = $rel->id;
                 $filing->amount = $donation['amount'];
                 $filing->fec_filing_id = $donation['fec_id'];
                 $filing->crp_cycle = $donation['cycle'];
                 $filing->crp_id = $donation['row_id'];
                 $filing->start_date = $donation['date'];
                 $filing->end_date = $donation['date'];
                 $filing->is_current = false;
                 $filing->save();
                 if ($this->debugMode) {
                     print "+ Added new FEC filing: " . $donation['fec_id'] . " (" . $donation['amount'] . ")\n";
                 }
                 //add reference if there's an fec_id
                 if ($donation['fec_id']) {
                     $ref = new Reference();
                     $ref->object_model = 'Relationship';
                     $ref->object_id = $rel->id;
                     $ref->source = $this->fecImageBaseUrl . $donation['fec_id'];
                     $ref->name = 'FEC Filing ' . $donation['fec_id'];
                     $ref->save();
                 }
             }
             //remove old filings from the relationship
             foreach ($donations['old'] as $donation) {
                 if ($this->debugMode) {
                     print "- Deleting FEC filing: {$donation['fec_id']}, {$donation['cycle']}, {$donation['row_id']} ({$donation['amount']})\n";
                 }
                 $sql = 'DELETE FROM fec_filing WHERE relationship_id = ? AND crp_cycle = ? AND crp_id = ?';
开发者ID:silky,项目名称:littlesis,代码行数:67,代码来源:OsProcessMatchesTask.class.php

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

示例12: executeAddBulk

 public function executeAddBulk($request)
 {
     $this->checkEntity($request, false, false);
     $this->reference_form = new ReferenceForm();
     $this->reference_form->setSelectObject($this->entity);
     $this->add_bulk_form = new AddBulkForm();
     //get possible default categories
     $this->categories = LsDoctrineQuery::create()->select('c.name, c.name')->from('RelationshipCategory c')->orderBy('c.id')->fetchAll(PDO::FETCH_KEY_PAIR);
     array_unshift($this->categories, '');
     if ($request->isMethod('post') && in_array($request->getParameter('commit'), array('Begin', 'Continue'))) {
         if ($request->hasParameter('ref_id')) {
             $this->ref_id = $request->getParameter('ref_id');
         } else {
             $refParams = $request->getParameter('reference');
             $this->reference_form->bind($refParams);
             $restOfParams = (array) $request->getParameterHolder();
             $restOfParams = array_shift($restOfParams);
             $this->add_bulk_form->bind($restOfParams, $request->getFiles());
             if (!$this->reference_form->isValid() || !$this->add_bulk_form->isValid()) {
                 return;
             }
             if ($this->ref_id = $refParams['existing_source']) {
                 $ref = Doctrine::getTable('Reference')->find($this->ref_id);
                 $url = $ref->source;
             } else {
                 $ref = new Reference();
                 $ref->object_model = 'Entity';
                 $ref->object_id = $this->entity->id;
                 $ref->source = $refParams['source'];
                 $ref->name = $refParams['name'];
                 $ref->source_detail = $refParams['source_detail'];
                 $ref->publication_date = $refParams['publication_date'];
                 $ref->save();
             }
             $this->ref_id = $ref->id;
             $this->reference = $ref;
         }
         $verify_method = $request->getParameter('verify_method');
         if ($this->add_method = $request->getParameter('add_method')) {
             if ($this->add_method == 'scrape') {
                 //scrape ref url
                 //set names to confirm
                 $browser = new sfWebBrowser();
                 $entity_types = $request->getParameter('entity_types');
                 //FIND NAMES AT URL USING COMBO OF OPENCALAIS & LS CUSTOM HTML PARSING
                 if (!$browser->get($ref->source)->responseIsError()) {
                     $text = $browser->getResponseText();
                     $this->names = LsTextAnalysis::getHtmlEntityNames($text, $entity_types);
                     $text = LsHtml::findParagraphs($text);
                     $this->text = preg_replace('/<[^b][^>]*>/is', " ", $text);
                     $this->confirm_names = true;
                     return;
                 } else {
                     $request->setError('csv', 'problems finding names at that url');
                 }
             } else {
                 if ($this->add_method == 'upload') {
                     $file = $this->add_bulk_form->getValue('file');
                     $filename = 'uploaded_' . sha1($file->getOriginalName());
                     $extension = $file->getExtension($file->getOriginalExtension());
                     $filePath = sfConfig::get('sf_temp_dir') . '/' . $filename . $extension;
                     $file->save($filePath);
                     if ($filePath) {
                         if ($spreadsheetArr = LsSpreadsheet::parse($filePath)) {
                             $names = $spreadsheetArr['rows'];
                             if (!in_array('name', $spreadsheetArr['headers'])) {
                                 $request->setError('file', 'The file you uploaded could not be parsed properly because there is no "name" column.');
                                 return;
                             }
                             if (in_array('summary', $spreadsheetArr['headers'])) {
                                 foreach ($names as &$name) {
                                     $name['summary'] = str_replace(array('?', "'"), "'", $name['summary']);
                                     $name['summary'] = str_replace(array('?', '?', '"'), '"', $name['summary']);
                                     if (isset($name['title'])) {
                                         $name['description1'] = $name['title'];
                                     }
                                 }
                                 unset($name);
                             }
                         } else {
                             $request->setError('file', 'The file you uploaded could not be parsed properly.');
                             return;
                         }
                     } else {
                         $request->setError('file', 'You need to upload a file.');
                         return;
                     }
                 } else {
                     if ($this->add_method == 'summary') {
                         //parse summary for names
                         $this->text = $this->entity->summary;
                         $entity_types = $request->getParameter('entity_types');
                         $this->names = LsTextAnalysis::getTextEntityNames($this->text, $entity_types);
                         $this->confirm_names = true;
                         return;
                     } else {
                         if ($this->add_method == 'text') {
                             $manual_names = $request->getParameter('manual_names');
                             if ($manual_names && $manual_names != "") {
                                 $manual_names = preg_split('#[\\r\\n]+#', $manual_names);
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:actions.class.php


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