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

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