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

Revision 868, 7.8 KB (checked in by max-horvath, 7 years ago)

2005-12-26 Max Horvath <max.horvath@…>

  • added new headers to every source file
  • converted file to represent a tab as four (4) spaces
  • added PhpDocumentor? documentation
  • added WiFiDog skin to HTMLeditor
  • language selection in a content class now shows the language name instead of the language code
  • added caching support to content classes Langstring and TrivialLangstring?
  • 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 <bock@step.polymtl.ca> - Technologies Coeus
41 * inc.
42 * @version    CVS: $Id$
43 * @link       http://sourceforge.net/projects/wifidog/
44 */
45
46require_once BASEPATH.'classes/Content/ContentGroup/ContentGroup.php';
47require_once BASEPATH.'classes/User.php';
48
49class PatternLanguage extends ContentGroup
50{
51    /**
52     * Get all pattern language objects
53     */
54    public static function getAllContent()
55    {
56       return parent::getAllContent("PatternLanguage");
57    }
58
59    function __construct($content_id)
60    {
61        parent :: __construct($content_id);
62
63        // A Pattern language can NEVER be expandable
64        $this->setIsExpandable(false);
65    }
66
67    /** Retreives the user interface of this object.  Anything that overrides this method should call the parent method with it's output at the END of processing.
68     * @param $subclass_admin_interface Html content of the interface element of a children
69     * @return The HTML fragment for this interface */
70    public function getUserUI($subclass_user_interface = null)
71    {
72        $html = '';
73        $html .= "<div class='user_ui_container'>\n";
74        $html .= "<div class='user_ui_object_class'>PatternLanguage (".get_class($this)." instance)</div>\n";
75
76        // Check if the user has already subscribed to Pattern language
77        $current_user = User::getCurrentUser();
78        if($current_user == null || $this->isUserSubscribed($current_user) == false)
79        {
80            // hyperlink to all users narrative
81            $html .= "<ul class='pattern_language_menu'>";
82            $html .= "<li><a class='pattern_language_big_links' href='/content/PatternLanguage/subscription.php'>"._("Subscribe to Pattern Language")."</a></li>";
83            $html .= "<li><a class='pattern_language_big_links' href='/content/PatternLanguage/archives.php'>"._("Read narratives archives")."</a></li>";
84            $html .= "</ul>";
85
86            // Until subscription is done DO NOT log this !
87            $this->setLoggingStatus(false);
88            // Tell the content group not to display elements until subscription is done
89            $parent_output = parent :: getUserUI($html, true);
90        }
91        else
92        {
93            // The user is subscribed to the pattern language show an element !
94            // hyperlink to user's narrative
95            $html .= "<ul class='pattern_language_menu'>";
96            $html .= "<li><a href='/content/PatternLanguage/narrative.php'>"._("Read my narrative")."</a></li>";
97            $html .= "<li><a href='/content/PatternLanguage/archives.php'>"._("Read narratives archives")."</a></li>";
98            $html .= "<li><a href='/content/PatternLanguage/subscription.php'>"._("Unsubscribe")."</a></li>";
99            $html .= "</ul>";
100
101            // Display the random pattern
102            $parent_output = parent :: getUserUI($html);
103        }
104
105        $html .= $subclass_user_interface;
106        $html .= "</div>\n";
107
108        return $parent_output;
109    }
110
111    /** Display the narrative
112     * @param $user The user who's narrative you want to grab
113     * @return the archive page HTML */
114    public function displayNarrative(User $user)
115    {
116        global $db;
117        // Debug values user_id = 8a90b1ea56cf27a0c61f9304da73bcd5
118        // PL : 3a3ea73dd2e2d03729e62b95d2574fc6
119        $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";
120        // OLD QUERY $sql = "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 content.content_type = 'PatternLanguage' ORDER BY content_group_element_id";
121        $db->ExecSql($sql, $rows, false);
122        $html = "";
123        if($rows)
124            foreach($rows as $row)
125            {
126                $cge = Content::getObject($row['content_group_element_id']);
127                $cge->setLoggingStatus(false);
128                $html .= $cge->getUserUI()."<p>";
129            }
130       return $html;
131    }
132
133    /** Get the list of all narratives
134     * @return the archive page HTML */
135    public function getNarrativeList()
136    {
137        global $db;
138        $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'";
139        $db->ExecSql($sql , $rows, false);
140        $narratives = array();
141        if($rows)
142            foreach($rows as $row)
143                $narratives[] = User::getObject($row['user_id']);
144        return $narratives;
145    }
146    /** Reloads the object from the database.  Should normally be called after a set operation.
147     * This function is private because calling it from a subclass will call the
148     * constructor from the wrong scope */
149    private function refresh()
150    {
151        $this->__construct($this->id);
152    }
153}
154
155/*
156 * Local variables:
157 * tab-width: 4
158 * c-basic-offset: 4
159 * c-hanging-comment-ender-p: nil
160 * End:
161 */
162
163?>
Note: See TracBrowser for help on using the browser.