本文整理汇总了PHP中Location::insertIfNotFound方法的典型用法代码示例。如果您正苦于以下问题:PHP Location::insertIfNotFound方法的具体用法?PHP Location::insertIfNotFound怎么用?PHP Location::insertIfNotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Location
的用法示例。
在下文中一共展示了Location::insertIfNotFound方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editAction
public function editAction()
{
if (!$this->hasACL('edit_employee')) {
$this->doNoAccessError();
}
$db = $this->dbfunc();
$status = ValidationContainer::instance();
$params = $this->getAllParams();
$id = $params['id'];
#// restricted access?? only show partners by organizers that we have the ACL to view // - removed 5/1/13, they dont want this, its used by site-rollup (datashare), and user-restrict by org.
#$org_allowed_ids = allowed_org_access_full_list($this); // doesnt have acl 'training_organizer_option_all'
#$site_orgs = allowed_organizer_in_this_site($this); // for sites to host multiple training organizers on one domain
#$siteOrgsClause = $site_orgs ? " AND partner.organizer_option_id IN ($site_orgs)" : "";
#if ($org_allowed_ids && $this->view->mode != 'add') {
# $validID = $db->fetchCol("SELECT partner.id FROM partner WHERE partner.id = $id AND partner.organizer_option_id in ($org_allowed_ids) $siteOrgsClause");
# if(empty($validID))
# $this->doNoAccessError ();
#
#}
if ($this->getRequest()->isPost()) {
//validate then save
$status->checkRequired($this, 'partner', t('Partner'));
if ($this->setting('display_partner_type')) {
$status->checkRequired($this, 'partner_type_option_id', t('Type of Partner'));
}
$status->checkRequired($this, 'address1', t('Address 1'));
$status->checkRequired($this, 'address2', t('Address 2'));
$status->checkRequired($this, 'province_id', t('Region A (Province)'));
$status->checkRequired($this, 'phone', t('Phone'));
$status->checkRequired($this, 'fax', t('Fax'));
if ($this->setting('display_employee_funder')) {
$status->checkRequired($this, 'partner_funder_option_id[]', t('Funder'));
}
#$status->checkRequired ( $this, 'funding_end_date[]', t ( 'Funding End Date' ) );
#if ($this->setting('display_employee_intended_transition'))
# $status->checkRequired ( $this, 'employee_transition_option_id', t ( 'Intended Transition' ) );
if ($this->setting('display_employee_agreement_end_date')) {
$status->checkRequired($this, 'agreement_end_date', t('Agreement End Date'));
}
if ($this->setting('display_employee_importance')) {
$status->checkRequired($this, 'partner_importance_option_id', t('Importance'));
}
#$status->checkRequired ( $this, 'comments', t ( 'Partner Comments' ) );
#$status->checkRequired ( $this, 'subpartner_id[]', t ( 'Sub Partner' ) );
$params['funding_end_date'] = $this->_array_me($params['funding_end_date']);
foreach ($params['funding_end_date'] as $i => $value) {
$params['funding_end_date'][$i] = $this->_date_to_sql($value);
}
$params['transition_confirmed'] = $params['transition_confirmed'] == 'on' ? 1 : 0;
$params['agreement_end_date'] = $this->_date_to_sql($params['agreement_end_date']);
$params['subpartner_id'] = $this->_array_me($params['subpartner_id']);
foreach ($params['subpartner_id'] as $i => $value) {
// strip empty values (it breaks MultiOptionList apparently)
if (empty($value)) {
unset($params['subpartner_id'][$i]);
}
}
//location save stuff
$params['location_id'] = regionFiltersGetLastID(null, $params);
// formprefix, criteria
if ($params['city']) {
$params['location_id'] = Location::insertIfNotFound($params['city'], $params['location_id'], $this->setting('num_location_tiers'));
}
if (!$status->hasError()) {
$id = $this->_findOrCreateSaveGeneric('partner', $params);
if (!$id) {
$status->setStatusMessage(t('That partner could not be saved.'));
} else {
MultiOptionList::updateOptions('partner_to_funder', 'partner_funder_option', 'partner_id', $id, 'partner_funder_option_id', $params['partner_funder_option_id'], 'funder_end_date', $params['funding_end_date']);
$db->query("DELETE FROM partner_to_subpartner WHERE partner_id = {$id}");
// updateOptions is not clearing the old options, I dont know why... todo
MultiOptionList::updateOptions('partner_to_subpartner', 'partner', 'partner_id', $id, 'subpartner_id', $params['subpartner_id']);
$status->setStatusMessage(t('The partner was saved.'));
$this->_redirect("partner/edit/id/{$id}");
}
}
}
if ($id) {
// read data from db
#// restricted access?? only show partners by organizers that we have the ACL to view
#$org_allowed_ids = allowed_org_access_full_list($this); // doesnt have acl 'training_organizer_option_all'
#$orgWhere = ($org_allowed_ids) ? " AND partner.organizer_option_id in ($org_allowed_ids) " : "";
#// restricted access?? only show organizers that belong to this site if its a multi org site
#$site_orgs = allowed_organizer_in_this_site($this); // for sites to host multiple training organizers on one domain
#$allowedWhereClause .= $site_orgs ? " AND partner.organizer_option_id in ($site_orgs) " : "";
// continue reading data
$sql = 'SELECT * FROM partner WHERE id = ' . $id . space . $orgWhere;
$row = $db->fetchRow($sql);
if (!$row) {
$status->setStatusMessage(t('Error finding that record in the database.'));
} else {
$params = $row;
// reassign form data
$region_ids = Location::getCityInfo($params['location_id'], $this->setting('num_location_tiers'));
$params['city'] = $region_ids[0];
$region_ids = Location::regionsToHash($region_ids);
$params = array_merge($params, $region_ids);
//get linked table data from option tables
$sql = "SELECT partner_funder_option_id,funder_end_date FROM partner_to_funder WHERE partner_id = {$id}";
$params['funder'] = $db->fetchAll($sql);
//.........这里部分代码省略.........
示例2: validateAndSave
protected function validateAndSave($facilityRow, $checkName = true)
{
$districtText = $this->tr('Region B (Health District)');
$provinceText = $this->tr('Region A (Province)');
$localRegionText = $this->tr('Region C (Local Region)');
//validate
$status = ValidationContainer::instance();
//check for required fields
if ($checkName) {
$status->checkRequired($this, 'facility_name', 'Facility name');
//check for unique
if ($this->_getParam('facility_name') and !Facility::isUnique($this->_getParam('facility_name'), $this->_getParam('id'))) {
$status->addError('facility_name', t('That name already exists.'));
}
}
// validate lat & long
require_once 'Zend/Validate/Float.php';
require_once 'Zend/Validate/Between.php';
$lat = $this->getSanParam('facility_latitude');
$long = $this->getSanParam('facility_longitude');
$validator = new Zend_Validate_Float();
$validbetween = new Zend_Validate_Between('-180', '180');
if ($lat && (!$validator->isValid($lat) || !$validbetween->isValid($lat))) {
$status->addError('facility_latitude', t('That latitude and longitude does not appear to be valid.'));
}
if ($long && (!$validator->isValid($long) || !$validbetween->isValid($long))) {
$status->addError('facility_longitude', t('That latitude and longitude does not appear to be valid.'));
}
$status->checkRequired($this, 'facility_type_id', t('Facility type'));
$status->checkRequired($this, 'facility_province_id', $provinceText);
if ($this->setting('display_region_b')) {
$status->checkRequired($this, 'facility_district_id', $districtText);
}
if ($this->setting('display_region_c')) {
$status->checkRequired($this, 'facility_region_c_id', $localRegionText);
}
//$status->checkRequired ( $this, 'facility_city', t ( "City is required." ) );
list($location_params, $facility_location_tier, $facility_location_id) = $this->getLocationCriteriaValues(array(), 'facility');
$city_id = false;
if ($this->getSanParam('facility_city') && !$this->getSanParam('is_new_city')) {
$city_id = Location::verifyHierarchy($location_params['facility_city'], $location_params['facility_city_parent_id'], $this->setting('num_location_tiers'));
if ($city_id === false) {
$status->addError('facility_city', t("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box."));
}
}
$sponsor_date_array = $this->getSanParam('sponsor_start_date');
// may or may not be array
$sponsor_end_date_array = $this->getSanParam('sponsor_end_date');
$sponsor_id = $this->getSanParam('facility_sponsor_id') ? $this->getSanParam('facility_sponsor_id') : null;
if (is_array($sponsor_id)) {
$sponsor_array = $sponsor_id;
$sponsor_id = $sponsor_id[0];
}
// todo case where multip array and no_allow_multi
if (@$this->setting('require_sponsor_dates')) {
$status->checkRequired($this, 'sponsor_option_id', t('Sponsor dates are required.') . "\n");
if ($this->setting('allow_multi_sponsors')) {
// and multiple sponsors option
if (!is_array($this->getSanParam('sponsor_option_id'))) {
$status->addError('sponsor_end_date', t('Sponsor dates are required.') . "\n");
}
foreach ($sponsor_array as $i => $val) {
if (empty($sponsor_date_array[$i]) || !empty($val)) {
$status->addError('sponsor_start_date', t('Sponsor dates are required.') . "\n");
}
if (empty($sponsor_end_date_array[$i]) || !empty($val)) {
$status->addError('sponsor_end_date', t('Sponsor dates are required.') . "\n");
}
}
}
}
// end validation
if ($status->hasError()) {
$status->setStatusMessage(t('The facility could not be saved.'));
} else {
$location_id = null;
if ($city_id === false && $this->getSanParam('is_new_city')) {
$location_id = Location::insertIfNotFound($location_params['facility_city'], $location_params['facility_city_parent_id'], $this->setting('num_location_tiers'));
if ($location_id === false) {
$status->addError('facility_city', t('Could not save that city.'));
}
} else {
if ($city_id) {
$location_id = $city_id;
} else {
if ($this->setting('display_region_c')) {
$location_id = $this->getSanParam('facility_region_c_id');
} else {
if ($this->setting('display_region_b')) {
$location_id = $this->getSanParam('facility_district_id');
} else {
$location_id = $this->getSanParam('facility_province_id');
}
}
}
if (strstr($location_id, '_')) {
$parts = explode('_', $location_id);
$location_id = $parts[count($parts) - 1];
}
}
//.........这里部分代码省略.........
示例3: doAddEditView
//.........这里部分代码省略.........
$facilityByName = new Facility();
$row = $facilityByName->fetchRow('id = ' . $facility_id);
//$row = $facilityByName->fetchRow($facilityByName->select()->where('facility_name = ?', $this->getSanParam('facilityInput')));
}
if (@$row->id) {
$personrow->facility_id = $row->id;
} else {
$status->addError('facilityInput', t('That facility name could not be found.'));
$errortext .= "That facility name could not be found.<br>";
error_log("That facility name could not be found.");
}
}
//get home city name
$city_id = false;
$criteria = $this->_getAllParams();
require_once 'views/helpers/Location.php';
$home_city_parent_id = regionFiltersGetLastID('home', $criteria);
if ($criteria['home_city'] && !$criteria['is_new_home_city']) {
$city_id = Location::verifyHierarchy($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers'));
if ($city_id === false) {
$status->addError('home_city', t("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box."));
$errortext .= "That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box.<br>";
error_log("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box.");
}
}
if ($status->hasError()) {
foreach ($status->messages as $k => $v) {
$errortext .= $v . "<br>";
}
$status->setStatusMessage(t('The person could not be saved. <br>' . $errortext));
} else {
$personrow = self::fillFromArray($personrow, $this->_getAllParams());
if ($city_id === false && $this->getSanParam('is_new_home_city')) {
$city_id = Location::insertIfNotFound($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers'));
if ($city_id === false) {
$status->addError('home_city', t('Could not save that city.'));
}
}
if ($city_id) {
$personrow->home_location_id = $city_id;
} else {
$home_location_id = Location::verifyHierarchy($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers'));
if ($home_location_id) {
$personrow->home_location_id = $home_location_id;
}
}
//these are transitionary database fields, will go away soon
// $personrow->home_district_id = null;
// $personrow->home_province_id = null;
if (!$personrow->home_city) {
$personrow->home_city = '';
}
// bugfix, field cannot be null.
if ($this->getSanParam('active')) {
$personrow->active = 'active';
} else {
$personrow->active = 'inactive';
}
$personrow->birthdate = @$this->getSanParam('birth-year') . '-' . @$this->getSanParam('birth-month') . '-' . @$this->getSanParam('birth-day');
//lookup custom 1 and 2
if ($this->getSanParam('custom1Input')) {
$id = OptionList::insertIfNotFound('person_custom_1_option', 'custom1_phrase', $this->getSanParam('custom1Input'));
$personrow->person_custom_1_option_id = $id;
} else {
$personrow->person_custom_1_option_id = null;
}
示例4: locationAddAction
/**
* New training location
*/
public function locationAddAction()
{
require_once 'models/table/TrainingLocation.php';
require_once 'models/table/Location.php';
$request = $this->getRequest();
$validateOnly = $request->isXmlHttpRequest();
if ($validateOnly) {
$this->setNoRenderer();
}
if ($request->isPost()) {
$tableObj = new TrainingLocation();
$location = $this->_getParam('training_location_name');
list($location_params, $location_tier, $location_id) = $this->getLocationCriteriaValues(array());
//validate
$status = ValidationContainer::instance();
$districtText = $this->tr('Region B (Health District)');
$provinceText = $this->tr('Region A (Province)');
$localRegionText = $this->tr('Region C (Local Region)');
$regionDText = $this->tr('Region D');
$regionEText = $this->tr('Region E');
$regionFText = $this->tr('Region F');
$regionGText = $this->tr('Region G');
$regionHText = $this->tr('Region H');
$regionIText = $this->tr('Region I');
$status->checkRequired($this, 'province_id', $provinceText);
if ($this->setting('display_region_b')) {
$status->checkRequired($this, 'district_id', $districtText);
}
if ($this->setting('display_region_c')) {
$status->checkRequired($this, 'region_c_id', $localRegionText);
}
if ($this->setting('display_region_d')) {
$status->checkRequired($this, 'region_d_id', $regionDText);
}
if ($this->setting('display_region_e')) {
$status->checkRequired($this, 'region_e_id', $regionEText);
}
if ($this->setting('display_region_f')) {
$status->checkRequired($this, 'region_f_id', $regionFText);
}
if ($this->setting('display_region_g')) {
$status->checkRequired($this, 'region_g_id', $regionGText);
}
if ($this->setting('display_region_h')) {
$status->checkRequired($this, 'region_h_id', $regionHText);
}
if ($this->setting('display_region_i')) {
$status->checkRequired($this, 'region_i_id', $regionIText);
}
//$status->checkRequired ( $this, 'city', t ( "City is required." ) );
$city_id = false;
if ($this->getSanParam('city') && !$this->getSanParam('is_new_city')) {
$city_id = Location::verifyHierarchy($location_params['city'], $location_params['city_parent_id'], $this->setting('num_location_tiers'));
if ($city_id === false) {
$status->addError('city', t("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box."));
}
}
// save
if (!$status->hasError()) {
$location_id = null;
if ($city_id === false && $this->getSanParam('is_new_city')) {
$location_id = Location::insertIfNotFound($location_params['city'], $location_params['city_parent_id'], $this->setting('num_location_tiers'));
if ($location_id === false) {
$status->addError('city', t('Could not save that city.'));
}
} else {
if ($city_id) {
$location_id = $city_id;
} else {
if ($this->setting('display_region_i')) {
$location_id = $this->getSanParam('region_i_id');
} else {
if ($this->setting('display_region_h')) {
$location_id = $this->getSanParam('region_h_id');
} else {
if ($this->setting('display_region_g')) {
$location_id = $this->getSanParam('region_g_id');
} else {
if ($this->setting('display_region_f')) {
$location_id = $this->getSanParam('region_f_id');
} else {
if ($this->setting('display_region_e')) {
$location_id = $this->getSanParam('region_e_id');
} else {
if ($this->setting('display_region_d')) {
$location_id = $this->getSanParam('region_d_id');
} else {
if ($this->setting('display_region_c')) {
$location_id = $this->getSanParam('region_c_id');
} else {
if ($this->setting('display_region_b')) {
$location_id = $this->getSanParam('district_id');
} else {
$location_id = $this->getSanParam('province_id');
}
}
}
//.........这里部分代码省略.........
示例5: importLocationAction
/**
* Import a training location
*/
public function importLocationAction()
{
$this->view->assign('pageTitle', t('Import a training location'));
require_once 'models/table/Location.php';
require_once 'models/table/TrainingLocation.php';
// template redirect
if ($this->getSanParam('download')) {
return $this->importLocationTemplateAction();
}
if (!$this->hasACL('import_training_location')) {
$this->doNoAccessError();
}
//CSV STUFF
$filename = $_FILES['upload']['tmp_name'];
if ($filename) {
$trainingLocationObj = new TrainingLocation();
$errs = array();
while ($row = $this->_csv_get_row($filename)) {
$values = array();
if (!is_array($row)) {
continue;
}
// sanity?
if (!isset($cols)) {
// set headers (field names)
$cols = $row;
// first row is headers (field names)
continue;
}
$countValidFields = 0;
if (!empty($row)) {
// add
foreach ($row as $i => $v) {
// proccess each column
if (empty($v) && $v !== '0') {
continue;
}
if ($v == 'n/a') {
// has to be able to process values from a data export
$v = NULL;
}
$countValidFields++;
$delimiter = strpos($v, ',');
// is this field a comma seperated list too (or array)?
if ($delimiter && $v[$delimiter - 1] != '\\') {
// handle arrays as field values(Export), and comma seperated values(import manual entry), and strings or int
$values[$cols[$i]] = explode(',', $this->sanitize($v));
} else {
$values[$cols[$i]] = $this->sanitize($v);
}
}
}
// done now all fields are named and in $values['my_field']
if ($countValidFields) {
//validate
if (isset($values['uuid'])) {
unset($values['uuid']);
}
if (isset($values['id'])) {
unset($values['id']);
}
if (isset($values['is_deleted'])) {
unset($values['is_deleted']);
}
if (isset($values['created_by'])) {
unset($values['created_by']);
}
if (isset($values['modified_by'])) {
unset($values['modified_by']);
}
if (isset($values['timestamp_created'])) {
unset($values['timestamp_created']);
}
if (isset($values['timestamp_updated'])) {
unset($values['timestamp_updated']);
}
//required
if (empty($values['training_location_name'])) {
$errs[] = t('Error adding training location, training location name cannot be empty.');
}
//locations
$num_location_tiers = $this->setting('num_location_tiers');
$bSuccess = true;
$location_id = null;
if ($values['location_id']) {
$location_id = $values['location_id'];
}
$tier = 1;
if (!$location_id) {
for ($i = 0; $i <= $num_location_tiers; $i++) {
// insert/find locations
$r = 1 + $i;
// first location field in csv row // could use this too: $values[t('Region A (Province)')]
if (empty($row[$r]) || $bSuccess == false) {
continue;
}
$location_id = Location::insertIfNotFound($row[$r], $location_id, $tier);
//.........这里部分代码省略.........