/** * Gets all user posts from blog, filtered by page and tags * @param int $blogid * @param string $sort * @param string $username * @param int $page * @param string $tags comma separated sequence of selected tag ids to filter by * @return array */ public static function get_blog_allposts($blogid, $sort, $username, $page = 0, $tags = null) { global $DB; $params = self::validate_parameters(self::get_blog_allposts_parameters(), array('blogid' => $blogid, 'sort' => $sort, 'username' => $username, 'page' => $page, 'tags' => $tags)); $user = $DB->get_field('user', 'id', array('username' => $params['username']), IGNORE_MISSING); if (!$user) { return array(); } $result = oublog_import_getallposts($params['blogid'], $params['sort'], $user, $params['page'], $params['tags']); if (!is_array($result[2])) { $result[2] = array(); } foreach ($result[0] as &$post) { if (isset($post->tags)) { $tagupdate = array(); // Update post tags into a format that Moodle WS can work with. foreach ($post->tags as $id => $tag) { $tagupdate[] = (object) array('id' => $id, 'tag' => $tag); } $post->tags = $tagupdate; } } return array('posts' => $result[0], 'total' => $result[1], 'tagnames' => $result[2]); }
$result = oublog_import_remote_call('mod_oublog_get_blog_allposts', array('blogid' => $boublogid, 'username' => $USER->username, 'sort' => $sort, 'page' => $page, 'tags' => $tags)); $posts = $result->posts; $total = $result->total; $tagnames = $result->tagnames; // Fix up post tags to required format as passed differently from WS. foreach ($posts as &$post) { if (isset($post->tags)) { $newtagarr = array(); foreach ($post->tags as $tag) { $newtagarr[$tag->id] = $tag->tag; } $post->tags = $newtagarr; } } } else { list($posts, $total, $tagnames) = oublog_import_getallposts($boublogid, $sort, $USER->id, $page, $tags); } if ($posts) { // Finish seting up table vars. $url = new moodle_url('/mod/oublog/import.php', $params + $stepinfo); $table->define_baseurl($url); $perpage = $total < $perpage ? $total : $perpage; $table->pagesize($perpage, $total); $taghead = get_string('import_step1_table_tags', 'oublog'); if (!empty($tagnames)) { // Add tag filter removal links. $taghead .= '<br />'; foreach ($tagnames as $tagid => $tag) { $tagaarcopy = explode(',', $tags); unset($tagaarcopy[array_search($tagid, $tagaarcopy)]); $turl = new moodle_url('/mod/oublog/import.php', array_merge($params, $stepinfo, array('tags' => implode(',', $tagaarcopy))));