Find.

@param WikiView[] $wikiViews The wiki views.
@param string $category The category.
@param string $package The package.
@param string $page The page.
@return WikiView Returns the wiki view in case of success, null otherwise.
354238
public static function find(array $wikiViews, $category, $package, $page) {
        $wikiView = null;
        foreach ($wikiViews as $current) {
            if ($category !== $current->getCategory() || $package !== $current->getPackage() || $page !== $current->getPage()) {
                continue;
            }
            $wikiView = $current;
            break;
        }
        return $wikiView;
    }
803102
public function getSubjectsPager(Category $category, $page = 1, $max = 20)
    {
        $subjects = $this->forumRepo->findSubjects($category);

        return $this->pagerFactory->createPagerFromArray($subjects, $page, $max);
    }
1073352
public function findByCategory(Category $category, $order, $orderBy, $page, $limit): Paginator
    {
        $qb = $this->createQueryBuilder('page')
            ->where('page.category = :category')
            ->andWhere('page.enabled = :enabled')
            ->orderBy('page.'.$orderBy, $order)
            ->setMaxResults($limit)
            ->setFirstResult($limit * ($page-1))
            ->setParameter('category', $category)
            ->setParameter('enabled', true)
        ;

        return new Paginator($qb->getQuery()->useResultCache($this->cacheEnabled, $this->cacheTtl));
    }
902018
public function showCategory($category, $pagenumber = 1)
    {
        if (!$this->category->exists($category)) {
            return \Response::view($this->theme.'.404', array('global' => $this->global), 404);
        }

        $categoryObject = $this->category->getCategory($category);
        $parent = $this->category->getParentCategory($category);
        $subCategories = $this->category->getSubCategories($category);
        $posts = $this->post->getAll($category);

        $viewParamaters = array(
            'global' => $this->global,
            'category' => $categoryObject,
            'parent' => $parent,
            'subCategories' => $subCategories,
            'posts' => $posts,
            'pageNumber' => $pagenumber
        );

        return \View::make($this->theme.'.category', $viewParamaters);
    }
1226939
public function find(PageDocument $page)
    {
        $request = $this->requestStack->getCurrentRequest();

        $template = $page->getDefault(AbstractPhpcrDocument::DEFAULT_TEMPLATE_KEY);
        if ($template === null) {
            $defaults = [];

            /** @var RouteEnhancerInterface $enhancer */
            foreach ($this->dynamicRouter->getRouteEnhancers() as $enhancer) {
                $defaults = array_merge($defaults, $enhancer->enhance(['_content' => $page], $request));
            }

            if (array_key_exists(AbstractPhpcrDocument::DEFAULT_TEMPLATE_KEY, $defaults)) {
                $template = $defaults[AbstractPhpcrDocument::DEFAULT_TEMPLATE_KEY];
            }
        }

        return $template;
    }
705588
public function bind(Package $package = null)
    {
        $package = $package ?: new Package();
        
        $navMap = $this->xml->navMap;
        
        $this->consumeNavMap($navMap, $package->navigation->chapters);
        
        return $package;
    }
289222
public function index(Listener $listener, $category = null)
    {
        $presenter = $this->presenter->setCategory($category);
        $modules   = $presenter->modules();
        return $listener->show(compact('modules', 'category'));
    }
