| 1 |
<?php
|
| 2 |
function load_section_list(array & $result, callable $filter, callable $udf_value_gen, mysqli $db_conn, array $filter_param = array()) : bool
|
| 3 |
{
|
| 4 |
$sql = "SELECT SID, section_config.CID, section_config.title AS s_title, section_config.comment,
|
| 5 |
section_class.title AS c_title, section_config.recommend
|
| 6 |
FROM section_config INNER JOIN section_class ON section_config.CID = section_class.CID
|
| 7 |
WHERE section_class.enable AND section_config.enable
|
| 8 |
ORDER BY section_class.sort_order, section_config.sort_order";
|
| 9 |
|
| 10 |
$rs = mysqli_query($db_conn, $sql);
|
| 11 |
if ($rs == false)
|
| 12 |
{
|
| 13 |
return false;
|
| 14 |
}
|
| 15 |
|
| 16 |
$last_cid = -1;
|
| 17 |
$last_c_title = "";
|
| 18 |
$section_list = array();
|
| 19 |
while ($row = mysqli_fetch_array($rs))
|
| 20 |
{
|
| 21 |
if ($row["CID"] != $last_cid)
|
| 22 |
{
|
| 23 |
if (count($section_list) > 0)
|
| 24 |
{
|
| 25 |
array_push($result, array(
|
| 26 |
"cid" => $last_cid,
|
| 27 |
"title" => $last_c_title,
|
| 28 |
"sections" => $section_list,
|
| 29 |
));
|
| 30 |
|
| 31 |
$section_list = array();
|
| 32 |
}
|
| 33 |
|
| 34 |
$last_cid = $row["CID"];
|
| 35 |
$last_c_title = $row["c_title"];
|
| 36 |
}
|
| 37 |
|
| 38 |
if (call_user_func($filter, $row, $filter_param))
|
| 39 |
{
|
| 40 |
array_push($section_list, array(
|
| 41 |
"sid" => $row["SID"],
|
| 42 |
"title" => $row["s_title"],
|
| 43 |
"comment" => $row["comment"],
|
| 44 |
"udf_values" => call_user_func($udf_value_gen, $row, $filter_param),
|
| 45 |
));
|
| 46 |
}
|
| 47 |
}
|
| 48 |
|
| 49 |
if (count($section_list) > 0)
|
| 50 |
{
|
| 51 |
array_push($result, array(
|
| 52 |
"cid" => $last_cid,
|
| 53 |
"title" => $last_c_title,
|
| 54 |
"sections" => $section_list,
|
| 55 |
));
|
| 56 |
}
|
| 57 |
|
| 58 |
mysqli_free_result($rs);
|
| 59 |
|
| 60 |
return true;
|
| 61 |
}
|