Stud.IP  jlu_3.3 Revision
Icon Class Reference
Collaboration diagram for Icon:
Collaboration graph

Public Member Functions

 __construct ($icon, $size=Icon::DEFAULT_SIZE, $color=Icon::DEFAULT_COLOR, $attributes=array(), $static=false)
 
 __toString ()
 
 render ($type=Icon::SVG)
 

Static Public Member Functions

static create ($source, $size=Icon::DEFAULT_SIZE, $color=Icon::DEFAULT_COLOR, $icon=false, $attributes=array())
 

Data Fields

const SVG = 1
 
const PNG = 2
 
const CSS_BACKGROUND = 4
 
const INPUT = 256
 
const DEFAULT_SIZE = 16
 
const DEFAULT_COLOR = 'blue'
 

Static Public Attributes

static $icon_colors
 

Protected Member Functions

 render_img ($type, $as_input)
 
 render_css_background ()
 
 get_asset ($type)
 
 get_size ()
 
 tag_options ($options)
 

Static Protected Member Functions

static rearrange ($input, $defaults=array(), $extra=false)
 

Protected Attributes

 $icon
 
 $size = null
 
 $color = null
 
 $attributes = array()
 
 $static = false
 

Detailed Description

Icon class is used to create icon objects which can be rendered as svg or png. Output will be html. Optionally, the icon can be rendered as a css background.

Author
Jan-Hendrik Willms tleil.nosp@m.ax+s.nosp@m.tudip.nosp@m.@gma.nosp@m.il.co.nosp@m.m
Since
3.2

Constructor & Destructor Documentation

◆ __construct()

__construct (   $icon,
  $size = Icon::DEFAULT_SIZE,
  $color = Icon::DEFAULT_COLOR,
  $attributes = array(),
  $static = false 
)

Constructor of the object.

Parameters
String$sourceName of the icon, may contain a mixed definition like 'icons/16/blue/add/seminar.png' due to compatibility issues with Assets::img().
int$sizeSize of the icon, defaults to fixed default icon size
String$colorColor of the icon, defaults to fixed default icon color
Array$attributesAdditional attributes to pass the rendered output
bool$staticDefines whether the icon is static (not from assets folder)

Member Function Documentation

◆ __toString()

__toString ( )

Function to be called whenever the object is converted to string.

Returns
String representation
Here is the call graph for this function:

◆ create()

static create (   $source,
  $size = Icon::DEFAULT_SIZE,
  $color = Icon::DEFAULT_COLOR,
  $icon = false,
  $attributes = array() 
)
static
Parameters
String$sourceName of the icon, may contain a mixed definition like 'icons/16/blue/add/seminar.png' due to compatibility issues with Assets::img().
int$sizeSize of the icon, defaults to fixed default icon size
String$colorColor of the icon, defaults to fixed default icon color
mixed$iconExtra icon to apply to the icon, default is none
Array$attributesAdditional attributes to pass the rendered output
Returns
Icon object
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_asset()

get_asset (   $type)
protected

Get the correct asset for the icon.

Parameters
int$typeEither svg or png, no other assets are defined.
Returns
String containing the url of the corresponding asset
Exceptions
Exceptionif an invalid type was passed
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_size()

get_size ( )
protected

Get the size of the icon. If a size was passed as a parameter and inside the attributes array during icon construction, the size from the attributes will be used.

Returns
int Size of the icon in pixels
Here is the caller graph for this function:

◆ rearrange()

static rearrange (   $input,
  $defaults = array(),
  $extra = false 
)
staticprotected

Rearranges passed parameters. Tries to detect given size, color and extra icon.

Parameters
mixed$inputEither a relative or absolute url or an array
Array$defaultsDefault values for size, color and extra icon
mixed$extraExtra icon to apply to the icon, defaults to none
Returns
Array with the guessed values
Here is the call graph for this function:
Here is the caller graph for this function:

◆ render()

render (   $type = Icon::SVG)

Renders the icon as svg, png or css background.

Parameters
int$typeDefines in which manner the icon should be rendered, defaults to svg.
Returns
String containing the rendered output
Exceptions
Exceptionif no valid type was passed
Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_css_background()

render_css_background ( )
protected

Renders the icon as a set of css background rules.

Returns
String containing the html representation for css backgrounds
Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_img()

render_img (   $type,
  $as_input 
)
protected

Renders the icon inside a img html tag.

Parameters
int$typeDefines in which manner the icon should be rendered, should be either Icon::SVG or Icon::PNG.
Returns
String containing the html representation for the icon.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tag_options()

tag_options (   $options)
protected

Renders an array of options as html attributes.

Parameters
Array$options1-dimensional associative array of options
Returns
String containing the representation of the options as html tag attributes.
Here is the caller graph for this function:

Field Documentation

◆ $attributes

$attributes = array()
protected

◆ $color

$color = null
protected

◆ $icon

$icon
protected

◆ $icon_colors

$icon_colors
static
Initial value:
= array(
'black', 'blue', 'green', 'grey', 'lightblue', 'red', 'white', 'yellow',
)

◆ $size

$size = null
protected

◆ $static

$static = false
protected

◆ CSS_BACKGROUND

const CSS_BACKGROUND = 4

◆ DEFAULT_COLOR

const DEFAULT_COLOR = 'blue'

◆ DEFAULT_SIZE

const DEFAULT_SIZE = 16

◆ INPUT

const INPUT = 256

◆ PNG

const PNG = 2

◆ SVG

const SVG = 1

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