263172
public function Index($CategoryIdentifier = '', $Page = '0') {
      // Figure out which category layout to choose (Defined on "Homepage" settings page).
      $Layout = C('Vanilla.Categories.Layout');
      
      if ($CategoryIdentifier == '') {
         switch($Layout) {
            case 'mixed':
               $this->View = 'discussions';
               $this->Discussions();
               break;
            case 'table':
               $this->Table();
               break;
            default:
               $this->View = 'all';
               $this->All();
               break;
         }
         return;
      } else {
         $Category = CategoryModel::Categories($CategoryIdentifier);
         
         if (empty($Category)) {
            if ($CategoryIdentifier)
               throw NotFoundException();
         }
         $Category = (object)$Category;
         Gdn_Theme::Section($Category->CssClass);
         
         // Load the breadcrumbs.
			$this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category)));
         
         $this->SetData('Category', $Category, TRUE);
         
         $this->Title(htmlspecialchars(GetValue('Name', $Category, '')));
         $this->Description(GetValue('Description', $Category), TRUE);
         
         
         if ($Category->DisplayAs == 'Categories') {
            if (GetValue('Depth', $Category) > 0) {
               // Heading don't make sense if we've cascaded down one level.
               SaveToConfig('Vanilla.Categories.DoHeadings', FALSE, FALSE);
            }
            
            Trace($this->DeliveryMethod(), 'delivery method');
            Trace($this->DeliveryType(), 'delivery type');
            Trace($this->SyndicationMethod, 'syndication');
            
            if ($this->SyndicationMethod != SYNDICATION_NONE) {
               // RSS can't show a category list so just tell it to expand all categories.
               SaveToConfig('Vanilla.ExpandCategories', TRUE, FALSE);
            } else {
               // This category is an overview style category and displays as a category list.
               switch($Layout) {
                  case 'mixed':
                     $this->View = 'discussions';
                     $this->Discussions();
                     break;
                  case 'table':
                     $this->Table();
                     break;
                  default:
                     $this->View = 'all';
                     $this->All();
                     break;
               }
               return;
            }
         }
         
         Gdn_Theme::Section('DiscussionList');
         // Figure out which discussions layout to choose (Defined on "Homepage" settings page).
         $Layout = C('Vanilla.Discussions.Layout');
         switch($Layout) {
            case 'table':
               if ($this->SyndicationMethod == SYNDICATION_NONE)
                  $this->View = 'table';
               break;
            default:
               // $this->View = 'index';
               break;
         }
         
         // Load the subtree.
         if (C('Vanilla.ExpandCategories'))
            $Categories = CategoryModel::GetSubtree($CategoryIdentifier);
         else
            $Categories = array($Category);
         
         $this->SetData('Categories', $Categories);
   
         // Setup head
         $this->AddCssFile('vanilla.css');
         $this->Menu->HighlightRoute('/discussions');
         if ($this->Head) {
            $this->AddJsFile('discussions.js');
            $this->Head->AddRss($this->SelfUrl.'/feed.rss', $this->Head->Title());
         }
         
         // Set CategoryID
         $CategoryID = GetValue('CategoryID', $Category);
         $this->SetData('CategoryID', $CategoryID, TRUE);
         
         // Add modules
         $this->AddModule('NewDiscussionModule');
         $this->AddModule('DiscussionFilterModule');
         $this->AddModule('CategoriesModule');
         $this->AddModule('BookmarkedModule');
         
         // Get a DiscussionModel
         $DiscussionModel = new DiscussionModel();
         $CategoryIDs = ConsolidateArrayValuesByKey($this->Data('Categories'), 'CategoryID');
         $Wheres = array('d.CategoryID' => $CategoryIDs);
         $this->SetData('_ShowCategoryLink', count($CategoryIDs) > 1);
         
         // Check permission
         $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category));
         
         // Set discussion meta data.
         $this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30);
         $this->FireEvent('BeforeGetDiscussions');
         list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']);
         
         if (!is_numeric($Offset) || $Offset < 0)
            $Offset = 0;
            
         $CountDiscussions = $DiscussionModel->GetCount($Wheres);
         $this->SetData('CountDiscussions', $CountDiscussions);
         $this->SetData('_Limit', $Limit);
         
         // We don't wan't child categories in announcements.
         $Wheres['d.CategoryID'] = $CategoryID;
         $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
         $this->SetData('AnnounceData', $AnnounceData, TRUE);
         $Wheres['d.CategoryID'] = $CategoryIDs;
         
         $this->DiscussionData = $this->SetData('Discussions', $DiscussionModel->GetWhere($Wheres, $Offset, $Limit));
   
         // Build a pager
         $PagerFactory = new Gdn_PagerFactory();
         $this->Pager = $PagerFactory->GetPager('Pager', $this);
         $this->Pager->ClientID = 'Pager';
         $this->Pager->Configure(
            $Offset,
            $Limit,
            $CountDiscussions,
            array('CategoryUrl')
         );
         $this->Pager->Record = $Category;
         PagerModule::Current($this->Pager);
         $this->SetData('_Page', $Page);
   
         // Set the canonical Url.
         $this->CanonicalUrl(CategoryUrl($Category, PageNumber($Offset, $Limit)));
         
         // Change the controller name so that it knows to grab the discussion views
         $this->ControllerName = 'DiscussionsController';
         // Pick up the discussions class
         $this->CssClass = 'Discussions Category-'.GetValue('UrlCode', $Category);
         
         // Deliver JSON data if necessary
         if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
            $this->SetJson('LessRow', $this->Pager->ToString('less'));
            $this->SetJson('MoreRow', $this->Pager->ToString('more'));
            $this->View = 'discussions';
         }
         // Render default view.
         $this->FireEvent('BeforeCategoriesRender');
         $this->Render();
      }
   }
