0ebe3c50c6b4de32c7ea7d88d64e1dc871626316
[atutor.git] / mods / photo_album / classes / pa_mypic.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 image data for the my pictures view\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        class Mypic\r
31  * @see         class Pa\r
32  */\r
33 class Mypic extends Pa{\r
34         var $mode=POSTED_NEW;\r
35         var $image_array=Array();\r
36         var $page_array=Array();\r
37         var $current_page=-1;\r
38         var $show_page_left_buttons=false;\r
39         var $show_page_right_buttons=false;\r
40         var $total=NOT_SET;\r
41         var $last_page=NOT_SET;\r
42         \r
43         /**\r
44          * @desc        class constructor\r
45          */\r
46         function Mypic(){\r
47                 parent::init();\r
48                 $this->setMode();\r
49                 $this->checkCurrentPage();\r
50                 $this->setImages();\r
51                 $this->setPages();\r
52         \r
53         }\r
54         \r
55         /**\r
56          * @desc        This function decides whether to display left arrow and right arrow buttons for the page table\r
57          */\r
58         function setPages(){\r
59                 $temp=get_page_array(MYPIC_NUMBER_OF_IMAGE, MYPIC_NUMBER_OF_IMAGE_PAGE, $this->getVariable('current_page'), $this->getVariable('last_page'));\r
60                 $current=$this->getVariable('current_page');\r
61                 if ($current > 1){\r
62                         $this->setVariable('show_page_left_buttons', true);\r
63                 } \r
64                 if ($current < $temp['last_page']){\r
65                         $this->setVariable('show_page_right_buttons', true);\r
66                 }\r
67                 $this->page_array=&$temp;\r
68                 \r
69         }       \r
70         \r
71         /**\r
72          * @desc        This function sets the mode value for the image display.  The mode value can be one of POSTED_NEW, APPROVED, DISAPPROVED\r
73          */\r
74         function setMode(){\r
75                 if (isset($_GET['mode'])){\r
76                         $this->setVariable('mode', intval($_GET['mode']));\r
77                 } \r
78         }\r
79         \r
80         /**\r
81          * @desc        This function checks the current page is valid.  Otherwise, the current page is set to 1\r
82          */\r
83         function checkCurrentPage(){\r
84                 $total=get_total_image_number(MY_PIC, $this->getVariable('course_id'), $this->getVariable('mode'));\r
85                 $last_page=get_last_page(MYPIC_NUMBER_OF_IMAGE, $total);\r
86                 $this->setVariable('total', $total);\r
87                 $this->setVariable('last_page', $last_page);\r
88                 \r
89                 if (!isset($_GET['current_page'])){\r
90                         $this->setVariable('current_page', FIRST_PAGE);\r
91                 } else {\r
92                         $current_page=to_pos_int($_GET['current_page']);\r
93                         if ($current_page > $last_page){\r
94                                 $this->setVariable('current_page',$last_page);\r
95                         } else {\r
96                                 $this->setVariable('current_page', $current_page);\r
97                         }\r
98                 }\r
99         }\r
100         \r
101         /**\r
102          * @desc        This function sets the image array\r
103          */\r
104         function setImages(){\r
105                 $array=get_image_array(MY_PIC, parent::getVariable('course_id'), $this->getVariable('mode'), $this->getVariable('current_page'), MYPIC_NUMBER_OF_IMAGE, $_SESSION['login']);\r
106                 $this->image_array=&$array;\r
107         }\r
108                         \r
109         /**\r
110          * @desc        This function sets the given string to a value for the class object\r
111          * @param       String  $string         string name to set up\r
112          * @param       mixed   $value          string value\r
113          */\r
114         function setVariable($string, $value){\r
115                 switch ($string){\r
116                         case 'mode':\r
117                                 if ($value==APPROVED || $value==DISAPPROVED || $value==POSTED_NEW){\r
118                                         $this->{$string}=$value;\r
119                                 }\r
120                         break;\r
121                         case 'current_page':\r
122                         case 'last_page':\r
123                         case 'total':\r
124                                 if (is_int($value)){\r
125                                         $this->{$string}=$value;\r
126                                 } else {\r
127                                         parent::storeError("value ".$string." is not integer");\r
128                                 }\r
129                         break;\r
130                         case 'show_page_left_buttons':\r
131                         case 'show_page_right_buttons':\r
132                                 if (is_bool($value)){\r
133                                         $this->{$string}=$value;\r
134                                 } else {\r
135                                         parent::storeError("value ".$string." is not boolean");\r
136                                 }\r
137                         break;\r
138                 }\r
139         }\r
140 }