Elgg  Version 4.3
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Elgg\EntityIconService Class Reference

Entity icon service. More...

Public Member Functions

 __construct (Config $config, PluginHooksService $hooks, EntityTable $entities, UploadService $uploads, ImageService $images, MimeTypeService $mimetype, HttpRequest $request)
 Constructor. More...
 
 saveIconFromUploadedFile (\ElggEntity $entity, $input_name, $type= 'icon', array $coords=[])
 Saves icons using an uploaded file as the source. More...
 
 saveIconFromLocalFile (\ElggEntity $entity, $filename, $type= 'icon', array $coords=[])
 Saves icons using a local file as the source. More...
 
 saveIconFromElggFile (\ElggEntity $entity,\ElggFile $file, $type= 'icon', array $coords=[])
 Saves icons using a file located in the data store as the source. More...
 
 saveIcon (\ElggEntity $entity,\ElggFile $file, $type= 'icon', array $coords=[])
 Saves icons using a created temporary file. More...
 
 getIcon (\ElggEntity $entity, $size, $type= 'icon', $generate=true)
 Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore. More...
 
 deleteIcon (\ElggEntity $entity, $type= 'icon', $retain_master=false)
 Removes all icon files and metadata for the passed type of icon. More...
 
 getIconURL (\ElggEntity $entity, $params=[])
 Get the URL for this entity's icon. More...
 
 getFallbackIconUrl (\ElggEntity $entity, array $params=[])
 Returns default/fallback icon. More...
 
 getIconLastChange (\ElggEntity $entity, $size, $type= 'icon')
 Returns the timestamp of when the icon was changed. More...
 
 hasIcon (\ElggEntity $entity, $size, $type= 'icon')
 Returns if the entity has an icon of the passed type. More...
 
 getSizes ($entity_type=null, $entity_subtype=null, $type= 'icon')
 Returns a configuration array of icon sizes. More...
 

Protected Member Functions

 prepareIcon ($filename)
 Prepares an icon. More...
 
 generateIcon (\ElggEntity $entity,\ElggFile $file, $type= 'icon', $coords=[], $icon_size= '')
 Generate an icon for the given entity. More...
 
 detectCroppingCoordinates ()
 Automagicly detect cropping coordinates. More...
 
 hasWebPSupport ()
 Checks if browser has WebP support and if the webserver is able to generate. More...
 

Protected Attributes

 $mimetype
 
 $request
 

Detailed Description

Entity icon service.

Definition at line 18 of file EntityIconService.php.

Constructor & Destructor Documentation

Elgg\EntityIconService::__construct ( Config  $config,
PluginHooksService  $hooks,
EntityTable  $entities,
UploadService  $uploads,
ImageService  $images,
MimeTypeService  $mimetype,
HttpRequest  $request 
)

Constructor.

Parameters
Config$configConfig
PluginHooksService$hooksHook registration service
EntityTable$entitiesEntity table
UploadService$uploadsUpload service
ImageService$imagesImage service
MimeTypeService$mimetypeMimeType service
Request$requestHttp Request service

Definition at line 69 of file EntityIconService.php.

Member Function Documentation

Elgg\EntityIconService::deleteIcon ( \ElggEntity  $entity,
  $type = 'icon',
  $retain_master = false 
)

Removes all icon files and metadata for the passed type of icon.

Parameters
\ElggEntity$entityEntity that owns icons
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
bool$retain_masterKeep the master icon (default: false)
Returns
bool

Definition at line 470 of file EntityIconService.php.

Elgg\EntityIconService::detectCroppingCoordinates ( )
protected

Automagicly detect cropping coordinates.

Based in the input names x1, x2, y1 and y2

Returns
false|array

Definition at line 666 of file EntityIconService.php.

Elgg\EntityIconService::generateIcon ( \ElggEntity  $entity,
\ElggFile  $file,
  $type = 'icon',
  $coords = [],
  $icon_size = '' 
)
protected

Generate an icon for the given entity.

Parameters
\ElggEntity$entityTemporary ElggFile instance
\ElggFile$fileTemporary ElggFile instance
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
array$coordsAn array of cropping coordinates x1, y1, x2, y2
string$icon_sizeThe icon size to generate (leave empty to generate all supported sizes)
Returns
bool

Definition at line 319 of file EntityIconService.php.

Elgg\EntityIconService::getFallbackIconUrl ( \ElggEntity  $entity,
array  $params = [] 
)

Returns default/fallback icon.

Parameters
\ElggEntity$entityEntity
array$paramsIcon params
Returns
string

Definition at line 554 of file EntityIconService.php.

Elgg\EntityIconService::getIcon ( \ElggEntity  $entity,
  $size,
  $type = 'icon',
  $generate = true 
)

Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.

