001: /*
002: * Copyright (c) Rafael Steil
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creation date: Mar 28, 2003 / 8:09:08 PM
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.view.admin;
044:
045: import net.jforum.dao.DataAccessDriver;
046: import net.jforum.dao.RankingDAO;
047: import net.jforum.entities.Ranking;
048: import net.jforum.repository.RankingRepository;
049: import net.jforum.util.preferences.TemplateKeys;
050:
051: /**
052: * @author Rafael Steil
053: * @version $Id: RankingAction.java,v 1.11 2006/12/02 03:19:51 rafaelsteil Exp $
054: */
055: public class RankingAction extends AdminCommand {
056: // List
057: public void list() {
058: this .context.put("ranks", DataAccessDriver.getInstance()
059: .newRankingDAO().selectAll());
060: this .setTemplateName(TemplateKeys.RANKING_LIST);
061: }
062:
063: // One more, one more
064: public void insert() {
065: this .setTemplateName(TemplateKeys.RANKING_INSERT);
066: this .context.put("action", "insertSave");
067: }
068:
069: // Edit
070: public void edit() {
071: this .setTemplateName(TemplateKeys.RANKING_EDIT);
072: this .context.put("action", "editSave");
073: this .context.put("rank", DataAccessDriver.getInstance()
074: .newRankingDAO().selectById(
075: this .request.getIntParameter("ranking_id")));
076: }
077:
078: // Save information
079: public void editSave() {
080: Ranking r = new Ranking();
081: r.setTitle(this .request.getParameter("rank_title"));
082: r.setId(this .request.getIntParameter("rank_id"));
083:
084: boolean special = "1".equals(this .request
085: .getParameter("rank_special"));
086: r.setSpecial(special);
087:
088: if (!special) {
089: r.setMin(this .request.getIntParameter("rank_min"));
090: }
091:
092: DataAccessDriver.getInstance().newRankingDAO().update(r);
093: RankingRepository.loadRanks();
094: this .list();
095: }
096:
097: // Delete
098: public void delete() {
099: String ids[] = this .request.getParameterValues("rank_id");
100:
101: RankingDAO rm = DataAccessDriver.getInstance().newRankingDAO();
102:
103: if (ids != null) {
104: for (int i = 0; i < ids.length; i++) {
105: rm.delete(Integer.parseInt(ids[i]));
106: }
107: }
108:
109: this .list();
110: }
111:
112: // A new one
113: public void insertSave() {
114: Ranking r = new Ranking();
115: r.setTitle(this .request.getParameter("rank_title"));
116:
117: boolean special = "1".equals(this .request
118: .getParameter("rank_special"));
119: r.setSpecial(special);
120:
121: if (!special) {
122: r.setMin(this .request.getIntParameter("rank_min"));
123: }
124:
125: DataAccessDriver.getInstance().newRankingDAO().addNew(r);
126:
127: RankingRepository.loadRanks();
128:
129: this.list();
130: }
131: }
|