http://atutor.ca/atutor/mantis/view.php?id=4644
authorharris wong <hwong@ocad.ca>
Fri, 17 Dec 2010 15:52:11 +0000 (15:52 -0000)
committerharris wong <hwong@ocad.ca>
Fri, 17 Dec 2010 15:52:11 +0000 (15:52 -0000)
docs/install/db/atutor_upgrade_2.0.1_to_2.0.2.sql
docs/mods/_standard/photos/include/classes/PhotoAlbum.class.php
docs/mods/_standard/photos/module_groups.php [new file with mode: 0644]

index 8278265..68cf552 100644 (file)
@@ -5,4 +5,12 @@ UPDATE `themes` SET `type` = 'Mobile' WHERE `dir_name` = 'mobile';
 INSERT INTO `modules` (`dir_name`, `status`, `privilege`, `admin_privilege`, `cron_interval`, `cron_last_run`) VALUES('_standard/vimeo', 2, 0, 1, 0, 0);
 
 # add the IDI Default theme
-INSERT INTO `themes` VALUES ('IDI Theme', '2.0', 'idi', 'Desktop', '2010-12-02', 'The theme created for the IDI course server.', '1');
\ No newline at end of file
+INSERT INTO `themes` VALUES ('IDI Theme', '2.0', 'idi', 'Desktop', '2010-12-02', 'The theme created for the IDI course server.', '1');
+
+# A mapping table between photo album and atutor's groups
+CREATE TABLE `pa_groups` (
+  `group_id` INTEGER UNSIGNED NOT NULL,
+  `album_id` INTEGER UNSIGNED NOT NULL,
+  PRIMARY KEY (`group_id`, `album_id`)
+) ENGINE = MyISAM
+
index aac4150..3eb707b 100644 (file)
@@ -174,6 +174,7 @@ class PhotoAlbum {
         * @param       int                     permission, 0 for private, 1 for shared
         * @param       int                     album author
         * @param       int                     OPTIONAL, Photo cover for this album
+     * @return  int         album_id, FALSE if failed.
         */
        function createAlbum($name, $location, $description, $type, $permission, $member_id, $photo_id=0){
                global $addslashes, $db;
@@ -197,7 +198,10 @@ class PhotoAlbum {
                        $sql = "INSERT INTO ".TABLE_PREFIX."pa_course_album (course_id, album_id) VALUES ($_SESSION[course_id], $aid)";
                        $result = mysql_query($sql, $db);
                }
-               return $result;
+        if (!$result) {
+            return false;
+        }
+               return $aid;
        }
 
        /** 
diff --git a/docs/mods/_standard/photos/module_groups.php b/docs/mods/_standard/photos/module_groups.php
new file mode 100644 (file)
index 0000000..598ee1f
--- /dev/null
@@ -0,0 +1,66 @@
+<?php\r
+/****************************************************************************/\r
+/* ATutor                                                                                                                                      */\r
+/****************************************************************************/\r
+/* Copyright (c) 2002-2010                                                  */\r
+/* Inclusive Design Institute                                               */\r
+/* http://atutor.ca                                                                                                                    */\r
+/*                                                                                                                                                     */\r
+/* This program is free software. You can redistribute it and/or                       */\r
+/* modify it under the terms of the GNU General Public License                         */\r
+/* as published by the Free Software Foundation.                                                       */\r
+/****************************************************************************/\r
+// $Id$\r
+/**\r
+ * create an album for photo with the following attributes\r
+ *\r
+ * album type: course albums\r
+ * album permission: private\r
+ * album location: n/a\r
+ * album description: group description/na\r
+ * album creator: instructor_id\r
+ */\r
+require_once (AT_INCLUDE_PATH.'../mods/_standard/photos/include/lib.inc.php');\r
+require_once (AT_INCLUDE_PATH.'../mods/_standard/photos/include/classes/PhotoAlbum.class.php');\r
+function photos_create_group($group_id) {\r
+       global $db;\r
+    $group_id = intval($group_id);\r
+    //get group name\r
+    $sql = 'SELECT title FROM ' . TABLE_PREFIX . "groups WHERE group_id=$group_id";\r
+    $result = mysql_query($sql, $db);\r
+    $group_info = mysql_fetch_assoc($result);\r
+    \r
+    $pa = new PhotoAlbum();\r
+    $album_name = $group_info['title'] . '(' . _AT('group') . ')';\r
+    $album_location = _AT('na');\r
+    $album_description = _AT('na');\r
+    $album_type = AT_PA_TYPE_COURSE_ALBUM;\r
+    $album_permission = AT_PA_PRIVATE_ALBUM;\r
+\r
+    $album_id = $pa->createAlbum($album_name, $album_location, $album_description, $album_type, $album_permission, $_SESSION['member_id'], 0);\r
+    if ($album_id === false){\r
+        //TODO: sql failure.\r
+        $msg->addError('PA_CREATE_ALBUM_FAILED');\r
+        $result = false;\r
+    } else {\r
+        $sql = 'INSERT INTO '.TABLE_PREFIX."pa_groups (group_id, album_id) VALUES ($group_id, $album_id)";\r
+        $result = mysql_query($sql, $db);\r
+    }\r
+}\r
+\r
+// delete group\r
+function photos_delete_group($group_id) {\r
+       global $db;\r
+       $group_id = intval($group_id);\r
+       $sql = "SELECT album_id FROM ".TABLE_PREFIX."pa_groups WHERE group_id=$group_id";\r
+       $result = mysql_query($sql, $db);\r
+       while ($row = mysql_fetch_assoc($result)) {\r
+        $pa = new PhotoAlbum($row['album_id']);\r
+               $pa->deleteAlbum();\r
+       }\r
+\r
+       $sql = "DELETE FROM ".TABLE_PREFIX."pa_groups WHERE group_id=$group_id";\r
+       $result = mysql_query($sql, $db);\r
+}\r
+\r
+?>
\ No newline at end of file