Exemplo n.º 1
0
 private function listRelevantFeedItems($count = 100)
 {
     // Hämtar alla FeedItems som berör en medlem
     if (empty($this->relevantFeedItems)) {
         global $db;
         $sql = "\n\t\t\t\nSELECT \n\tid \nFROM \n\t" . self::RELATION_TABLE . " \nWHERE \n\tmedlem_id IN (\n\t\tSELECT id \n\t\tFROM " . self::MEDLEM_TABLE . " \n\t\tWHERE \n\t\t\n\t\t\tid IN \n\t\t\t\t( \n\t\t\t\t\tSELECT kontakt_id \n\t\t\t\t\tFROM " . Adressbok::RELATION_TABLE . "\n\t\t\t\t\tWHERE medlem_id = " . $this->getMedlem()->getId() . "\n\n\t\t\t\t) OR id IN (\n\t\t\t\t\tSELECT medlem_id \n\t\t\t\t\tFROM " . Foretag::KEY_TABLE . " \n\t\t\t\t\tWHERE lag_id in (\n\t\t\t\t\t\tSELECT lag_id \n\t\t\t\t\t\tFROM " . Foretag::KEY_TABLE . " \n\t\t\t\t\t\tWHERE medlem_id = " . $this->getMedlem()->getId() . "\n\t\t\t\t\t)\t\t\n\t\t\t\t)\n\t\t\n\t)\t\n\tOR\n\tgrupp_id IN (\n\t\n\t\tSELECT grupp_id \n\t\tFROM " . Grupp::RELATION_TABLE . " \n\t\tWHERE medlem_id = " . $this->getMedlem()->getId() . "\n\t\n\t)\n\n\t" . "\n\tOR\n\tid IN (\n\t\n\t\tSELECT\n\t\t\t" . self::RELATION_TABLE . ".id\n\t\tFROM\n\t\t\t" . self::RELATION_TABLE . " JOIN " . Grupp::RELATION_TABLE . "\n\t\t\tON " . self::RELATION_TABLE . ".medlem_id = " . Grupp::RELATION_TABLE . ".medlem_id\n\t\tWHERE \n\t\t\t" . self::RELATION_TABLE . ".medlem_id = " . $this->getMedlem()->getId() . " AND\n\t\t\t" . self::RELATION_TABLE . ".datum >= " . Grupp::RELATION_TABLE . ".datum\n\n\t)\n\tOR\n\t(typ = 'lagttilliadressbok' AND params = '" . $this->getMedlem()->getId() . "|" . $this->getMedlem()->getANamn() . "')\n\tOR\n\t(typ = 'valkommen' AND medlem_id = " . $this->getMedlem()->getId() . ")\n";
         $this->relevantFeedItems = FeedItem::listByIds($db->valuesAsArray($sql));
         /* Lag and Foretagsfeeds */
         global $USER;
         if (isset($USER)) {
             $foretag = $USER->getForetag();
             if (isset($foretag)) {
                 $foretagFeeds = array();
                 $foretagFeeds = FeedItem::getForetagItems($foretag);
                 $this->relevantFeedItems = array_merge($this->relevantFeedItems, $foretagFeeds);
             }
             $lag = $USER->getLag();
             if (isset($lag)) {
                 $lagFeeds = array();
                 $lagFeeds = FeedItem::getLagItems($lag);
                 $this->relevantFeedItems = array_merge($this->relevantFeedItems, $lagFeeds);
             }
             if (true || isset($lag) || isset($foretag)) {
                 /* no need to sort if no feeds are added, handled thru mobject-fetch */
                 $this->relevantFeedItems = self::sortFeeds($this->relevantFeedItems);
             }
         }
     }
     // print_r($this->relevantFeedItems);
     return $this->relevantFeedItems;
 }