本文整理汇总了PHP中Database::fetch_assoc方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::fetch_assoc方法的具体用法?PHP Database::fetch_assoc怎么用?PHP Database::fetch_assoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::fetch_assoc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "cronid,timenumber,timetype,timeinterval,last_update,jobdata,date_added,status";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by cronid desc';
$result = array();
$command = "select {$selectFields} from cronjobs {$whereQuery} {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$query = Database::query($queryCMD);
$inputData['isHook'] = isset($inputData['isHook']) ? $inputData['isHook'] : 'yes';
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
if (isset($row['jobdata'])) {
$row['jobdata'] = String::jsonToArray($row['jobdata']);
}
$row['date_addedFormat'] = Render::dateFormat($row['date_added']);
$result[] = $row;
}
} else {
return false;
}
// print_r($result);die();
return $result;
}
示例2: check_download_survey
/**
* @package chamilo.survey
* @author Arnaud Ligot <arnaud@cblue.be>
* @version $Id: $
*
* A small peace of code to enable user to access images included into survey
* which are accessible by non authenticated users. This file is included
* by document/download.php
*/
function check_download_survey($course, $invitation, $doc_url)
{
require_once 'survey.lib.php';
// Getting all the course information
$_course = CourseManager::get_course_information($course);
$course_id = $_course['real_id'];
// Database table definitions
$table_survey = Database::get_course_table(TABLE_SURVEY);
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
// Now we check if the invitationcode is valid
$sql = "SELECT * FROM {$table_survey_invitation}\n\t WHERE\n\t c_id = {$course_id} AND\n\t invitation_code = '" . Database::escape_string($invitation) . "'";
$result = Database::query($sql);
if (Database::num_rows($result) < 1) {
Display::display_error_message(get_lang('WrongInvitationCode'), false);
Display::display_footer();
exit;
}
$survey_invitation = Database::fetch_assoc($result);
// Now we check if the user already filled the survey
if ($survey_invitation['answered'] == 1) {
Display::display_error_message(get_lang('YouAlreadyFilledThisSurvey'), false);
Display::display_footer();
exit;
}
// Very basic security check: check if a text field from a survey/answer/option contains the name of the document requested
// Fetch survey ID
// If this is the case there will be a language choice
$sql = "SELECT * FROM {$table_survey}\n\t WHERE\n\t c_id = {$course_id} AND\n\t code='" . Database::escape_string($survey_invitation['survey_code']) . "'";
$result = Database::query($sql);
if (Database::num_rows($result) > 1) {
if ($_POST['language']) {
$survey_invitation['survey_id'] = $_POST['language'];
} else {
echo '<form id="language" name="language" method="POST" action="' . api_get_self() . '?course=' . $_GET['course'] . '&invitationcode=' . $_GET['invitationcode'] . '">';
echo ' <select name="language">';
while ($row = Database::fetch_assoc($result)) {
echo '<option value="' . $row['survey_id'] . '">' . $row['lang'] . '</option>';
}
echo '</select>';
echo ' <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />';
echo '</form>';
display::display_footer();
exit;
}
} else {
$row = Database::fetch_assoc($result);
$survey_invitation['survey_id'] = $row['survey_id'];
}
$sql = "SELECT count(*)\n\t FROM {$table_survey}\n\t WHERE\n\t c_id = {$course_id} AND\n\t survey_id = " . $survey_invitation['survey_id'] . " AND (\n title LIKE '%{$doc_url}%'\n or subtitle LIKE '%{$doc_url}%'\n or intro LIKE '%{$doc_url}%'\n or surveythanks LIKE '%{$doc_url}%'\n )\n\t\t UNION\n\t\t SELECT count(*)\n\t\t FROM {$table_survey_question}\n\t\t WHERE\n\t\t c_id = {$course_id} AND\n\t\t survey_id = " . $survey_invitation['survey_id'] . " AND (\n survey_question LIKE '%{$doc_url}%'\n or survey_question_comment LIKE '%{$doc_url}%'\n )\n\t\t UNION\n\t\t SELECT count(*)\n\t\t FROM {$table_survey_question_option}\n\t\t WHERE\n\t\t c_id = {$course_id} AND\n\t\t survey_id = " . $survey_invitation['survey_id'] . " AND (\n option_text LIKE '%{$doc_url}%'\n )";
$result = Database::query($sql);
if (Database::num_rows($result) == 0) {
Display::display_error_message(get_lang('WrongInvitationCode'), false);
Display::display_footer();
exit;
}
return $_course;
}
示例3: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "id,parentid,date_added,title,url,status,sort_order";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by id desc';
$result = array();
$command = "select {$selectFields} from " . Database::getPrefix() . "links {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : -1;
$md5Query = md5($queryCMD);
if ($cache == 'yes') {
// Load dbcache
$loadCache = Cache::loadKey('dbcache/system/link/' . $md5Query, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
$inputData['isHook'] = isset($inputData['isHook']) ? $inputData['isHook'] : 'yes';
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
if (isset($row['title'])) {
$row['title'] = String::decode($row['title']);
}
if (isset($row['date_added'])) {
$row['date_addedFormat'] = Render::dateFormat($row['date_added']);
}
if (isset($row['url']) && !preg_match('/^http/i', $row['url'])) {
if (preg_match('/^\\/(.*?)$/i', $row['url'], $matches)) {
$tmp = $matches[1];
$row['urlFormat'] = System::getUrl() . $tmp;
}
}
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
Cache::saveKey('dbcache/system/link/' . $md5Query, serialize($result));
// end save
return $result;
}
示例4: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "userid,groupid,username,firstname,lastname,image,email,password,userdata,ip,verify_code,parentid,date_added,forgot_code,forgot_date";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by date_added desc';
$result = array();
$prefix = '';
$prefixall = Database::isPrefixAll();
if ($prefixall != false || $prefixall == 'no') {
$prefix = Database::getPrefix();
}
$command = "select {$selectFields} from " . $prefix . "users {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : -1;
$md5Query = md5($queryCMD);
if ($cache == 'yes') {
// Load dbcache
$loadCache = Cache::loadKey('dbcache/system/user/' . $md5Query, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
// echo $queryCMD;die();
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
if (isset($row['date_added'])) {
$row['date_addedFormat'] = Render::dateFormat($row['date_added']);
}
if (isset($row['image'])) {
$row['imageFormat'] = self::getAvatar($row['image']);
}
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
Cache::saveKey('dbcache/system/user/' . $md5Query, serialize($result));
// end save
return $result;
}
示例5: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "groupid,group_title,groupdata";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by groupid desc';
$result = array();
$prefix = '';
$prefixall = Database::isPrefixAll();
if ($prefixall != false || $prefixall == 'no') {
$prefix = Database::getPrefix();
}
$command = "select {$selectFields} from " . $prefix . "usergroups {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : 15;
$md5Query = md5($queryCMD);
if ($cache == 'yes') {
// Load dbcache
$loadCache = Cache::loadKey('dbcache/system/usergroup/' . $md5Query, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
$inputData['isHook'] = isset($inputData['isHook']) ? $inputData['isHook'] : 'yes';
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
if (isset($row['date_added'])) {
$row['date_addedFormat'] = Render::dateFormat($row['date_added']);
}
if (isset($row['groupdata'])) {
$row['groupdata'] = self::arrayToLine($row['groupdata']);
}
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
Cache::saveKey('dbcache/system/usergroup/' . $md5Query, serialize($result));
// end save
return $result;
}
示例6: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "requestid,userid,total_request,date_added,status,comments";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by requestid desc';
$result = array();
$command = "select {$selectFields} from " . Database::getPrefix() . "request_payments {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : 1;
if ($cache == 'yes') {
// Load dbcache
$loadCache = DBCache::get($queryCMD, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
$inputData['isHook'] = isset($inputData['isHook']) ? $inputData['isHook'] : 'yes';
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
if (isset($row['comments'])) {
$row['comments'] = String::decode($row['comments']);
}
if (isset($row['date_added'])) {
$row['date_addedFormat'] = Render::dateFormat($row['date_added']);
}
if ($inputData['isHook'] == 'yes') {
if (isset($row['comments'])) {
$row['comments'] = Shortcode::load($row['comments']);
}
}
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
DBCache::make(md5($queryCMD), $result);
// end save
return $result;
}
示例7: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "userid,company,firstname,lastname,address_1,address_2,city,state,postcode,country,phone,fax";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by userid desc';
$result = array();
$command = "select {$selectFields} from " . Database::getPrefix() . "address {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : -1;
$md5Query = md5($queryCMD);
if ($cache == 'yes') {
// Load dbcache
$loadCache = Cache::loadKey('dbcache/system/address/' . $md5Query, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
$inputData['isHook'] = isset($inputData['isHook']) ? $inputData['isHook'] : 'yes';
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
if (isset($row['title'])) {
$row['title'] = String::decode($row['title']);
}
if (isset($row['friendly_url'])) {
$row['url'] = self::url($row);
}
if (isset($row['date_added'])) {
$row['date_addedFormat'] = Render::dateFormat($row['date_added']);
}
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
Cache::saveKey('dbcache/system/address/' . $md5Query, serialize($result));
// end save
return $result;
}
示例8: external_get_user_info
/**
* Gets user info from external source
* @param string login
* @param string password
* @return user array with at least the following fields:
* firstname
* lastname
* status
* email
* login
* password
* or false if no data
* */
function external_get_user_info($login, $password)
{
//Those are the mandatory fields for user creation.
//See external_add_user function for all the fields you can have.
$table = USERINFO_TABLE;
$sql = "SELECT * from {$table} where username='" . Database::escape_string($login) . "'";
$result = Database::query($sql);
if (Database::num_rows($result) == 0) {
//false password
return false;
}
$user_info = Database::fetch_assoc($result);
// User status
$admin = false;
switch ($user_info['status']) {
case 'admin':
$status = COURSEMANAGER;
$admin = true;
break;
case 'teacher':
$status = COURSEMANAGER;
break;
case 'user':
$status = STUDENT;
break;
default:
$status = STUDENT;
}
// Language
switch ($user_info['language']) {
case 'FR':
$language = 'french';
break;
case 'EN':
$language = 'english';
break;
default:
$language = 'english';
break;
}
//Can Send Message ?
$can_send_message = $user_info['can_send_message'] == 1 ? 'yes' : 'no';
$u = array('firstname' => $user_info['firstname'], 'lastname' => $user_info['lastname'], 'status' => $status, 'admin' => $admin, 'email' => $user_info['email'], 'username' => $user_info['username'], 'language' => $language, 'password' => DEFAULT_PASSWORD, 'courses' => $user_info['courses'], 'profile_link' => $user_info['profile_link'], 'worldwide_bu' => $user_info['worlwide_bu'], 'manager' => $user_info['manager'], 'extra' => array('position_title' => $user_info['position_title'], 'country' => $user_info['country'], 'job_family' => $user_info['job_family'], 'country_bu' => $user_info['country_bu'], 'worldwide_bu' => $user_info['worldwide_bu'], 'profile_link' => $user_info['profile_link'], 'can_send_message' => $can_send_message, 'update_type' => 'external_logininfo'));
return $u;
//Please return false if user does not exist
//return false;
}
示例9: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "postid,catid";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by date_added desc';
$result = array();
$command = "select {$selectFields} from " . Database::getPrefix() . "post_categories {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : -1;
$md5Query = md5($queryCMD);
if ($cache == 'yes') {
// Load dbcache
$loadCache = Cache::loadKey('dbcache/system/postcategory/' . $md5Query, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
$inputData['isHook'] = isset($inputData['isHook']) ? $inputData['isHook'] : 'yes';
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
Cache::saveKey('dbcache/system/postcategory/' . $md5Query, serialize($result));
// end save
return $result;
}
示例10: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "metaid,foldername,func,zonename,layoutname,layoutposition,content,status,type";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by metaid desc';
$result = array();
$command = "select {$selectFields} from plugins_meta {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : 15;
$md5Query = md5($queryCMD);
if ($cache == 'yes') {
// Load dbcache
$loadCache = Cache::loadKey('dbcache/system/pluginmeta/' . $md5Query, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
Cache::saveKey('dbcache/system/pluginmeta/' . $md5Query, serialize($result));
// end save
return $result;
}
示例11: getRecentPosts
/**
* Get recent posts
*
* Returns an array of all recent posts, given a certain posts amount.
*
* @param int $amount Number of posts to get (defaults to 10).
* @param int $offset How many posts to skip.
* @return array Array of {@link Post} instances of all recent posts.
*/
function getRecentPosts($amount = '%', $offset = 0)
{
// default amount from setting
if ($amount == '%') {
$amount = $this->getSetting('recent_count');
}
// db query
$sql = 'SELECT `postid`, `time`, `content`, `comments_count` ' . 'FROM `+posts` ' . 'WHERE 1 ' . 'ORDER BY `postid` DESC ' . 'LIMIT ' . ($offset + 0) . ',' . ($amount + 0);
$q = $this->db->query($sql) or $this->displayError('site->getRecentPosts', $this->db->error());
$recent = array();
while ($postdata = $this->db->fetch_assoc($q)) {
$post = new Post($this);
$post->fetch_from_array($postdata);
$recent[] = $post;
}
// while
return $recent;
}
示例12: storage_get_all_users
function storage_get_all_users()
{
$sql = "select user_id, username, firstname, lastname\n\t\tfrom " . Database::get_main_table(TABLE_MAIN_USER) . "\n\t\torder by user_id asc";
$res = Database::query($sql);
$results = array();
while ($row = Database::fetch_assoc($res)) {
$results[] = $row;
}
return json_encode($results);
}
示例13: IN
$all_visible_files_path[] = $all_visible_files['path'];
$files[$all_visible_files['path']] = $all_visible_files;
}
// 2nd: Get all folders that are invisible in the given path
$sql = "SELECT path, session_id, docs.id, props.to_group_id, docs.c_id\n FROM {$doc_table} AS docs INNER JOIN {$prop_table} AS props\n ON\n docs.id = props.ref AND\n docs.c_id = props.c_id\n WHERE\n docs.c_id = {$courseId} AND\n props.tool = '" . TOOL_DOCUMENT . "' AND\n docs.path LIKE '" . $querypath . "/%' AND\n props.visibility <> '1' AND\n (props.session_id IN ('0', '{$sessionId}') OR props.session_id IS NULL) AND\n docs.filetype = 'folder'";
$query2 = Database::query($sql);
// If we get invisible folders, we have to filter out these results from all visible files we found
if (Database::num_rows($query2) > 0) {
$files = array();
// Add item to an array
while ($invisible_folders = Database::fetch_assoc($query2)) {
//3rd: Get all files that are in the found invisible folder (these are "invisible" too)
$sql = "SELECT path, docs.id, props.to_group_id, docs.c_id\n FROM {$doc_table} AS docs\n INNER JOIN {$prop_table} AS props\n ON\n docs.id = props.ref AND\n docs.c_id = props.c_id\n WHERE\n docs.c_id = {$courseId} AND\n props.tool ='" . TOOL_DOCUMENT . "' AND\n docs.path LIKE '" . $invisible_folders['path'] . "/%' AND\n docs.filetype = 'file' AND\n (props.session_id IN ('0', '{$sessionId}') OR props.session_id IS NULL) AND\n props.visibility ='1'";
$query3 = Database::query($sql);
// Add tem to an array
while ($files_in_invisible_folder = Database::fetch_assoc($query3)) {
$files_in_invisible_folder_path[] = $files_in_invisible_folder['path'];
$files[$files_in_invisible_folder['path']] = $files_in_invisible_folder;
}
}
// Compare the array with visible files and the array with files in invisible folders
// and keep the difference (= all visible files that are not in an invisible folder)
$files_for_zipfile = diff((array) $all_visible_files_path, (array) $files_in_invisible_folder_path);
} else {
// No invisible folders found, so all visible files can be added to the zipfile
$files_for_zipfile = $all_visible_files_path;
}
Session::write('doc_files_to_download', $files);
// Add all files in our final array to the zipfile
for ($i = 0; $i < count($files_for_zipfile); $i++) {
$zip->add($sysCoursePath . $courseInfo['path'] . '/document' . $files_for_zipfile[$i], PCLZIP_OPT_REMOVE_PATH, $sysCoursePath . $courseInfo['path'] . '/document' . $remove_dir, PCLZIP_CB_PRE_ADD, 'fixDocumentNameCallback');
示例14: getGroupsByDepthLevel
/**
* Get the subgroups ID from a group.
* The default $levels value is 10 considering it as a extensive level of depth
* @param int $groupId The parent group ID
* @param int $levels The depth levels
* @return array The list of ID
*/
public static function getGroupsByDepthLevel($groupId, $levels = 10)
{
$groups = array();
$groupId = intval($groupId);
$groupTable = Database::get_main_table(TABLE_USERGROUP);
$groupRelGroupTable = Database::get_main_table(TABLE_USERGROUP_REL_USERGROUP);
$select = "SELECT ";
$from = "FROM {$groupTable} g1 ";
for ($i = 1; $i <= $levels; $i++) {
$tableIndexNumber = $i;
$tableIndexJoinNumber = $i - 1;
$select .= "g{$i}.id as id_{$i} ";
$select .= $i != $levels ? ", " : null;
if ($i == 1) {
$from .= "INNER JOIN {$groupRelGroupTable} gg0 ON g1.id = gg0.subgroup_id and gg0.group_id = {$groupId} ";
} else {
$from .= "LEFT JOIN {$groupRelGroupTable} gg{$tableIndexJoinNumber} ";
$from .= " ON g{$tableIndexJoinNumber}.id = gg{$tableIndexJoinNumber}.group_id ";
$from .= "LEFT JOIN {$groupTable} g{$tableIndexNumber} ";
$from .= " ON gg{$tableIndexJoinNumber}.subgroup_id = g{$tableIndexNumber}.id ";
}
}
$result = Database::query("{$select} {$from}");
while ($item = Database::fetch_assoc($result)) {
foreach ($item as $groupId) {
if (!empty($groupId)) {
$groups[] = $groupId;
}
}
}
return array_map('intval', $groups);
}
示例15: get
public static function get($inputData = array())
{
$limitQuery = "";
$limitShow = isset($inputData['limitShow']) ? $inputData['limitShow'] : 0;
$limitPage = isset($inputData['limitPage']) ? $inputData['limitPage'] : 0;
$limitPage = (int) $limitPage > 0 ? $limitPage : 0;
$limitPosition = $limitPage * (int) $limitShow;
$limitQuery = (int) $limitShow == 0 ? '' : " limit {$limitPosition},{$limitShow}";
$limitQuery = isset($inputData['limitQuery']) ? $inputData['limitQuery'] : $limitQuery;
$field = "commentid,postid,type,fullname,email,parentid,date_added,status,content";
$selectFields = isset($inputData['selectFields']) ? $inputData['selectFields'] : $field;
$whereQuery = isset($inputData['where']) ? $inputData['where'] : '';
$orderBy = isset($inputData['orderby']) ? $inputData['orderby'] : 'order by commentid desc';
$result = array();
$command = "select {$selectFields} from " . Database::getPrefix() . "comments {$whereQuery}";
$command .= " {$orderBy}";
$queryCMD = isset($inputData['query']) ? $inputData['query'] : $command;
$queryCMD .= $limitQuery;
$cache = isset($inputData['cache']) ? $inputData['cache'] : 'yes';
$cacheTime = isset($inputData['cacheTime']) ? $inputData['cacheTime'] : -1;
$md5Query = md5($queryCMD);
if ($cache == 'yes') {
// Load dbcache
$loadCache = Cache::loadKey('dbcache/system/comment/' . $md5Query, $cacheTime);
if ($loadCache != false) {
$loadCache = unserialize($loadCache);
return $loadCache;
}
// end load
}
$query = Database::query($queryCMD);
if (isset(Database::$error[5])) {
return false;
}
$inputData['isHook'] = isset($inputData['isHook']) ? $inputData['isHook'] : 'yes';
if ((int) $query->num_rows > 0) {
while ($row = Database::fetch_assoc($query)) {
if (isset($row['fullname'])) {
$row['fullname'] = String::decode($row['fullname']);
}
if (isset($row['content'])) {
$row['content'] = String::decode($row['content']);
}
if (isset($row['date_added'])) {
$row['date_addedFormat'] = Render::dateFormat($row['date_added']);
}
if ($inputData['isHook'] == 'yes') {
if (isset($row['content'])) {
$row['content'] = Shortcode::toHTML($row['content']);
}
}
$result[] = $row;
}
} else {
return false;
}
// Save dbcache
Cache::saveKey('dbcache/system/comment/' . $md5Query, serialize($result));
// end save
return $result;
}