571730
public function view(User $user, Category $category)
    {

        if ($user->canDo('block.category.view') && $user->isAdmin()) {
            return true;
        }

        return $user->id == $category->user_id;
    }
338189
public function show(CategoryRequest $request, Category $category)
    {

        if ($category->exists) {
            $view = 'block::admin.category.show';
        } else {
            $view = 'block::admin.category.new';
        }

        return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('block::category.name'))
            ->data(compact('category'))
            ->view($view)
            ->output();
    }
74568
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllCategories(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllCategories();
        }
    }
1115324
public function getCategoryAlias(NewsCategoryModel $category, PageModel $page)
    {
        if ($category instanceof Multilingual) {
            return $category->getAlias($page->language);
        }

        return $category->alias;
    }
479313
public function view($slug = null)
    {
        //The category can be passed as query string, from a widget
        if ($this->request->getQuery('q')) {
            return $this->redirect([$this->request->getQuery('q')]);
        }

        $page = $this->request->getQuery('page', 1);

        //Sets the cache name
        $cache = sprintf('category_%s_limit_%s_page_%s', md5($slug), $this->paginate['limit'], $page);

        //Tries to get data from the cache
        list($posts, $paging) = array_values(Cache::readMany(
            [$cache, sprintf('%s_paging', $cache)],
            $this->PostsCategories->getCacheName()
        ));

        //If the data are not available from the cache
        if (empty($posts) || empty($paging)) {
            $query = $this->PostsCategories->Posts->find('active')
                ->find('forIndex')
                ->where([sprintf('%s.slug', $this->PostsCategories->getAlias()) => $slug]);

            is_true_or_fail(!$query->isEmpty(), I18N_NOT_FOUND, RecordNotFoundException::class);

            $posts = $this->paginate($query);

            //Writes on cache
            Cache::writeMany([
                $cache => $posts,
                sprintf('%s_paging', $cache) => $this->request->getParam('paging'),
            ], $this->PostsCategories->getCacheName());
        //Else, sets the paging parameter
        } else {
            $this->request = $this->request->withParam('paging', $paging);
        }

        $this->set('category', $posts->extract('category')->first());
        $this->set(compact('posts'));
    }
221390
public static void main(String[] args) throws WikiApiException {

        // load a sample document (the contents are equal to "DarmstadtWikipediaArticle.txt")
        String documentText = TestFile.getFileText();
		
		// get a ParsedPage object
		MediaWikiParserFactory pf = new MediaWikiParserFactory();
		MediaWikiParser parser = pf.createParser();
		ParsedPage pp = parser.parse(documentText);
		
        // only the links to other Wikipedia language editions
        for (Link language : pp.getLanguages()) {
            System.out.println(language.getTarget());
        }

        //get the internal links of each section
        for (Section section : pp.getSections()){
            System.out.println("Section: " + section.getTitle());

            for (Link link : section.getLinks(Link.type.INTERNAL)) {
                System.out.println("  " + link.getTarget());
            }
        }
    }
718436
public function findView($view)
	{
		$view = $this->viewFolder.DIRECTORY_SEPARATOR.ltrim($view, DIRECTORY_SEPARATOR);

		return $this->finder->findFileReversed($view);
	}
