PHP Class Pressbooks\Catalog

Show file Open project: pressbooks/pressbooks Class Usage Examples

Public Properties

Property Type Description
$currentVersion integer The value for option: pressbooks_catalog_version
$maxTagsGroup integer Maximum number allowed in tags_group column

Protected Properties

Property Type Description
$dbColumns array Column structure of catalog_table
$dbLinkTable Catalog tables, set in constructor
$dbTable Catalog tables, set in constructor
$dbTagsTable Catalog tables, set in constructor
$profileMetaKeys array Profile keys, stored in user_meta table
$userId integer User ID to construct this object

Public Methods

Method Description
__construct ( integer $user_id )
addMenu ( ) WP Hook, Instantiate UI
delete ( boolean $for_real = false ) : integer | false Delete an entire catalog.
deleteBook ( integer $blog_id, boolean $for_real = false ) : integer | false Delete a book from a user catalog.
deleteCache ( ) Delete the cache(s)
deleteCacheByBookId ( integer $book_id ) Delete the cache(s) by Book ID
deleteLogo ( ) WP_Ajax hook for pb_delete_catalog_logo
deleteTag ( string $tag, integer $blog_id, integer $tag_group, boolean $for_real = false ) : integer | false Delete a tag.
deleteTags ( $blog_id, $tag_group ) : integer | false Delete all tags from a user catalog
formAddByUrl ( ) Add Book by URL
formSubmit ( ) Catch me
get ( ) : array Get an entire catalog.
getAggregate ( ) : array Get all data for an entire catalog, cached
getBook ( integer $blog_id ) : array Get a book from a user catalog.
getBookIds ( ) : array Get only blog IDs.
getByTagId ( integer $tag_group, integer $tag_id ) : array Get catalog by tag id
getProfile ( ) : array Get catalog profile.
getTags ( integer $tag_group, boolean $show_hidden_tags = true ) : array Get tags
getTagsByBook ( integer $blog_id, integer $tag_group ) : array Get all tags for a book
getUserId ( ) : integer Get User ID
isCurrentAction ( $action ) : boolean Two actions are possible in a generic WP_List_Table form. The first takes precedence.
isFormSubmission ( ) : boolean Check if a user submitted something to index.php?page=pb_catalog
loadTemplate ( integer $userId ) Find and load our catalog template.
purgeOrphanTags ( ) Find all IDs in dbTagsTable that have no matching ID in dbLinkTable and delete them.
save ( array $items ) Save an entire catalog.
saveBook ( $blog_id, array $item ) : integer | false Save a book to a user catalog.
saveProfile ( array $item ) Save catalog profile
saveTag ( string $tag, integer $blog_id, integer $tag_group ) : integer | false Save tag
stringToTags ( string $tags ) : array Return an array of tags from a comma delimited string
tagsToString ( array $tags ) : string Return a comma delimited string from an SQL array of tags, in alphabetical order.
thumbnailFromUserId ( integer $user_id, string $size ) : string Catalog image is stored in user's active Media Library.
upgrade ( integer $version ) Upgrade catalog.
uploadLogo ( string $meta_key )

Protected Methods

Method Description
createOrUpdateTables ( ) DB Delta the initial Catalog tables.
formBulk ( $action ) Save bulk actions
formProfile ( ) Save catalog profile to database
formTags ( ) Save tags to database

Method Details

__construct() public method

public __construct ( integer $user_id )
$user_id integer (optional)

addMenu() static public method

WP Hook, Instantiate UI
static public addMenu ( )

createOrUpdateTables() protected method

If you change this, then don't forget to also change $this->dbColumns
See also: dbColumns
See also: http://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table
protected createOrUpdateTables ( )

delete() public method

Delete an entire catalog.
public delete ( boolean $for_real = false ) : integer | false
$for_real boolean (optional)
return integer | false

deleteBook() public method

Delete a book from a user catalog.
public deleteBook ( integer $blog_id, boolean $for_real = false ) : integer | false
$blog_id integer
$for_real boolean (optional)
return integer | false

deleteCache() public method

Delete the cache(s)
public deleteCache ( )

deleteCacheByBookId() public method

Delete the cache(s) by Book ID
public deleteCacheByBookId ( integer $book_id )
$book_id integer

deleteTag() public method

