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

Revision 877, 8.4 KB (checked in by fproulx, 7 years ago)

2005-12-29 Fran�ois Proulx <francois.proulx@…>

  • Added Aidan's file_exists_incpath function to Dependencies class
  • Translated and standardized most of PostgreSQL abstraction class.
  • Removed blank lines at end of many files
  • Tested the new Phlickr package, which fixes URL on Flickr
  • 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 Gregoire <bock@step.polymtl.ca>
40 * @copyright  2004-2005 Benoit Gregoire, Technologies Coeus inc.
41 * @version    CVS: $Id$
42 * @link       http://sourceforge.net/projects/wifidog/
43 */
44
45require_once('classes/Content/ContentGroup/ContentGroup.php');
46require_once('classes/User.php');
47
48/**
49 * @package    WiFiDogAuthServer
50 * @subpackage ContentClasses
51 * @author     Benoit Gregoire <bock@step.polymtl.ca>
52 * @copyright  2004-2005 Benoit Gregoire, Technologies Coeus inc.
53 */
54class PatternLanguage extends ContentGroup
55{
56
57    /**
58     * Constructor
59     *
60     * @param string $content_id Content Id
61     *
62     * @return void
63     *
64     * @access protected
65     */
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     *
81     * @access public
82     * @static
83     */
84    public static function getAllContent()
85    {
86       return parent::getAllContent("PatternLanguage");
87    }
88
89    /**
90     * Retreives the user interface of this object.
91     *
92     * Anything that overrides this method should call the parent method with
93     * it's output at the END of processing.
94     *
95     * @param string $subclass_admin_interface HTML content of the interface
96     *                                         element of a children
97     *
98     * @return The HTML fragment for this interface
99     *
100     * @access public
101     */
102    public function getUserUI($subclass_user_interface = null)
103    {
104        // Init values
105        $html = '';
106
107        $html .= "<div class='user_ui_container'>\n";
108        $html .= "<div class='user_ui_object_class'>PatternLanguage (".get_class($this)." instance)</div>\n";
109
110        // Check if the user has already subscribed to Pattern language
111        $current_user = User::getCurrentUser();
112
113        if($current_user == null || $this->isUserSubscribed($current_user) == false) {
114            // hyperlink to all users narrative
115            $html .= "<ul class='pattern_language_menu'>";
116            $html .= "<li><a class='pattern_language_big_links' href='/content/PatternLanguage/subscription.php'>"._("Subscribe to Pattern Language")."</a></li>";
117            $html .= "<li><a class='pattern_language_big_links' href='/content/PatternLanguage/archives.php'>"._("Read narratives archives")."</a></li>";
118            $html .= "</ul>";
119
120            // Until subscription is done DO NOT log this !
121            $this->setLoggingStatus(false);
122
123            // Tell the content group not to display elements until subscription is done
124            $parent_output = parent :: getUserUI($html, true);
125        } else {
126            /*
127             * The user is subscribed to the pattern language show an element!
128             * hyperlink to user's narrative
129             */
130            $html .= "<ul class='pattern_language_menu'>";
131            $html .= "<li><a href='/content/PatternLanguage/narrative.php'>"._("Read my narrative")."</a></li>";
132            $html .= "<li><a href='/content/PatternLanguage/archives.php'>"._("Read narratives archives")."</a></li>";
133            $html .= "<li><a href='/content/PatternLanguage/subscription.php'>"._("Unsubscribe")."</a></li>";
134            $html .= "</ul>";
135
136            // Display the random pattern
137            $parent_output = parent :: getUserUI($html);
138        }
139
140        $html .= $subclass_user_interface;
141        $html .= "</div>\n";
142
143        return $parent_output;
144    }
145
146    /**
147     * Display the narrative
148     *
149     * @param string $user The user who's narrative you want to grab
150     *
151     * @return the archive page HTML
152     *
153     * @access public
154     */
155    public function displayNarrative(User $user)
156    {
157        // Define globals
158        global $db;
159
160        // Init values
161        $html = "";
162        $rows = null;
163
164        /**
165         * @internal Debug values user_id = 8a90b1ea56cf27a0c61f9304da73bcd5
166         * @internal PL: 3a3ea73dd2e2d03729e62b95d2574fc6
167         */
168
169        $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";
170        $db->execSql($sql, $rows, false);
171
172        if ($rows) {
173            foreach($rows as $row) {
174                $cge = Content::getObject($row['content_group_element_id']);
175                $cge->setLoggingStatus(false);
176                $html .= $cge->getUserUI()."<p>";
177            }
178        }
179
180        return $html;
181    }
182
183    /**
184     * Get the list of all narratives
185     *
186     * @return the archive page HTML
187     *
188     * @access public
189     */
190    public function getNarrativeList()
191    {
192        // Define globals
193        global $db;
194
195        // Init values
196        $narratives = array();
197        $rows = null;
198
199        $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'";
200        $db->execSql($sql , $rows, false);
201
202        if ($rows) {
203            foreach($rows as $row) {
204                $narratives[] = User::getObject($row['user_id']);
205            }
206        }
207
208        return $narratives;
209    }
210
211    /**
212     * Reloads the object from the database.
213     *
214     * Should normally be called after a set operation.
215     *
216     * This function is private because calling it from a subclass will call the
217     * constructor from the wrong scope
218     *
219     * @return void
220     *
221     * @access private
222     */
223    private function refresh()
224    {
225        $this->__construct($this->id);
226    }
227}
228
229/*
230 * Local variables:
231 * tab-width: 4
232 * c-basic-offset: 4
233 * c-hanging-comment-ender-p: nil
234 * End:
235 */
236
237?>
Note: See TracBrowser for help on using the browser.