/** * Get book data * Sort by featured DESC, title ASC * * @param PB_Catalog $catalog * * @return array */ function _books(PB_Catalog $catalog) { $books = $catalog->getAggregate(); foreach ($books as $key => $val) { // Deleted if ($val['deleted']) { unset($books[$key]); continue; } // Calculate cover height $books[$key]['cover_height'] = _cover_height($val['cover_url']['pb_cover_medium']); } return \PressBooks\Utility\multi_sort($books, 'featured:desc', 'title:asc'); }
/** * Render "Catalog Logo" meta box * * @param int $user_id */ function catalog_logo_box($user_id) { $meta_key = 'pb_catalog_logo'; $image_url = \PressBooks\Catalog::thumbnailFromUserId($user_id, 'pb_cover_medium'); $action = 'pb_delete_catalog_logo'; $nonce = wp_create_nonce('pb-delete-catalog-logo'); render_cover_image_box($meta_key, absint($user_id), $image_url, $action, $nonce); }
/** * Display catalog */ function do_catalog() { if (!array_key_exists('catalog', $GLOBALS['wp_query']->query_vars)) { // Don't do anything and return return; } $user_login = get_query_var('catalog'); if (!is_main_site()) { // Hard redirect location(network_site_url("/catalog/{$user_login}")); } $user = get_user_by('login', $user_login); if (false == $user) { $msg = __('No catalog was found for user', 'pressbooks') . ": {$user_login}"; $args = array('response' => '404'); wp_die($msg, '', $args); } \PressBooks\Catalog::loadTemplate($user->ID); exit; }
/** * @return array */ protected function getItemsData() { // TODO: Improve search filter for big data $catalog_obj = new Catalog(); $data = $catalog_obj->getAggregate(); foreach ($data as $key => $val) { $data[$key]['status'] = 1 == $val['deleted'] ? 0 : 1; $data[$key]['privacy'] = 1 == $val['private'] ? __('Private', 'pressbooks') : __('Public', 'pressbooks'); $data[$key]['cover'] = $val['cover_url']['pb_cover_small']; } return $this->searchFilter($data); }