142641
public function getVideosFromCategory(array $category, $page = 1)
    {
        $videos = [];

        $totalTestedItems = $this->countVideosFromCategory($category['category_id'], self::TESTED_IMAGE);
        $totalTestItems = $this->countVideosFromCategory($category['category_id'], self::TEST_IMAGE);
        $this->totalItems = $totalTestedItems + $totalTestItems;//$this->countTotalItems($category->category_id);

        if ($this->totalItems <= 0) {
            return [];
        }

        $items_per_page = (int) Yii::$app->getModule('videos')->settings->get('items_per_page', self::ITEMS_PER_PAGE);
        $test_items_percent = (int) Yii::$app->getModule('videos')->settings->get('test_items_percent', self::TEST_ITEMS_PERCENT);

            // Проверим, является ли текущая страница валидной.
        $totalPages = ceil($this->totalItems / $items_per_page);
        if ($page > $totalPages) {
            throw new NotFoundHttpException();
        }

        $tested_per_page = ceil(((100 - $test_items_percent) / 100) * $items_per_page);
        $test_per_page = floor(($test_items_percent / 100) * $items_per_page);

            // Если ли вообще у нас на странице тестовые ролики.
        if ($totalTestItems === 0 || $test_per_page === 0) {
            $tested_per_page = $items_per_page;
            $test_per_page = 0;
        }

        if ($totalTestItems > 0 && $totalTestItems < $test_per_page) {
            if ($page == 1) {
                $test_per_page = $totalTestItems;
                $tested_per_page = $items_per_page - $test_per_page;
            } else {
                $test_per_page = 0;
                $tested_per_page = $items_per_page;
            }
        }

            // Высчитаем смещение и получим завершившие тест тумбы
        $testedOffset = ($page - 1) * $tested_per_page;
        $testedItems = $this->getVideosFromStats($tested_per_page, $testedOffset, $category['category_id'], self::TESTED_IMAGE);
        $actuallyTestedImagesNumber = count($testedItems);

            // Если тестовые ролики есть, найдем их и запишем в массив видео.
        if ($totalTestItems > 0 && $test_per_page > 0) {
            $testOffset = ($page - 1) * $test_per_page;

                // Если на странице нехватает завершивших тест, то доберем больше тестовых.
            if ($actuallyTestedImagesNumber < $tested_per_page) {
                    // если завершивших тест вообще нет, увеличим смещение тестовых.
                if ($actuallyTestedImagesNumber === 0 && $testOffset > 0) {
                    $a = floor($totalTestedItems / $tested_per_page);
                    $b = $totalTestedItems - ($tested_per_page * $a);
                    $testOffset += ($items_per_page - ($test_per_page + $b));
                }

                    // Доберем тестируемые.
                $test_per_page = $items_per_page - $actuallyTestedImagesNumber;
            }

            $testItems = $this->getVideosFromStats($test_per_page, $testOffset, $category['category_id'], self::TEST_IMAGE);

            $testedNum = count($testedItems);
            $testNum = count($testItems);

            $testItemStart = (int) Yii::$app->getModule('videos')->settings->get('test_items_start', self::TEST_ITEMS_START);

                // перемешаем тестовые и не тестовые местами
            if (count($testedItems) >= $testItemStart && $testNum > 0) {

                $totalItemsOnPage = $testedNum + $testNum;
                    // Вычислим места, в которых будут стоять тестовые тумбы.
                $filledArray = range(0, $totalItemsOnPage - 1);
                array_splice($filledArray, 0, $testItemStart);
                $randKeys = (array) array_rand($filledArray, $testNum);
                $testPlacePositions = array_values(array_intersect_key($filledArray, array_flip($randKeys)));

                $testPlaceIterator = new \ArrayIterator($testPlacePositions);
                //$testPlaceIterator->rewind();
                /*$testIterator = new \ArrayIterator($testItems);
                $testedIterator = new \ArrayIterator($testedItems);

                for ($i = 0; $i < $totalItemsOnPage; $i++) {
                    if ($i === $testPlaceIterator->current()) {
                        //if ($testIterator->current() != false) {
                            $videos[$testIterator->key()] = $testIterator->current();
                        //}
                        $testIterator->next();
                        $testPlaceIterator->next();
                    } else {
                        //if ($testedIterator->current() != false) {
                            $videos[$testedIterator->key()] = $testedIterator->current();
                        //}
                        $testedIterator->next();
                    }
                }*/


                for ($i = 0; $i < $totalItemsOnPage; $i++) {
                    if ($i === $testPlaceIterator->current()) {
                        $video = array_shift($testItems);

                        $testPlaceIterator->next();
                    } else {
                        $video = array_shift($testedItems);
                    }

                        // нормализуем массив видео.
                    $videos[$video['image_id']] = $video['video'];
                    $videos[$video['image_id']]['image'] = $video['image'];
                    $videos[$video['image_id']]['categories'] = $video['categories'];
                }


            } else {
                $items = $testedItems + $testItems;
                foreach ($items as $item) {
                    $videos[$item['image_id']] = $item['video'];
                    $videos[$item['image_id']]['image'] = $item['image'];
                    $videos[$item['image_id']]['categories'] = $item['categories'];
                }
            }

        } else {
            //$videos = $testedItems;
            foreach ($testedItems as $item) {
                $videos[$item['image_id']] = $item['video'];
                $videos[$item['image_id']]['image'] = $item['image'];
                $videos[$item['image_id']]['categories'] = $item['categories'];
            }
        }

        return $videos;
    }
405788
public function actionGetCategoryRouteRules(string $category, string $format = 'Craft', $siteId = null): Response
    {
        return $this->asJson(RouteMap::$plugin->routes->getCategoryRouteRules($category, $format, $siteId));
    }