PHP Class Ansel_Storage, horde

Copyright 2001-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Michael J Rubinsky ([email protected])
Show file Open project: horde/horde

Protected Properties

Property Type Description
$_db Horde_Db_Adapter database handle
$_images array Local cache of retrieved images
$_shares Horde_Share The Horde_Shares object to use for this scope.

Public Methods

Method Description
__construct ( Horde_Core_Share_Driver $shareOb ) : Ansel_Storage Const'r
__get ( string $property ) Property accessor
buildGalleries ( array $shares ) : array Build an array of Ansel_Gallery objects from an array of Horde_Share_Object objects.
buildGallery ( Horde_Share_Object $share ) : Ansel_Gallery Build a single Ansel_Gallery object from a Horde_Share_Object
clearImageAttributes ( integer $image_id ) Clears an image's attributes from storage.
countGalleries ( $userid, array $params = [] ) : integer Return the count of galleries that the user has specified permissions to and that match any of the requested attributes.
createGallery ( array $attributes = [], Horde_Perms_Permission $perm = null, integer $parent = null ) : Ansel_Gallery Create and initialise a new gallery object.
emptyGallery ( Ansel_Gallery $gallery ) Empties a gallery of all images.
ensureHash ( string $hash ) Ensure the style hash is recorded in the database.
galleryExists ( integer $gallery_id = null, string $slug = null ) : boolean Check if a gallery exists. Need to do this here so we can also check by gallery slug.
getGalleries ( array $ids, integer $perms = Horde_Perms::SHOW ) : array Retrieve an array of Ansel_Gallery objects for the requested ids
getGalleriesBySlugs ( array $slugs, $perms = Horde_Perms::SHOW ) : array Retrieve an array of Ansel_Gallery objects for the given slugs.
getGallery ( integer $gallery_id, array $overrides = [] ) : Ansel_Gallery Retrieve an Ansel_Gallery given the share id
getGalleryBySlug ( string $slug, array $overrides = [] ) : Ansel_Gallery Retrieve an Ansel_Gallery given the gallery's slug
getHashes ( ) : array Get a list of all known styleHashes.
getImage ( integer $id ) : Ansel_Image Returns the image corresponding to the given id.
getImageAttributes ( integer $image_id ) : array Get image's attribtues from storage
getImageJson ( array $images, Ansel_Style $style = null, boolean $full = false, string $image_view = 'mini', boolean $view_links = false ) : string Retrieve json data for an arbitrary list of image ids, not necessarily from the same gallery.
getImages ( array $params = [] ) : array Return the images corresponding to the given ids.
getImagesGeodata ( array $image_ids = [], integer $gallery = null ) : array Return images' geolocation data.
getRandomGallery ( array $params = [] ) Returns a random Ansel_Gallery from a list fitting the search criteria.
getRecentImages ( array $galleries = [], integer $limit = 10, array $slugs = [] ) : array Returns a list of Ansel_Images of the most recently added images for the current user.
getRecentImagesGeodata ( string $user = null, integer $start, integer $count = 8 ) : array Like getRecentImages, but returns geotag data for the most recently added images from the current user. Useful for providing images to help locate images at the same place.
listAllGalleries ( ) : array Returns a list of ALL galleries, regardless of permissions.
listGalleries ( array $params = [] ) : array Retrieves the current user's gallery list from storage.
listImages ( array $params = [] ) : array Lists a slice of the image ids in the given gallery.
removeGallery ( Ansel_Gallery $gallery ) Removes an Ansel_Gallery.
removeImage ( integer $image_id ) Deletes an Ansel_Image from data storage.
saveImage ( Ansel_Image $image ) : integer Save image details to storage. Does NOT update the cached image files.
saveImageAttribute ( integer $image_id, $attribute, string $value ) Store an image attribute to storage
searchLocations ( string $search = '' ) : array Search for a textual location string from the passed in search token.
setImageSortOrder ( integer $imageId, integer $pos ) Set image sort order
setImagesGallery ( array $image_ids, integer $gallery_id ) Set the gallery id for a set of images. Useful for bulk updating images when moving from one gallery to another.
setStorage ( mixed $storage ) Backend setter

Protected Methods

Method Description
_getImageCommentCounts ( array $ids ) : array Get the total number of comments for an image.
_getImageFields ( $alias = '' ) : string Helper function to get a string of field names
_toImageDriverName ( string $field ) : string Convert an Ansel_Image property to it's backend storage field name.

Method Details

__construct() public method

Const'r
public __construct ( Horde_Core_Share_Driver $shareOb ) : Ansel_Storage
$shareOb Horde_Core_Share_Driver
return Ansel_Storage

__get() public method

Property accessor
public __get ( string $property )
$property string The property to access.

_getImageCommentCounts() protected method

Get the total number of comments for an image.
protected _getImageCommentCounts ( array $ids ) : array
$ids array Array of image ids
return array of results. @see forums/numMessagesBatch api call

