84ec777e5f90f29aad79f15db041c76ccee048ec
[atutor.git] / mods / photo_album / classes / pa_mycomment.class.php
1 <?php\r
2 /*==============================================================\r
3   Photo Album\r
4  ==============================================================\r
5   Copyright (c) 2006 by Dylan Cheon & Kelvin Wong\r
6   Institute for Assistive Technology / University of Victoria\r
7   http://www.canassist.ca/                                    \r
8                                                                \r
9   This program is free software. You can redistribute it and/or\r
10   modify it under the terms of the GNU General Public License  \r
11   as published by the Free Software Foundation.                \r
12  ==============================================================\r
13  */\r
14 // $Id:\r
15 \r
16 /**\r
17  * @desc        This file generates comment data for the mycomment mode\r
18  * @author      Dylan Cheon & Kelvin Wong\r
19  * @copyright   2006, Institute for Assistive Technology / University of Victoria \r
20  * @link        http://www.canassist.ca/                                    \r
21  * @license GNU\r
22  */\r
23 \r
24 require_once ('define.php');\r
25 require_once ('classes/pa.class.php');\r
26 require_once ('include/general_func.php');\r
27 require_once ('include/data_func.php');\r
28 \r
29 /** \r
30  * @desc        Mycomment class.  \r
31  * @see         Pa\r
32  */\r
33  \r
34 class Mycomment extends Pa{\r
35         var $mode=POSTED_NEW;\r
36         var $comment_array=Array();\r
37         var $page_array=Array();\r
38         var $current_page=-1;\r
39         var $show_page_left_buttons=false;\r
40         var $show_page_right_buttons=false;\r
41         var $total=NOT_SET;\r
42         var $last_page=NOT_SET;\r
43         \r
44         /** \r
45          * @desc        constructor\r
46          */\r
47         function Mycomment(){\r
48                 parent::init();\r
49                 $this->setMode();\r
50                 $this->checkCurrentPage();\r
51                 $this->setComments();\r
52                 $this->setPages();\r
53         \r
54         }\r
55         \r
56         /**\r
57          * @desc        This function decides whether to display left arrow and right arrow buttons in the page table\r
58          */\r
59         function setPages(){\r
60                 $temp=get_page_array(MYCOMMENT_NUMBER_OF_COMMENT, MYCOMMENT_NUMBER_OF_COMMENT_PAGE, $this->getVariable('current_page'), $this->getVariable('last_page'));\r
61                 $current=$this->getVariable('current_page');\r
62                 if ($current > 1){\r
63                         $this->setVariable('show_page_left_buttons', true);\r
64                 } \r
65                 if ($current < $temp['last_page']){\r
66                         $this->setVariable('show_page_right_buttons', true);\r
67                 }\r
68                 $this->page_array=&$temp;\r
69                 \r
70         }       \r
71         \r
72         /**\r
73          * @desc        This function sets the mode value for the comments displayed.  The mode value can be one of POSTED_NEW, APPROVED, DISAPPROVED\r
74          */\r
75         function setMode(){\r
76                 if (isset($_GET['mode'])){\r
77                         $this->setVariable('mode', intval($_GET['mode']));\r
78                 } \r
79         }\r
80         \r
81         /**\r
82          * @desc        This function checks the current page is valid.  Otherwise, the current page is 1\r
83          */\r
84         function checkCurrentPage(){\r
85                 $total=get_total_comment_number(MY_COMMENT, $this->getVariable('course_id'), $this->getVariable('mode'));\r
86                 $last_page=get_last_page(MYCOMMENT_NUMBER_OF_COMMENT, $total);\r
87                 $this->setVariable('total', $total);\r
88                 $this->setVariable('last_page', $last_page);\r
89                 \r
90                 if (!isset($_GET['current_page'])){\r
91                         $this->setVariable('current_page', FIRST_PAGE);\r
92                 } else {\r
93                         $current_page=to_pos_int($_GET['current_page']);\r
94                         if ($current_page > $last_page){\r
95                                 $this->setVariable('current_page',$last_page);\r
96                         } else {\r
97                                 $this->setVariable('current_page', $current_page);\r
98                         }\r
99                 }\r
100         }\r
101         \r
102         /**\r
103          * @desc        This function sets the comment array\r
104          */\r
105         function setComments(){\r
106                 $array=get_comment_array(MY_COMMENT, parent::getVariable('course_id'), $this->getVariable('mode'), NOT_SET, MYCOMMENT_NUMBER_OF_COMMENT, $this->getVariable('current_page'));\r
107                 $this->comment_array=&$array;\r
108         }\r
109                         \r
110         /**\r
111          * @desc        This function sets the given string value for the class object\r
112          * @param       String  $string         string name to set\r
113          * @param       mixed   $value          string value\r
114          */\r
115         function setVariable($string, $value){\r
116                 switch ($string){\r
117                         case 'mode':\r
118                                 if ($value==APPROVED || $value==DISAPPROVED || $value==POSTED_NEW){\r
119                                         $this->{$string}=$value;\r
120                                 }\r
121                         break;\r
122                         case 'current_page':\r
123                         case 'last_page':\r
124                         case 'total':\r
125                                 if (is_int($value)){\r
126                                         $this->{$string}=$value;\r
127                                 } else {\r
128                                         parent::storeError("value ".$string." is not integer");\r
129                                 }\r
130                         break;\r
131                         case 'show_page_left_buttons':\r
132                         case 'show_page_right_buttons':\r
133                                 if (is_bool($value)){\r
134                                         $this->{$string}=$value;\r
135                                 } else {\r
136                                         parent::storeError("value ".$string." is not boolean");\r
137                                 }\r
138                         break;\r
139                 }\r
140         }\r
141 }