changed git call from https to git readonly
[atutor.git] / mods / photo_album / classes / pa_index.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 thumbnail image data for the index page - thumbnail 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 ('pa.class.php');\r
25 \r
26 /** \r
27  * @desc        class Pa_index.\r
28  * @see         class Pa\r
29  */\r
30 class Pa_Index extends Pa {\r
31         var $current_page=0;\r
32         var $show_page_left_buttons=false;\r
33         var $show_page_right_buttons=false;\r
34         var $image_array=Array();\r
35         var $page_array=Array();\r
36         var $total=NOT_SET;\r
37         var $last_page=NOT_SET;\r
38         \r
39         /** \r
40          * @desc        class constructor\r
41          */\r
42         function Pa_Index (){\r
43                 parent::init();\r
44                 $this->checkCurrentPage();\r
45                 $this->setImages();\r
46                 $this->setPages();\r
47         }\r
48         \r
49         /**\r
50          * @desc        this function sets the image array to display the index page\r
51          */\r
52         function setImages(){\r
53                 $temp=get_image_array(STUDENT, $this->getVariable('course_id'), APPROVED, $this->getVariable('current_page'), THUMB_NUMBER_OF_IMAGE);\r
54                 $this->image_array=&$temp;\r
55         }\r
56         \r
57         /**\r
58          * @desc        This function decides whether the left arrow and right arrow button should be displayed in the page table\r
59          */\r
60         function setPages(){\r
61                 $temp=get_page_array(THUMB_NUMBER_OF_IMAGE, THUMB_NUMBER_OF_IMAGE_PAGE, $this->getVariable('current_page'), $this->getVariable('last_page'));\r
62                 if ($temp['current'] >1 ){\r
63                         $this->setVariable('show_page_left_buttons', true);\r
64                 }\r
65                 if ($temp['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          * @desc        This function sets the given string value\r
73          * @param       String  $string         string name to be set up\r
74          * @param       mixed   $value          string value\r
75          */\r
76         function setVariable($string, $value){\r
77                 switch ($string){\r
78                         case 'current_page':\r
79                         case 'total':\r
80                         case 'last_page':\r
81                                 if (is_int($value)){\r
82                                         $this->{$string}=$value;\r
83                                 } else {\r
84                                         parent::storeError("variable ".$string." is not an positive int");\r
85                                 }\r
86                         break;\r
87                         case 'show_page_left_buttons':\r
88                         case 'show_page_right_buttons':\r
89                                 if (is_bool($value)){\r
90                                         $this->{$string}=$value;\r
91                                 } else {\r
92                                         parent::storeError("variable ".$string." is not boolean");\r
93                                 }\r
94                         break;\r
95                 }\r
96         }\r
97         \r
98         /**\r
99          * @desc        This function checks whether the current page value is valid.  Otherwise it sets 1 for the current page value\r
100          */\r
101         function checkCurrentPage(){\r
102                 $total=get_total_image_number(STUDENT, $this->getVariable('course_id'), APPROVED);\r
103                 $last_page=get_last_page(THUMB_NUMBER_OF_IMAGE, $total);\r
104                 $this->setVariable('total', $total);\r
105                 $this->setVariable('last_page', $last_page);\r
106                 \r
107                 if (!isset($_GET['current_page'])){\r
108                         $this->setVariable('current_page', FIRST_PAGE);\r
109                 } else {\r
110                         $current_page=to_pos_int($_GET['current_page']);\r
111                         if ($current_page > $last_page){\r
112                                 $this->setVariable('current_page',$last_page);\r
113                         } else {\r
114                                 $this->setVariable('current_page', $current_page);\r
115                         }\r
116                 }\r
117         }\r
118 }