Get a book from a user catalog.

@param int $blog_id

@return array
18334
function getBook( $blog_id ) {

		/** @var $wpdb \wpdb */
		global $wpdb;

		$sql = "SELECT * FROM {$this->dbTable} WHERE users_id = %d AND blogs_id = %d AND deleted = 0 ";

		return $wpdb->get_row( $wpdb->prepare( $sql, $this->userId, $blog_id ), ARRAY_A ); // @codingStandardsIgnoreLine
	}
845344
public function index($id = null)
    {
        // process v1.authors.books route
        if ('v1.authors.books' === \Route::currentRouteName()) {
            return json()->setMeta($this->meta)->withPagination(
                Author::find($id)->books()->latest()->paginate(5),
                new BookTransformer
            );
        }

        // Respond with pagination
        return json()->setMeta($this->meta)->withPagination(
            $this->model->latest()->paginate(5),
            new BookTransformer
        );

        // Respond as a collection
        //return json()->setMeta($this->meta)->withCollection(
        //    $this->model->latest()->get(),
        //    new BookTransformer
        //);
    }
882989
public function listPages($blogId, $optParams = array()) {
      $params = array('blogId' => $blogId);
      $params = array_merge($params, $optParams);
      $data = $this->__call('list', array($params));
      if ($this->useObjects()) {
        return new Google_PageList($data);
      } else {
        return $data;
      }
    }
619540
protected function createBook() {
		$host = wp_parse_url( network_home_url(), PHP_URL_HOST );
		if ( is_subdomain_install() ) {
			$domain = $this->getSubdomainOrSubDirectory( $this->targetBookUrl ) . '.' . $host;
			$path = '/';
		} else {
			$domain = $host;
			$path = '/' . $this->getSubdomainOrSubDirectory( $this->targetBookUrl );
		}

		if ( ! $this->targetBookTitle ) {
			$this->targetBookTitle = $this->sourceBookMetadata['name'];
		}

		$user_id = get_current_user_id();
		// Disable automatic redirect to new book dashboard
		add_filter(
			'pb_redirect_to_new_book', function () {
				return false;
			}
		);
		// Remove default content so that the book only contains the results of the clone operation
		add_filter( 'pb_default_book_content', [ $this, 'removeDefaultBookContent' ] );
		$result = wpmu_create_blog( $domain, $path, $this->targetBookTitle, $user_id );
		remove_all_filters( 'pb_redirect_to_new_book' );
		remove_filter( 'pb_default_book_content', [ $this, 'removeDefaultBookContent' ] );
		if ( is_wp_error( $result ) ) {
			return false;
		}

		return $result;
	}
436019
public function getByProduct($product_id)
    {
        $result = null;
        $this->hook->attach('rating.get.before', $product_id, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $sql = 'SELECT rating, votes FROM rating WHERE product_id=?';
        $result = $this->db->fetch($sql, array($product_id));

        $this->hook->attach('rating.get.after', $product_id, $result, $this);
        return $result;
    }
145625
private static function get_active_plugins_basenames( $blog_id = 0 ) {
            if ( is_multisite() && $blog_id > 0 ) {
                $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
            } else {
                $active_basenames = get_option( 'active_plugins' );
            }

            if ( is_multisite() ) {
                $network_active_basenames = get_site_option( 'active_sitewide_plugins' );

                if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
                    $active_basenames = array_merge( $active_basenames, $network_active_basenames );
                }
            }

            return $active_basenames;
        }
146743
public function getBlogPosts()
    {
        $blog_posts = BlogPost::get()
            ->filter('ParentID', $this->ID)
            ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now())));

        $this->extend('updateGetBlogPosts', $blog_posts);
        return $blog_posts;
    }
1149231
public function getAll($excludeUnpublished = false, Blog $blog = null)
    {
        $this->clearInstance();
        $this->qb = $this->getInstance();

        //If $excludeUnpublished === true, we exclude the non published results
        if ($excludeUnpublished) {
            $this->qb
                ->andWhere('article.status = :status')
                ->orWhere('article.status = :scheduled_status AND article.publishedAt <= :now')
                ->setParameter('status', PageStatus::PUBLISHED)
                ->setParameter('scheduled_status', PageStatus::SCHEDULED)
                ->setParameter('now', new \DateTime());
        }

        if (null != $blog) {
            $this->qb
                ->andWhere('article.blog = :blog')
                ->setParameter('blog', $blog->getId());
        }

        return $this;
    }
1011399
function getTagsByBook( $blog_id, $tag_group ) {

		/** @var $wpdb \wpdb */
		global $wpdb;

		$sql = "SELECT DISTINCT {$this->dbTagsTable}.id, {$this->dbTagsTable}.tag FROM {$this->dbTagsTable}
 				INNER JOIN {$this->dbLinkTable} ON {$this->dbLinkTable}.tags_id = {$this->dbTagsTable}.id
 				INNER JOIN {$this->dbTable} ON {$this->dbTable}.users_id = {$this->dbLinkTable}.users_id AND {$this->dbTable}.blogs_id = {$this->dbLinkTable}.blogs_id
 				WHERE {$this->dbLinkTable}.tags_group = %d AND {$this->dbLinkTable}.users_id = %d AND {$this->dbLinkTable}.blogs_id = %d
 				ORDER BY {$this->dbTagsTable}.tag ASC ";

		return $wpdb->get_results( $wpdb->prepare( $sql, $tag_group, $this->userId, $blog_id ), ARRAY_A ); // @codingStandardsIgnoreLine
	}
