Browse Source

Adding course announcements tags see BT#2723 partial waiting feedback for global announcements ...

Julio Montoya 13 years ago
parent
commit
f49b2424a0
2 changed files with 53 additions and 28 deletions
  1. 43 11
      main/announcements/announcements.inc.php
  2. 10 17
      main/announcements/announcements.php

+ 43 - 11
main/announcements/announcements.inc.php

@@ -3,6 +3,7 @@
 /**
 * Include file with functions for the announcements module.
 * @package chamilo.announcements
+* @todo use OOP
 */
 
 /**
@@ -10,9 +11,39 @@
  *
  */
 class AnnouncementManager  {
-	
-	private function __construct() {
+    
+    
+	public function __construct() {
 	}	
+	
+	public function get_tags() {
+	    return array('((user_name))','((teacher_name))','((teacher_email))','((course_title))', '((course_link))');
+	}
+	
+	public function parse_content($content, $course_code) {
+    	$reader_info  = api_get_user_info(api_get_user_id());
+		$course_info  = api_get_course_info($course_code);
+	    $teacher_list = Coursemanager::get_teacher_list_from_course_code($course_info['code']);
+	    
+	    $teacher_name = '';
+	    if (!empty($teacher_list)) {
+	        foreach($teacher_list as $teacher_data) {    	  
+	            $teacher_name  = api_get_person_name($teacher_data['firstname'], $teacher_data['lastname']);
+	            $teacher_email = $teacher_data['email'];
+	            break;
+	        }
+	    }    	    
+		$course_link = api_get_course_url();
+		
+		$data['username']        = $reader_info['username'];    		
+		$data['teacher_name']    = $teacher_name;
+		$data['teacher_email']   = $teacher_email;    		
+		$data['course_title']    = $course_info['name'];
+		$data['course_link']     = Display::url($course_link, $course_link);
+	
+        $content = str_replace(self::get_tags(), $data, $content);
+        return $content;	    
+	}
 		
 	/**
 	 * Gets all announcements from a course 
@@ -149,11 +180,11 @@ class AnnouncementManager  {
     		if (api_is_allowed_to_edit(false,true) || (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
     		    $modify_icons = "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$announcement_id."\">".Display::return_icon('edit.png', get_lang('Edit'),'',22)."</a>";
                 if ($result['visibility'] == 1) {
-                    $image_visibility="visible";
-                    $alt_visibility=get_lang('Hide');
+                    $image_visibility = "visible";
+                    $alt_visibility = get_lang('Hide');
                 } else {
                     $image_visibility="invisible";
-                    $alt_visibility=get_lang('Visible');
+                    $alt_visibility = get_lang('Visible');
                 }
                 global $stok;
                 
@@ -167,9 +198,11 @@ class AnnouncementManager  {
                 }                            
                 echo "<tr><th style='text-align:right'>$modify_icons</th></tr>";
     		}
+    		    		
+    		$content = self::parse_content($content, api_get_course_id());
     		
     		echo "<tr><td>$content</td></tr>";       		
-    		//echo "<tr><td class=\"announcements_datum\">" . get_lang('AnnouncementPublishedOn') . " : " .api_convert_and_format_date($result['end_date'], DATE_FORMAT_LONG). "</td></tr>";
+
             echo "<tr><td class=\"announcements_datum\">" . get_lang('LastUpdateDate') . " : " .api_convert_and_format_date($result['insert_date'], DATE_TIME_FORMAT_LONG). "</td></tr>";
             
             // User or group icon
@@ -179,15 +212,14 @@ class AnnouncementManager  {
             }            
             $sent_to        = self::sent_to('announcement', $announcement_id);            
             $sent_to_form   = self::sent_to_form($sent_to);
-            echo Display::tag('td', get_lang('SentTo').' : '.$sent_to_form, array('class'=>'announcements_datum'));            
-            
-    		
+            echo Display::tag('td', get_lang('SentTo').' : '.$sent_to_form, array('class'=>'announcements_datum'));     
+                		
     	    $attachment_list = self::get_attachment($announcement_id);
         
             if (count($attachment_list)>0) {
                 echo "<tr><td>";
-                $realname=$attachment_list['path'];
-                $user_filename=$attachment_list['filename'];
+                $realname = $attachment_list['path'];
+                $user_filename = $attachment_list['filename'];
                 $full_file_name = 'download.php?file='.$realname;
                 echo '<br/>';                
                 echo Display::return_icon('attachment.gif',get_lang('Attachment'));

+ 10 - 17
main/announcements/announcements.php

@@ -3,14 +3,14 @@
 /**
  * @author Frederik Vermeire <frederik.vermeire@pandora.be>, UGent Internship
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: code cleaning
- * @author Julio Montoya <gugli100@gmail.com>, MORE code cleaning
+ * @author Julio Montoya <gugli100@gmail.com>, MORE code cleaning 2011
  *
  * @abstract The task of the internship was to integrate the 'send messages to specific users' with the
  *			 Announcements tool and also add the resource linker here. The database also needed refactoring
  *			 as there was no title field (the title was merged into the content field)
  * @package chamilo.announcements
  * @todo make AWACS out of the configuration settings
- * @todo this file is 1200+ lines without any functions -> needs to be split into
+ * @todo this file is 1300+ lines without any functions -> needs to be split into
  * multiple functions
 */
 /*
@@ -461,7 +461,6 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
 					if (!empty($_SESSION['toolgroup'])) {
 						$insert_id = AnnouncementManager::add_group_announcement($safe_emailTitle,$safe_newContent,$order,array('GROUP:'.$_SESSION['toolgroup']),$_POST['selectedform'],$file,$file_comment);
 					} else {
-
 						$insert_id = AnnouncementManager::add_announcement($safe_emailTitle, $safe_newContent, $order, $_POST['selectedform'], $file, $file_comment);
 					}
 				    //store_resources($_SESSION['source_type'],$insert_id);
@@ -570,7 +569,6 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
 										ON $tbl_user.user_id = $tbl_session_course_user.id_user
 										AND $tbl_session_course_user.course_code = '".$_course['id']."'
 										AND $tbl_session_course_user.id_session = ".api_get_session_id();
-
 			    		}
 			    	}
 
@@ -602,7 +600,7 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
                                 $mail_body = api_get_person_name($myrow["lastname"], $myrow["firstname"], null, PERSON_NAME_EMAIL_ADDRESS)."<br />\n".stripslashes($emailTitle)."<br />";
 
 	                            // Main part of the email
-	                            $mail_body .= trim(stripslashes($newContent));
+	                            $mail_body .= trim(stripslashes(AnnouncementManager::parse_content($newContent)));
                                 // Signature of email: sender name and course URL after -- line
 	                            $mail_body .= "<br />-- <br />";
 	                            $mail_body .= api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS)." \n";
@@ -620,12 +618,11 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
                                 $sql = 'SELECT path, filename FROM '.$tbl_announcement_attachment.' WHERE announcement_id = "'.$insert_id.'"';
                                 $rs_attach = Database::query($sql);
                                 if (Database::num_rows($rs_attach) > 0) {
-                                        $row_attach  = Database::fetch_array($rs_attach);
-                                        $path_attach = api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/announcements/'.$row_attach['path'];
-                                        $filename_attach = $row_attach['filename'];
-                                        $data_file = array('path' => $path_attach,'filename' => $filename_attach);
+                                    $row_attach  = Database::fetch_array($rs_attach);
+                                    $path_attach = api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/announcements/'.$row_attach['path'];
+                                    $filename_attach = $row_attach['filename'];
+                                    $data_file = array('path' => $path_attach,'filename' => $filename_attach);
                                 }
-
                                 @api_mail_html($recipient_name, $mailid, stripslashes($emailSubject), $mail_body, $sender_name, $sender_email, null, $data_file, true);
 	                        //}
 
@@ -803,7 +800,7 @@ $result = Database::query($sql);
 $announcement_number = Database::num_rows($result);
 
 /*
-		ADD ANNOUNCEMENT / DELETE ALL
+	ADD ANNOUNCEMENT / DELETE ALL
 */
 
 $show_actions = false;
@@ -1000,12 +997,6 @@ if ($display_form) {
 
 	echo '<input type="hidden" name="id" value="'.$announcement_to_modify.'" />';
 
-	/*if ($surveyid) {
-	$content_to_modify='<br /><a href="'.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name">'.get_lang('ClickHereToOpenSurvey').'</a><br />
-									'.get_lang('OrCopyPasteUrl').' <br />
-									'.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name&nbsp;';
-	}*/
-
     $oFCKeditor = new FCKeditor('newContent') ;
 	$oFCKeditor->Width		= '100%';
 	$oFCKeditor->Height		= '300';
@@ -1020,6 +1011,8 @@ if ($display_form) {
 
 	echo '<div class="row"><div class="formw">';
 	
+	echo Display::display_normal_message(get_lang('Tags').' <br /><br />'.implode('<br />', AnnouncementManager::get_tags()), false);
+			
 	echo $oFCKeditor->CreateHtml();
 	echo '</div></div>';