Table Class
Convenience class for building a Table. Useful for display rows of data from a database or another collection of associative arrays.
$table = new Canteen\HTML5\Table(
array(
array('id'=>1, 'first'=>'James', 'last'=>'Smith'),
array('id'=>2, 'first'=>'Mary', 'last'=>'Denver'),
array('id'=>3, 'first'=>'Charlie', 'last'=>'Rose')
),
array('ID', 'First Name', 'Last Name')
);
Constructor
Table
-
data
-
[headers=null]
-
[checkbox=null]
Parameters:
-
data
ArrayThe collection of Dictionary objects
-
[headers=null]
Array optionalAn optional collection of header labels for each value
-
[checkbox=null]
String optionalIf we should add a checkbox to each row, this is the name of the attribute to use as a value. For instance
array('id'=>2)
is<input type="checkbox" name="id[]" value="2">
Item Index
Methods
Properties
Methods
__get
-
name
General purpose getter to get attribute values
Parameters:
-
name
StringThe name of the property to set
__set
-
name
-
value
General purpose setter to set attribute values
addChild
-
childNode
Add's a child to this NodeContainer. The child to add cannot be null.
Returns:
The instance of this container
addChildAt
-
childNode
-
index
Add a child at a specific index
Parameters:
Returns:
The instance of this container
appendTo
-
container
Add this child to a node container at the end
Parameters:
-
container
NodeContainerThe node container to add to
Returns:
The instance of this Node
getAttribute
-
[name=null]
Fetch and attribute by name from this Node. The attribute name cannot be null; if so, this function will throw an Exception.
Parameters:
-
[name=null]
String optionalThe name of the attribute to fetch
Returns:
The attribute's value, if any or null
getChildAt
-
[index=0]
Gets a child of this Node container at given index. If no index is passed in, getChild() will return the child at index zero (0).
Parameters:
-
[index=0]
Int optionalThe index to fetch child Node at
Returns:
The child Node
getChildren
()
Array
Returns an array of all children attached to this Node container.
Returns:
The collection of Node objects
getData
-
name
Get the data-* HTML5 attribute value, if set
Parameters:
-
name
StringThe name of the data attribute
Returns:
The value of the data
getParent
()
NodeContainer
private
Returns the parent node of this node, if a parent exists. If no parent exists, this function returns null.
Returns:
The parent node object
isEmpty
-
var
Checks if a variable is really "empty". Code borrowed from PHP.net at http://us3.php.net/manual/en/function.empty.php#90767 because we were previously using empty() to see if a variable is empty or not. But empty() dosen't work for attributes that have a value of "0", so we need something more robust here.
- an unset variable -> empty
- null -> empty
- 0 -> NOT empty
- "0" -> NOT empty
- false -> empty
- true -> NOT empty
- 'string value' -> NOT empty
- " "(white space) -> empty
- array()(empty array) -> empty
Parameters:
-
var
MixedThe variable to check for empty on
prepareChild
-
childNode
Before adding a child, we should do some checking for basic types and convert it into a more useable Node object.
Returns:
The child node
prependTo
-
container
Add this child to the beginning of a node container
Parameters:
-
container
NodeContainerThe node container to prepend to to
Returns:
The instance of this Node
removeChild
-
[childNode=null]
Removes the first instance of child from this.
Once the first instance of the child
is removed, this function will return. It returns
true if a child was removed and false if no child
was removed.
Parameters:
-
[childNode=null]
Node optionalThe node to remove
Returns:
If successfully removed
removeChildAt
-
index
Remove a child as a specific index
Parameters:
-
index
IntThe index to remove child at
Returns:
The instance of the node container
removeChildren
()
NodeContainer
Removes all children attached to this Node container
Returns:
The instance of the node container
setAttribute
-
[name=null]
-
[value=null]
-
The
Given a name and value pair, sets an attribute on this Node. The name and value cannot be empty; if so, this function will throw an Exception. Note if the attribute already exists and the caller wants to set an attribute of the same name, this function will not create a new Attribute, but rather update the value of the existing named attribute.
setAttributes
-
values
Set the list of all attributes.
Parameters:
-
values
DictionaryAn attributes array(name=>value, name=>value)
Returns:
The instance of this Node
setParent
-
[parent=null]
Sets the parent of this Node. Note that this function is protected and can only be called by classes that extend Node. The parent cannot be null; this function will throw an Exception if the parent node is empty.
Parameters:
-
[parent=null]
NodeContainer optionalThe parent container node