fix chapter page
This commit is contained in:
@@ -36,6 +36,75 @@ class ChapterModel extends MongoModel
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $strKey
|
||||
* @param array $arrFilter
|
||||
* @param integer $intPage
|
||||
* @param integer $intLimit
|
||||
* @param integer $intLifeTime
|
||||
* @param array $arrSort
|
||||
* @return array
|
||||
*/
|
||||
public function getCommonNovelPageOnCache(
|
||||
string $strKey,
|
||||
array $arrFilter,
|
||||
int $intPage = 1,
|
||||
int $intLimit = 20,
|
||||
int $intLifeTime = 24 * 3600,
|
||||
array $arrSort = ['c_sort_num' => 1]
|
||||
): array {
|
||||
try {
|
||||
|
||||
$arrResult = Cache::get($strKey);
|
||||
|
||||
// if (empty($arrResult)) {
|
||||
if (true) {
|
||||
$arrOptions = self::$arrChapterOptions;
|
||||
|
||||
$arrOptions = array_merge($arrOptions, [
|
||||
'sort' => $arrSort,
|
||||
// 'limit' => $intCount * 3,
|
||||
'skip' => ($intPage - 1) * $intLimit,
|
||||
'limit' => $intLimit,
|
||||
]);
|
||||
|
||||
|
||||
$Cursor = $this->getCol()->find($arrFilter, $arrOptions);
|
||||
|
||||
$intTotal = $this->getCol()->countDocuments($arrFilter);
|
||||
|
||||
$arrResult = iterator_to_array($Cursor);
|
||||
|
||||
if (!empty($arrResult)) {
|
||||
foreach($arrResult as &$arrChapter){
|
||||
applyToKeys($arrChapter, ['created_at', 'updated_at'], 'formatMongoDate');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$arrResult = [
|
||||
'data' => $arrResult,
|
||||
'total' => $intTotal,
|
||||
'page' => $intPage,
|
||||
'limit' => $intLimit,
|
||||
'pages' => ceil($intTotal / $intLimit)
|
||||
];
|
||||
|
||||
if (!empty($arrResult)) {
|
||||
Cache::set($strKey, $arrResult, $intLifeTime);
|
||||
}
|
||||
}
|
||||
|
||||
return $arrResult;
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user