IMPORTANT: The 'for_real' option is extremely destructive. Do not use unless you know what you are doing.
public deleteTag ( string $tag, integer $blog_id, integer $tag_group, boolean $for_real = false ) : integer | false
$tag string
$blog_id integer
$tag_group integer
$for_real boolean (optional)
return integer | false

deleteTags() public method

Note: Doesn't actually delete a tag, just removes the association in dbLinkTable
public deleteTags ( $blog_id, $tag_group ) : integer | false
$blog_id
$tag_group
return integer | false

formAddByUrl() static public method

Add Book by URL
static public formAddByUrl ( )

formBulk() protected static method

Save bulk actions
protected static formBulk ( $action )
$action

formProfile() protected static method

Save catalog profile to database
protected static formProfile ( )

formSubmit() static public method

Catch me
static public formSubmit ( )

formTags() protected static method

Save tags to database
protected static formTags ( )

get() public method

Get an entire catalog.
public get ( ) : array
return array

getAggregate() public method

Get all data for an entire catalog, cached
public getAggregate ( ) : array
return array

getBook() public method

Get a book from a user catalog.
public getBook ( integer $blog_id ) : array
$blog_id integer
return array

getBookIds() public method

Get only blog IDs.
public getBookIds ( ) : array
return array

getByTagId() public method

Get catalog by tag id
public getByTagId ( integer $tag_group, integer $tag_id ) : array
$tag_group integer
$tag_id integer
return array

getProfile() public method

Get catalog profile.
public getProfile ( ) : array
return array

getTags() public method

Get tags
public getTags ( integer $tag_group, boolean $show_hidden_tags = true ) : array
$tag_group integer
$show_hidden_tags boolean (optional)
return array

getTagsByBook() public method

Get all tags for a book
public getTagsByBook ( integer $blog_id, integer $tag_group ) : array
$blog_id integer
$tag_group integer
return array

getUserId() public method

Get User ID
public getUserId ( ) : integer
return integer

isCurrentAction() static public method

Two actions are possible in a generic WP_List_Table form. The first takes precedence.
See also: WP_List_Table::current_action
static public isCurrentAction ( $action ) : boolean
$action
return boolean

isFormSubmission() static public method

Check if a user submitted something to index.php?page=pb_catalog
static public isFormSubmission ( ) : boolean
return boolean

loadTemplate() static public method

Find and load our catalog template.
static public loadTemplate ( integer $userId )
$userId integer

purgeOrphanTags() public method

Find all IDs in dbTagsTable that have no matching ID in dbLinkTable and delete them.
public purgeOrphanTags ( )

save() public method

Save an entire catalog.
public save ( array $items )
$items array

saveBook() public method

Save a book to a user catalog.
public saveBook ( $blog_id, array $item ) : integer | false
$blog_id
$item array
return integer | false

saveProfile() public method

Save catalog profile
public saveProfile ( array $item )
$item array

saveTag() public method

Save tag
public saveTag ( string $tag, integer $blog_id, integer $tag_group ) : integer | false
$tag string
$blog_id integer
$tag_group integer
return integer | false

stringToTags() static public method

Return an array of tags from a comma delimited string
static public stringToTags ( string $tags ) : array
$tags string
return array

tagsToString() static public method

Return a comma delimited string from an SQL array of tags, in alphabetical order.
static public tagsToString ( array $tags ) : string
$tags array
return string

thumbnailFromUserId() static public method

Catalog image is stored in user's active Media Library.
static public thumbnailFromUserId ( integer $user_id, string $size ) : string
$user_id integer
$size string
return string

upgrade() public method

Upgrade catalog.
public upgrade ( integer $version )
$version integer

Property Details

$currentVersion static public property

The value for option: pressbooks_catalog_version
See also: install()
static public int $currentVersion
return integer

$dbColumns protected property

Column structure of catalog_table
protected array $dbColumns
return array

$dbLinkTable protected property

Catalog tables, set in constructor
protected $dbLinkTable

$dbTable protected property

Catalog tables, set in constructor
protected $dbTable

$dbTagsTable protected property

Catalog tables, set in constructor
protected $dbTagsTable

$maxTagsGroup static public property

Maximum number allowed in tags_group column
static public int $maxTagsGroup
return integer

$profileMetaKeys protected property

Profile keys, stored in user_meta table
protected array $profileMetaKeys
return array

$userId protected property

User ID to construct this object
protected int $userId
return integer