root/trunk/wifidog-auth/wifidog/classes/Content/PatternLanguage/PatternLanguage.php

Revision 1421, 7.7 KB (checked in by benoitg, 4 years ago)

Update my email address

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
36/**
37 * @package    WiFiDogAuthServer
38 * @subpackage ContentClasses
39 * @author     Benoit Grégoire <benoitg@coeus.ca>
40 * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
41 * @version    Subversion $Id$
42 * @link       http://www.wifidog.org/
43 */
44
45/**
46 * Load required classes
47 */
48require_once('classes/Content/ContentGroup/ContentGroup.php');
49require_once('classes/User.php');
50
51/**
52 * @package    WiFiDogAuthServer
53 * @subpackage ContentClasses
54 * @author     Benoit Grégoire <benoitg@coeus.ca>
55 * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
56 */
57class PatternLanguage extends ContentGroup
58{
59
60    /**
61     * Constructor
62     *
63     * @param string $content_id Content Id
64     *
65     * @return void     */
66    protected function __construct($content_id)
67    {
68        parent::__construct($content_id);
69
70        /*
71         * A Pattern language can NEVER be expandable
72         */
73        $this->setIsExpandable(false);
74    }
75
76    /**
77     * Get all pattern language objects
78     *
79     * @return function
80     * @static
81     */
82    public static function getAllContent()
83    {
84       return parent::getAllContent("PatternLanguage");
85    }
86
87    /**
88     * Retreives the user interface of this object.
89     * @return The HTML fragment for this interface
90     */
91    public function getUserUI()
92    {
93        // Init values
94        $html = '';
95
96        // Check if the user has already subscribed to Pattern language
97        $current_user = User::getCurrentUser();
98
99        if($current_user == null || $this->isUserSubscribed($current_user) == false) {
100            // hyperlink to all users narrative
101            $html .= "<ul class='pattern_language_menu'>";
102            $html .= "<li><a class='pattern_language_big_links' href='/content/PatternLanguage/subscription.php'>"._("Subscribe to Pattern Language")."</a></li>";
103            $html .= "<li><a class='pattern_language_big_links' href='/content/PatternLanguage/archives.php'>"._("Read narratives archives")."</a></li>";
104            $html .= "</ul>";
105
106            // Until subscription is done DO NOT log this !
107            $this->setLoggingStatus(false);
108                        $this->setUserUIMainDisplayContent($html);
109            // Tell the content group not to display elements until subscription is done
110            $parent_output = parent :: getUserUI(true);
111        } else {
112            /*
113             * The user is subscribed to the pattern language show an element!
114             * hyperlink to user's narrative
115             */
116            $html .= "<ul class='pattern_language_menu'>";
117            $html .= "<li><a href='/content/PatternLanguage/narrative.php'>"._("Read my narrative")."</a></li>";
118            $html .= "<li><a href='/content/PatternLanguage/archives.php'>"._("Read narratives archives")."</a></li>";
119            $html .= "<li><a href='/content/PatternLanguage/subscription.php'>"._("Unsubscribe")."</a></li>";
120            $html .= "</ul>";
121                        $this->setUserUIMainDisplayContent($html);
122            // Display the random pattern
123            $parent_output = parent :: getUserUI();
124        }
125        return $parent_output;
126    }
127
128    /**
129     * Display the narrative
130     *
131     * @param string $user The user who's narrative you want to grab
132     *
133     * @return the archive page HTML
134     */
135    public function displayNarrative(User $user)
136    {
137       
138        $db = AbstractDb::getObject();
139
140        // Init values
141        $html = "";
142        $rows = null;
143
144        /**
145         * @internal Debug values user_id = 8a90b1ea56cf27a0c61f9304da73bcd5
146         * @internal PL: 3a3ea73dd2e2d03729e62b95d2574fc6
147         */
148
149        $sql = "SELECT * FROM (SELECT DISTINCT ON (content_group_element_id) content_group_element_id, first_display_timestamp FROM content_display_log AS cdl JOIN content_group_element AS cge ON (cdl.content_id = cge.content_group_element_id) JOIN content ON (content.content_id = cge.content_group_id) where user_id = '{$user->getId()}' AND cge.content_group_id = '{$this->getId()}' AND content.content_type = 'PatternLanguage') AS patterns ORDER BY first_display_timestamp";
150        $db->execSql($sql, $rows, false);
151
152        if ($rows) {
153            foreach($rows as $row) {
154                $cge = Content::getObject($row['content_group_element_id']);
155                $cge->setLoggingStatus(false);
156                $html .= $cge->getUserUI()."<p>";
157            }
158        }
159
160        return $html;
161    }
162
163    /**
164     * Get the list of all narratives
165     *
166     * @return the archive page HTML
167     */
168    public function getNarrativeList()
169    {
170       
171        $db = AbstractDb::getObject();
172
173        // Init values
174        $narratives = array();
175        $rows = null;
176
177        $sql = "SELECT DISTINCT user_id FROM content_display_log AS cdl JOIN content_group_element AS cge ON (cdl.content_id = cge.content_group_element_id) JOIN content ON (content.content_id = cge.content_group_id) WHERE content_type = 'PatternLanguage'";
178        $db->execSql($sql , $rows, false);
179
180        if ($rows) {
181            foreach($rows as $row) {
182                $narratives[] = User::getObject($row['user_id']);
183            }
184        }
185
186        return $narratives;
187    }
188
189    /**
190     * Reloads the object from the database.
191     *
192     * Should normally be called after a set operation.
193     *
194     * This function is private because calling it from a subclass will call the
195     * constructor from the wrong scope
196     *
197     * @return void
198
199     */
200    private function refresh()
201    {
202        $this->__construct($this->id);
203    }
204}
205
206/*
207 * Local variables:
208 * tab-width: 4
209 * c-basic-offset: 4
210 * c-hanging-comment-ender-p: nil
211 * End:
212 */
213
214
Note: See TracBrowser for help on using the browser.