remove old readme
[atutor.git] / mods / _standard / blogs / module_news.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010                                             */
6 /* Inclusive Design Institute                                          */
7 /* http://atutor.ca                                                                                                        */
8 /*                                                                                                                                         */
9 /* This program is free software. You can redistribute it and/or           */
10 /* modify it under the terms of the GNU General Public License             */
11 /* as published by the Free Software Foundation.                                           */
12 /***********************************************************************/
13 // $Id$
14 /*
15  * Get the latest updates of this module
16  * @return list of news, [timestamp]=>
17  */
18 function blogs_news() {
19     global $db, $enrolled_courses, $system_courses;
20     $news = array();
21
22     if ($enrolled_courses == ''){
23         return $news;
24     } 
25
26     $sql = "SELECT G.group_id, G.title, G.modules, T.course_id FROM ".TABLE_PREFIX."groups G INNER JOIN ".TABLE_PREFIX."groups_types  T USING (type_id) WHERE T.course_id IN $enrolled_courses ORDER BY G.title";
27
28
29     $result = mysql_query($sql, $db);
30     if ($result){
31         if (mysql_num_rows($result) > 0) {
32             while ($row = mysql_fetch_assoc($result)) {
33                 if (strpos($row['modules'], '_standard/blogs') !== FALSE) {
34                     // retrieve the last posted date/time from this blog
35                     $sql = "SELECT MAX(date) AS date FROM ".TABLE_PREFIX."blog_posts WHERE owner_type=".BLOGS_GROUP." AND owner_id={$row['group_id']}";
36                     $date_result = mysql_query($sql, $db);
37                     $row2 = mysql_fetch_assoc($date_result);                                    
38                     $last_updated = ' - ' . _AT('last_updated', AT_date(_AT('forum_date_format'), $row2['date'], AT_DATE_MYSQL_DATETIME));
39                 
40                     $link_title = $row['title'];
41                     $news[] = array('time'=>$row2['date'], 
42                     'object'=>$row, 
43                     'alt'=>_AT('blogs'),
44                     'course'=>$system_courses[$row['course_id']]['title'],
45                     'thumb'=>'images/home-blogs_sm.png', 
46                     'link'=>'<a href="bounce.php?course='.$row['course_id'].'&p='.urlencode('mods/_standard/blogs/view.php?ot='.BLOGS_GROUP.SEP.'oid='.$row['group_id']).'"'.
47                       (strlen($link_title) > SUBLINK_TEXT_LEN ? ' title="'.AT_print($link_title, 'blog_posts.title').'"' : '') .'>'. 
48                       AT_print(validate_length($link_title, SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY), 'blog_posts.title') .'</a>');
49                 }
50             }
51         }
52     }
53     return $news;
54 }
55
56 ?>