root/de.inside.Gewinnspiel/files/lib/page/IndexPage.class.php @ 718

Revision 718, 6.2 kB (checked in by Tatzelwurm, 5 years ago)

Neue Version, leider noch mit Fehlern.

  • Property svn:mime-type set to text/plain
  • Property svn:executable set to *
Line 
1<?
2// wcf imports
3require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
4require_once(WCF_DIR.'lib/page/SortablePage.class.php');
5
6/**
7 * Gewinnspiel Index, liest die Gewinnspiele aus der DB,
8 * kontrolliert die Berechtigungen, ob bereits mitgespielt wurde und das
9 * Gewinnspiel (noch) aktuell ist. Abgelaufene Spiele und Gewinnspiele zu
10 * denen man keine Berechtigung hat werden entsprechend gekennzeichnet.
11 * @author              Robert "Tatzelwurm" Hempel
12 * @copyright   2007/2008 INSIDE das Hörspiel
13 * @license     GNU LGPL http://www.gnu.org/licenses/lgpl.txt
14 * @package             de.inside.Gewinnspiel
15 */
16
17class IndexPage extends SortablePage {
18
19        public $templateName = 'index';
20        public $itemsPerPage = 10;
21        public $gwsID;
22        public $gwsGroupIDs = array();
23        public $money;
24        public $gewinnspiele = array();
25        public $userID;
26        public $username;
27        public $email;
28        public $highlight = '';
29        public $defaultSortField = 'timeout';
30        public $sortField;
31       
32        private $gamesCache = array();
33        private $enableSmilies = true;
34        private $enableBBCodes = true;
35       
36        /**
37         * @see Page::readParameters()
38         */
39        public function readParameters() {
40                parent::readParameters();
41                // get UserID + Name + E-Mail
42                $this->userID   = WCF::getUser()->userID;
43                $this->username = WCF::getUser()->username;
44                $this->email    = WCF::getUser()->email;
45                // get game id and action
46                if (isset($_REQUEST['gwsID'])) $this->gwsID = intval($_REQUEST['gwsID']);
47                if (isset($_REQUEST['action'])) $this->action = $_REQUEST['action'];
48
49                GWSPCore::getCache()->addResource('competition-games-'.PACKAGE_ID,
50                        GWSP_DIR.'cache/competition.games-'.PACKAGE_ID.'.php',
51                        GWSP_DIR.'lib/system/cache/CacheBuilderGWSPGames.class.php');
52                GWSPCore::getCache()->addResource('competition-user-'.PACKAGE_ID,
53                        GWSP_DIR.'cache/competition.user-'.PACKAGE_ID.'.php',
54                        GWSP_DIR.'lib/system/cache/CacheBuilderGWSPUser.class.php');
55                       
56                // Action !!!!
57                if ($this->action == 'go' && $this->gwsID) $this->startGame();
58        }
59
60        public function readData() {
61                parent::readData();
62                $this->gamesCache = GWSPCore::getCache()->get('competition-games-'.PACKAGE_ID);
63                $this->userCache = GWSPCore::getCache()->get('competition-user-'.PACKAGE_ID);
64                $this->readGewinnspiele();
65        }
66       
67        /**
68         * @see Page::assignVariables();
69         */
70        public function assignVariables() {
71                parent::assignVariables();
72                $this->userID = WCF::getUser()->userID;
73                GWSPCore::getTPL()->assign('selfLink', 'IndexPage.php?'.SID_ARG_2ND);
74                GWSPCore::getTPL()->assign(array(
75                        'gewinnspiele' => $this->gewinnspiele,
76                        'gamescount' => $this->countItems(),
77                        ));
78        }
79
80        /**
81         * @see Page::show()
82         */
83        public function show() {
84                require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php');
85                HeaderMenu::setActiveMenuItem('gws.header.menu.gamemenue');
86               
87                // check permission
88                GWSPCore::getUser()->checkPermission('user.gewinnspiel.canViewGewinnspiel');
89
90                parent::show();
91        }
92
93        public function countItems() {
94                parent::countItems();
95
96                $sql = "SELECT  COUNT(gwsID)
97                                AS gwsID
98                                FROM gwsp".GWSP_N."_game";
99                $row = GWSPCore::getDB()->getFirstRow($sql);
100
101                return $row['gwsID'];
102        }
103       
104        public function validateSortField() {
105                parent::validateSortField();
106
107                switch ($this->sortField) {
108                        case 'gwsID':
109                        case 'gwsTitel':
110                        case 'starttime':
111                        case 'timeout':
112                        case 'done':break;
113                        default: $this->sortField = $this->defaultSortField;
114                }
115        }
116       
117        protected function readGewinnspiele() {
118                $gameData = array();
119               
120                if (count($this->gamesCache)) {
121                        foreach ($this->gamesCache  as $key => $row) {
122                                $gameData[] = $this->gamesCache[$key];
123                        }
124                        if (count($gameData)) {
125                                // Hole eine Liste von Spalten
126                                foreach ($gameData as $key => $row) {
127                                        $row['done'] = $row['permission'] = false;
128                                        // Check for Guthaben Plugin
129                                if (!defined('GUTHABEN_ENABLE_GLOBAL')){
130                                                $row['money'] = 0;
131                                        }
132                                        // Check gruppe permission
133                                        $IDs = explode(',', $row['groupIDs']);
134                                        require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
135                                        foreach ($IDs as $gruppe) {
136                                                if (Group::isMember($gruppe)) {
137                                                        $row['permission'] = true;
138                                                        break;
139                                                }
140                                        }
141                                        // Kontrolle ob User schon teilgenommen hat (nicht bei GÀsten)
142                                        foreach ($this->userCache as $users){
143                                                if ($users['userID'] == GWSPCore::getUser()->userID && $users['gwsID'] == $row['gwsID']) {
144                                                        $row['done'] = true;
145                                                        break;
146                                                }
147                                        }
148                                        $sortarray[$key]  = $row[$this->sortField];
149                                }
150                                // Sortieren der Liste
151                                if ($this->sortOrder == 'DESC') array_multisort($sortarray, SORT_DESC, $gameData);
152                                if ($this->sortOrder == 'ASC') array_multisort($sortarray, SORT_ASC, $gameData);
153                        }
154
155                        for ($i = 0; $i< count($gameData); $i++){
156                                $gameData[$i]['done'] = $gameData[$i]['permission'] = false;
157                                if (!defined('GUTHABEN_ENABLE_GLOBAL')){
158        //                                      $gameData[$i]['money'] = 0;
159                                        }
160                                        // Check gruppe permission
161                                // Check gruppe permission
162                                $IDs = explode(',', $gameData[$i]['groupIDs']);
163                                require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
164                                foreach ($IDs as $gruppe) {
165                                        if (Group::isMember($gruppe)) {
166                                                $gameData[$i]['permission'] = true;
167                                                break;
168                                        }
169                                }
170                                // Kontrolle ob User schon teilgenommen hat (nicht bei GÀsten)
171                                foreach ($this->userCache as $key => $users){
172                                        if ($users['userID'] == GWSPCore::getUser()->userID && $users['gwsID'] == $gameData[$i]['gwsID']) {
173                                                $gameData[$i]['done'] = true;
174                                                break;
175                                        }
176                                }
177                                $this->gewinnspiele[] = $gameData[$i];
178                        }
179                }       
180        }
181
182        protected function getTimeDate() {
183                $datetime = DateUtil::formatDate(null,null,true,true);
184                return $datetime;
185        }
186
187        protected function startGame() {
188                $sql = "SELECT  `groupIDs`
189                                FROM    gwsp".GWSP_N."_game
190                                WHERE   gwsID = ".$this->gwsID."";
191                $result = GWSPCore::getDB()->sendQuery($sql);
192                $row = GWSPCore::getDB()->fetchArray($result);
193                $this->gwsGroupIDs = explode(',',$row['groupIDs']);
194                require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
195                $canplay = false;
196                foreach ($this->gwsGroupIDs as $groupID){
197                        if (Group::isMember($groupID)) $canplay = true;
198                }
199                if (!$canplay) {
200                        require_once(WCF_DIR.'lib/system/exception/NamedUserException.class.php');
201                        throw new NamedUserException(GWSPCore::getLanguage()->get('gws.gewinnspiel.nogroupe'));
202                }
203        }
204}
205
206?>
Note: See TracBrowser for help on using the browser.