/** * 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; } } }
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; } }
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)); }
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); }
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 $image->addReference($mp['image']); $this->printDebug("Saved image reference"); } unset($image); } // Add party image? if ($mp['party_image']) { if ($fileName = ImageTable::createFiles($mp['party_image'])) { //insert image record $partyImage = new Image(); $partyImage->filename = $fileName; $partyImage->title = $partyEntity['name']; $partyImage->caption = 'From YourNextMP under CC-BY-SA license.'; $partyImage->is_featured = true; $partyImage->is_free = true; $partyImage->url = $mp['party_image']; $this->printDebug("Imported image: " . $partyImage->filename); } $partyImage->Entity = $partyEntity; $partyImage->save(); if ($mp['party_image']) { //save image source $partyImage->addReference($mp['party_image']); $this->printDebug("Saved image reference"); } unset($partyImage); } unset($entity); unset($partyEntity); } }
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'); } }
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(); $default_type = $this->getRequestParameter('default_type'); for ($i = 0; $i < $this->getRequestParameter('count'); $i++) { if ($entity_id = $request->getParameter('entity_' . $i)) { $selected_entity_id = null; if ($entity_id == 'new') { $name = $request->getParameter('new_name_' . $i); if ($default_type == 'Person') { $new_entity = PersonTable::parseFlatName($name); } else { $new_entity = new Entity(); $new_entity->addExtension('Org'); $new_entity->name = trim($name); } if ($types = $request->getParameter('new_extensions_' . $i)) { foreach ($types as $type) { $new_entity->addExtension($type); } } $new_entity->save(); $new_entity->blurb = $request->getParameter('new_blurb_' . $i); $ref = Doctrine::getTable('Reference')->find($request->getParameter('ref_id')); $new_entity->addReference($ref->source, null, null, $ref->name); $new_entity->save(); $selected_entity_id = $new_entity->id; } else { if ($entity_id > 0) { $selected_entity_id = $entity_id; } } if ($selected_entity_id) { $q = LsDoctrineQuery::create()->from('LsListEntity le')->where('le.list_id = ? AND le.entity_id = ?', array($this->list['id'], $selected_entity_id)); if (!$q->count()) { $ls_list_entity = new LsListEntity(); $ls_list_entity->list_id = $this->list->id; $ls_list_entity->entity_id = $selected_entity_id; $ls_list_entity->rank = $request->getParameter('entity_' . $i . '_rank'); $ls_list_entity->save(); LsCache::clearEntityCacheById($selected_entity_id); } } } } $this->clearCache($this->list); $this->clearRailsCache($this->list->id); $this->redirect($this->list->getInternalUrl()); } else { $request->setError('name', 'The name you entered is invalid'); } } } }
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; }
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; } }
public function processEntity($id, $newTrans, $oldTrans) { //get person names so we can make sure added donations are from the right person $sql = 'SELECT * FROM person WHERE entity_id = ?'; $stmt = $this->db->execute($sql, array($id)); if (!($donorPerson = $stmt->fetch(PDO::FETCH_ASSOC))) { if ($this->debugMode) { print "* Can't find Person record for donor with entity_id " . $id . "; skipping..."; } return; } if ($this->debugMode) { print "\n=== Processing entity " . $id . " (" . PersonTable::getLegalName($donorPerson) . ") ===\n"; } $recipients = array(); //get donations from all the newly matched transactions $newDonations = $this->getDonations($newTrans); foreach ($newDonations as $donation) { if (!$this->namesAreCompatible($donorPerson, $donation)) { if ($this->debugMode) { print "* Skipping donation with incompatible donor name: " . $donation['donor_name'] . "\n"; } continue; } $cycle = $donation['cycle']; $recipientId = $donation['recipient_id']; if (isset($recipients[$cycle][$recipientId]['new'])) { $recipients[$cycle][$recipientId]['new'][] = $donation; } else { if (!isset($recipients[$cycle])) { $recipients[$cycle] = array(); } $recipients[$cycle][$recipientId] = array(); $recipients[$cycle][$recipientId]['new'] = array($donation); $recipients[$cycle][$recipientId]['old'] = array(); } } //get donations from all the old transactions $oldDonations = $this->getDonations($oldTrans); foreach ($oldDonations as $donation) { $cycle = $donation['cycle']; $recipientId = $donation['recipient_id']; if (isset($recipients[$cycle][$recipientId]['old'])) { $recipients[$cycle][$recipientId]['old'][] = $donation; } else { if (!isset($recipients[$cycle])) { $recipients[$cycle] = array(); } $recipients[$cycle][$recipientId] = array(); $recipients[$cycle][$recipientId]['old'] = array($donation); $recipients[$cycle][$recipientId]['new'] = array(); } } //if there are NO already-processed matches, and no matches to remove, //ie, if we're going from no matches to any number of matches, //we can delete existing donation relationships for this entity $deleteRels = false; if (!count($oldDonations)) { $sql = 'SELECT COUNT(*) FROM os_entity_transaction WHERE entity_id = ? AND is_processed = 1'; $stmt = $this->db->execute($sql, array($id)); if (!$stmt->fetch(PDO::FETCH_COLUMN)) { $deleteRels = true; } } if ($deleteRels) { if ($this->debugMode) { print "- Removing old donation relationships...\n"; } //first get ids $sql = 'SELECT DISTINCT r.id FROM relationship r ' . 'LEFT JOIN fec_filing f ON (f.relationship_id = r.id) ' . 'WHERE r.entity1_id = ? AND r.category_id = ? AND r.is_deleted = 0 ' . 'AND f.id IS NOT NULL'; $stmt = $this->db->execute($sql, array($id, RelationshipTable::DONATION_CATEGORY)); $relIds = $stmt->fetchAll(PDO::FETCH_COLUMN); if (count($relIds)) { //soft delete them $sql = 'UPDATE relationship SET is_deleted = 1, updated_at = ? WHERE id IN (' . implode(',', $relIds) . ')'; $params = array(LsDate::getCurrentDateTime()); $this->db->execute($sql, $params); //create modification records of the deletions $sql = 'INSERT INTO modification (object_model, object_id, object_name, is_delete, created_at, updated_at) ' . 'VALUES '; $params = array(); foreach ($relIds as $relId) { $sql .= '(?, ?, ?, ?, ?, ?), '; $now = LsDate::getCurrentDateTime(); $params = array_merge($params, array('Relationship', $relId, 'Relationship ' . $relId, true, $now, $now)); } $sql = substr($sql, 0, strlen($sql) - 2); $stmt = $this->db->execute($sql, $params); } } //make sure the entity hasn't been deleted in the meantime! $sql = 'SELECT id FROM entity WHERE id = ? AND is_deleted = 0'; $stmt = $this->db->execute($sql, array($id)); if (!$stmt->fetch(PDO::FETCH_COLUMN)) { //skip to the end $recipients = array(); } //create filings/relationships for each cycle-recipient pair foreach ($recipients as $cycle => $recipients) { foreach ($recipients as $recipientId => $donations) { //if it's a committee recipient, try to determine //whether it belongs to a candidate if (strpos($recipientId, 'C') === 0) { $recipientId = $this->getFinalRecipientIdByCycleAndCommitteeId($cycle, $recipientId); } //find the entity with this recipient id, or generate a new one if (!($recipientEntity = $this->getEntityByRecipientId($recipientId))) { if ($this->debugMode) { print "* Couldn't find or create entity for recipient " . $recipientId . "; skipping...\n"; } 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 = ?'; $stmt = $this->db->execute($sql, array($rel->id, $donation['cycle'], $donation['row_id'])); } //recompute fields based on filings if (!$rel->updateFromFecFilings()) { if ($this->debugMode) { print "- Deleting donation relationship with no filings: " . $rel->id . "\n"; } //no remaining filings for this relationship, so delete it! $rel->delete(); } else { if ($this->debugMode) { print "Relationship " . $rel->id . " updated with " . $rel->filings . " filings totaling " . $rel->amount . "\n"; } //add a reference to OS donation search for the relationship, if necessary $sql = 'SELECT COUNT(*) FROM reference ' . 'WHERE object_model = ? AND object_id = ? AND name = ?'; $stmt = $this->db->execute($sql, array('Relationship', $rel->id, 'FEC contribution search')); if (!$stmt->fetch(PDO::FETCH_COLUMN)) { $ref = new Reference(); $ref->object_model = 'Relationship'; $ref->object_id = $rel->id; $ref->source = sprintf($this->fecSearchUrlPattern, strtoupper($donorPerson['name_last']), strtoupper($donorPerson['name_first'])); $ref->name = 'FEC contribution search'; $ref->save(); if ($this->debugMode) { print "+ Added reference to FEC contribution search\n"; } } } //clear cache for recipient LsCache::clearEntityCacheById($recipientEntity['id']); } } //update os_entity_transaction $sql = 'UPDATE os_entity_transaction SET is_processed = is_verified, is_synced = 1 WHERE entity_id = ?'; $stmt = $this->db->execute($sql, array($id)); //make sure that all removed matches result in deleted fec filings and updated relationships for this entity $this->cleanupFecFilings($id, $oldDonations); //update opensecrets categories based on matched donations $this->printDebug("Updating industry categories based on matched donations..."); $newCategories = OsPerson::updateCategories($id); foreach ($newCategories as $categoryId) { $this->printDebug("+ Added industry category: " . $categoryId); } //clear cache for donor LsCache::clearEntityCacheById($id); }
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; $ref->object_model = 'Relationship'; $ref->save(); $redirect = 'relationship/toolbar?url=' . $refSource . '&title=' . $refName . '&created_id=' . $rel->id; //if there's a bulk queue, remove one from the start if ($isBulk = $request->getParameter('is_bulk')) { $names = $this->getUser()->getAttribute('toolbar_names'); array_shift($names); if (count($names)) { $this->getUser()->setAttribute('toolbar_names', $names); //keep track of entity order while in queue $this->getUser()->setAttribute('toolbar_switched', $request->getParameter('is_switched', 0)); $redirect = 'relationship/toolbar?created_id=' . $rel->id; } else { //queue is finished; go to entity profile $entityId = $this->getUser()->getAttribute('toolbar_entity'); $entity = Doctrine::getTable('Entity')->find($entityId); $redirect = $entity->getInternalUrl(); $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->getUser()->setAttribute('toolbar_switched', null); } } LsCache::clearEntityCacheById($entity1['id']); LsCache::clearEntityCacheById($entity2['id']); $this->redirect($redirect); } //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']; } } } } $this->is_switched = $this->getUser()->getAttribute('toolbar_switched', 0); } if ($createdId = $request->getParameter('created_id')) { $this->created_rel = Doctrine::getTable('Relationship')->find($createdId); } $this->setLayout($bulkEntityId ? 'layout' : 'toolbar'); }
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); $manual_names = array_map('trim', $manual_names); $names = array(); foreach ($manual_names as $name) { $names[] = array('name' => $name); } } else { $request->setError('csv', 'You did not add names properly.'); return; } } else { if ($this->add_method == 'db_search') { $this->db_search = true; } } } } } } //intermediate scrape page -- takes confirmed names, builds names arr if ($confirmed_names = $request->getParameter('confirmed_names')) { $restOfParams = (array) $request->getParameterHolder(); $restOfParams = array_shift($restOfParams); $this->add_bulk_form->bind($restOfParams, $request->getFiles()); if (!$this->add_bulk_form->isValid()) { $this->reference = Doctrine::getTable('reference')->find($this->ref_id); $this->names = unserialize(stripslashes($request->getParameter('names'))); $this->confirm_names = true; return; } $names = array(); foreach ($confirmed_names as $cn) { $names[] = array('name' => $cn); } $manual_names = $request->getParameter('manual_names'); if ($manual_names && $manual_names != "") { $manual_names = preg_split('#[\\r\\n]+#', $manual_names); $manual_names = array_map('trim', $manual_names); foreach ($manual_names as $name) { $names[] = array('name' => $name); } } } // LOAD IN RELATIONSHIP DEFAULTS if (isset($verify_method)) { $defaults = $request->getParameter('relationship'); if ($verify_method == 'enmasse') { $this->default_type = $request->getParameter('default_type'); $this->order = $request->getParameter('order'); $category_name = $request->getParameter('relationship_category_all'); $this->extensions = ExtensionDefinitionTable::getByTier(2, $this->default_type); $extensions_arr = array(); foreach ($this->extensions as $ext) { $extensions_arr[] = $ext->name; } } else { $category_name = $request->getParameter('relationship_category_one'); } if ($category_name) { $this->category_name = $category_name; if (!($category = Doctrine::getTable('RelationshipCategory')->findOneByName($category_name))) { $request->setError('csv', 'You did not select a relationship category.'); return; } $formClass = $category_name . 'Form'; $categoryForm = new $formClass(new Relationship()); $categoryForm->setDefaults($defaults); $this->form_schema = $categoryForm->getFormFieldSchema(); if (in_array($category_name, array('Position', 'Education', 'Membership', 'Donation', 'Lobbying', 'Ownership'))) { $this->field_names = array('description1', 'start_date', 'end_date', 'is_current'); } else { $this->field_names = array('description1', 'description2', 'start_date', 'end_date', 'is_current'); } $extraFields = array('Position' => array('is_board', 'is_executive'), 'Education' => array('degree_id'), 'Donation' => array('amount'), 'Transaction' => array('amount'), 'Lobbying' => array('amount'), 'Ownership' => array('percent_stake', 'shares')); if (isset($extraFields[$category_name])) { $this->field_names = array_merge($this->field_names, $extraFields[$category_name]); } } $this->matches = array(); // BOOT TO TOOLBAR OR LOOK FOR MATCHES FOR ENMASSE ADD if (isset($names) && count($names) > 0 || isset($this->db_search)) { if ($verify_method == 'onebyone') { if (isset($category_name)) { $defaults['category'] = $category_name; } $toolbar_names = array(); foreach ($names as $name) { $toolbar_names[] = $name['name']; } $this->getUser()->setAttribute('toolbar_names', $toolbar_names); $this->getUser()->setAttribute('toolbar_entity', $this->entity->id); $this->getUser()->setAttribute('toolbar_defaults', $defaults); $this->getUser()->setAttribute('toolbar_ref', $this->ref_id); $this->redirect('relationship/toolbar'); } else { $this->category_name = $category_name; if (isset($this->db_search)) { $num = $request->getParameter('num', 10); $page = $request->getParameter('page', 1); $q = LsDoctrineQuery::create()->from('Entity e')->where('(e.summary rlike ? or e.blurb rlike ?)', array('[[:<:]]' . $this->entity->name . '[[:>:]]', '[[:<:]]' . $this->entity->name . '[[:>:]]')); foreach ($this->entity->Alias as $alias) { $q->orWhere('(e.summary rlike ? or e.blurb rlike ?)', array('[[:<:]]' . $alias->name . '[[:>:]]', '[[:<:]]' . $alias->name . '[[:>:]]')); } $q->setHydrationMode(Doctrine::HYDRATE_ARRAY); $cat_id = constant('RelationshipTable::' . strtoupper($category_name) . '_CATEGORY'); $q->whereParenWrap(); $q->andWhere('NOT EXISTS (SELECT DISTINCT l.relationship_id FROM Link l ' . 'WHERE l.entity1_id = e.id AND l.entity2_id = ? AND l.category_id = ?)', array($this->entity['id'], $cat_id)); $summary_matches = $q->execute(); foreach ($summary_matches as $summary_match) { $aliases = array(); foreach ($this->entity->Alias as $alias) { $aliases[] = LsString::escapeStringForRegex($alias->name); } $aliases = implode("|", $aliases); $summary_match['summary'] = preg_replace('/(' . $aliases . ')/is', '<strong>$1</strong>', $summary_match['summary']); $this->matches[] = array('search_results' => array($summary_match)); } } else { 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); } $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 = $names[$i]; $match['search_results'] = $pager->execute(); if (isset($names[$i]['types'])) { $types = explode(',', $names[$i]['types']); $types = array_map('trim', $types); $match['types'] = array(); foreach ($types as $type) { if (in_array($type, $extensions_arr)) { $match['types'][] = $type; } } } $this->matches[] = $match; } } } } } } } else { if ($page = $this->getRequestParameter('page')) { $this->page = $page; $this->num = $this->getRequestParameter('num', 50); } else { if ($request->isMethod('post') && $request->getParameter('commit') == 'Submit') { $this->ref_id = $this->getRequestParameter('ref_id'); $entity_ids = array(); $relationship_category = $this->getRequestParameter('category_name'); $order = $this->getRequestParameter('order'); $default_type = $request->getParameter('default_type'); $default_ref = Doctrine::getTable('Reference')->find($request->getParameter('ref_id')); for ($i = 0; $i < $this->getRequestParameter('count'); $i++) { if ($entity_id = $request->getParameter('entity_' . $i)) { $selected_entity_id = null; $relParams = $request->getParameter("relationship_" . $i); if ($relParams['ref_name']) { $ref['source'] = $relParams['ref_source']; $ref['name'] = $relParams['ref_name']; } if ($entity_id == 'new') { $name = $request->getParameter('new_name_' . $i); if ($default_type == 'Person') { $new_entity = PersonTable::parseFlatName($name); } else { $new_entity = new Entity(); $new_entity->addExtension('Org'); $new_entity->name = trim($name); } $new_entity->save(); $new_entity->blurb = $request->getParameter('new_blurb_' . $i); $new_entity->summary = $request->getParameter('new_summary_' . $i); if (!$ref) { $ref = $default_ref; } $new_entity->addReference($ref['source'], null, null, $ref['name']); if ($types = $request->getParameter('new_extensions_' . $i)) { foreach ($types as $type) { $new_entity->addExtension($type); } } $new_entity->save(); $selected_entity_id = $new_entity->id; } else { if ($entity_id > 0) { $selected_entity_id = $entity_id; LsCache::clearEntityCacheById($selected_entity_id); } } if ($selected_entity_id) { $startDate = $relParams['start_date']; $endDate = $relParams['end_date']; unset($relParams['start_date'], $relParams['end_date'], $relParams['ref_name'], $relParams['ref_url']); $rel = new Relationship(); $rel->setCategory($relationship_category); if ($order == '1') { $rel->entity1_id = $this->entity['id']; $rel->entity2_id = $selected_entity_id; } else { $rel->entity2_id = $this->entity['id']; $rel->entity1_id = $selected_entity_id; } //only set dates if valid if ($startDate && preg_match('#^\\d{4}-\\d{2}-\\d{2}$#', Dateable::convertForDb($startDate))) { $rel->start_date = Dateable::convertForDb($startDate); } if ($endDate && preg_match('#^\\d{4}-\\d{2}-\\d{2}$#', Dateable::convertForDb($endDate))) { $rel->end_date = Dateable::convertForDb($endDate); } $rel->fromArray($relParams, null, $hydrateCategory = true); if ($request->hasParameter('add_method') && $request->getParameter('add_method') == 'db_search') { $refs = EntityTable::getSummaryReferences($selected_entity_id); if (count($refs)) { $ref = $refs[0]; } else { $refs = EntityTable::getAllReferencesById($selected_entity_id); if (count($refs)) { $ref = $refs[0]; } } } if (!$ref) { $ref = $default_ref; } $rel->saveWithRequiredReference(array('source' => $ref['source'], 'name' => $ref['name'])); $ref = null; } } } $this->clearCache($this->entity); $this->redirect($this->entity->getInternalUrl()); } else { if ($request->isMethod('post') && $request->getParameter('commit') == 'Cancel') { $this->redirect($this->entity->getInternalUrl()); } } } } }