/**
  * Subscribe current user from news
  */
 function subscribeNews()
 {
     global $ilUser, $ilCtrl;
     include_once "./Services/News/classes/class.ilNewsSubscription.php";
     ilNewsSubscription::_subscribe($_GET["ref_id"], $ilUser->getId());
     $ilCtrl->returnToParent($this);
 }
 /**
  * Get all news items for a user.
  */
 static function _getNewsItemsOfUser($a_user_id, $a_only_public = false, $a_prevent_aggregation = false, $a_per = 0, &$a_cnt = NULL)
 {
     global $ilAccess;
     $news_item = new ilNewsItem();
     $news_set = new ilSetting("news");
     $per = $a_per;
     include_once "./Services/News/classes/class.ilNewsSubscription.php";
     include_once "./Services/Block/classes/class.ilBlockSetting.php";
     // this is currently not used
     $ref_ids = ilNewsSubscription::_getSubscriptionsOfUser($a_user_id);
     if (ilObjUser::_lookupPref($a_user_id, "pd_items_news") != "n") {
         // get all items of the personal desktop
         $pd_items = ilObjUser::_lookupDesktopItems($a_user_id);
         foreach ($pd_items as $item) {
             if (!in_array($item["ref_id"], $ref_ids)) {
                 $ref_ids[] = $item["ref_id"];
             }
         }
         // get all memberships
         include_once 'Services/Membership/classes/class.ilParticipants.php';
         $crs_mbs = ilParticipants::_getMembershipByType($a_user_id, 'crs');
         $grp_mbs = ilParticipants::_getMembershipByType($a_user_id, 'grp');
         $items = array_merge($crs_mbs, $grp_mbs);
         foreach ($items as $i) {
             $item_references = ilObject::_getAllReferences($i);
             if (is_array($item_references) && count($item_references)) {
                 foreach ($item_references as $ref_id) {
                     if (!in_array($ref_id, $ref_ids)) {
                         $ref_ids[] = $ref_id;
                     }
                 }
             }
         }
     }
     $data = array();
     foreach ($ref_ids as $ref_id) {
         if (!$a_only_public) {
             // this loop should not cost too much performance
             $acc = $ilAccess->checkAccessOfUser($a_user_id, "read", "", $ref_id);
             if (!$acc) {
                 continue;
             }
         }
         if (ilNewsItem::getPrivateFeedId() != false) {
             global $rbacsystem;
             $acc = $rbacsystem->checkAccessOfUser(ilNewsItem::getPrivateFeedId(), "read", $ref_id);
             if (!$acc) {
                 continue;
             }
         }
         $obj_id = ilObject::_lookupObjId($ref_id);
         $obj_type = ilObject::_lookupType($obj_id);
         $news = $news_item->getNewsForRefId($ref_id, $a_only_public, false, $per, $a_prevent_aggregation, false, false, false, $a_user_id);
         // counter
         if (!is_null($a_cnt)) {
             $a_cnt[$ref_id] = count($news);
         }
         $data = ilNewsItem::mergeNews($data, $news);
     }
     $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
     return $data;
 }