Note
Returned ElggIcon object may be a placeholder. Use ElggIcon::exists() to validate if file has been written to filestore
Parameters
\ElggEntity$entityEntity that owns the icon
string$sizeSize of the icon
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
bool$generateTry to generate an icon based on master if size doesn't exists
Returns
Exceptions
InvalidParameterException

Definition at line 402 of file EntityIconService.php.

Elgg\EntityIconService::getIconLastChange ( \ElggEntity  $entity,
  $size,
  $type = 'icon' 
)

Returns the timestamp of when the icon was changed.

Parameters
\ElggEntity$entityEntity that owns the icon
string$sizeThe size of the icon
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
Returns
int|null A unix timestamp of when the icon was last changed, or null if not set.

Definition at line 589 of file EntityIconService.php.

Elgg\EntityIconService::getIconURL ( \ElggEntity  $entity,
  $params = [] 
)

Get the URL for this entity's icon.

Plugins can register for the 'entity:icon:url', <type> plugin hook to customize the icon for an entity.

Parameters
\ElggEntity$entityEntity that owns the icon
mixed$paramsA string defining the size of the icon (e.g. tiny, small, medium, large) or an array of parameters including 'size'
Returns
string|void

Definition at line 514 of file EntityIconService.php.

Elgg\EntityIconService::getSizes (   $entity_type = null,
  $entity_subtype = null,
  $type = 'icon' 
)

Returns a configuration array of icon sizes.

Parameters
string$entity_typeEntity type
string$entity_subtypeEntity subtype
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
Returns
array
Exceptions
InvalidParameterException

Definition at line 620 of file EntityIconService.php.

Elgg\EntityIconService::hasIcon ( \ElggEntity  $entity,
  $size,
  $type = 'icon' 
)

Returns if the entity has an icon of the passed type.

Parameters
\ElggEntity$entityEntity that owns the icon
string$sizeThe size of the icon
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
Returns
bool

Definition at line 605 of file EntityIconService.php.

Elgg\EntityIconService::hasWebPSupport ( )
protected

Checks if browser has WebP support and if the webserver is able to generate.

Returns
bool

Definition at line 696 of file EntityIconService.php.

Elgg\EntityIconService::prepareIcon (   $filename)
protected

Prepares an icon.

Parameters
string$filenamethe file to prepare
Returns
void

Definition at line 291 of file EntityIconService.php.

Elgg\EntityIconService::saveIcon ( \ElggEntity  $entity,
\ElggFile  $file,
  $type = 'icon',
array  $coords = [] 
)

Saves icons using a created temporary file.

Parameters
\ElggEntity$entityTemporary ElggFile instance
\ElggFile$fileTemporary ElggFile instance
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
array$coordsAn array of cropping coordinates x1, y1, x2, y2
Returns
bool

Definition at line 204 of file EntityIconService.php.

Elgg\EntityIconService::saveIconFromElggFile ( \ElggEntity  $entity,
\ElggFile  $file,
  $type = 'icon',
array  $coords = [] 
)

Saves icons using a file located in the data store as the source.

Parameters
\ElggEntity$entityEntity to own the icons
\ElggFile$fileAn ElggFile instance
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
array$coordsAn array of cropping coordinates x1, y1, x2, y2
Returns
bool
Exceptions
InvalidParameterException

Definition at line 172 of file EntityIconService.php.

Elgg\EntityIconService::saveIconFromLocalFile ( \ElggEntity  $entity,
  $filename,
  $type = 'icon',
array  $coords = [] 
)

Saves icons using a local file as the source.

Parameters
\ElggEntity$entityEntity to own the icons
string$filenameThe full path to the local file
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
array$coordsAn array of cropping coordinates x1, y1, x2, y2
Returns
bool
Exceptions
InvalidParameterException

Definition at line 139 of file EntityIconService.php.

Elgg\EntityIconService::saveIconFromUploadedFile ( \ElggEntity  $entity,
  $input_name,
  $type = 'icon',
array  $coords = [] 
)

Saves icons using an uploaded file as the source.

Parameters
\ElggEntity$entityEntity to own the icons
string$input_nameForm input name
string$typeThe name of the icon. e.g., 'icon', 'cover_photo'
array$coordsAn array of cropping coordinates x1, y1, x2, y2
Returns
bool

Definition at line 97 of file EntityIconService.php.

Member Data Documentation

Elgg\EntityIconService::$mimetype
protected

Definition at line 51 of file EntityIconService.php.

Elgg\EntityIconService::$request
protected

Definition at line 56 of file EntityIconService.php.


The documentation for this class was generated from the following file: