<commit_before>/* Schools.java
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Copyright (C) 2015 Universiteit Gent
 * 
 * This file is part of the Rasbeb project, an interactive web
 * application for Bebras competitions.
 * 
 * Corresponding author:
 * 
 * <NAME>
 * Department of Applied Mathematics, Computer Science and Statistics
 * Ghent University 
 * Krijgslaan 281-S9
 * B-9000 GENT Belgium
 * 
 * The Rasbeb Web Application is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * The Rasbeb Web Application is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with the Degage Web Application (file LICENSE in the
 * distribution).  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package controllers;

import be.bebras.rasbeb.db.Filter;
import be.bebras.rasbeb.db.dao.SchoolDAO;
import be.bebras.rasbeb.db.data.School;
import bindings.Pager;
import bindings.SchoolsFilter;
import bindings.Sorter;
import db.DataAccess;
import db.InjectContext;
import play.data.Form;
import play.mvc.Controller;
import play.mvc.Result;

import static be.bebras.rasbeb.db.dao.SchoolDAO.Field.*;

/**
 * Controller for actions on schools.
 */
public class Schools extends Controller {

    /**
     * Gathers the arguments needed to show a schools data table. Used in {@link #list} but
     * also in
     */
    public static class ListArgs {
        public Iterable<School> list;
        public int count;
        public SchoolsFilter f;
        public Sorter s;
        public Pager p;
    }

    /**
     * Create a new {@link ListArgs} object filled from the current database context
     */
    public static ListArgs createListArgs (SchoolsFilter sf, Sorter sorter, Pager pager) {

        ListArgs args = new ListArgs();
        SchoolDAO dao = DataAccess.getInjectedContext().getSchoolDAO();
        Filter<SchoolDAO.Field> filter = dao.createListSchoolsFilter();
        filter.fieldContains(NAME, sf.name());
        filter.fieldContains(STREET, sf.street());
        filter.fieldStartsWith(ZIP, sf.zip());
        filter.fieldContains(TOWN, sf.town());

        args.list = dao.listSchoolsOfCurrentYear(filter, valueOf(sorter.sortColumn()), sorter.ascending(),
                pager.offset(), pager.limit());
        args.count = (int)dao.countSchools(filter);
        args.f = sf;
        args.p = pager;
        args.s = sorter;

        return args;
    }

    /**
     * Show a list of all schools<commit_msg>Fixed incorrect page count in list of schools<commit_after>/* Schools.java
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Copyright (C) 2015 Universiteit Gent
 * 
 * This file is part of the Rasbeb project, an interactive web
 * application for Bebras competitions.
 * 
 * Corresponding author:
 * 
 * <NAME>
 * Department of Applied Mathematics, Computer Science and Statistics
 * Ghent University 
 * Krijgslaan 281-S9
 * B-9000 GENT Belgium
 * 
 * The Rasbeb Web Application is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * The Rasbeb Web Application is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with the Degage Web Application (file LICENSE in the
 * distribution).  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package controllers;

import be.bebras.rasbeb.db.Filter;
import be.bebras.rasbeb.db.dao.SchoolDAO;
import be.bebras.rasbeb.db.data.School;
import bindings.Pager;
import bindings.SchoolsFilter;
import bindings.Sorter;
import db.DataAccess;
import db.InjectContext;
import play.data.Form;
import play.mvc.Controller;
import play.mvc.Result;

import static be.bebras.rasbeb.db.dao.SchoolDAO.Field.*;

/**
 * Controller for actions on schools.
 */
public class Schools extends Controller {

    /**
     * Gathers the arguments needed to show a schools data table. Used in {@link #list} but
     * also in
     */
    public static class ListArgs {
        public Iterable<School> list;
        public int count;
        public SchoolsFilter f;
        public Sorter s;
        public Pager p;
    }

    /**
     * Create a new {@link ListArgs} object filled from the current database context
     */
    public static ListArgs createListArgs (SchoolsFilter sf, Sorter sorter, Pager pager) {

        ListArgs args = new ListArgs();
        SchoolDAO dao = DataAccess.getInjectedContext().getSchoolDAO();
        Filter<SchoolDAO.Field> filter = dao.createListSchoolsFilter();
        filter.fieldContains(NAME, sf.name());
        filter.fieldContains(STREET, sf.street());
        filter.fieldStartsWith(ZIP, sf.zip());
        filter.fieldContains(TOWN, sf.town());

        args.list = dao.listSchoolsOfCurrentYear(filter, valueOf(sorter.sortColumn()), sorter.ascending(),
                pager.offset(), pager.limit());
        args.count = (int)dao.countSchoolsOfCurrentYear(filter);
        args.f = sf;
        args.p = pager;
        args.s = sorter;

        return args;
    }

    /**
     * Show a list of all schools
{'fraction_non_alphanumeric': 0.10946291560102302, 'fraction_numerical': 0.00443307757885763, 'mean_word_length': 3.2080344332855093, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '956450', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1624, 'n_words': 582}