<commit_before>/**********************************************************************************
 * $URL$
 * $Id$
 ***********************************************************************************
 *
 * Copyright (c) 2005, 2006, 2007, 2008 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.opensource.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **********************************************************************************/
package org.sakaiproject.tool.section.jsf.backingbean;

import java.io.Serializable;
import java.sql.Time;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.section.api.coursemanagement.Course;
import org.sakaiproject.section.api.coursemanagement.CourseSection;
import org.sakaiproject.tool.section.jsf.JsfUtil;
import org.sakaiproject.util.ResourceLoader;

/**
 * Controls the add sections page.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class AddSectionsBean extends CourseDependentBean implements SectionEditor, Serializable {
	private static final long serialVersionUID = 1L;
	private static final Log log = LogFactory.getLog(AddSectionsBean.class);
	
	private Integer numToAdd;
	private String category;
	private List<SelectItem> categoryItems;
	private List<SelectItem> numSectionsSelectItems;
	private List<CourseSection> sections;
	private String rowStyleClasses;
	private 	String elementToFocus;
	private transient boolean sectionsChanged;
    private String[] daysOfWeek = null;

	/**
	 * @inheritDoc
	 */
	public void init() {
		if(log.isDebugEnabled()) log.debug("sections = " + sections);
		if(log.isDebugEnabled()) log.debug("sectionsChanged = " + sectionsChanged);

		numSectionsSelectItems = new ArrayList<SelectItem>(10);
		for(int i=0; i < 10;) {
			Integer currVal = ++i;
			numSectionsSelectItems.add(new SelectItem(currVal));
		}
		if(numToAdd == null) numToAdd = 1;
		
		if(sections == null || sectionsChanged) {
			if(log.isDebugEnabled()) log.debug("initializing add sections bean");
			List categories = getSectionCategories();
			populateSections();
			categoryItems = new ArrayList<SelectItem>();
			for(Iterator iter = categories.iterator(); iter.hasNext();) {
				String cat = (String)iter.next();
				categoryItems.add(new SelectItem(cat, getCategoryName(cat)));
			}
		}
        initDaysOfWeek();
	}

	/**
	 * Responds to a change in the sections selector in the UI.<commit_msg>SAK-22537 patch from Raul for configurable limit groups when adding sections<commit_after>/**********************************************************************************
 * $URL$
 * $Id$
 ***********************************************************************************
 *
 * Copyright (c) 2005, 2006, 2007, 2008 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.opensource.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **********************************************************************************/
package org.sakaiproject.tool.section.jsf.backingbean;

import java.io.Serializable;
import java.sql.Time;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.api.ComponentManager;
import org.sakaiproject.section.api.coursemanagement.Course;
import org.sakaiproject.section.api.coursemanagement.CourseSection;
import org.sakaiproject.tool.section.jsf.JsfUtil;
import org.sakaiproject.util.ResourceLoader;

/**
 * Controls the add sections page.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class AddSectionsBean extends CourseDependentBean implements SectionEditor, Serializable {
	private static final long serialVersionUID = 1L;
	private static final Log log = LogFactory.getLog(AddSectionsBean.class);
	
	private Integer numToAdd;
	private String category;
	private List<SelectItem> categoryItems;
	private List<SelectItem> numSectionsSelectItems;
	private List<CourseSection> sections;
	private String rowStyleClasses;
	private 	String elementToFocus;
	private transient boolean sectionsChanged;
    private String[] daysOfWeek = null;

	/**
	 * @inheritDoc
	 */
	public void init() {
		if(log.isDebugEnabled()) log.debug("sections = " + sections);
		if(log.isDebugEnabled()) log.debug("sectionsChanged = " + sectionsChanged);

		ComponentManager cm = org.sakaiproject.component.cover.ComponentManager.getInstance();
		ServerConfigurationService serverConfigurationService = (ServerConfigurationService) cm.get(ServerConfigurationService.class); 

		int limit = serverConfigurationService.getInt("sections.maxgroups.category", 10);
		if (limit <= 0) limit = 10;

		numSectionsSelectItems = new ArrayList<SelectItem>(limit);
		for(int i = 0; i < limit;) {
			Integer currVal = ++i;
			numSectionsSelectItems.add(new SelectItem(currVal));
		}
		if(numToAdd == null) numToAdd = 1;
		
		if(sections == null || sectionsChanged) {
			if(log.isDebugEnabled()) log.debug("initializing add sections bean");
			List categories = getSectionCategories();
			populateSections();
			categoryItems = new ArrayList<SelectItem>();
			for(Iterator iter = categories.iterator(); iter.hasNext();) {
				String cat = (String)iter.next();
				categoryItems.add(new SelectItem(cat, getCategoryName(cat)));
			}
		}
        initDaysOfWeek();
	}

	/**
	 * Responds to a change in the sections selector in the UI.
{'fraction_non_alphanumeric': 0.16722878021360316, 'fraction_numerical': 0.008431703204047217, 'mean_word_length': 5.2982300884955755, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 21, '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': '2282497', 'n_tokens_mistral': 2087, 'n_tokens_neox': 1902, 'n_words': 532}