
Public Member Functions | |
| __construct ($id="") | |
| canCreateDirectory ($shortName=false) | |
| Determines whether a subdirectory can be created with the given shortname. | |
| canCreateResource ($shortName=false, $contentType=SnapResource::TYPE_STDXML) | |
| Determines whether a subresource can be created with the given shortname and type. | |
| countContents ($constraint=array(), $limit=array(), $order=array()) | |
| Retrieves number of children of this directory, using constraints. | |
| createDirectory ($shortName, $name="", $description="") | |
| Creates a new subdirectory in this directory. | |
| createResource ($shortName, $contentType=SnapResource::TYPE_STDXML, $name="", $description="") | |
| Creates a resource in this directory. | |
| listContents ($constraint=array(), $limit=array(), $order=array(), $count=false) | |
| Retrieves array of objects representing the contents of this directory. | |
| toCacheDump () | |
Static Public Member Functions | |
| static | lookup ($path) |
| Retrieves a directory by path. | |
| static | retrieve ($id) |
| Retrieves a directory by ID. | |
Protected Member Functions | |
| doDestroy () | |
| This method implements the directory-specific part of destroying a file. | |
| loadMaxDirOrdinal () | |
| Loads the maximum directory ordinal for this directory. | |
| loadMaxResOrdinal () | |
| Loads the maximum resource ordinal for this directory. | |
A directory is a container for resources and other directories. It is a type of file (see SnapFile) and thus can be linked, unlinked, deleted, etc. It is important to note that you never create a SnapDirectory object directly. You will get them indirectly from factory methods in this class, or query methods, such as listContents().
Definition at line 26 of file SnapDirectory.php5.
| SnapDirectory::__construct | ( | $ | id = "" |
) |
| SnapDirectory::canCreateDirectory | ( | $ | shortName = false |
) |
Determines whether a subdirectory can be created with the given shortname.
In order for a subdirectory to be created, the following conditions must apply:
If you do not provide a shortname, then the first two checks will not be done. This is useful if you merely want to test the ability to create any subdirectories at all. Right now, it is equivalent to calling mayCreateDirectory() on the permission object belonging to this directory, but in the future, there may be other checks. It is best to use the can* methods whenever possible.
If a subdirectory cannot be created, this method returns false and sets the reason to a descriptive sentence. You can find this reason by calling getReason(). It does not generate errors directly.
| $shortName | [string]: name of the new subdirectory, or false to ignore shortname check |
Definition at line 254 of file SnapDirectory.php5.
References SnapDBI::freeResult(), and SnapObject::setReason().
Referenced by createDirectory().
| SnapDirectory::canCreateResource | ( | $ | shortName = false, |
|
| $ | contentType = SnapResource::TYPE_STDXML | |||
| ) |
Determines whether a subresource can be created with the given shortname and type.
In order for a subresource to be created, the following conditions must apply:
If you provide a shortname of false, then the first two checks will be skipped. If you provide no arguments, shortname defaults to false and the content type defaults to SnapResource::TYPE_STDXML and the first two checks will not be done. This is useful if you merely want to test the ability to create any subresources at all. Right now, it is equivalent to calling mayCreateResource() on the permission object belonging to this directory, but in the future, there may be other checks. It is best to use the can* methods whenever possible.
If a subresource cannot be created, this method returns false and sets the reason to a descriptive sentence. You can find this reason by calling getReason(). It does not generate errors directly.
| $shortName | [string]: name of the new subresource, or false to ignore shortname check | |
| $contentType | [int]: resource content type, defaults to SnapResource::TYPE_STDXML |
Definition at line 314 of file SnapDirectory.php5.
References SnapDBI::freeResult(), SnapObject::getId(), SnapDBI::getNumRows(), SnapFile::getPermission(), SnapContent::isValidType(), SnapDBI::query(), and SnapObject::setReason().
Referenced by createResource().
| SnapDirectory::countContents | ( | $ | constraint = array(), |
|
| $ | limit = array(), |
|||
| $ | order = array() | |||
| ) |
Retrieves number of children of this directory, using constraints.
See the documentation for listContents() for more on the parameters to this method
| $constraint | [array]: trim down results by conditions | |
| $limit | [array]: limit number of results by count and offset | |
| $order | [array]: sort results |
Definition at line 636 of file SnapDirectory.php5.
References listContents().
| SnapDirectory::createDirectory | ( | $ | shortName, | |
| $ | name = "", |
|||
| $ | description = "" | |||
| ) |
Creates a new subdirectory in this directory.
The subdirectory is created with the given metadata. You must, at the very least, specify a shortname, which is the name of the first and only link to the subdirectory. If you do not specifiy a regular name, the shortname will be used. The description field is more fully optional and if left blank, no default description will be provided. To create a directory, you must have CreateDirectory on this (the parent) directory. The new directory inherits all permissions from this directory automatically.
| $shortName | [string]: short name of new directory (name of first and only link) | |
| $name | [string]: regular, descriptive name of new directory; $shortName is used if $name is empty | |
| $description | [string]: description of directory |
Definition at line 366 of file SnapDirectory.php5.
References SnapDBI::cancelTransaction(), canCreateDirectory(), SnapObject::checkValid(), SnapDBI::commitTransaction(), SnapDirectoryGroupPermission::copy(), SnapDirectoryUserPermission::copy(), SnapObject::getId(), SnapDBI::getInsertId(), SnapObject::getReason(), SnapFile::mklink(), SnapCache::putById(), SnapDBI::query(), SObject::setError(), and SnapDBI::startTransaction().
| SnapDirectory::createResource | ( | $ | shortName, | |
| $ | contentType = SnapResource::TYPE_STDXML, |
|||
| $ | name = "", |
|||
| $ | description = "" | |||
| ) |
Creates a resource in this directory.
The resource is created with the given metadata. If the name is omitted, the short name is used as the name as well. Note that the content type parameter is 2nd, not 4th as in snap2.0. You must have the CreateResource permission on this directory to create a resource in it. All permissions from this directory are propagated to the new resource, except for those which only apply to directories
| $shortName | [string]: short name of resource | |
| $contentType | [integer]: resource content type (cannot be changed after resource creation) | |
| $name | [string]: descriptive name of resource; $shortName is used if this parameter is empty | |
| $description | [string]: description of resource |
Definition at line 434 of file SnapDirectory.php5.
References SnapDBI::cancelTransaction(), canCreateResource(), SnapObject::checkValid(), SnapDBI::commitTransaction(), SnapResourceGroupPermission::copy(), SnapResourceUserPermission::copy(), SnapObject::getId(), SnapDBI::getInsertId(), SnapObject::getReason(), SnapFile::mklink(), SnapCache::putById(), SnapDBI::query(), SObject::setError(), and SnapDBI::startTransaction().
| SnapDirectory::doDestroy | ( | ) | [protected] |
This method implements the directory-specific part of destroying a file.
For internal use only.
This method iterates over all the child files and deletes those that have only one parent (that is, this directory itself), and unlinks from this directory those children that have multiple parents. If a child is a directory, then it will recursively do the same thing when its delete() method is called.
Reimplemented from SnapFile.
Definition at line 56 of file SnapDirectory.php5.
References SnapObject::getId(), SnapFile::getParents(), and listContents().
| SnapDirectory::listContents | ( | $ | constraint = array(), |
|
| $ | limit = array(), |
|||
| $ | order = array(), |
|||
| $ | count = false | |||
| ) |
Retrieves array of objects representing the contents of this directory.
This method allows you to trim down the result set and sort it, mostly arbitrarily. The first parameter can be an array that specifies constraints that are converted into a WHERE clause on the database query. See Guide to Database Constraints for more on how to specify a constraint array. The second parameter lets you limit the number of results. As a simple number, a 'LIMIT x' is appended to the query. If an array of two numbers is given, then the first number specifies the offset to start the resultset at and the second specifies the number of records after that. The final parameter specifies how to order the results. If the elements in the array are not associative, then they are passed directly to the ORDER BY clause as is. If they are associative, then the key specifies the column and the value specifies either ASC or DESC.
| $constraint | [array]: trim down results by conditions | |
| $limit | [array]: limit number of results by count and offset | |
| $order | [array]: sort results | |
| $count | [boolean]: if true, only return a count of objects in directory, rather than objects themselves |
Definition at line 501 of file SnapDirectory.php5.
References SnapResource::$ATTRIBUTES, SnapObject::checkValid(), SnapDBI::criteriaToString(), SnapDBI::freeResult(), SnapCache::getById(), SnapObject::getId(), SnapDBI::getRow(), SObject::getStaticError(), SnapDBI::limitToString(), SnapDBI::orderToString(), SnapCache::putById(), SnapCache::putByPath(), SnapDBI::query(), SObject::setError(), and SnapPermissionCache::warmCache().
Referenced by countContents(), and doDestroy().
| SnapDirectory::loadMaxDirOrdinal | ( | ) | [protected] |
Loads the maximum directory ordinal for this directory.
For internal use only.
A maximum ordinal is calculated by querying the DirectoryLink table on the 'ordinal' column and finding the maximum using the SQL 'MAX()' function. This does not count the number of subdirectories in the directory, but instead gets the ordinal of the subdirectory with the highest ordinal that is in this directory (canonically or not). The reordering methods should update ordinals such that the maximum ordinal is also equal to the number of directories in the directory. If there is a bug, however, this may not be the case.
Definition at line 80 of file SnapDirectory.php5.
References SnapObject::getId(), SnapObject::getType(), SnapDBI::query(), SObject::setError(), and SnapCache::updateById().
| SnapDirectory::loadMaxResOrdinal | ( | ) | [protected] |
Loads the maximum resource ordinal for this directory.
For internal use only.
See the description under loadMaxDirOrdinal() for more on what this means. This method does the same thing except that it does it on subresources instead of subdirectories.
Definition at line 100 of file SnapDirectory.php5.
References SnapObject::getId(), SnapObject::getType(), SnapDBI::query(), SObject::setError(), and SnapCache::updateById().
| static SnapDirectory::lookup | ( | $ | path | ) | [static] |
Retrieves a directory by path.
Use this method to retrieve a directory if you know its path. You cannot instantiate a directory and have it populate via a path anyways, but don't try, or worse things will happen.
| $path | [string]: path to directory (remember the trailing slash!) |
Reimplemented from SnapFile.
Definition at line 162 of file SnapDirectory.php5.
References Snap2::checkInit(), and SnapCache::getByPath().
Referenced by TKSDRResourceResultSet::bufferContributorIcons(), SnapObject::convertReference(), SnapFile::lookup(), Snap2::lookup(), TSD::setPermission(), and TSDBook::uploadCoverImage().
| static SnapDirectory::retrieve | ( | $ | id | ) | [static] |
Retrieves a directory by ID.
Use this method to get a SnapDirectory object if you know the ID. Do not instantiate a SnapDirectory object directly, or bad things will happen.
| $id | [integer]: ID of directory |
Definition at line 128 of file SnapDirectory.php5.
References Snap2::checkInit(), SnapCache::getById(), SnapObject::getId(), and SnapCache::putById().
Referenced by SnapObject::convertReference(), Snap2::getDeletedDirectory(), SnapFile::getParent(), Snap2::getRootDirectory(), and SnapFile::loadCanonicalParent().
| SnapDirectory::toCacheDump | ( | ) |
For internal use only.
Reimplemented from SnapObject.
Definition at line 39 of file SnapDirectory.php5.
1.5.6