public function report_curriculum($mc_id, $info = []) { $sql = <<<SQL SELECT \tscores.is_id, \tscores.sc_test, \tscores.sc_work, \tscores.sc_total, \tinfo_student.is_name, \tinfo_class.icl_number FROM \tscores INNER JOIN info_student on info_student.is_id = scores.is_id INNER JOIN info_class on info_class.icl_id = info_student.icl_id WHERE \tmc_id = :mc_id SQL; $r = []; foreach ($info as $n => $v) { $sql .= " AND {$n}=:" . str_replace(".", "_", $n); $r[":" . str_replace(".", "_", $n)] = $v; } $r[':mc_id'] = $mc_id; $stmt = $this->driver->getReader()->prepare($sql); if ($stmt->execute($r)) { return $stmt->fetchAll(\PDO::FETCH_ASSOC); } var_dump($stmt->errorInfo()); return false; }
/** * 检测用户,根据字符串数组 * @param string[] $list * @param int $u_id * @return int[] */ private function checkUser($list, $u_id) { $list = array_flip(array_flip($list)); if (count($list) > 10) { $this->throwMsg(-5); } $ss = $this->db->select("users", ['id'], ['user_name' => $list]); $list = []; foreach ($ss as $v) { $list[] = intval($v['id']); } if (count($list) < 1) { return []; } if ($u_id !== 0) { $ss = implode(",", $list); $sql = <<<EOM SELECT `users_id`, `follow_users_id` FROM `users_follow_users` WHERE (`users_id` = {$u_id} AND `follow_users_id` in ({$ss})) OR (`users_id` in ({$ss}) AND `follow_users_id` = {$u_id}); EOM; $stmt = $this->db->getReader()->query($sql); if ($stmt === false) { Log::write(_("Get sql message users error."), Log::SQL); $this->throwMsg(-8); } $ss = $stmt->fetchAll(\PDO::FETCH_ASSOC); unset($stmt); $list = []; foreach ($ss as $v) { if (!isset($list[$v['users_id']])) { $list[$v['users_id']] = intval($v['users_id']); } if (!isset($list[$v['follow_users_id']])) { $list[$v['follow_users_id']] = intval($v['follow_users_id']); } } if (isset($list[$u_id])) { unset($list[$u_id]); } } return $list; }
/** * 获取上一页和下一页的信息 */ private function getPreviousNext() { if ($this->gallery_id > 0) { $read = $this->db->getReader(); $stmt = $read->query("call getGalleryPreviousNextID(" . $read->quote($this->gallery_id) . ");"); if ($stmt !== false) { $list = $stmt->fetchAll(\PDO::FETCH_ASSOC); $this->info['previous_and_next'] = ['previous' => NULL, 'next' => NULL]; //释放连接操作 unset($stmt); if (isset($list[0]) && array_sum($list[0]) > 0) { $list = $list[0]; $info = $read->select("gallery", ['id', 'gallery_title'], ['id' => $list, 'ORDER' => 'id']); if ($info === false) { Log::write(_("Get gallery previous and next info error.") . join(",", $read->error()), Log::SQL); $this->throwMsg(-15); } else { for ($i = 0, $c = count($info); $i < $c; ++$i) { if ($info[$i]['id'] == $list['previous']) { $this->info['previous_and_next']['previous'] =& $info[$i]; } else { if ($info[$i]['id'] == $list['next']) { $this->info['previous_and_next']['next'] =& $info[$i]; } } } } } else { //为找到上一页和下一页数据 //可能仅仅一页,数组留空 } } else { Log::write(_("Gallery get previous and next page id error.") . join(", ", $read->error()), Log::SQL); $this->throwMsg(-15); } } }