Public Member Functions | |
__construct ($id= '') | |
Initializes new Book object. | |
addChapter ($name) | |
Creates a new chapter in this book. | |
delete () | |
Delete this book. | |
deleteChapterByName ($name) | |
Deletes any child chapters with given name. | |
getIdentifier () | |
Returns a string that identifies this book. | |
getParent () | |
INSERT BRIEF DESCRIPTION HERE. | |
isValid () | |
Determines whether book is valid to be in the database. | |
listChildren ($constraints=array(), $limit=array(), $order=array(), $cnt=false) | |
Returns a list of all chapters contained in this book, constrained by given criteria. | |
listValidChildren ($constraints=array(), $limit=array(), $order=array(), $cnt=false) | |
Returns list of chapters that have more than one section. | |
setCoverImage ($snapPath) | |
Sets or resets the cover image of this book. | |
uploadCoverImage ($tmpFile, $fileName= '') | |
Uploads a new cover image for this book. | |
Static Public Member Functions | |
static | getList ($constraints=array(), $limit=array(), $order=array(), $cnt=false) |
Returns a list of all books, constrained by given criteria. |
A book contains zero or more chapters, which may contain zero or more sections. A book is the root of a tree in the textbook side of TSD. This class provides methods to query books, list books, create new books, delete books and align/unalign books with resources.
To change the cover image of the book, use setCoverImage() or uploadCoverImage().
Attributes:
id
[int]: ID of book (-)title
[string]: Regular title of book, which can be extended by the gradeOrCourse
field (edit)gradeOrCourse
[string]: Course level or grade level of book (edit)coverImage
[int]: Snap ID of Snap2 resource that contains the cover image for the book (-) TSDBook::__construct | ( | $ | id = '' |
) |
Initializes new Book object.
If $id
is provided, then an attempt is made to populate this object from the database using that ID. Otherwise, an empty object is created, which can be filled with new data to be committed later. You cannot populate after creating the object.
$id | [int]: ID of book in database to populate from |
TSDBook::addChapter | ( | $ | name | ) |
Creates a new chapter in this book.
You must have the edit permission to add new chapters.
$name | [string]: name of chapter |
TSDBook::delete | ( | ) |
Delete this book.
Deletion also takes care of removing the resource from Snap2 for the cover image as well.
TSDBook::deleteChapterByName | ( | $ | name | ) |
Deletes any child chapters with given name.
This will only delete chapters that belong to this book and only if the name matches exactly (but case insensitive).
$name | [string]: name of chapter(s) to delete |
TSDBook::getIdentifier | ( | ) |
Returns a string that identifies this book.
The identifier string is not meant to uniquely identify the book, but rather for use for display purposes. For books, the identifier is a concatenation of the title with the gradeOrCourse field, separated by a space.
static TSDBook::getList | ( | $ | constraints = array() , |
|
$ | limit = array() , |
|||
$ | order = array() , |
|||
$ | cnt = false | |||
) | [static] |
Returns a list of all books, constrained by given criteria.
See Guide to Database Constraints for more about how to constraint the resultset. You can also request that the number of results be returned, rather than the results themselves.
$constraints | [array]: additional constraints on the result set | |
$limit | [array]: parameters for the LIMIT clause of the query | |
$order | [array]: how to order the results | |
$cnt | [boolean]: whether to return the number of results (if true) or the results themselves (if false, the default) |
TSDBook::getParent | ( | ) |
INSERT BRIEF DESCRIPTION HERE.
INSERT FULL DESCRIPTION HERE
TSDBook::isValid | ( | ) |
Determines whether book is valid to be in the database.
A book is valid if it has a non-empty title
and an empty or string gradeOrCourse
field, and a null or numeric coverImage
field (which should be a snap ID, but this is not checked). The id
of the book can either be empty, or a non-negative integer.
TSDBook::listChildren | ( | $ | constraints = array() , |
|
$ | limit = array() , |
|||
$ | order = array() , |
|||
$ | cnt = false | |||
) |
Returns a list of all chapters contained in this book, constrained by given criteria.
See Guide to Database Constraints for more about how to constraint the resultset. You can also request that the number of results be returned, rather than the results themselves.
Only chapters that belong to this book will be returned, although it is theoretically possible to circumvent this with the constraints array. With no arguments, an array of TSDChapter objects is returned, all of which belong to this book object.
$constraints | [array]: additional constraints on the result set | |
$limit | [array]: parameters for the LIMIT clause of the query | |
$order | [array]: how to order the results | |
$cnt | [boolean]: whether to return the number of results (if true) or the results themselves (if false, the default) |
$cnt
== true), or null if there was an error TSDBook::listValidChildren | ( | $ | constraints = array() , |
|
$ | limit = array() , |
|||
$ | order = array() , |
|||
$ | cnt = false | |||
) |
Returns list of chapters that have more than one section.
This method is the same as listChildren() except that it will only return chapters that have at least one section in them.
$constraints | [array]: additional constraints on the result set | |
$limit | [array]: parameters for the LIMIT clause of the query | |
$order | [array]: how to order the results | |
$cnt | [boolean]: whether to return the number of results (if true) or the results themselves (if false, the default) |
TSDBook::setCoverImage | ( | $ | snapPath | ) |
Sets or resets the cover image of this book.
This method requires that you have already uploaded the image into Snap2 somewhere. It will then store a link to that image in the database. You must have the edit permission in TSD to use this method.
$snapPath | [string]: path to image in Snap2 |
TSDBook::uploadCoverImage | ( | $ | tmpFile, | |
$ | fileName = '' | |||
) |
Uploads a new cover image for this book.
Unlike setCoverImage() this method allows you to directly upload an image for the cover of the book. It will be uploaded into a special directory in Snap2 and the ID of the image will be stored in the database. You must have the edit permission to use this method.
$tmpFile | [string]: path to image file on server | |
$fileName | [string]: original name of file (useful for browser file uploads); defaults to be basename($tmpFile). |