From 30e99c8720b53d0042a353a888a736d06c2b780e Mon Sep 17 00:00:00 2001
From: lonecatz 如果需要上传一个帮助文件:
+ 如果需要上传一个帮助文件:Moodle程序编写准则
@@ -12,25 +15,24 @@
-
好的: $quiz
好的: $errorstring
- 好的: $assignments (for an array of objects)
- 好的: $i (but only in little loops)
+ 好的: $assignments (用于数组)
+ 好的: $i (仅用于小型循环)
坏的: $Quiz
坏的: $aReallyLongVariableNameWithoutAGoodReason
@@ -52,31 +54,31 @@
1);
function forum_set_display_mode($mode=0)
+ function forum_set_display_mode($mode=0)
{
- global $USER,
+ global $USER,
$CFG;
- if ($mode)
+ if ($mode)
{
- $USER->mode
+ $USER->mode
= $mode;
- } else if (empty($USER->mode))
+ } else if (empty($USER->mode))
{
- $USER->mode
- = $CFG->forum_displaymode;
- }
+ $USER->mode
+ = $CFG->forum_displaymode;
+ }
}
if ($quiz->attempts)
+ if ($quiz->attempts)
{
- if ($numattempts >
- $quiz->attempts)
+ if ($numattempts >
+ $quiz->attempts)
{
- error($strtoomanyattempts,
- "view.php?id=$cm->id");
- }
+ error($strtoomanyattempts,
+ "view.php?id=$cm->id");
+ }
}
function forum_get_ratings_mean($postid,
- $scale, $ratings=NULL)
+
+/** foreach ($objects
- as $key =>
+ foreach ($objects
+ as $key =>
$thing) { Version: $Id$ Version: $Id$
+
+
+
+ * The description should be first, with asterisks laid out exactly
+ * like this example. If you want to refer to a another function,
+ * do it like this: {@link clean_param()}. Then, add descriptions
+ * for each parameter as follows.
+ *
+ * @param int $postid The PHP type is followed by the variable name
+ * @param array $scale The PHP type is followed by the variable name
+ * @param array $ratings The PHP type is followed by the variable name
+ * @return mixed
+ */
+function forum_get_ratings_mean($postid,
+ $scale, $ratings=NULL)
+ {
+ if (!$ratings)
{
- /// Return the mean rating of a post given
- to the current user by others.
- /// Scale is an array of possible ratings in the scale
- /// Ratings is an optional simple array of actual ratings (just integers)
-
- if (!$ratings)
- {
- $ratings
- = array(); //
+ $ratings
+ = array(); //
Initialize the empty array
- if ($rates
- = get_records("forum_ratings",
- "post", $postid))
+ if ($rates
+ = get_records("forum_ratings",
+ "post", $postid))
{
- //
+ //
Process each rating in turn
- foreach
- ($rates as $rate)
+ foreach
+ ($rates as $rate)
{
....etc
-
- process($thing);
+ process($thing);
}
- if ($x ==
- $y)
+ if ($x ==
+ $y)
{
- $a
+ $a
= $b;
- } else if ($x ==
+ } else if ($x ==
$z) {
- $a
+ $a
= $c;
} else {
- $a
+ $a
= $d;
}
-