Ejemplo n.º 1
0
 public static function listAsFeed($db, $app_root, $category = '')
 {
     //public ONLY!!!!!!
     $feed = new Dase_Atom_Feed();
     $feed->setId($app_root . '/sets');
     $feed->setFeedType('sets');
     $feed->setUpdated(date(DATE_ATOM));
     $feed->addAuthor();
     if ($category) {
         $scheme = '';
         $parts = explode('}', $category);
         if (1 == count($parts)) {
             $term = $parts[0];
         } elseif (2 == count($parts)) {
             $scheme = urldecode(trim($parts[0], '{'));
             $scheme = str_replace('http://daseproject.org/category/', '', $scheme);
             $term = $parts[1];
         } else {
             return $feed->asXml();
         }
         /***************newly refactored*******************/
         $tag_cat = new Dase_DBO_TagCategory($db);
         $tag_cat->term = $term;
         $tag_cat->scheme = $scheme;
         $in_set = array();
         $category_label = $term;
         foreach ($tag_cat->find() as $tc) {
             $in_set[] = $tc->tag_id;
             $category_label = $tc->label;
         }
         $feed->setTitle('Sets for ' . $category_label);
         $tags = new Dase_DBO_Tag($db);
         $tags->is_public = true;
         $tags->orderBy('updated DESC');
         foreach ($tags->find() as $tag) {
             $tag = clone $tag;
             if (!$tag->item_count) {
                 $tag->updateItemCount();
             }
             if ($tag->ascii_id and in_array($tag->id, $in_set)) {
                 $entry = $tag->injectAtomEntryData($feed->addEntry('set'), null, $app_root);
                 $entry->addCategory($tag->item_count, "http://daseproject.org/category/item_count");
             }
         }
         /*********************************************/
     } else {
         $feed->setTitle('All Public Sets');
         $tags = new Dase_DBO_Tag($db);
         $tags->is_public = true;
         $tags->orderBy('updated DESC');
         foreach ($tags->find() as $tag) {
             $tag = clone $tag;
             if (!$tag->item_count) {
                 $tag->updateItemCount();
             }
             if ($tag->ascii_id) {
                 //compat: make sure tag has ascii_id
                 $entry = $tag->injectAtomEntryData($feed->addEntry('set'), null, $app_root);
                 $entry->addCategory($tag->item_count, "http://daseproject.org/category/item_count");
             }
         }
     }
     $feed->sortByTitle();
     return $feed->asXml();
 }