Book Image

Mastering Joomla! 1.5 Extension and Framework Development Second Edition

Book Image

Mastering Joomla! 1.5 Extension and Framework Development Second Edition

Overview of this book

Joomla! is one of the world’s top open source content management systems, which enables you to build websites and powerful online applications. Out of the box, Joomla! does a great job of managing the content needed to enhance the functionality of your website. But for many people, the true power of Joomla! lies in its application framework that makes it possible for thousands of developers around the world to create powerful add-ons and extensions. This book will guide you through the complexities of implementing add-ons, components, modules, and plugins in Joomla! 1.5. If you feel that you’ve mastered the basics of creating Joomla! extensions, then this book will take you to the next level. Packed with expert advice on all aspects of programming with Joomla!, this book is an invaluable reference guide you will turn to again and again for your Joomla! development tasks. The book starts by explaining the structure and design of the Joomla! Framework. Then we move on to extending and storing data in standard fields and dealing with multilingual requirements. Further, you will discover best practices, design, and coding methods for Joomla! components, modules, plugins, and other extensions. Along the way, you will actually design and create a component, module, and plugin that work together to add functionality to the Joomla! framework. You will also learn about customizing the page output using JavaScript effects, making use of Web Services from within Joomla! and ensuring that your code is secure and error-free. You will discover how to easily create sophisticated extensions that are robust, user-friendly, and professional by taking advantage of the many libraries and utilities provided by the Joomla! framework. A comprehensive, up-to-date reference to the Joomla! Framework API is also included in the book. Finally, we will discuss advanced methods for rendering your extensions more robust, secure, and professional.
Table of Contents (18 chapters)
Mastering Joomla! 1.5 Extension and Framework Development
Credits
About the Author
About the Reviewer
Preface

JTable


abstract, extends JObject , located in / joomla/database/table.php

This class handles individual database tables. JTable uses a buffering mechanism which allows it to handle records on an individual basis. For further information on using the JTable class refer to Chapter 3, The Database.

Direct descendents

JTableMenuTypes

Menu Types table

JTableCategory

Category table

JTableUser

User table

JTableMenu

Menu table

JTableComponent

Component table

JTableARO

ARO table

JTablePlugin

Plugin table

JTableSection

Section table

JTableModule

Module table

JTableContent

Content table

JTableSession

Session table

JTableAROGroup

AroGroup table

Properties

JDatabase $_db = null

The database connector

string $_tbl = ' '

Table name

string $_tbl_key = ' '

Primary key

Inherited properties

Inherited from JObject:

  • JObject::$_errors

Inherited methods

Inherited from JObject:

  • JObject::JObject()

  • JObject::__construct()

  • JObject::get()

  • JObject::getError()

  • JObject::getErrors()

  • JObject::getProperties()

  • JObject::getPublicProperties()

  • JObject::set()

  • JObject::setError()

  • JObject::setProperties()

  • JObject::toString()

Methods

Constructor __construct

Class constructor. Builds a new JTable object. Sets the table and key field. Redefinition of JObject::__construct(); class constructor; redefined in descendant classes:

  • JTableMenuTypes::_construct(): constructor

  • JTableCategory::_construct(): constructor

  • JTableUser::_construct(): constructor

  • JTableMenu::_construct(): constructor

  • JTableComponent::_construct(): constructor

  • JTableARO::_construct(): constructor

  • JTablePlugin::_construct(): constructor

  • JTableSection::_construct(): constructor

  • JTableModule::_construct(): constructor

  • JTableContent::_construct(): constructor

  • JTableSession::_construct(): constructor

  • JTableAROGroup::_construct(): constructor

JTable __construct(string $table, string $key, JDatabase &$db)

  • string $table: The name of the table

  • string $key: The name of the primary key field in the table

  • object $db: A reference to the JDatabase connector object

addIncludePath

This method adds paths to search for JTable subclasses. $path can be a string or an array of strings.

array addIncludePath([$path = null])

  • string $path: A path to search

  • array: Returns an array of directory elements

bind

This method binds a subject (normally a record) to the object. For all public properties this method finds a corresponding key or property in $from and binds it to the object. This method can be overloaded or supplemented by the subclass. Redefined in descendants:

  • JTableUser::bind(): overloaded bind function

  • JTableMenu::bind(): overloaded bind function

  • JTableComponent::bind(): overloaded bind function

  • JTablePlugin::bind(): overloaded bind function

  • JTableSection::bind(): overloaded bind function

  • JTableModule::bind(): overloaded bind function

boolean bind($from, [$ignore])

  • mixed $from: An associative array or object

  • mixed $ignore: An array or space separated list of fields not to bind

  • boolean: Returns true upon success

canDelete

This method determines if there are any records linked to the buffered record or, if $oid is specified, the record identified by $oid. $joins identifies linked tables. $joins is an optional two-dimensional array; the inner arrays are associative, and must contain the keys name, idfield, and joinfield. name is the linked table name, idfield is the linked table's primary key, and joinfield is the foreign key in the linked table.

boolean canDelete([$oid = null], [$joins = null])

  • string $from: The record id

  • array $joins: An associative array of table join constraints

  • boolean: Returns tru e if there are no dependent records

check

