本文整理汇总了PHP中TextHelper::loadJson方法的典型用法代码示例。如果您正苦于以下问题:PHP TextHelper::loadJson方法的具体用法?PHP TextHelper::loadJson怎么用?PHP TextHelper::loadJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextHelper
的用法示例。
在下文中一共展示了TextHelper::loadJson方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAchievementsDefinitions
public static function getAchievementsDefinitions()
{
$dir = Config::$achievementsDefinitionsDirectory;
$imgFiles = scandir(Config::$imageDirectory . DIRECTORY_SEPARATOR . 'achievement');
$definitions = array_fill_keys(Media::getConstList(), []);
foreach (glob($dir . DIRECTORY_SEPARATOR . '*.json') as $file) {
$definition = TextHelper::loadJson($file);
$prevAch = null;
foreach ($definition->achievements as &$ach) {
foreach ($imgFiles as $f) {
if (preg_match('/' . $ach->id . '[^0-9a-zA-Z_-]/', $f)) {
$ach->path = $f;
}
}
$ach->next = null;
}
foreach ($definition->achievements as &$ach) {
if ($prevAch !== null) {
$prevAch->next = $ach;
}
$ach->prev = $prevAch;
$prevAch =& $ach;
}
unset($ach);
unset($prevAch);
$definitions[$definition->media][] = $definition;
}
foreach (Media::getConstList() as $key) {
uasort($definitions[$key], function ($a, $b) {
return $a->order - $b->order;
});
}
return $definitions;
}
示例2: work
public static function work(&$controllerContext, &$viewContext)
{
$viewContext->viewName = 'user-profile';
$viewContext->meta->title = $viewContext->user->name . '\'s profile — ' . Config::$title;
$viewContext->meta->description = $viewContext->user->name . '\'s profile.';
WebMediaHelper::addEntries($viewContext);
WebMediaHelper::addMiniSections($viewContext);
WebMediaHelper::addCustom($viewContext);
$viewContext->yearsOnMal = null;
if (intval($viewContext->user->join_date)) {
list($year, $month, $day) = explode('-', $viewContext->user->join_date);
$time = mktime(0, 0, 0, $month, $day, $year);
$diff = time() - $time;
$diff /= 3600 * 24;
$viewContext->yearsOnMal = $diff / 361.25;
}
$viewContext->friends = $viewContext->user->getFriends();
$viewContext->finished = [];
$viewContext->meanUserScore = [];
$viewContext->meanGlobalScore = [];
$viewContext->franchiseCount = [];
$viewContext->mismatchedCount = [];
foreach (Media::getConstList() as $media) {
$list = $viewContext->user->getMixedUserMedia($media);
$listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
$viewContext->finished[$media] = count($listFinished);
unset($listFinished);
$listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
$viewContext->meanUserScore[$media] = RatingDistribution::fromEntries($listNonPlanned)->getMeanScore();
$franchises = Model_MixedUserMedia::getFranchises($listNonPlanned);
$viewContext->franchiseCount[$media] = count(array_filter($franchises, function ($franchise) {
return count($franchise->ownEntries) > 1;
}));
unset($franchises);
unset($listNonPlanned);
if ($media == Media::Anime) {
$viewContext->episodes = array_sum(array_map(function ($mixedMediaEntry) {
return $mixedMediaEntry->finished_episodes;
}, $list));
} else {
$viewContext->chapters = array_sum(array_map(function ($mixedMediaEntry) {
return $mixedMediaEntry->finished_chapters;
}, $list));
}
$mismatched = $viewContext->user->getMismatchedUserMedia($list);
$viewContext->mismatchedCount[$media] = count($mismatched);
unset($mismatched);
unset($list);
$globalsCache = file_exists(Config::$globalsCachePath) ? TextHelper::loadJson(Config::$globalsCachePath, true) : [];
$viewContext->meanGlobalScore[$media] = array_map(function ($v) {
return RatingDistribution::fromArray($v);
}, $globalsCache['rating-dist'])[$media]->getMeanScore();
}
}
示例3: doInit
public static function doInit()
{
$list = TextHelper::loadSimpleList(Config::$bannedUsersListPath);
foreach ($list as $line) {
$tmp = strpos($line, "\t") === false ? [$line, self::USER_BAN_TOTAL] : explode("\t", $line);
list($userName, $banType) = $tmp;
self::$bannedUsers[strtolower($userName)] = $banType;
}
self::$bannedGenres = TextHelper::loadSimpleList(Config::$bannedGenresListPath);
self::$bannedCreators = TextHelper::loadSimpleList(Config::$bannedCreatorsListPath);
self::$bannedGenresForRecs = TextHelper::loadSimpleList(Config::$bannedGenresForRecsListPath);
self::$bannedFranchiseCoupling = TextHelper::loadJson(Config::$bannedFranchiseCouplingListPath, true);
}
示例4: work
public static function work(&$controllerContext, &$viewContext)
{
$viewContext->viewName = 'index-globals';
$viewContext->meta->title = 'MALgraph - global statistics';
$viewContext->meta->description = 'Global community statistics on MALgraph, an online tool that extends your MyAnimeList profile.';
WebMediaHelper::addHighcharts($viewContext);
WebMediaHelper::addInfobox($viewContext);
WebMediaHelper::addMiniSections($viewContext);
WebMediaHelper::addCustom($viewContext);
$globalsCache = file_exists(Config::$globalsCachePath) ? TextHelper::loadJson(Config::$globalsCachePath, true) : [];
$viewContext->userCount = $globalsCache['user-count'];
$viewContext->mediaCount = $globalsCache['media-count'];
$viewContext->ratingDistribution = array_map(function ($v) {
return RatingDistribution::fromArray($v);
}, $globalsCache['rating-dist']);
$viewContext->queuedUserCount = (new Queue(Config::$userQueuePath))->size();
$viewContext->queueSizes = TextHelper::loadJson(Config::$userQueueSizesPath, true);
}
示例5: function
<?php
require_once __DIR__ . '/../src/core.php';
CronRunner::run(__FILE__, function ($logger) {
$limit = 2 * 24 * 60 / 5;
$queueSizes = TextHelper::loadJson(Config::$userQueueSizesPath, true);
$userQueue = new Queue(Config::$userQueuePath);
$mediaQueue = new Queue(Config::$mediaQueuePath);
$key = date('c');
$queueSizes[$key] = [$userQueue->size(), $mediaQueue->size()];
ksort($queueSizes, SORT_NATURAL | SORT_FLAG_CASE);
while (count($queueSizes) > $limit) {
array_shift($queueSizes);
}
TextHelper::putJson(Config::$userQueueSizesPath, $queueSizes);
});