/** * get_activity_tree :: course_modinfo -> integer -> context -> array * @param \course_modinfo $modinfo * @param integer $section_number * @param \context $context * @return array */ function get_activity_tree(\course_modinfo $modinfo, $section_number, \context $context) { $completion_info = new \completion_info($modinfo->get_course()); return F\map(F\filter($modinfo->get_section_info_all(), function (\section_info $section_info) { return $section_info->visible; }), function (\section_info $section_info) use($completion_info, $section_number, $context) { $mods = F\map(F\filter($section_info->modinfo->cms, function (\cm_info $cm_info) use($section_info) { global $CFG; return ($cm_info->uservisible || $CFG->enableavailability && !empty($cm_info->availableinfo)) && (int) $cm_info->sectionnum === (int) $section_info->section; }), function (\cm_info $cm_info) use($completion_info, $context) { global $CFG; $canComplete = $CFG->enablecompletion && isloggedin() && !isguestuser() && (int) $completion_info->is_enabled($cm_info) === COMPLETION_TRACKING_MANUAL; $hasCompleted = false; if ($canComplete) { $completion_data = $completion_info->get_data($cm_info, true); $hasCompleted = F\contains([COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS], (int) $completion_data->completionstate); } return (object) ['id' => (int) $cm_info->id, 'name' => $cm_info->name, 'modname' => $cm_info->modname, 'current' => is_current_mod($cm_info, $context), 'available' => $cm_info->available, 'canComplete' => $canComplete, 'hasCompleted' => $hasCompleted]; }); return (object) ['id' => (int) $section_info->id, 'section' => (int) $section_info->section, 'name' => \get_section_name($section_info->modinfo->courseid, $section_info->section), 'current' => is_current_section($section_info, $section_number, $context), 'activities' => array_values($mods)]; }); }
/** * Find the styles that that match the passed size. * * @param RImg\Size $size * The size instance to match styles to. * * @return \stdClass[] * List of styles that fit the passed size. Same object definition as * $this->getStyles(). * * @see DrupalImageStyle::getStyles() */ private function stylesMatchingSize(RImg\Size $size) { # @todo Support Size instances without aspect ratio restrictions. # @todo Support Size instances with only width or only height restrictions. $styles = F\filter($this->getStyles(), function ($style) use($size) { return $style->firm and $size->matchesAspectRatio($style->width / $style->height); }); $min_width = $size->getMinWidth(); $max_width = $size->getMaxWidth(); $styles = F\group($styles, function ($style) use($min_width, $max_width) { if ($style->width < $min_width) { return 'less'; } if ($style->width > $max_width * 2) { # Multiplied for high DPI displays. return 'greater'; } return 'within'; }); if (!empty($styles['greater'])) { # Make sure the end of the range is covered. $styles['within'][] = F\head($styles['greater']); } if (empty($styles['within'])) { if (!empty($styles['less'])) { # Better to have something too small than something too non-existent. $styles = [F\last($styles['less'])]; } else { $styles = []; } } else { $styles = $styles['within']; } return F\unique($styles, function ($s) { return $s->width; }); }
}); } //var_dump(download(new ChapterPage( // new Chapter('Sudome', 'http://www.mangatown.com/manga/sundome/v01/c002/3.html'), // new Page('03', 'http://www.mangatown.com/manga/sundome/v01/c002/3.html'), // new PageImage('http://a.mangatown.com/store/manga/3412/01-002.0/compressed/002.jpg?v=51215960241') //))); //die; IO\getArgs()->map(get(0))->map(function (Maybe\Maybe $argument) { return $argument->map(function ($mangaUrl) { var_dump('started ', $mangaUrl); $mangaData = fetchMangaData($mangaUrl); var_dump('manga data ready'); $afterDownload = $mangaData->map(f\map(f\map(download))); var_dump('manga first run'); $afterDownload->map(function (Collection $collection) { $ttl = 2; do { var_dump('re-download'); $toRetry = f\filter(function (Maybe\Maybe $maybe) { return $maybe->extract() instanceof Either\Left; }, $collection); $count = count($toRetry); $collection = Collection::of($toRetry)->map(function ($a) use(&$ttl, $count) { var_dump('retry', $ttl, $count); return failed($a, $ttl); }); } while (count($toRetry) > 0); }); }); })->run();
/** * tests get_activity_tree flags activities which have not been manually completed * (by the logged in user) */ public function test_get_activity_tree_flags_activities_which_have_not_been_manually_completed() { // log in a (non-guest) user $user = $this->getDataGenerator()->create_user(); $this->setUser($user); // ensure the activity configured with manual completion settings has been completed $section_info = F\head($this->_section_info_all); $cm_info = F\head(F\filter($section_info->modinfo->cms, function (cm_info $cm_info) { return (int) $cm_info->id === $this->_wiki->cmid; })); $this->assertEquals(COMPLETION_TRACKING_MANUAL, $cm_info->completion); $completion = new completion_info($this->_course); $completion->update_state($cm_info, COMPLETION_INCOMPLETE); $activity_tree = B\get_activity_tree(get_fast_modinfo($this->_course), -1, context_module::instance($this->_wiki->cmid)); $this->assertFalse(F\head($activity_tree[(int) $cm_info->sectionnum]->activities)->hasCompleted); }