本文整理匯總了PHP中data_entry_helper::wrap方法的典型用法代碼示例。如果您正苦於以下問題:PHP data_entry_helper::wrap方法的具體用法?PHP data_entry_helper::wrap怎麽用?PHP data_entry_helper::wrap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類data_entry_helper
的用法示例。
在下文中一共展示了data_entry_helper::wrap方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: wrap_species_checklist
/**
* Wraps data from a species checklist grid: modified from original data_entry_helper
* function to allow multiple rows for the same species.
*/
private static function wrap_species_checklist($arr, $include_if_any_data = false)
{
if (array_key_exists('website_id', $arr)) {
$website_id = $arr['website_id'];
} else {
throw new Exception('Cannot find website id in POST array!');
}
// Set the default method of looking for rows to include - either using data, or the checkbox (which could be hidden)
$include_if_any_data = $include_if_any_data || isset($arr['rowInclusionCheck']) && $arr['rowInclusionCheck'] == 'hasData';
// Species checklist entries take the following format
// sc:<taxa_taxon_list_id>:[<occurrence_id>|<sequence(negative)>]:occAttr:<occurrence_attribute_id>[:<occurrence_attribute_value_id>]
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:occurrence:comment
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:present
// not doing occurrence images at this point - TBD
$records = array();
$subModels = array();
foreach ($arr as $key => $value) {
if (substr($key, 0, 3) == 'sc:') {
// Don't explode the last element for occurrence attributes
$a = explode(':', $key, 4);
if ($a[2]) {
$pos = strpos($a[1], '_');
$records[$a[2]]['taxa_taxon_list_id'] = $pos === false ? $a[1] : substr($a[1], 0, $pos);
$records[$a[2]][$a[3]] = $value;
// store any id so update existing record
if (is_numeric($a[2])) {
$records[$a[2]]['id'] = $a[2];
}
}
}
}
foreach ($records as $id => $record) {
$present = self::wrap_species_checklist_record_present($record, $include_if_any_data);
if (array_key_exists('id', $record) || $present) {
// must always handle row if already present in the db
if (!$present) {
$record['deleted'] = 't';
}
$record['website_id'] = $website_id;
if (array_key_exists('occurrence:determiner_id', $arr)) {
$record['determiner_id'] = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$record['record_status'] = $arr['occurrence:record_status'];
}
$occ = data_entry_helper::wrap($record, 'occurrence');
$subModels[] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
return $subModels;
}
示例2: get_form
/**
* Return the Indicia form code.
* Expects there to be a sample attribute with caption 'Email' containing the email
* address.
* @param array $args Input parameters.
* @param array $node Drupal node object
* @param array $response Response from Indicia services after posting a verification.
* @return HTML string
*/
public static function get_form($args, $node, $response)
{
global $user, $indicia_templates;
// put each param control in a div, which makes it easier to layout with CSS
$indicia_templates['prefix'] = '<div id="container-{fieldname}" class="param-container">';
$indicia_templates['suffix'] = '</div>';
$indicia_user_id = self::get_indicia_user_id($args);
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
$r = '';
if ($_POST) {
// dump out any errors that occurred on verification
if (data_entry_helper::$validation_errors) {
$r .= '<div class="page-notice ui-state-highlight ui-corner-all"><p>' . implode('</p></p>', array_values(data_entry_helper::$validation_errors)) . '</p></div>';
} else {
if (isset($_POST['email']) && !isset($response['error'])) {
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $user->mail . PHP_EOL . "\r\n";
$headers .= 'Return-Path: ' . $user->mail . "\r\n";
if (isset($_POST['photoHTML'])) {
$emailBody = str_replace('[photo]', '<br/>' . $_POST['photoHTML'], $_POST['email_content']);
} else {
$emailBody = $_POST['email_content'];
}
$emailBody = str_replace("\n", "<br/>", $emailBody);
// Send email. Depends upon settings in php.ini being correct
$success = mail($_POST['email_to'], $_POST['email_subject'], wordwrap($emailBody, 70), $headers);
if ($success) {
$r .= '<div class="page-notice ui-state-highlight ui-corner-all"><p>An email was sent to ' . $_POST['email_to'] . '.</p></div>';
} else {
$r .= '<div class="page-notice ui-widget-content ui-corner-all ui-state-highlight left">The webserver is not correctly configured to send emails. Please send the following email manually: <br/>' . '<div id="manual-email"><span>To:</span><div>' . $_POST['email_to'] . '</div>' . '<span>Subject:</span><div>' . $_POST['email_subject'] . '</div>' . '<span>Content:</span><div>' . $emailBody . '</div>' . '</div></div><div style="clear: both">';
}
} else {
if (isset($_POST['occurrence:record_status']) && isset($response['success']) && $args['emails_enabled']) {
$r .= self::get_notification_email_form($args, $response, $auth);
}
}
}
if (isset($_POST['action']) && $_POST['action'] == 'send_to_verifier' && $args['log_send_to_verifier']) {
$comment = str_replace(array('%email%', '%date%', '%user%'), array($_POST['email_to'], date('jS F Y'), $user->name), $args['log_send_to_verifier_comment']);
} elseif (isset($_POST['action']) && ($_POST['action'] = 'general_comment')) {
$comment = $_POST['comment'];
}
// If there is a comment to save, add it to the occurrence comments
if (isset($comment)) {
// get our own write tokens for this submission, as the main ones are used in the JavaScript form.
$loggingAuth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
$sub = data_entry_helper::wrap(array('comment' => $comment, 'occurrence_id' => $_POST['occurrence:id'], 'created_by_id' => $indicia_user_id), 'occurrence_comment');
$logResponse = data_entry_helper::forward_post_to('occurrence_comment', $sub, $loggingAuth['write_tokens']);
if (!array_key_exists('success', $logResponse)) {
$r .= data_entry_helper::dump_errors($response, false);
}
}
}
//extract fixed parameters for report grid.
$params = explode(",", $args['fixed_params']);
foreach ($params as $param) {
$keyvals = explode("=", $param);
$key = trim($keyvals[0]);
$val = trim($keyvals[1]);
$extraParams[$key] = $val;
}
// plus defaults which are not fixed
$params = explode("\n", $args['param_defaults']);
foreach ($params as $param) {
$keyvals = explode("=", $param);
$key = trim($keyvals[0]);
$val = trim($keyvals[1]);
$paramDefaults[$key] = $val;
}
$actions = array();
if ($args['send_for_verification']) {
// store authorisation details as a global in js, since some of the JavaScript needs to be able to access Indicia data
data_entry_helper::$javascript .= 'auth=' . json_encode($auth) . ';';
$actions[] = array('caption' => str_replace(' ', ' ', lang::get('Send to verifier')), 'class' => 'send_for_verification_btn', 'javascript' => 'indicia_send_to_verifier(\'{taxon}\', {occurrence_id}, ' . $user->uid . ', ' . $args['website_id'] . '); return false;');
$r .= self::get_send_for_verification_form();
}
$actions[] = array('caption' => str_replace(' ', ' ', lang::get('Verify')), 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, true, ' . $user->uid . '); return false;');
$actions[] = array('caption' => str_replace(' ', ' ', lang::get('Reject')), 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, false, ' . $user->uid . '); return false;');
$actions[] = array('caption' => str_replace(' ', ' ', lang::get('Comments')), 'javascript' => 'indicia_comments(\'{taxon}\', {occurrence_id}, ' . $user->uid . ', \'' . $auth['read']['nonce'] . '\', \'' . $auth['read']['auth_token'] . '\'); return false;');
if (isset($args['path_to_record_details_page']) && $args['path_to_record_details_page']) {
$actions[] = array('caption' => str_replace(' ', ' ', lang::get('View details')), 'url' => '{rootFolder}' . $args['path_to_record_details_page'], 'urlParams' => array('occurrence_id' => '{occurrence_id}'));
}
// default columns behaviour is to just include anything returned by the report plus add an actions column
$columns = array(array('display' => 'Actions', 'actions' => $actions));
// this can be overridden
if (isset($args['columns_config']) && !empty($args['columns_config'])) {
$columns = array_merge(json_decode($args['columns_config'], true), $columns);
}
$r .= data_entry_helper::report_grid(array('id' => 'verification-grid', 'dataSource' => $args['report_name'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => $columns, 'rowId' => 'occurrence_id', 'itemsPerPage' => 10, 'autoParamsForm' => $args['auto_params_form'], 'extraParams' => $extraParams, 'paramDefaults' => $paramDefaults));
//.........這裏部分代碼省略.........
示例3: session_start
<?php
session_start();
require '../../../client_helpers/data_entry_helper.php';
require '../data_entry_config.php';
$base_url = helper_config::$base_url;
$readAuth = data_entry_helper::get_read_auth($config['website_id'], $config['password']);
// Store data from the previous page into the session
data_entry_helper::add_post_to_session();
// To post our data, we need to get the whole lot from the session
$data = data_entry_helper::extract_session_array();
// Collect up the sample, sample attributes and grid data
$sampleMod = data_entry_helper::wrap($data, 'sample');
$smpAttrs = data_entry_helper::wrap_attributes($data, 'sample');
$occurrences = data_entry_helper::wrap_species_checklist($data);
// Add the occurrences in as submodels
$sampleMod['subModels'] = $occurrences;
// and link in the attributes of the sample
$sampleMod['metaFields']['smpAttributes']['value'] = $smpAttrs;
// Wrap submission and submit
$submission = array('submission' => array('entries' => array(array('model' => $sampleMod))));
$response = data_entry_helper::forward_post_to('save', $submission);
if (array_key_exists('success', $response)) {
// on success, redirect to the thank you page
header('Location:success.php');
die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
示例4: wrap_species_checklist
/**
* Wraps data from a species checklist grid (generated by
* data_entry_helper::species_checklist) into a suitable format for submission. This will
* return an array of submodel entries which can be dropped directly into the subModel
* section of the submission array. If there is a field occurrence:determiner_id or
* occurrence:record_status in the main form data, then these values are applied to each
* occurrence created from the grid. For example, place a hidden field in the form named
* "occurrence:record_status" with a value "C" to set all occurrence records to completed
* as soon as they are entered.
*
* @param array $arr Array of data generated by data_entry_helper::species_checklist method.
* @param boolean $include_if_any_data If true, then any list entry which has any data
* set will be included in the submission. Set this to true when hiding the select checkbox
* in the grid.
*/
public static function wrap_species_checklist($arr, $include_if_any_data = false)
{
if (array_key_exists('website_id', $arr)) {
$website_id = $arr['website_id'];
} else {
throw new Exception('Cannot find website id in POST array!');
}
// determiner and record status can be defined globally for the whole list.
if (array_key_exists('occurrence:determiner_id', $arr)) {
$determiner_id = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$record_status = $arr['occurrence:record_status'];
}
// Species checklist entries take the following format
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:occAttr:<occurrence_attribute_id>[:<occurrence_attribute_value_id>]
// or
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:occurrence:comment
// or
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:occurrence_image:fieldname:uniqueImageId
$records = array();
$subModels = array();
foreach ($arr as $key => $value) {
if (substr($key, 0, 3) == 'sc:') {
// Don't explode the last element for occurrence attributes
$a = explode(':', $key, 4);
$records[$a[1]][$a[3]] = $value;
// store any id so update existing record
if ($a[2]) {
$records[$a[1]]['id'] = $a[2];
}
}
}
foreach ($records as $id => $record) {
if (array_key_exists('present', $record) || array_key_exists('id', $record) || $include_if_any_data && implode('', $record) != '') {
if (array_key_exists('id', $record) && array_key_exists('control:checkbox', $arr) && !array_key_exists('present', $record)) {
// checkboxes do not appear if not checked. If uncheck, delete record.
$record['deleted'] = 't';
}
$record['taxa_taxon_list_id'] = $id;
$record['website_id'] = $website_id;
if (isset($determiner_id)) {
$record['determiner_id'] = $determiner_id;
}
if (isset($record_status)) {
$record['record_status'] = $record_status;
}
$occAttrs = data_entry_helper::wrap_attributes($record, 'occurrence');
$occ = data_entry_helper::wrap($record, 'occurrence');
$occ['metaFields']['occAttributes']['value'] = $occAttrs;
self::attachOccurrenceImagesToModel($occ, $record);
$subModels[] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
return $subModels;
}
示例5: wrap_species_checklist_with_subsamples
/**
* Wraps data from a species checklist grid with subsamples (generated by
* data_entry_helper::species_checklist) into a suitable format for submission. This will
* return an array of submodel entries which can be dropped directly into the subModel
* section of the submission array. If there is a field occurrence:determiner_id or
* occurrence:record_status in the main form data, then these values are applied to each
* occurrence created from the grid. For example, place a hidden field in the form named
* "occurrence:record_status" with a value "C" to set all occurrence records to completed
* as soon as they are entered.
*
* @param array $arr Array of data generated by data_entry_helper::species_checklist method.
* @param boolean $include_if_any_data If true, then any list entry which has any data
* set will be included in the submission. This defaults to false, unless the grid was
* created with rowInclusionCheck=hasData in the grid options.
* @param array $zero_attrs Set to an array of abundance attribute field IDs that can be
* treated as abundances. Alternatively set to true to treat all occurrence custom attributes
* as possible zero abundance indicators.
* @param array $zero_values Set to an array of values which are considered to indicate a
* zero abundance record if found for one of the zero_attrs. Values are case-insensitive. Defaults to
* array('0','None','Absent').
* @param array Array of grid ids to ignore when building sub-samples for occurrences, useful for creating
* customised submissions that only need to build sub-samples for some grids. The grid id comes from the @id option given
* to the species grid.
*/
public static function wrap_species_checklist_with_subsamples($arr, $include_if_any_data = false, $zero_attrs = true, $zero_values = array('0', 'None', 'Absent'), $gridsToExclude = array())
{
if (array_key_exists('website_id', $arr)) {
$website_id = $arr['website_id'];
} else {
throw new Exception('Cannot find website id in POST array!');
}
// determiner and record status can be defined globally for the whole list.
if (array_key_exists('occurrence:determiner_id', $arr)) {
$determiner_id = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$record_status = $arr['occurrence:record_status'];
}
// Set the default method of looking for rows to include - either using data, or the checkbox (which could be hidden)
$include_if_any_data = $include_if_any_data || isset($arr['rowInclusionCheck']) && $arr['rowInclusionCheck'] == 'hasData';
// Species checklist entries take the following format.
// sc:<subsampleIndex>:[<sample_id>]:sample:deleted
// sc:<subsampleIndex>:[<sample_id>]:sample:geom
// sc:<subsampleIndex>:[<sample_id>]:sample:entered_sref
// sc:<subsampleIndex>:[<sample_id>]:smpAttr:[<sample_attribute_id>]
// sc:<rowIndex>:[<occurrence_id>]:occurrence:sampleIDX (val set to subsample index)
// sc:<rowIndex>:[<occurrence_id>]:present (checkbox with val set to ttl_id
// sc:<rowIndex>:[<occurrence_id>]:occAttr:<occurrence_attribute_id>[:<occurrence_attribute_value_id>]
// sc:<rowIndex>:[<occurrence_id>]:occurrence:comment
// sc:<rowIndex>:[<occurrence_id>]:occurrence_medium:fieldname:uniqueImageId
$occurrenceRecords = array();
$sampleRecords = array();
$subModels = array();
foreach ($arr as $key => $value) {
$gridExcluded = false;
foreach ($gridsToExclude as $gridToExclude) {
if (substr($key, 0, strlen($gridToExclude) + 3) == 'sc:' . $gridToExclude) {
$gridExcluded = true;
}
}
if ($gridExcluded === false && substr($key, 0, 3) == 'sc:' && substr($key, 2, 7) != ':-idx-:' && substr($key, 2, 3) != ':n:') {
//discard the hidden cloneable rows
// Don't explode the last element for occurrence attributes
$a = explode(':', $key, 4);
$b = explode(':', $a[3], 2);
if ($b[0] == "sample" || $b[0] == "smpAttr") {
$sampleRecords[$a[1]][$a[3]] = $value;
if ($a[2]) {
$sampleRecords[$a[1]]['id'] = $a[2];
}
} else {
$occurrenceRecords[$a[1]][$a[3]] = $value;
if ($a[2]) {
$occurrenceRecords[$a[1]]['id'] = $a[2];
}
}
}
}
foreach ($sampleRecords as $id => $sampleRecord) {
$sampleRecords[$id]['occurrences'] = array();
}
foreach ($occurrenceRecords as $id => $record) {
$sampleIDX = $record['occurrence:sampleIDX'];
unset($record['occurrence:sampleIDX']);
$present = self::wrap_species_checklist_record_present($record, $include_if_any_data, $zero_attrs, $zero_values, array());
if (array_key_exists('id', $record) || $present !== null) {
// must always handle row if already present in the db
if ($present === null) {
// checkboxes do not appear if not checked. If uncheck, delete record.
$record['deleted'] = 't';
} else {
$record['zero_abundance'] = $present ? 'f' : 't';
}
$record['taxa_taxon_list_id'] = $record['present'];
$record['website_id'] = $website_id;
if (isset($determiner_id)) {
$record['determiner_id'] = $determiner_id;
}
if (isset($record_status)) {
$record['record_status'] = $record_status;
//.........這裏部分代碼省略.........
示例6: get_submission
/**
* Handles the construction of a submission array from a set of form values.
* @param array $values Associative array of form data values.
* @param array $args iform parameters.
* @return array Submission structure.
*/
public static function get_submission($values, $args)
{
$subsampleModels = array();
$read = array('nonce' => $values['read_nonce'], 'auth_token' => $values['read_auth_token']);
if (!isset($values['page']) || $values['page'] == 'site') {
// submitting the first page, with top level sample details
// keep the first count date on a subsample for use later.
// only create if a new sample: if existing, then this will already exist.
if (isset($values['C1:sample:date']) && !isset($values['sample:id'])) {
$sampleMethods = helper_base::get_termlist_terms(array('read' => $read), 'indicia:sample_methods', array('Timed Count Count'));
$smp = array('fkId' => 'parent_id', 'model' => array('id' => 'sample', 'fields' => array('survey_id' => array('value' => $values['sample:survey_id']), 'website_id' => array('value' => $values['website_id']), 'date' => array('value' => $values['C1:sample:date']), 'sample_method_id' => array('value' => $sampleMethods[0]['id']))), 'copyFields' => array('entered_sref' => 'entered_sref', 'entered_sref_system' => 'entered_sref_system'));
// 'copyFields' => array('date_start'=>'date_start','date_end'=>'date_end','date_type'=>'date_type'));
$subsampleModels[] = $smp;
}
} else {
if ($values['page'] == 'occurrences') {
// at this point there is a parent supersample.
// loop from 1 to numberOfCounts, or number of existing subsamples, whichever is bigger.
$subSamples = data_entry_helper::get_population_data(array('table' => 'sample', 'extraParams' => $read + array('parent_id' => $values['sample:id']), 'nocache' => true));
for ($i = 1; $i <= max(count($subSamples), $args['numberOfCounts']); $i++) {
if (isset($values['C' . $i . ':sample:id']) || isset($values['C' . $i . ':sample:date']) && $values['C' . $i . ':sample:date'] != '') {
$subSample = array('website_id' => $values['website_id'], 'survey_id' => $values['sample:survey_id']);
$occurrences = array();
$occModels = array();
foreach ($values as $field => $value) {
$parts = explode(':', $field, 2);
if ($parts[0] == 'C' . $i) {
$subSample[$parts[1]] = $value;
}
if ($parts[0] == 'O' . $i) {
$occurrences[$parts[1]] = $value;
}
}
ksort($occurrences);
foreach ($occurrences as $field => $value) {
// have take off O<i> do is now <j>:<ttlid>:<occid>:<attrid>:<attrvalid> - sorted in <j> order
$parts = explode(':', $field);
$occurrence = array('website_id' => $values['website_id']);
if ($parts[1] != '--ttlid--') {
$occurrence['taxa_taxon_list_id'] = $parts[1];
}
if ($parts[2] != '--occid--') {
$occurrence['id'] = $parts[2];
}
if ($value == '') {
$occurrence['deleted'] = 't';
} else {
if ($parts[4] == '--valid--') {
$occurrence['occAttr:' . $parts[3]] = $value;
} else {
$occurrence['occAttr:' . $parts[3] . ':' . $parts[4]] = $value;
}
}
if (array_key_exists('occurrence:determiner_id', $values)) {
$occurrence['determiner_id'] = $values['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $values)) {
$occurrence['record_status'] = $values['occurrence:record_status'];
}
if (isset($occurrence['id']) || !isset($occurrence['deleted'])) {
$occ = data_entry_helper::wrap($occurrence, 'occurrence');
$occModels[] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
$smp = array('fkId' => 'parent_id', 'model' => data_entry_helper::wrap($subSample, 'sample'), 'copyFields' => array('entered_sref' => 'entered_sref', 'entered_sref_system' => 'entered_sref_system'));
// from parent->to child
if (!isset($subSample['sample:deleted']) && count($occModels) > 0) {
$smp['model']['subModels'] = $occModels;
}
$subsampleModels[] = $smp;
}
}
}
}
$sampleMod = submission_builder::build_submission($values, array('model' => 'sample'));
if (count($subsampleModels) > 0) {
$sampleMod['subModels'] = $subsampleModels;
}
return $sampleMod;
}
示例7: get_form
//.........這裏部分代碼省略.........
$parts = explode(':', $key);
if ($parts[0] == 'location' && $value) {
iform_loctools_insertlocation($node, $value, $parts[1]);
}
}
}
}
} else {
if (array_key_exists('merge_sample_id1', $_GET) && array_key_exists('merge_sample_id2', $_GET) && user_access($args['edit_permission'])) {
$mode = 2;
// first check can access the 2 samples given
$parentLoadID = $_GET['merge_sample_id1'];
$url = $svcUrl . '/data/sample/' . $parentLoadID . "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"];
$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$entity = json_decode(curl_exec($session), true);
if (count($entity) == 0 || $entity[0]["parent_id"]) {
return '<p>' . lang::get('LANG_No_Access_To_Sample') . ' ' . $parentLoadID . '</p>';
}
// The check for id2 is slightly different: there is the possiblity that someone will F5/refresh their browser, after the transfer and delete have taken place.
// In this case we carry on, but do not do the transfer and delete.
$url = $svcUrl . '/data/sample/' . $_GET['merge_sample_id2'] . "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"];
$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$entity = json_decode(curl_exec($session), true);
if (count($entity) > 0 && !$entity[0]["parent_id"]) {
// now get child samples and point to new parent.
$url = $svcUrl . '/data/sample?mode=json&view=detail&auth_token=' . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . '&parent_id=' . $_GET['merge_sample_id2'];
$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$entities = json_decode(curl_exec($session), true);
if (count($entities) > 0) {
foreach ($entities as $entity) {
$Model = data_entry_helper::wrap(array('id' => $entity['id'], 'parent_id' => $_GET['merge_sample_id1']), 'sample');
$request = data_entry_helper::$base_url . "/index.php/services/data/save";
$postargs = 'submission=' . json_encode($Model) . '&auth_token=' . $auth['write_tokens']['auth_token'] . '&nonce=' . $auth['write_tokens']['nonce'] . '&persist_auth=true';
$postresponse = data_entry_helper::http_post($request, $postargs, false);
// the response array will always feature an output, which is the actual response or error message. if it is not json format, assume error text, and json encode that.
$response = $postresponse['output'];
if (!json_decode($response, true)) {
return "<p>" . lang::get('LANG_Error_When_Moving_Sample') . ": id " . $entity['id'] . " : " . $response;
}
}
}
// finally delete the no longer used sample
$Model = data_entry_helper::wrap(array('id' => $_GET['merge_sample_id2'], 'deleted' => 'true'), 'sample');
$request = data_entry_helper::$base_url . "/index.php/services/data/save";
$postargs = 'submission=' . json_encode($Model) . '&auth_token=' . $auth['write_tokens']['auth_token'] . '&nonce=' . $auth['write_tokens']['nonce'] . '&persist_auth=true';
$postresponse = data_entry_helper::http_post($request, $postargs, false);
// the response array will always feature an output, which is the actual response or error message. if it is not json format, assume error text, and json encode that.
$response = $postresponse['output'];
if (!json_decode($response, true)) {
return "<p>" . lang::get('LANG_Error_When_Deleting_Sample') . ": id " . $entity['id'] . " : " . $response;
}
}
} else {
if (array_key_exists('sample_id', $_GET)) {
$mode = 2;
$parentLoadID = $_GET['sample_id'];
} else {
if (array_key_exists('occurrence_id', $_GET)) {
$mode = 3;
$childLoadID = $_GET['occurrence_id'];
$thisOccID = $childLoadID;
} else {
if (array_key_exists('new', $_GET)) {
示例8: wrap_species_checklist_with_subsamples
public static function wrap_species_checklist_with_subsamples($arr, $section_id_attribute, $subsites, $subSampleIds, $include_if_any_data = false, $zero_attrs = true, $zero_values = array('0', 'None', 'Absent'))
{
if (array_key_exists('website_id', $arr)) {
$website_id = $arr['website_id'];
} else {
throw new Exception('Cannot find website id in POST array!');
}
// determiner and record status can be defined globally for the whole list.
if (array_key_exists('occurrence:determiner_id', $arr)) {
$determiner_id = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$record_status = $arr['occurrence:record_status'];
}
// Set the default method of looking for rows to include - either using data, or the checkbox (which could be hidden)
$include_if_any_data = $include_if_any_data || isset($arr['rowInclusionCheck']) && $arr['rowInclusionCheck'] == 'hasData';
// Species checklist entries take the following format.
// sc:<subsampleIndex>:[<sample_id>]:sample:deleted
// sc:<subsampleIndex>:[<sample_id>]:sample:geom
// sc:<subsampleIndex>:[<sample_id>]:sample:entered_sref
// sc:<subsampleIndex>:[<sample_id>]:smpAttr:[<sample_attribute_id>]
// sc:<rowIndex>:[<occurrence_id>]:occurrence:sampleIDX (val set to subsample index)
// sc:<rowIndex>:[<occurrence_id>]:present (checkbox with val set to ttl_id
// sc:<rowIndex>:[<occurrence_id>]:occAttr:<occurrence_attribute_id>[:<occurrence_attribute_value_id>]
// sc:<rowIndex>:[<occurrence_id>]:occurrence:comment
// sc:<rowIndex>:[<occurrence_id>]:occurrence_medium:fieldname:uniqueImageId
$occurrenceRecords = array();
$sampleRecords = array();
$subModels = array();
foreach ($arr as $key => $value) {
if (substr($key, 0, 3) == 'sc:' && substr($key, 2, 7) != ':-idx-:' && substr($key, 2, 3) != ':n:') {
//discard the hidden cloneable rows
// Don't explode the last element for occurrence attributes
$a = explode(':', $key, 4);
$b = explode(':', $a[3], 3);
if ($value && count($b) >= 2) {
if ($b[0] == "occAttr" && $b[1] == $section_id_attribute) {
if (!isset($sampleRecords['smp' . $value])) {
$sampleRecords['smp' . $value] = array();
}
$occurrenceRecords[$a[1]]['sectionIdVal'] = $value;
}
}
$occurrenceRecords[$a[1]][$a[3]] = $value;
if ($a[2]) {
$occurrenceRecords[$a[1]]['id'] = $a[2];
}
}
}
foreach ($occurrenceRecords as $record) {
$present = !empty($record['present']);
if (array_key_exists('id', $record) || $present) {
// must always handle row if already present in the db
if (!$present) {
// checkboxes do not appear if not checked. If uncheck, delete record.
$record['deleted'] = 't';
}
$record['zero_abundance'] = self::recordZeroAbundance($record, $section_id_attribute);
$record['taxa_taxon_list_id'] = $record['present'];
$record['website_id'] = $website_id;
if (isset($determiner_id)) {
$record['determiner_id'] = $determiner_id;
}
if (isset($record_status)) {
$record['record_status'] = $record_status;
}
$occ = data_entry_helper::wrap($record, 'occurrence');
// At this point, a deleted record only has present=0 and an id. No link to the sample since our section ID field has been
// disabled. So we need to use the subSampleIds data to work out the original site ID and link via that.
if (isset($record['sectionIdVal'])) {
$sectionId = $record['sectionIdVal'];
} else {
$orderedSubSites = array_keys($subSampleIds);
$sectionId = $orderedSubSites[$record['occurrence:sampleIDX']];
}
$sampleRecords["smp{$sectionId}"]['occurrences'][] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
// convert subsites to a keyed array, for easier lookup
$keyedSS = array();
foreach ($subsites as $ss) {
$keyedSS["ss{$ss['id']}"] = $ss;
}
foreach ($sampleRecords as $id => $sampleRecord) {
$idx = preg_replace('/^smp/', '', $id);
$subsite = $keyedSS["ss{$idx}"];
$occs = $sampleRecord['occurrences'];
unset($sampleRecord['occurrences']);
$sampleRecord['website_id'] = $website_id;
// copy essentials down to each subsample
if (!empty($arr['survey_id'])) {
$sampleRecord['survey_id'] = $arr['survey_id'];
}
if (!empty($arr['sample:date'])) {
$sampleRecord['date'] = $arr['sample:date'];
}
if (!empty($arr['subsample:sample_method_id'])) {
$sampleRecord['sample_method_id'] = $arr['subsample:sample_method_id'];
}
$sampleRecord['entered_sref'] = $subsite['centroid_sref'];
//.........這裏部分代碼省略.........
開發者ID:joewoodhouse,項目名稱:client_helpers,代碼行數:101,代碼來源:dynamic_transect_sections_sample_occurrence.php
示例9: wrap_species_checklist
/**
* Wraps data from a species checklist grid: modified from original data_entry_helper
* function to allow multiple rows for the same species, plus linking to survey method
*/
private static function wrap_species_checklist($arr, $method)
{
if (array_key_exists('website_id', $arr)) {
$website_id = $arr['website_id'];
} else {
throw new Exception('Cannot find website id in POST array!');
}
// occurrences are included dependant on the present field... If present is
// Species checklist entries take the following format
// sc:<method-meaning-id>:<taxa_taxon_list_id>:[<occurrence_id>|<sequence(negative)>]:occAttr:<occurrence_attribute_id>[:<occurrence_attribute_value_id>]
// sc:<method-meaning-id>:<taxa_taxon_list_id>:[<occurrence_id>|<sequence(negative)>]:present
// not doing occurrence images at this point - TBD
$records = array();
$subModels = array();
foreach ($arr as $key => $value) {
if (substr($key, 0, 3) == 'sc:') {
// Don't explode the last element for occurrence attributes
$a = explode(':', $key, 5);
if ($a[3] && $a[1] == $method) {
if (!array_key_exists($a[3], $records)) {
$records[$a[3]]['taxa_taxon_list_id'] = $a[2];
if (is_numeric($a[3]) && $a[3] > 0) {
$records[$a[3]]['id'] = $a[3];
}
}
$records[$a[3]][$a[4]] = $value;
// does attrs and present field
}
}
}
foreach ($records as $id => $record) {
$present = self::wrap_species_checklist_record_present($record);
if (array_key_exists('id', $record) || $present) {
// must always handle row if already present in the db
if (!$present) {
$record['deleted'] = 't';
}
$record['website_id'] = $website_id;
if (array_key_exists('occurrence:determiner_id', $arr)) {
$record['determiner_id'] = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$record['record_status'] = $arr['occurrence:record_status'];
}
$occ = data_entry_helper::wrap($record, 'occurrence');
$subModels[] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
return $subModels;
}
示例10: wrap_species_checklist_with_third_level_samples
/**
* Based on wrap_species_checklist_with_third_level_samples in data_entry_helper.
* Altered for Seasearch as it needs to understand there is a third level of samples. There is one third level sample for each occurrence to hold its spatial reference.
*/
private static function wrap_species_checklist_with_third_level_samples($arr, $include_if_any_data = false, $zero_attrs = true, $zero_values = array('0', 'None', 'Absent'), $gridsToExclude = array())
{
if (array_key_exists('website_id', $arr)) {
$website_id = $arr['website_id'];
} else {
throw new Exception('Cannot find website id in POST array!');
}
// determiner and record status can be defined globally for the whole list.
if (array_key_exists('occurrence:determiner_id', $arr)) {
$determiner_id = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$record_status = $arr['occurrence:record_status'];
}
// Set the default method of looking for rows to include - either using data, or the checkbox (which could be hidden)
$include_if_any_data = $include_if_any_data || isset($arr['rowInclusionCheck']) && $arr['rowInclusionCheck'] == 'hasData';
$occurrenceRecords = array();
$sampleRecord = array();
$sampleRecords = array();
$subModels = array();
foreach ($arr as $key => $value) {
$gridExcluded = false;
foreach ($gridsToExclude as $gridToExclude) {
if (substr($key, 0, strlen($gridToExclude) + 3) == 'sc:' . $gridToExclude) {
$gridExcluded = true;
}
}
//Only look at rows on occurrences grid excluding the clonable row
if ($gridExcluded === false && strpos($key, 'sc:') !== false && strpos($key, '-idx-') === false) {
//discard the hidden cloneable rows
// Don't explode the last element for occurrence attributes
$a = explode(':', $key, 4);
$b = explode(':', $a[3], 2);
//At this stage we just collected all the information to create a general sample which
//can be duplicated for each occurrence. This sample is then altered later in submission to set things like entered_sref.
if ($b[0] == "sample" || $b[0] == "smpAttr") {
$sampleRecord[$a[1]][$a[3]] = $value;
} else {
//Make a list of occurrences
$occurrenceRecords[$a[1]][$a[3]] = $value;
}
}
}
$sampleRecords = array();
foreach ($occurrenceRecords as $id => $record) {
$present = data_entry_helper::wrap_species_checklist_record_present($record, $include_if_any_data, $zero_attrs, $zero_values, array());
if (array_key_exists('id', $record) || $present !== null) {
// must always handle row if already present in the db
if ($present === null) {
// checkboxes do not appear if not checked. If uncheck, delete record.
$record['deleted'] = 't';
} else {
$record['zero_abundance'] = $present ? 'f' : 't';
}
$record['taxa_taxon_list_id'] = $record['present'];
$record['website_id'] = $website_id;
if (isset($determiner_id)) {
$record['determiner_id'] = $determiner_id;
}
if (isset($record_status)) {
$record['record_status'] = $record_status;
}
$occ = data_entry_helper::wrap($record, 'occurrence');
data_entry_helper::attachOccurrenceMediaToModel($occ, $record);
//Duplicate the general sample record for each occurrence, these are then altered later in submission specifically for the occurrence
$sampleRecords[] = $sampleRecord;
//Added the occurrence to the sample
$sampleRecords[count($sampleRecords) - 1]['occurrences'] = array();
$sampleRecords[count($sampleRecords) - 1]['occurrences'][] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
foreach ($sampleRecords as $id => $sampleRecord) {
$occs = $sampleRecord['occurrences'];
unset($sampleRecord['occurrences']);
$sampleRecord['website_id'] = $website_id;
// copy essentials down to each subsample
if (!empty($arr['survey_id'])) {
$sampleRecord['survey_id'] = $arr['survey_id'];
}
if (!empty($arr['sample:date'])) {
$sampleRecord['date'] = $arr['sample:date'];
}
if (!empty($arr['sample:entered_sref_system'])) {
$sampleRecord['entered_sref_system'] = $arr['sample:entered_sref_system'];
}
if (!empty($arr['sample:location_name']) && empty($sampleRecord['location_name'])) {
$sampleRecord['location_name'] = $arr['sample:location_name'];
}
if (!empty($arr['sample:input_form'])) {
$sampleRecord['input_form'] = $arr['sample:input_form'];
}
$subSample = data_entry_helper::wrap($sampleRecord, 'sample');
// Add the subsample/soccurrences in as subModels without overwriting others such as a sample image
if (array_key_exists('subModels', $subSample)) {
$subSample['subModels'] = array_merge($sampleMod['subModels'], $occs);
} else {
//.........這裏部分代碼省略.........
示例11: wrap_species_checklist
/**
* Wraps data from a species checklist grid: modified from original data_entry_helper
* function to allow multiple rows for the same species.
*/
private static function wrap_species_checklist($arr)
{
if (!array_key_exists('website_id', $arr)) {
throw new Exception('Cannot find website id in POST array!');
}
// not doing occurrence images at this point - TBD
$samples = array();
$occurrences = array();
foreach ($arr as $key => $value) {
// Don't explode the last element for attributes
$a = explode(':', $key, 6);
// sc:--GroupID--:--SampleID--:--TTLID--:--OccurrenceID--
if ($a[0] == 'sc' && $a[1] != '' && $a[1] != '--GroupID--') {
$b = explode(':', $a[5]);
if ($a[1]) {
// key on the Group ID
$occurrences[$a[1]]['taxa_taxon_list_id'] = $a[3];
if ($b[0] == 'sample' || $b[0] == 'smpAttr') {
$samples[$a[1]][$a[5]] = $value;
} else {
// for a multiple entry checkbox group, need to remove the sc:--GroupID--:--SampleID--:--TTLID--:--OccurrenceID-- to give value:occAttr:value[:value]
$newvalue = $value;
if (is_array($value)) {
$newvalue = array();
foreach ($value as $X) {
$tokens = explode(':', $X, 7);
$newvalue[] = count($tokens) == 7 ? $tokens[0] . ':' . $tokens[6] : $X;
}
}
$occurrences[$a[1]][$a[5]] = $newvalue;
}
// store any id so update existing record prefix
if (is_numeric($a[2]) && $a[2] > 0) {
$samples[$a[1]]['id'] = $a[2];
}
if (is_numeric($a[4]) && $a[4] > 0) {
$occurrences[$a[1]]['id'] = $a[4];
}
}
}
}
$subModels = array();
foreach ($occurrences as $id => $occurrence) {
$present = self::wrap_species_checklist_record_present($occurrence);
if (array_key_exists('id', $occurrence) || $present) {
// must always handle row if already present in the db
if (!$present) {
$occurrence['deleted'] = 't';
}
$occurrence['website_id'] = $arr['website_id'];
if (array_key_exists('occurrence:determiner_id', $arr)) {
$occurrence['determiner_id'] = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$occurrence['record_status'] = $arr['occurrence:record_status'];
}
$occ = data_entry_helper::wrap($occurrence, 'occurrence');
if (isset($arr['includeSubSample'])) {
if (!$present) {
$samples[$id]['deleted'] = 't';
}
$samples[$id]['website_id'] = $arr['website_id'];
$samples[$id]['entered_sref_system'] = '2169';
// TBD
$samples[$id]['survey_id'] = $arr['survey_id'];
$smp = data_entry_helper::wrap($samples[$id], 'sample');
$smp['subModels'] = array(array('fkId' => 'sample_id', 'model' => $occ));
$smp = array('fkId' => 'parent_id', 'model' => $smp);
if (!isset($samples[$id]['date'])) {
$smp['copyFields'] = array('date_start' => 'date_start', 'date_end' => 'date_end', 'date_type' => 'date_type');
}
// from parent->to child
$subModels[] = $smp;
} else {
$subModels[] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
}
return $subModels;
}
示例12: wrap_species_checklist
/**
* Wraps data from a species checklist grid (generated by
* data_entry_helper::species_checklist) into a suitable format for submission. This will
* return an array of submodel entries which can be dropped directly into the subModel
* section of the submission array. If there is a field occurrence:determiner_id or
* occurrence:record_status in the main form data, then these values are applied to each
* occurrence created from the grid. For example, place a hidden field in the form named
* "occurrence:record_status" with a value "C" to set all occurrence records to completed
* as soon as they are entered.
*
* @param array $arr Array of data generated by data_entry_helper::species_checklist method.
* @param boolean $include_if_any_data If true, then any list entry which has any data
* set will be included in the submission. This defaults to false, unless the grid was
* created with rowInclusionCheck=hasData.
* in the grid.
*/
public static function wrap_species_checklist($arr, $include_if_any_data = false)
{
if (array_key_exists('website_id', $arr)) {
$website_id = $arr['website_id'];
} else {
throw new Exception('Cannot find website id in POST array!');
}
// determiner and record status can be defined globally for the whole list.
if (array_key_exists('occurrence:determiner_id', $arr)) {
$determiner_id = $arr['occurrence:determiner_id'];
}
if (array_key_exists('occurrence:record_status', $arr)) {
$record_status = $arr['occurrence:record_status'];
}
// Set the default method of looking for rows to include - either using data, or the checkbox (which could be hidden)
$include_if_any_data = $include_if_any_data || isset($arr['rowInclusionCheck']) && $arr['rowInclusionCheck'] == 'hasData';
// Species checklist entries take the following format
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:occAttr:<occurrence_attribute_id>[:<occurrence_attribute_value_id>]
// or
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:occurrence:comment
// or
// sc:<taxa_taxon_list_id>:[<occurrence_id>]:occurrence_image:fieldname:uniqueImageId
$records = array();
$subModels = array();
foreach ($arr as $key => $value) {
if (substr($key, 0, 3) == 'sc:') {
// Don't explode the last element for occurrence attributes
$a = explode(':', $key, 4);
$records[$a[1]][$a[3]] = $value;
// store any id so update existing record
if ($a[2]) {
$records[$a[1]]['id'] = $a[2];
}
}
}
foreach ($records as $id => $record) {
$present = self::wrap_species_checklist_record_present($record, $include_if_any_data);
if (array_key_exists('id', $record) || $present) {
// must always handle row if already present in the db
if (!$present) {
// checkboxes do not appear if not checked. If uncheck, delete record.
$record['deleted'] = 't';
}
$record['taxa_taxon_list_id'] = $id;
$record['website_id'] = $website_id;
if (isset($determiner_id)) {
$record['determiner_id'] = $determiner_id;
}
if (isset($record_status)) {
$record['record_status'] = $record_status;
}
$occ = data_entry_helper::wrap($record, 'occurrence');
self::attachOccurrenceImagesToModel($occ, $record);
$subModels[] = array('fkId' => 'sample_id', 'model' => $occ);
}
}
return $subModels;
}