Example #1
0
 /**
  * function displayForumIndex
  *
  * @param  object  $userObj
  * @param  integer $id_course
  * @param  integer $expand_index
  * @param  string  $order
  * @param  integer $id_course_instance
  * @param  string  $container_div_name
  * @return string  -
  */
 public static function displayForumIndex($userObj, $id_course, $expand_index, $order, $id_course_instance, $with_icons = NULL, $container_div_name = NULL)
 {
     $dh = $GLOBALS['dh'];
     $show_visits = !$GLOBALS['hide_visits'];
     /**
      *
      */
     if (!isset($id_course_instance)) {
         //return "";
         return new CText('');
     }
     // vito, 3 ottobre 2008
     $container_div = "";
     if ($container_div_name != NULL) {
         $container_div = $container_div_name;
     } else {
         $container_div = 'id_forum_index';
     }
     $show_icons = FALSE;
     if ($with_icons) {
         $show_icons = TRUE;
     }
     $callback_params = array('container_div' => $container_div);
     if ($order == 'chrono' || $order == 'struct') {
         $order_by_date = TRUE;
     } else {
         $order_by_date = FALSE;
     }
     /*
      * Get tutor id for this course instance
      */
     $class_tutor_id = $dh->course_instance_tutor_get($id_course_instance);
     if (AMA_DataHandler::isError($class_tutor_id)) {
         return $class_tutor_id;
     }
     $callback_params['user_id'] = $userObj->getId();
     $callback_params['class_tutors_ids'] = $class_tutor_id;
     $callback_params['show_icons'] = $show_icons;
     $forum_data = $dh->get_notes_for_this_course_instance($id_course_instance, $userObj->id_user, $order_by_date, $show_visits);
     switch ($userObj->tipo) {
         // sarebbe meglio $userObj->getType()
         case AMA_TYPE_AUTHOR:
             $callback = 'forumAuthorCallback';
             break;
         case AMA_TYPE_TUTOR:
             $callback = 'forumTutorCallback';
             $callback_params['id_course_instance'] = $id_course_instance;
             break;
         case AMA_TYPE_STUDENT:
             $callback = 'forumStudentCallback';
             $callback_params['id_course_instance'] = $id_course_instance;
             break;
     }
     if (AMA_DataHandler::isError($forum_data)) {
         return $forum_data;
     } else {
         //retrieving data about nodes' visits
         //first: retrieve visits data about all nodes of selected course and arrange them into an associative array
         $someone_there_data = array();
         $tmp_someone_there_data = ADALoggableUser::is_someone_there_courseFN($id_course_instance);
         if (!empty($tmp_someone_there_data)) {
             foreach ($tmp_someone_there_data as $v) {
                 $someone_there_data[$v['id_nodo']][] = $v;
             }
         }
         unset($tmp_someone_there_data);
         //free memory
         foreach ($forum_data as $k => $v) {
             //let's check if there are records for the node
             if (isset($someone_there_data[$v['id_nodo']])) {
                 $forum_data[$k]['is_someone_there'] = count($someone_there_data[$v['id_nodo']]) >= 1;
             } else {
                 $forum_data[$k]['is_someone_there'] = false;
             }
         }
         unset($someone_there_data);
         //free memory
     }
     /*
      * Attach the subtrees containing notes to the root node for this course instance.
      * This is required in order to display the index.
      */
     $forum_root_node = $id_course . '_' . ADA_DEFAULT_NODE;
     $notes_parent_nodes = array();
     // First, save all the parent ids for the notes in the forum
     foreach ($forum_data as $note) {
         $notes_parent_nodes[$note['id_nodo']] = TRUE;
     }
     // Then, if a note has a parent id which is not a note, attach it to
     // forum_root_node
     for ($i = 0; $i < count($forum_data); $i++) {
         if (!isset($notes_parent_nodes[$forum_data[$i]['id_nodo_parent']])) {
             $forum_data[$i]['id_nodo_parent'] = $forum_root_node;
         }
     }
     $index = CDOMElement::create('div', "id:{$container_div}");
     if ($order == 'chrono') {
         $index->addChild(self::ordered($forum_data, $callback, $callback_params, $forum_root_node));
     } else {
         $index->addChild(self::struct($forum_data, $forum_root_node, $expand_index, $callback, $callback_params));
     }
     return $index;
 }