1319198
protected function getPreview($blog_id, $content, $content_id) {
        $results=$this->extend('getPreview', $blog_id, $content, $content_id);
        if($results && is_array($results)) {
            $results=array_filter($results, function($v) {return !is_null($v);});
        
            if(count($results)>0) {
                return array_shift($results);
            }
        }
        
        
        //Detect if the record already exists or not so we can decide whether to create a new record or edit an existing
        $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
        if(!empty($existing) && $existing!==false && $existing->exists()) {
            $resultID=$content_id;
            
            $this->editPost($content_id, $content, false, true);
        }else {
            $resultID=$this->newPost($blog_id, $content, false, true);
            
            //Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
            if(is_object($resultID)) {
                return $resultID;
            }
            
            //Find the object
            $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($resultID))->first();
        }
        
        //Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
        if(is_object($resultID)) {
            return $resultID;
        }
        
        
        //Generate a preview token record
        $token=new KapostPreviewToken();
        $token->Code=sha1(uniqid(time().$resultID));
        $token->KapostRefID=$resultID;
        $token->write();
        
        
        //Return the details to kapost
        return array(
                    'url'=>Controller::join_links(Director::absoluteBaseURL(), 'kapost-service/preview', $resultID, '?auth='.$token->Code),
                    'id'=>$resultID
                );
    }
1020025
public function get_from_post_id(int $id) : ?forum_entity {
        $alias = $this->get_table_alias();
        $thistable = new dml_table(self::TABLE, $alias, $alias);
        $coursemoduletable = new dml_table('course_modules', 'cm', 'cm_');
        $coursetable = new dml_table('course', 'c', 'c_');

        $tablefields = $thistable->get_field_select();
        $coursemodulefields = $coursemoduletable->get_field_select();
        $coursefields = $coursetable->get_field_select();

        $fields = implode(', ', [
            $tablefields,
            context_helper::get_preload_record_columns_sql('ctx'),
            $coursemodulefields,
            $coursefields,
        ]);

        $tables = "{forum_posts} p";
        $tables .= " JOIN {forum_discussions} d ON d.id = p.discussion";
        $tables .= ' JOIN {' . self::TABLE . "} {$alias} ON {$alias}.id = d.forum";
        $tables .= " JOIN {modules} m ON m.name = 'forum'";
        $tables .= " JOIN {course_modules} cm ON cm.module = m.id AND cm.instance = {$alias}.id";
        $tables .= ' JOIN {context} ctx ON ctx.contextlevel = ' . CONTEXT_MODULE .  ' AND ctx.instanceid = cm.id';
        $tables .= " JOIN {course} c ON c.id = {$alias}.course";

        $sql = "SELECT {$fields} FROM {$tables} WHERE p.id = :postid";
        $records = $this->get_db()->get_records_sql($sql, [
            'postid' => $id,
        ]);

        $records = $this->transform_db_records_to_entities($records);
        return count($records) ? array_shift($records) : null;
    }
457535
private static function get_all_plugins( $blog_id = 0 ) {
            self::require_plugin_essentials();

            $all_plugins = fs_get_plugins();

            $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );

            foreach ( $all_plugins as $basename => &$data ) {
                // By default set to inactive (next foreach update the active plugins).
                $data['is_active'] = false;
                // Enrich with plugin slug.
                $data['slug'] = self::get_plugin_slug( $basename );
            }

            // Flag active plugins.
            foreach ( $active_plugins_basenames as $basename ) {
                if ( isset( $all_plugins[ $basename ] ) ) {
                    $all_plugins[ $basename ]['is_active'] = true;
                }
            }

            return $all_plugins;
        }
716060
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllStoreCredits(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllStoreCredits();
        }
    }
160677
private function get_site_notices( $blog_id = 0 ) {
            if ( 0 == $blog_id || $blog_id == $this->_blog_id ) {
                return $this->_notices;
            }

            return FS_Admin_Notice_Manager::instance(
                $this->_id,
                $this->_title,
                $this->_module_unique_affix,
                false,
                $blog_id
            );
        }
258544
static function deleteBookObjectCache() {

		global $blog_id;

		// Book Object
		wp_cache_delete( "book-inf-$blog_id", 'pb' ); // Delete the cached value for getBookInfo()
		wp_cache_delete( "book-str-$blog_id", 'pb' ); // Delete the cached value for getBookStructure()
		wp_cache_delete( "book-cnt-$blog_id", 'pb' ); // Delete the cached value for getBookContents()
		static::$__order = [];

		// Subsections
		delete_transient( static::SUBSECTIONS_TRANSIENT );

		// User Catalog
		( new Catalog() )->deleteCacheByBookId( $blog_id );

		// Output buffers
		delete_transient( Xhtml11::TRANSIENT );

		/**
		 * @since 5.0.0
		 *
		 * @param int $blog_id
		 */
		do_action( 'pb_cache_delete', $blog_id );
		set_transient( 'pb_cache_deleted', time(), DAY_IN_SECONDS );
	}
627700
private function get_site( $site_id ) {
		global $wpdb;

		// Load site data
		$site = $wpdb->get_row(
			$wpdb->prepare(
				"SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d",
				$site_id
			)
		);

		if ( ! empty( $site ) ) {
			// Only care about domain and path which are set here
			return $site;
		}

		return false;
	}
815325
public function get_items( $priority = 1000, $user_id = 0 ) {
		// Get the current author ID, if not specified.
		if ( ! $user_id ) {
			$user_id = get_queried_object_id();
		}

		// Create the author breadcrumb item.
		$item = Carbon_Breadcrumb_Item::factory( $this->get_type(), $priority );
		$item->set_id( $user_id );
		$item->setup();

		return array( $item );
	}