本文整理汇总了PHP中okapi\Db::field_exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::field_exists方法的具体用法?PHP Db::field_exists怎么用?PHP Db::field_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类okapi\Db
的用法示例。
在下文中一共展示了Db::field_exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _call
//.........这里部分代码省略.........
# If we're here, then we also know that the "Needs maintenance" log type is supported
# by this OC site. However, it's a separate log type, so we might have to submit
# two log types together:
if ($logtype == 'Comment') {
# If user submits a "Comment", we'll just change its type to "Needs maintenance".
# Only one log entry will be issued.
$logtype = 'Needs maintenance';
$second_logtype = null;
$second_formatted_comment = null;
} elseif ($logtype == 'Found it') {
# If "Found it", then we'll issue two log entries: one "Found it" with the
# original comment, and second one "Needs maintenance" with empty comment.
$second_logtype = 'Needs maintenance';
$second_formatted_comment = "";
} elseif ($logtype == "Didn't find it") {
# If "Didn't find it", then we'll issue two log entries, but this time
# we'll do this the other way around. The first "Didn't find it" entry
# will have an empty comment. We will move the comment to the second
# "Needs maintenance" log entry. (It's okay for this behavior to change
# in the future, but it seems natural to me.)
$second_logtype = 'Needs maintenance';
$second_formatted_comment = $formatted_comment;
$formatted_comment = "";
} else {
if ($logtype == 'Will attend' || $logtype == 'Attended') {
# OC branches which know maintenance logs do not allow them on event caches.
throw new CannotPublishException(_("Event caches cannot \"need maintenance\"."));
} else {
throw new Exception();
}
}
} else {
# User didn't check the "Needs maintenance" flag OR "Needs maintenance" log type
# isn't supported by this server.
$second_logtype = null;
$second_formatted_comment = null;
}
# Finally! Insert the rows into the log entries table. Update
# cache stats and user stats.
$log_uuid = self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $logtype, $when, $formatted_comment, $value_for_text_html_field);
self::increment_cache_stats($cache['internal_id'], $when, $logtype);
self::increment_user_stats($user['internal_id'], $logtype);
if ($second_logtype != null) {
# Reminder: This will never be called while SUPPORTS_LOGTYPE_NEEDS_MAINTENANCE is off.
self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $second_logtype, $when + 1, $second_formatted_comment, $value_for_text_html_field);
self::increment_cache_stats($cache['internal_id'], $when + 1, $second_logtype);
self::increment_user_stats($user['internal_id'], $second_logtype);
}
# Save the rating.
if ($rating) {
# This code will be called for OCPL branch only. Earlier, we made sure,
# to set $rating to null, if we're running on OCDE.
# OCPL has a little strange way of storing cumulative rating. Instead
# of storing the sum of all ratings, OCPL stores the computed average
# and update it using multiple floating-point operations. Moreover,
# the "score" field in the database is on the -3..3 scale (NOT 1..5),
# and the translation made at retrieval time is DIFFERENT than the
# one made here (both of them are non-linear). Also, once submitted,
# the rating can never be changed. It surely feels quite inconsistent,
# but presumably has some deep logic into it. See also here (Polish):
# http://wiki.opencaching.pl/index.php/Oceny_skrzynek
switch ($rating) {
case 1:
$db_score = -2.0;
break;
case 2:
$db_score = -0.5;
break;
case 3:
$db_score = 0.7;
break;
case 4:
$db_score = 1.7;
break;
case 5:
$db_score = 3.0;
break;
default:
throw new Exception();
}
Db::execute("\n update caches\n set\n score = (score*votes + '" . mysql_real_escape_string($db_score) . "')/(votes + 1),\n votes = votes + 1\n where cache_id = '" . mysql_real_escape_string($cache['internal_id']) . "'\n ");
Db::execute("\n insert into scores (user_id, cache_id, score)\n values (\n '" . mysql_real_escape_string($user['internal_id']) . "',\n '" . mysql_real_escape_string($cache['internal_id']) . "',\n '" . mysql_real_escape_string($db_score) . "'\n );\n ");
}
# Save recommendation.
if ($recommend) {
if (Db::field_exists('cache_rating', 'rating_date')) {
Db::execute("\n insert into cache_rating (user_id, cache_id, rating_date)\n values (\n '" . mysql_real_escape_string($user['internal_id']) . "',\n '" . mysql_real_escape_string($cache['internal_id']) . "',\n from_unixtime('" . mysql_real_escape_string($when) . "')\n );\n ");
} else {
Db::execute("\n insert into cache_rating (user_id, cache_id)\n values (\n '" . mysql_real_escape_string($user['internal_id']) . "',\n '" . mysql_real_escape_string($cache['internal_id']) . "'\n );\n ");
}
}
# We need to delete the copy of stats-picture for this user. Otherwise,
# the legacy OC code won't detect that the picture needs to be refreshed.
$filepath = Okapi::get_var_dir() . '/images/statpics/statpic' . $user['internal_id'] . '.jpg';
if (file_exists($filepath)) {
unlink($filepath);
}
# Success. Return the uuid.
return $log_uuid;
}
示例2: call
//.........这里部分代码省略.........
}
if ($row['hint']) {
$results[$cache_code]['hints'][strtolower($row['language'])] = $row['hint'];
$results[$cache_code]['hints2'][strtolower($row['language'])] = htmlspecialchars_decode(mb_ereg_replace("<br />", "", $row['hint']), ENT_COMPAT);
}
}
foreach ($results as &$result_ref) {
$result_ref['short_description'] = Okapi::pick_best_language($result_ref['short_descriptions'], $langpref);
$result_ref['description'] = Okapi::pick_best_language($result_ref['descriptions'], $langpref);
$result_ref['hint'] = Okapi::pick_best_language($result_ref['hints'], $langpref);
$result_ref['hint2'] = Okapi::pick_best_language($result_ref['hints2'], $langpref);
}
# Remove unwanted fields.
foreach (array('short_description', 'short_descriptions', 'description', 'descriptions', 'hint', 'hints', 'hint2', 'hints2') as $field) {
if (!in_array($field, $fields)) {
foreach ($results as &$result_ref) {
unset($result_ref[$field]);
}
}
}
}
# Images.
if (in_array('images', $fields) || in_array('preview_image', $fields)) {
if (in_array('images', $fields)) {
foreach ($results as &$result_ref) {
$result_ref['images'] = array();
}
}
if (in_array('preview_image', $fields)) {
foreach ($results as &$result_ref) {
$result_ref['preview_image'] = null;
}
}
if (Db::field_exists('pictures', 'mappreview')) {
$preview_field = "mappreview";
} else {
$preview_field = "0";
}
$sql = "\n select object_id, uuid, url, title, spoiler, " . $preview_field . " as preview\n from pictures\n where\n object_id in ('" . implode("','", array_map('mysql_real_escape_string', array_keys($cacheid2wptcode))) . "')\n and display = 1\n and object_type = 2\n and unknown_format = 0\n ";
if (Settings::get('OC_BRANCH') == 'oc.pl') {
// oc.pl installation allows arbitrary order of the geocache's images
$sql .= "order by object_id, seq, date_created";
} else {
$sql .= "order by object_id, date_created";
}
$rs = Db::query($sql);
unset($sql);
$prev_cache_code = null;
while ($row = mysql_fetch_assoc($rs)) {
$cache_code = $cacheid2wptcode[$row['object_id']];
if ($cache_code != $prev_cache_code) {
# Group images together. Images must have unique captions within one cache.
self::reset_unique_captions();
$prev_cache_code = $cache_code;
}
if (Settings::get('OC_BRANCH') == 'oc.de') {
$object_type_param = 'type=2&';
} else {
$object_type_param = '';
}
$image = array('uuid' => $row['uuid'], 'url' => $row['url'], 'thumb_url' => Settings::get('SITE_URL') . 'thumbs.php?' . $object_type_param . 'uuid=' . $row['uuid'], 'caption' => $row['title'], 'unique_caption' => self::get_unique_caption($row['title']), 'is_spoiler' => $row['spoiler'] ? true : false);
if (in_array('images', $fields)) {
$results[$cache_code]['images'][] = $image;
}
if ($row['preview'] != 0 && in_array('preview_image', $fields)) {
$results[$cache_code]['preview_image'] = $image;
示例3: _call
//.........这里部分代码省略.........
# If user submits a "Comment", we'll just change its type to
# "Needs maintenance". Only one log entry will be issued.
$logtype = 'Needs maintenance';
$second_logtype = null;
$second_formatted_comment = null;
} elseif ($logtype == 'Found it') {
# If "Found it", then we'll issue two log entries: one "Found
# it" with the original comment, and second one "Needs
# maintenance" with empty comment.
$second_logtype = 'Needs maintenance';
$second_formatted_comment = "";
} elseif ($logtype == "Didn't find it") {
# If "Didn't find it", then we'll issue two log entries, but this time
# we'll do this the other way around. The first "Didn't find it" entry
# will have an empty comment. We will move the comment to the second
# "Needs maintenance" log entry. (It's okay for this behavior to change
# in the future, but it seems natural to me.)
$second_logtype = 'Needs maintenance';
$second_formatted_comment = $formatted_comment;
$formatted_comment = "";
} else {
if ($logtype == 'Will attend' || $logtype == 'Attended') {
# OC branches which allow maintenance logs, still don't allow them on
# event caches.
throw new CannotPublishException(_("Event caches cannot \"need maintenance\"."));
} else {
throw new Exception();
}
}
} else {
# User didn't check the "Needs maintenance" flag OR "Needs maintenance"
# log type isn't supported by this server.
$second_logtype = null;
$second_formatted_comment = null;
}
# Finally! Insert the rows into the log entries table. Update
# cache stats and user stats.
$log_uuids = array(self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $logtype, $when, $formatted_comment, $value_for_text_html_field, $needs_maintenance2));
self::increment_cache_stats($cache['internal_id'], $when, $logtype);
self::increment_user_stats($user['internal_id'], $logtype);
if ($second_logtype != null) {
# Reminder: This will only be called for OCPL branch.
$log_uuids[] = self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $second_logtype, $when + 1, $second_formatted_comment, $value_for_text_html_field, 'null');
self::increment_cache_stats($cache['internal_id'], $when + 1, $second_logtype);
self::increment_user_stats($user['internal_id'], $second_logtype);
}
# Save the rating.
if ($rating) {
# This code will be called for OCPL branch only. Earlier, we made sure,
# to set $rating to null, if we're running on OCDE.
# OCPL has a little strange way of storing cumulative rating. Instead
# of storing the sum of all ratings, OCPL stores the computed average
# and update it using multiple floating-point operations. Moreover,
# the "score" field in the database is on the -3..3 scale (NOT 1..5),
# and the translation made at retrieval time is DIFFERENT than the
# one made here (both of them are non-linear). Also, once submitted,
# the rating can never be changed. It surely feels quite inconsistent,
# but presumably has some deep logic into it. See also here (Polish):
# http://wiki.opencaching.pl/index.php/Oceny_skrzynek
switch ($rating) {
case 1:
$db_score = -2.0;
break;
case 2:
$db_score = -0.5;
break;
case 3:
$db_score = 0.7;
break;
case 4:
$db_score = 1.7;
break;
case 5:
$db_score = 3.0;
break;
default:
throw new Exception();
}
Db::execute("\n update caches\n set\n score = (\n score*votes + '" . Db::escape_string($db_score) . "'\n ) / (votes + 1),\n votes = votes + 1\n where cache_id = '" . Db::escape_string($cache['internal_id']) . "'\n ");
Db::execute("\n insert into scores (user_id, cache_id, score)\n values (\n '" . Db::escape_string($user['internal_id']) . "',\n '" . Db::escape_string($cache['internal_id']) . "',\n '" . Db::escape_string($db_score) . "'\n );\n ");
}
# Save recommendation.
if ($recommend) {
if (Db::field_exists('cache_rating', 'rating_date')) {
Db::execute("\n insert into cache_rating (user_id, cache_id, rating_date)\n values (\n '" . Db::escape_string($user['internal_id']) . "',\n '" . Db::escape_string($cache['internal_id']) . "',\n from_unixtime('" . Db::escape_string($when) . "')\n );\n ");
} else {
Db::execute("\n insert into cache_rating (user_id, cache_id)\n values (\n '" . Db::escape_string($user['internal_id']) . "',\n '" . Db::escape_string($cache['internal_id']) . "'\n );\n ");
}
}
# Finalize the transaction.
Db::execute("commit");
# We need to delete the copy of stats-picture for this user. Otherwise,
# the legacy OC code won't detect that the picture needs to be refreshed.
$filepath = Okapi::get_var_dir() . '/images/statpics/statpic' . $user['internal_id'] . '.jpg';
if (file_exists($filepath)) {
unlink($filepath);
}
# Success. Return the uuids.
return $log_uuids;
}