This method is used to validate the contents of the record buffer. This should be overridden in subclasses. Redefined in descendants:

  • JTableMenuTypes::check(): overloaded check function

  • JTableCategory::check(): overloaded check function

  • JTableUser::check(): overloaded check function

  • JTableMenu::check(): overloaded check function

  • JTableComponent::check(): overloaded check function

  • JTableSection::check(): overloaded check function

  • JTableModule::check(): overloaded check function

  • JTableContent::check(): overloaded check function

boolean check()

  • boolean: Returns true upon success

checkin

This method checks in the buffered record or, if $oid is specified, checks in the record identified by $oid. This sets the record's checked_out field to zero and checked_out_time to a null date-time.

boolean checkin([$oid = null])

  • string $oid: The record id

  • boolean: Returns true upon success

checkout

This method checks out the buffered record or, if #oid is specified, checks out the record identified by $oid. This sets the record's checked_out field to $who and checked_out_time to the current date-time.

boolean checkout($who, [$oid = null])

  • integer $who: The id of the user

  • mixed $oid: The primary key value for the row

  • boolean: Returns true upon success or if checkout is not supported

delete

This method deletes the buffered record or, if $oid is specified, deletes the record identified by $oid. Redefined in descendants:

  • JTableUser::delete(): overloaded delete function

  • JTableSession::delete(): overloaded delete function

boolean delete( [$oid = null])

  • string $oid: The record ID

  • boolean: Returns true upon success

getDBO

This method returns a reference to the JDatabase connection object.

JDatabase &getDBO()

  • string $oid: The record ID

  • object: Returns a reference to the JDatabase connection object

getInstance

This method returns a reference to a new JTable subclass object. $type is the name of the file the class resides in and the class name suffix, normally the entity name. $prefix is the class name prefix. Core JTable subclasses use the prefix 'JTable'; third-party JTable classes tend to use the prefix 'Table'.

JTable &getInstance($type, [$prefix = 'JTable'], [$config = array()])

  • string $type: The table type to instantiate

  • string $prefix: An optional prefix for the table class name

  • array $options: An optional configuration array for the table

  • object: Returns a reference to a JTable subclass object

getKeyName

This method returns the name of the primary key field.

string getKeyName()

  • string: Returns the name of the primary key

getNextOrder

This method returns the next place available in the current ordering. Using reorder() before using this method will ensure there are no gaps in the ordering.

integer getNextOrder([$where = ''])

  • string $where: The query WHERE clause for selecting MAX(ordering)

  • integer: Returns the next place available in the current ordering

getTableName

This method returns the name of the table.

string getTableName()

  • string: Returns the name of the table

hit

This method increases the hit counter of the buffered record or, if $oid is specified, the record identified by $oid.

void hit([$oid = null], [$log = false])

  • string $oid: The record ID

  • boolean $log: No effect

  • void: No return type

isCheckedOut

This static method determines if the buffered record is checked out by any user other than the current user. If used statically (both $with and $against must be specified) compares $with to $against.

boolean isCheckedOut($with, [$against = null])

  • integer $with: The user ID to compare

  • integer $against: The user ID to compare when used as a static function

  • boolean: Returns true if any other user has the record checked out

load

This method resets the record buffer and loads a single record into the buffer. $oid is the value of the record's primary key.

boolean load([$oid = null])

  • string $oid: The record ID

  • boolean: Returns true upon success

move

This method moves a record up or down the ordering (the table must have an ordering field). -1 = move up, 1 = move down.

void move($dirn, [$where = ''])

  • integer $dirn: The direction to move

  • string $where: The query WHERE clause

  • void: No return type

publish

This method sets the publish value of records identified by $cid, an array of record IDs (this only works when the table's primary key is numeric). Although $cid is optional, if it is not specified the method will fail. If the table has a checked_out field, any records that are checked out by other users will not be affected.

boolean publish([$cid = null], [$publish = 1] , [$user_id = 0])

  • array $cid: An array of ID numbers

  • integer $publish: Publishing value; 1=publishing, 0=unpublishing

  • integer $user_id: The user ID performing the operation.

  • boolean: Returns true upon success

reorder

This method removes gaps in ordering.

void reorder([$where = ''])

  • string $where: An additional WHERE clause to limit ordering

  • void: No return type

reset

This method resets the object to the initial class option values.

void reset()

  • void : No return type

save

This method binds $source to the object; $source must be an object or an associative array. The method checks the buffer, stores the buffer, checks-in the record, and if $order_filter is specified, uses it to determine which field must be common during the execution of the reorder() method.

boolean save($source, [$order_filter = ''] , [$ignore = = ''])

  • array $source: A source array for binding to class properties

  • string $order_filter: Filter for the order updating

  • mixed $ignore: An array or space separated list of fields not to bind

  • boolean: Returns true upon success

setDBO

This method sets the JDatabase connection object.

void setDBO(&$db)

  • object $db: The JDatabase connection object

  • void: No return type

store

This method saves the record buffer to the database. If the record buffer primary key property is set an UPDATE will be executed, otherwise an INSERT will be executed. Redefined in descendants:

  • JTableUser::store(): stores a record.

boolean store([$updateNulls = false])

  • boolean $updateNulls: If false null object variables are not updated

  • boolean: Returns true upon success

toXML

This method returns an XML representation of the buffered record. Redefined in descendants:

  • JTableContent::toXML(): converts a record to XML

string toXML([$mapKeysToText = false])

  • boolean $mapKeysToText: If true map foreign keys to text values

  • string: Returns an XML string