_getImageFields() protected method

Helper function to get a string of field names
protected _getImageFields ( $alias = '' ) : string
return string

_toImageDriverName() protected method

Convert an Ansel_Image property to it's backend storage field name.
protected _toImageDriverName ( string $field ) : string
$field string The field name
return string The converted field name suitable for use in backend.

buildGalleries() public method

Build an array of Ansel_Gallery objects from an array of Horde_Share_Object objects.
public buildGalleries ( array $shares ) : array
$shares array An array of Horde_Share_Object objects.
return array Ansel_Gallery objects.

buildGallery() public method

Build a single Ansel_Gallery object from a Horde_Share_Object
public buildGallery ( Horde_Share_Object $share ) : Ansel_Gallery
$share Horde_Share_Object The share
return Ansel_Gallery

clearImageAttributes() public method

Clears an image's attributes from storage.
public clearImageAttributes ( integer $image_id )
$image_id integer The image to clear

countGalleries() public method

Return the count of galleries that the user has specified permissions to and that match any of the requested attributes.
public countGalleries ( $userid, array $params = [] ) : integer
$params array Parameter array:
 (integer)perm          The level of permissions to require for a
                        gallery to return it [Horde_Perms::SHOW]
 (mixed)attributes      Restrict the galleries counted to those
                        matching $attributes. An array of
                        attribute/values pairs or a gallery owner
                        username.
(Ansel_Gallery)parent   The parent share to start counting at.
(boolean)all_levels      Return all levels, or just the direct children of
                        $parent? [true]
(array)tags             Filter results by galleries tagged with tags.
return integer The count

createGallery() public method

Create and initialise a new gallery object.
public createGallery ( array $attributes = [], Horde_Perms_Permission $perm = null, integer $parent = null ) : Ansel_Gallery
$attributes array The gallery attributes.
$perm Horde_Perms_Permission The permissions for the gallery if the defaults are not desirable.
$parent integer The id of the parent gallery (if any)
return Ansel_Gallery A new gallery object.

emptyGallery() public method

Empties a gallery of all images.
public emptyGallery ( Ansel_Gallery $gallery )
$gallery Ansel_Gallery The ansel gallery to empty.

ensureHash() public method

Ensure the style hash is recorded in the database.
public ensureHash ( string $hash )
$hash string The hash to record.

galleryExists() public method

Check if a gallery exists. Need to do this here so we can also check by gallery slug.
public galleryExists ( integer $gallery_id = null, string $slug = null ) : boolean
$gallery_id integer The gallery id
$slug string The gallery slug
return boolean

getGalleries() public method

Retrieve an array of Ansel_Gallery objects for the requested ids
public getGalleries ( array $ids, integer $perms = Horde_Perms::SHOW ) : array
$ids array Gallery ids to fetch
$perms integer Horde_Perms constant for the perms required.
return array An array of Ansel_Gallery objects

getGalleriesBySlugs() public method

Retrieve an array of Ansel_Gallery objects for the given slugs.
public getGalleriesBySlugs ( array $slugs, $perms = Horde_Perms::SHOW ) : array
$slugs array The gallery slugs.
return array An array of Ansel_Gallery objects.

getGallery() public method

Retrieve an Ansel_Gallery given the share id
public getGallery ( integer $gallery_id, array $overrides = [] ) : Ansel_Gallery
$gallery_id integer The gallery_id to fetch
$overrides array An array of attributes that should be overridden when the gallery is returned.
return Ansel_Gallery

getGalleryBySlug() public method

Retrieve an Ansel_Gallery given the gallery's slug
public getGalleryBySlug ( string $slug, array $overrides = [] ) : Ansel_Gallery
$slug string The gallery slug
$overrides array An array of attributes that should be overridden when the gallery is returned.
return Ansel_Gallery The gallery object

getHashes() public method

Get a list of all known styleHashes.
public getHashes ( ) : array
return array An array of style hashes.

getImage() public method

Returns the image corresponding to the given id.
public getImage ( integer $id ) : Ansel_Image
$id integer The image_id of the image to retrieve.
return Ansel_Image The image object requested..

getImageAttributes() public method

Get image's attribtues from storage
public getImageAttributes ( integer $image_id ) : array
$image_id integer The image id
return array A image attribute hash

getImageJson() public method

Retrieve json data for an arbitrary list of image ids, not necessarily from the same gallery.
public getImageJson ( array $images, Ansel_Style $style = null, boolean $full = false, string $image_view = 'mini', boolean $view_links = false ) : string
$images array An array of image ids
$style Ansel_Style A gallery style to force if requesting pretty thumbs.
$full boolean Generate full urls
$image_view string Which image view to use? screen, thumb etc..
$view_links boolean Include links to the image view
return string The json data

getImages() public method

