public static function shortcode_answers($atts) { if (empty($atts['author'])) { return; } $limit = isset($atts['limit']) ? $atts['limit'] : 5; $atts['pagination'] = isset($atts['pagination']) ? $atts['pagination'] : 1; // $answersCount = CMA_Answer::countForUser($atts['author'], $approved = true, $onlyVisible = true); $answers = CMA_Answer::getByUser($atts['author'], $approved = true, $limit, $page = 1, $onlyVisible = true); $totalPages = ceil(CMA_Answer::countForUser($atts['author'], $approved = true, $onlyVisible = true) / $limit); $authorSlug = ''; $user = get_user_by(is_numeric($atts['author']) ? 'id' : 'slug', $atts['author']); if (!empty($user)) { $authorSlug = $user->user_nicename; } $public = false; $currentPage = 1; $ajax = (!isset($atts['ajax']) or $atts['ajax']) ? true : false; return CMA_BaseController::_loadView('answer/widget/answers-list', compact('answers', 'atts', 'public', 'authorSlug', 'currentPage', 'totalPages', 'limit', 'ajax')); }
public static function answersAction() { $limit = intval(self::_getParam('limit')); if (empty($limit)) { $limit = 5; } $currentPage = max(1, intval(self::_getParam('page'))); $totalPages = 1; $answers = array(); $authorSlug = ''; $ajax = false; if ($authorSlug = self::_getParam('author')) { if ($user = get_user_by('slug', $authorSlug)) { $authorSlug = $user->user_nicename; $answers = CMA_Answer::getByUser($user->ID, $approved = true, $limit, $currentPage, $onlyVisible = true); $totalPages = ceil(CMA_Answer::countForUser($user->ID, $approved = true, $limit, $currentPage, $onlyVisible = true) / $limit); } } $public = false; return array('content' => self::_loadView('answer/widget/answers-list', compact('answers', 'currentPage', 'totalPages', 'authorSlug', 'limit', 'ajax', 'public'))); }