Return the images corresponding to the given ids.
public getImages ( array $params = [] ) : array
$params array function parameters:
  'ids'        - An array of image ids to fetch.
  'preserve'   - Preserve the order of the image ids when returned.
  'gallery_id' - Return all images from requested gallery (ignores 'ids').
  'from'       - If passing a gallery, start at this image.
  'count'      - If passing a gallery, return this many images.
return array An array of Ansel_Image objects.

getImagesGeodata() public method

Return images' geolocation data.
public getImagesGeodata ( array $image_ids = [], integer $gallery = null ) : array
$image_ids array An array of image_ids to look up.
$gallery integer A gallery id. If this is provided, will return all images in the gallery that have geolocation data ($image_ids would be ignored).
return array of geodata

getRandomGallery() public method

Returns a random Ansel_Gallery from a list fitting the search criteria.
See also: Ansel_Storage::listGalleries()
public getRandomGallery ( array $params = [] )
$params array

getRecentImages() public method

Returns a list of Ansel_Images of the most recently added images for the current user.
public getRecentImages ( array $galleries = [], integer $limit = 10, array $slugs = [] ) : array
$galleries array An array of gallery ids to search in. If left empty, will search all galleries with Horde_Perms::SHOW.
$limit integer The maximum number of images to return
$slugs array An array of gallery slugs.
return array An array of Ansel_Image objects

getRecentImagesGeodata() public method

Like getRecentImages, but returns geotag data for the most recently added images from the current user. Useful for providing images to help locate images at the same place.
public getRecentImagesGeodata ( string $user = null, integer $start, integer $count = 8 ) : array
$user string Limit images to this user
$start integer Start a slice at this image number
$count integer Include this many images
return array An array of image ids

listAllGalleries() public method

Returns a list of ALL galleries, regardless of permissions.
public listAllGalleries ( ) : array
return array

listGalleries() public method

Retrieves the current user's gallery list from storage.
public listGalleries ( array $params = [] ) : array
$params array Optional parameters:
  (integer)perm      The permissions filter to use [Horde_Perms::SHOW]
  (mixed)attributes  Restrict the galleries returned to those matching
                     the filters. Can be an array of attribute/values
                     pairs or a gallery owner username.
  (integer)parent    The parent share to start listing at.
  (boolean)all_levels If set, return all levels below parent, not just
                     direct children [TRUE]
  (integer)from      The gallery to start listing at.
  (integer)count     The number of galleries to return.
  (string)sort_by    Attribute to sort by.
  (integer)direction The direction to sort by [Ansel::SORT_ASCENDING]
  (array)tags        An array of tags to limit results by.
return array An array of Ansel_Gallery objects

listImages() public method

Lists a slice of the image ids in the given gallery.
public listImages ( array $params = [] ) : array
$params array Filter parameters.
 integer|array 'gallery_id'  - A gallery id to list images from
 integer 'offset'            - The image to start listing from
 integer 'limit'             - How many images to return
 array|string 'fields'       - The fields to return
 string 'sort'               - The field to sort by.
 array  'filter'             - Additional filters. Each element is an
                               array containing 'property', 'op', and
                               'value' keys. Passing 'IN' as the 'op'
                               and an array as 'value' will produce a
                               SQL IN conditional.
return array An array of images. Either an array of ids, or an array of field values, keyed by id.

removeGallery() public method

Removes an Ansel_Gallery.
public removeGallery ( Ansel_Gallery $gallery )
$gallery Ansel_Gallery The gallery to delete

removeImage() public method

Deletes an Ansel_Image from data storage.
public removeImage ( integer $image_id )
$image_id integer The image id(s) to remove.

saveImage() public method

Save image details to storage. Does NOT update the cached image files.
public saveImage ( Ansel_Image $image ) : integer
$image Ansel_Image The image to save.
return integer The image id

saveImageAttribute() public method

Store an image attribute to storage
public saveImageAttribute ( integer $image_id, $attribute, string $value )
$image_id integer The image id
$value string The attrbute value

searchLocations() public method

Used for location autocompletion.
public searchLocations ( string $search = '' ) : array
$search string Search fragment for autocompleting location strings
return array The results

setImageSortOrder() public method

Set image sort order
public setImageSortOrder ( integer $imageId, integer $pos )
$imageId integer The image id
$pos integer The new sort order position

setImagesGallery() public method

Set the gallery id for a set of images. Useful for bulk updating images when moving from one gallery to another.
public setImagesGallery ( array $image_ids, integer $gallery_id )
$image_ids array An array of image ids
$gallery_id integer The gallery id to move the images to.

setStorage() public method

Backend setter
public setStorage ( mixed $storage )
$storage mixed The backend storage driver.

Property Details

$_db protected property

database handle
protected Horde_Db_Adapter $_db
return Horde_Db_Adapter

$_images protected property

Local cache of retrieved images
protected array $_images
return array

$_shares protected property

The Horde_Shares object to use for this scope.
protected Horde_Share $_shares
return Horde_Share