mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
merging changes and bug fixes from sandboxes
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@757 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
7c7a2151ab
commit
6019c0d98d
17 changed files with 1507 additions and 1396 deletions
|
@ -2,9 +2,9 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Access Control List.
|
||||
* Access Control List factory class.
|
||||
*
|
||||
* Long description for file
|
||||
* Permissions system.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Access Control List.
|
||||
* Access Control List abstract class.
|
||||
*
|
||||
* @filesource
|
||||
* @author CakePHP Authors/Developers
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
* Creates ready-to-use file skeletons for applications.
|
||||
*
|
||||
* Creates controller, model, view files, and the required directories on demand.
|
||||
* Used by /scripts/bake.php.
|
||||
|
@ -38,7 +38,7 @@
|
|||
uses('object', 'inflector');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
* Creates ready-to-use file skeletons for applications.
|
||||
*
|
||||
* Bake class creates files in configured application directories. This is a
|
||||
* base class for /scripts/add.php.
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Cache
|
||||
* Caching for Cake.
|
||||
*
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -39,9 +39,9 @@
|
|||
uses('model');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
* Caching for Cake.
|
||||
*
|
||||
*
|
||||
* Long description for class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Pear::DB layer for DBO.
|
||||
* {@link http://pear.php.net/package/DB PEAR::DB} layer for DBO.
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
|
@ -32,14 +32,14 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Create an include path required Pear libraries.
|
||||
* Create an include path required PEAR libraries.
|
||||
*/
|
||||
uses('dbo');
|
||||
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . PEAR);
|
||||
vendor('Pear/DB');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
* {@link http://pear.php.net/package/DB PEAR::DB} layer for DBO.
|
||||
*
|
||||
* Long description for class
|
||||
*
|
||||
|
@ -114,7 +114,7 @@ class DBO_Pear extends DBO
|
|||
|
||||
/**
|
||||
* Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
|
||||
* :WARNING: :TODO: POSTGRESQL & MYSQL ONLY! Pear::DB doesn't support universal table listing.
|
||||
* :WARNING: :TODO: POSTGRESQL & MYSQL ONLY! PEAR::DB doesn't support universal table listing.
|
||||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
|
@ -221,9 +221,13 @@ class DBO_Pear extends DBO
|
|||
function lastNumRows ()
|
||||
{
|
||||
if (method_exists($this->_result, 'numRows'))
|
||||
{
|
||||
return $this->_result->numRows();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,7 +250,7 @@ class DBO_Pear extends DBO
|
|||
*/
|
||||
function selectLimit ($limit, $offset='0')
|
||||
{
|
||||
return ' '.$this->_pear->modifyLimitQuery('', $offset, $limit);
|
||||
return ' ' . $this->_pear->modifyLimitQuery('', $offset, $limit);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
uses('dbo');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
* PostgreSQL layer for DBO.
|
||||
*
|
||||
* Long description for class
|
||||
*
|
||||
|
@ -81,32 +81,32 @@ class DBO_Postgres extends DBO
|
|||
return pg_close($this->_conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes given SQL statement.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @return resource Result resource identifier
|
||||
*/
|
||||
/**
|
||||
* Executes given SQL statement.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @return resource Result resource identifier
|
||||
*/
|
||||
function execute ($sql)
|
||||
{
|
||||
return pg_query($this->_conn, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a row from given resultset as an array .
|
||||
*
|
||||
* @return array The fetched row as an array
|
||||
*/
|
||||
/**
|
||||
* Returns a row from given resultset as an array .
|
||||
*
|
||||
* @return array The fetched row as an array
|
||||
*/
|
||||
function fetchRow ()
|
||||
{
|
||||
return pg_fetch_array();
|
||||
return pg_fetch_array($this->_result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
|
||||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
/**
|
||||
* Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
|
||||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
function tablesList ()
|
||||
{
|
||||
$sql = "SELECT a.relname AS name
|
||||
|
@ -130,12 +130,12 @@ class DBO_Postgres extends DBO
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
* @param string $table_name Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
* @param string $table_name Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
function fields ($table_name)
|
||||
{
|
||||
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$table_name}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
|
||||
|
@ -150,56 +150,56 @@ class DBO_Postgres extends DBO
|
|||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @return string Quoted and escaped
|
||||
*/
|
||||
/**
|
||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @return string Quoted and escaped
|
||||
*/
|
||||
function prepareValue ($data)
|
||||
{
|
||||
return "'".pg_escape_string($data)."'";
|
||||
return "'" . pg_escape_string($data) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message
|
||||
*/
|
||||
function lastError ()
|
||||
{
|
||||
$last_error = pg_last_error($this->_result);
|
||||
$last_error = pg_last_error($this->_conn);
|
||||
return $last_error? $last_error: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
|
||||
*
|
||||
* @return int Number of affected rows
|
||||
*/
|
||||
/**
|
||||
* Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
|
||||
*
|
||||
* @return int Number of affected rows
|
||||
*/
|
||||
function lastAffected ()
|
||||
{
|
||||
return $this->_result? pg_affected_rows($this->_result): false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
/**
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
function lastNumRows ()
|
||||
{
|
||||
return $this->_result? pg_num_rows($this->_result): false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @param string $table Name of the database table
|
||||
* @param string $field Name of the ID database field. Defaults to "id"
|
||||
* @return int
|
||||
*/
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @param string $table Name of the database table
|
||||
* @param string $field Name of the ID database field. Defaults to "id"
|
||||
* @return int
|
||||
*/
|
||||
function lastInsertId ($table, $field='id')
|
||||
{
|
||||
$sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max";
|
||||
|
@ -208,13 +208,13 @@ class DBO_Postgres extends DBO
|
|||
return $data['max'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
*
|
||||
* @param int $limit Limit of results returned
|
||||
* @param int $offset Offset from which to start results
|
||||
* @return string SQL limit/offset statement
|
||||
*/
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
*
|
||||
* @param int $limit Limit of results returned
|
||||
* @param int $offset Offset from which to start results
|
||||
* @return string SQL limit/offset statement
|
||||
*/
|
||||
function selectLimit ($limit, $offset=null)
|
||||
{
|
||||
return " LIMIT {$limit}".($offset? " OFFSET {$offset}": null);
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
uses('dbo');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
* DBO implementation for the SQLite DBMS.
|
||||
*
|
||||
* Long description for class
|
||||
*
|
||||
|
@ -95,7 +95,7 @@ class DBO_SQLite extends DBO
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a row from given resultset as an array .
|
||||
* Returns a row from given resultset as an array.
|
||||
*
|
||||
* @return array The fetched row as an array
|
||||
*/
|
||||
|
@ -129,12 +129,12 @@ class DBO_SQLite extends DBO
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
* @param string $table_name Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
* @param string $table_name Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
function fields($table_name)
|
||||
{
|
||||
$fields = false;
|
||||
|
@ -148,70 +148,68 @@ class DBO_SQLite extends DBO
|
|||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @return string Quoted and escaped
|
||||
*/
|
||||
/**
|
||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @return string Quoted and escaped
|
||||
*/
|
||||
function prepareValue($data)
|
||||
{
|
||||
return "'".sqlite_escape_string($data)."'";
|
||||
return "'" . sqlite_escape_string($data) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message
|
||||
*/
|
||||
function lastError()
|
||||
{
|
||||
return sqlite_last_error($this->_conn)? sqlite_last_error($this->_conn).': '.sqlite_error_string(sqlite_last_error($this->_conn)): null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
|
||||
*
|
||||
* @return int Number of affected rows
|
||||
*/
|
||||
/**
|
||||
* Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
|
||||
*
|
||||
* @return int Number of affected rows
|
||||
*/
|
||||
function lastAffected()
|
||||
{
|
||||
return $this->_result? sqlite_changes($this->_conn): false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
/**
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
function lastNumRows()
|
||||
{
|
||||
return $this->_result? sqlite_num_rows($this->_result): false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function lastInsertId()
|
||||
{
|
||||
return sqlite_last_insert_rowid($this->_conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
*
|
||||
* @param int $limit Limit of results returned
|
||||
* @param int $offset Offset from which to start results
|
||||
* @return string SQL limit/offset statement
|
||||
*/
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
*
|
||||
* @param int $limit Limit of results returned
|
||||
* @param int $offset Offset from which to start results
|
||||
* @return string SQL limit/offset statement
|
||||
*/
|
||||
function selectLimit($limit, $offset=null)
|
||||
{
|
||||
return " LIMIT {$limit}".($offset? ", {$offset}": null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -140,7 +140,7 @@ class Dispatcher extends Object
|
|||
else
|
||||
{
|
||||
// Check to see if controller is scaffolded
|
||||
$classVars = get_class_vars($ctrlClass);
|
||||
$classVars = get_object_vars($controller);
|
||||
foreach ($classVars as $name => $value)
|
||||
{
|
||||
if($name === 'scaffold')
|
||||
|
@ -161,7 +161,7 @@ class Dispatcher extends Object
|
|||
if (!method_exists($controller, $params['action']))
|
||||
{
|
||||
// Check to see if controller is scaffolded
|
||||
$classVars = get_class_vars($ctrlClass);
|
||||
$classVars = get_object_vars($controller);
|
||||
foreach ($classVars as $name => $value)
|
||||
{
|
||||
if($name === 'scaffold')
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Access Control List.
|
||||
* Access Control List.
|
||||
*
|
||||
* Long description for file
|
||||
* To-be-implemented.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -35,7 +35,7 @@
|
|||
/**
|
||||
* Access Control List helper library.
|
||||
*
|
||||
* Long description for class
|
||||
* To-be-implemented.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs.helpers
|
||||
|
@ -46,7 +46,7 @@
|
|||
{
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Helper for Access Control List functionality.
|
||||
*
|
||||
* @return AclHelper
|
||||
*/
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
* Helper for AJAX operations.
|
||||
*
|
||||
* Long description for file
|
||||
* Helps doing AJAX using the Prototype library.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -35,7 +35,7 @@
|
|||
/**
|
||||
* AjaxHelper helper library.
|
||||
*
|
||||
* Long description for class
|
||||
* Helps doing AJAX using the Prototype library.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs.helpers
|
||||
|
@ -49,79 +49,80 @@ uses('helpers/html', 'helpers/javascript');
|
|||
class AjaxHelper extends Helper
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns link to remote action
|
||||
*
|
||||
* Returns a link to a remote action defined by <i>options[url]</i>
|
||||
* (using the urlFor format) that's called in the background using
|
||||
* XMLHttpRequest. The result of that request can then be inserted into a
|
||||
* DOM object whose id can be specified with <i>options[update]</i>.
|
||||
* Usually, the result would be a partial prepared by the controller with
|
||||
* either renderPartial or renderPartialCollection.
|
||||
*
|
||||
* Examples:
|
||||
* <code>
|
||||
* linkToRemote("Delete this post",
|
||||
* array("update" => "posts", "url" => "delete/{$postid->id}"));
|
||||
* linkToRemote(imageTag("refresh"),
|
||||
* array("update" => "emails", "url" => "list_emails" ));
|
||||
* </code>
|
||||
*
|
||||
* By default, these remote requests are processed asynchronous during
|
||||
* which various callbacks can be triggered (for progress indicators and
|
||||
* the likes).
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* linkToRemote (word,
|
||||
* array("url" => "undo", "n" => word_counter),
|
||||
* array("complete" => "undoRequestCompleted(request)"));
|
||||
* </code>
|
||||
*
|
||||
* The callbacks that may be specified are:
|
||||
*
|
||||
* - <i>loading</i>:: Called when the remote document is being
|
||||
* loaded with data by the browser.
|
||||
* - <i>loaded</i>:: Called when the browser has finished loading
|
||||
* the remote document.
|
||||
* - <i>interactive</i>:: Called when the user can interact with the
|
||||
* remote document, even though it has not
|
||||
* finished loading.
|
||||
* - <i>complete</i>:: Called when the XMLHttpRequest is complete.
|
||||
*
|
||||
* If you for some reason or another need synchronous processing (that'll
|
||||
* block the browser while the request is happening), you can specify
|
||||
* <i>options[type] = synchronous</i>.
|
||||
*
|
||||
* You can customize further browser side call logic by passing
|
||||
* in Javascript code snippets via some optional parameters. In
|
||||
* their order of use these are:
|
||||
*
|
||||
* - <i>confirm</i>:: Adds confirmation dialog.
|
||||
* -<i>condition</i>:: Perform remote request conditionally
|
||||
* by this expression. Use this to
|
||||
* describe browser-side conditions when
|
||||
* request should not be initiated.
|
||||
* - <i>before</i>:: Called before request is initiated.
|
||||
* - <i>after</i>:: Called immediately after request was
|
||||
* initiated and before <i>loading</i>.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating link.
|
||||
* @param string $title title of link
|
||||
* @param array $options options for javascript function
|
||||
* @param array $html_options options for link
|
||||
* @return string html code for link to remote action
|
||||
*/
|
||||
function linkToRemote ($html, $title, $options = null, $html_options = null) {
|
||||
// mouse click should call our remote function
|
||||
$html_options['onclick'] = $this->remoteFunction($html, $options);
|
||||
|
||||
// generate actual link
|
||||
return $html->link($title, '#', $html_options);
|
||||
}
|
||||
/**
|
||||
* Returns link to remote action
|
||||
*
|
||||
* Returns a link to a remote action defined by <i>options[url]</i>
|
||||
* (using the urlFor format) that's called in the background using
|
||||
* XMLHttpRequest. The result of that request can then be inserted into a
|
||||
* DOM object whose id can be specified with <i>options[update]</i>.
|
||||
* Usually, the result would be a partial prepared by the controller with
|
||||
* either renderPartial or renderPartialCollection.
|
||||
*
|
||||
* Examples:
|
||||
* <code>
|
||||
* linkToRemote("Delete this post",
|
||||
* array("update" => "posts", "url" => "delete/{$postid->id}"));
|
||||
* linkToRemote(imageTag("refresh"),
|
||||
* array("update" => "emails", "url" => "list_emails" ));
|
||||
* </code>
|
||||
*
|
||||
* By default, these remote requests are processed asynchronous during
|
||||
* which various callbacks can be triggered (for progress indicators and
|
||||
* the likes).
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* linkToRemote (word,
|
||||
* array("url" => "undo", "n" => word_counter),
|
||||
* array("complete" => "undoRequestCompleted(request)"));
|
||||
* </code>
|
||||
*
|
||||
* The callbacks that may be specified are:
|
||||
*
|
||||
* - <i>loading</i>:: Called when the remote document is being
|
||||
* loaded with data by the browser.
|
||||
* - <i>loaded</i>:: Called when the browser has finished loading
|
||||
* the remote document.
|
||||
* - <i>interactive</i>:: Called when the user can interact with the
|
||||
* remote document, even though it has not
|
||||
* finished loading.
|
||||
* - <i>complete</i>:: Called when the XMLHttpRequest is complete.
|
||||
*
|
||||
* If you for some reason or another need synchronous processing (that'll
|
||||
* block the browser while the request is happening), you can specify
|
||||
* <i>options[type] = synchronous</i>.
|
||||
*
|
||||
* You can customize further browser side call logic by passing
|
||||
* in Javascript code snippets via some optional parameters. In
|
||||
* their order of use these are:
|
||||
*
|
||||
* - <i>confirm</i>:: Adds confirmation dialog.
|
||||
* -<i>condition</i>:: Perform remote request conditionally
|
||||
* by this expression. Use this to
|
||||
* describe browser-side conditions when
|
||||
* request should not be initiated.
|
||||
* - <i>before</i>:: Called before request is initiated.
|
||||
* - <i>after</i>:: Called immediately after request was
|
||||
* initiated and before <i>loading</i>.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating link.
|
||||
* @param string $title Title of link
|
||||
* @param array $options Options for JavaScript function
|
||||
* @param array $html_options Options for link
|
||||
* @return string HTML code for link to remote action
|
||||
*/
|
||||
function linkToRemote ($html, $title, $options = null, $html_options = null)
|
||||
{
|
||||
// mouse click should call our remote function
|
||||
$html_options['onclick'] = $this->remoteFunction($html, $options);
|
||||
|
||||
/**
|
||||
* Creates javascript function for remote AJAX call
|
||||
// generate actual link
|
||||
return $html->link($title, '#', $html_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates JavaScript function for remote AJAX call
|
||||
*
|
||||
* This function creates the javascript needed to make a remote call
|
||||
* it is primarily used as a helper for linkToRemote.
|
||||
|
@ -131,47 +132,52 @@ class AjaxHelper extends Helper
|
|||
* @param array $options options for javascript
|
||||
* @return string html code for link to remote action
|
||||
*/
|
||||
function remoteFunction ($html, $options = null) {
|
||||
$javascript_options = $this->__optionsForAjax($options);
|
||||
$func = isset($options['update']) ? "new Ajax.Updater('{$options['update']}', " : "new Ajax.Request(";
|
||||
function remoteFunction ($html, $options = null)
|
||||
{
|
||||
$javascript_options = $this->__optionsForAjax($options);
|
||||
$func = isset($options['update']) ? "new Ajax.Updater('{$options['update']}', " : "new Ajax.Request(";
|
||||
|
||||
$func .= "'" . $html->url(isset($options['url']) ? $options['url'] : "") . "'";
|
||||
$func .= ", $javascript_options)";
|
||||
$func .= "'" . $html->url(isset($options['url']) ? $options['url'] : "") . "'";
|
||||
$func .= ", $javascript_options)";
|
||||
|
||||
if (isset($options['before'])) {
|
||||
$func .= "{$options['before']}; $function";
|
||||
}
|
||||
if (isset($options['after'])) {
|
||||
$func .= "$func; {$options['before']};";
|
||||
}
|
||||
if (isset($options['condition'])) {
|
||||
$func .= "if ({$options['condition']}) { $func; }";
|
||||
}
|
||||
if (isset($options['confirm'])) {
|
||||
$func .= "if (confirm('" . $this->escapeScript($options['confirm']) . "')) { $func; }";
|
||||
}
|
||||
return $func;
|
||||
}
|
||||
if (isset($options['before']))
|
||||
{
|
||||
$func .= "{$options['before']}; $function";
|
||||
}
|
||||
if (isset($options['after']))
|
||||
{
|
||||
$func .= "$func; {$options['before']};";
|
||||
}
|
||||
if (isset($options['condition']))
|
||||
{
|
||||
$func .= "if ({$options['condition']}) { $func; }";
|
||||
}
|
||||
if (isset($options['confirm']))
|
||||
{
|
||||
$func .= "if (confirm('" . $this->escapeScript($options['confirm']) . "')) { $func; }";
|
||||
}
|
||||
return $func;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Periodically call remote url via AJAX.
|
||||
*
|
||||
* Periodically calls the specified url (<i>options[url]</i>) every <i>options[frequency]</i> seconds (default is 10).
|
||||
* Usually used to update a specified div (<i>options[update]</i>) with the results of the remote call.
|
||||
* The options for specifying the target with url and defining callbacks is the same as linkToRemote.
|
||||
*
|
||||
* @param JavascriptHelper $script script helper generating the block
|
||||
* @param array $options callback options
|
||||
* @return string javascript code
|
||||
* @param JavascriptHelper $script Script helper generating the block
|
||||
* @param array $options Callback options
|
||||
* @return string Javascript code
|
||||
*/
|
||||
function remoteTimer ($script, $options = null)
|
||||
{
|
||||
$frequency = (isset($options['frequency']))? $options['frequency'] : 10;
|
||||
$code = "new PeriodicalExecuter(function() {" . $this->remote_function($options) . "}, $frequency)";
|
||||
return $script->codeBlock($code);
|
||||
}
|
||||
function remoteTimer ($script, $options = null)
|
||||
{
|
||||
$frequency = (isset($options['frequency']))? $options['frequency'] : 10;
|
||||
$code = "new PeriodicalExecuter(function() {" . $this->remote_function($options) . "}, $frequency)";
|
||||
return $script->codeBlock($code);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns form tag that will submit using Ajax.
|
||||
*
|
||||
* Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular
|
||||
|
@ -179,42 +185,43 @@ class AjaxHelper extends Helper
|
|||
* will work just like a regular submission as viewed by the receiving side (all elements available in params).
|
||||
* The options for specifying the target with :url and defining callbacks is the same as link_to_remote.
|
||||
*
|
||||
* @param HtmlHelper $html HtmlHelper creating this form
|
||||
* @param HtmlHelper $html HtmlHelper creating this form
|
||||
* @param JavascriptHelper $script JavascriptHelper creating this form
|
||||
* @param string $id form id
|
||||
* @param array $options callback options
|
||||
* @return string javascript code
|
||||
* @param string $id Form id
|
||||
* @param array $options Callback options
|
||||
* @return string JavaScript code
|
||||
*/
|
||||
function form ($html, $script, $id, $options = null) {
|
||||
$options['form'] = true;
|
||||
$options['html']['id'] = $id;
|
||||
//$options['html']['onsubmit'] = $this->remoteFunction($options) . "; return false;";
|
||||
return $html->formTag(null, "post", $options) . $script->event("$('$id')", "submit", "function(){" . $this->remoteFunction($options) . "; return false;}");
|
||||
}
|
||||
function form ($html, $script, $id, $options = null)
|
||||
{
|
||||
$options['form'] = true;
|
||||
$options['html']['id'] = $id;
|
||||
//$options['html']['onsubmit'] = $this->remoteFunction($options) . "; return false;";
|
||||
return $html->formTag(null, "post", $options) . $script->event("$('$id')", "submit", "function(){" . $this->remoteFunction($options) . "; return false;}");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a button input tag that will submit using Ajax
|
||||
*
|
||||
* Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular
|
||||
* reloading POST arrangement. <i>options</i> argument is the same as in <i>form_remote_tag</i>
|
||||
*
|
||||
* @param HtmlHelper $html
|
||||
* @param string $name input button name
|
||||
* @param string $value input button value
|
||||
* @param array $options callback options
|
||||
* @return string ajaxed input button
|
||||
* @param HtmlHelper $html HtmlHelper creating this form
|
||||
* @param string $name Input button name
|
||||
* @param string $value Input button value
|
||||
* @param array $options Callback options
|
||||
* @return string Ajaxed input button
|
||||
*/
|
||||
function submit ($html, $name, $value, $options = null)
|
||||
{
|
||||
$options['with'] = 'Form.serialize(this.form)';
|
||||
$options['html']['type'] = 'button';
|
||||
$options['html']['onclick'] = $this->remoteFunction($html, $options) . "; return false;";
|
||||
$options['html']['name'] = $name;
|
||||
$options['html']['value'] = $value;
|
||||
return $html->tag("input", $options['html'], false);
|
||||
}
|
||||
function submit ($html, $name, $value, $options = null)
|
||||
{
|
||||
$options['with'] = 'Form.serialize(this.form)';
|
||||
$options['html']['type'] = 'button';
|
||||
$options['html']['onclick'] = $this->remoteFunction($html, $options) . "; return false;";
|
||||
$options['html']['name'] = $name;
|
||||
$options['html']['value'] = $value;
|
||||
return $html->tag("input", $options['html'], false);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Observe field and call ajax on change.
|
||||
*
|
||||
* Observes the field with the DOM ID specified by <i>field_id</i> and makes
|
||||
|
@ -239,18 +246,20 @@ class AjaxHelper extends Helper
|
|||
* @see linkToRemote().
|
||||
*
|
||||
* @param JavaScriptHelper $script
|
||||
* @param string $field_id DOM ID of field to observe
|
||||
* @param array $options ajax options
|
||||
* @return string ajax script
|
||||
* @param string $field_id DOM ID of field to observe
|
||||
* @param array $options ajax options
|
||||
* @return string ajax script
|
||||
*/
|
||||
function observeField ($html, $script, $field_id, $options = null) {
|
||||
if (!isset($options['with'])) {
|
||||
$options['with'] = "Form.Element.serialize('$field_id')";
|
||||
}
|
||||
return $script->codeBlock($this->__buildObserver($html, 'Form.Element.Observer', $field_id, $options));
|
||||
}
|
||||
function observeField ($html, $script, $field_id, $options = null)
|
||||
{
|
||||
if (!isset($options['with']))
|
||||
{
|
||||
$options['with'] = "Form.Element.serialize('$field_id')";
|
||||
}
|
||||
return $script->codeBlock($this->__buildObserver($html, 'Form.Element.Observer', $field_id, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Observe entire form and call ajax on change.
|
||||
*
|
||||
* Like @see observeField(), but operates on an entire form identified by the
|
||||
|
@ -258,215 +267,241 @@ class AjaxHelper extends Helper
|
|||
* the default value of the <i>with</i> option evaluates to the
|
||||
* serialized (request string) value of the form.
|
||||
*
|
||||
* @param HtmlHelper $html
|
||||
* @param JavaScriptHelper $script
|
||||
* @param string $field_id DOM ID of field to observe
|
||||
* @param array $options ajax options
|
||||
* @return string ajax script
|
||||
* @param string $field_id DOM ID of field to observe
|
||||
* @param array $options ajax options
|
||||
* @return string ajax script
|
||||
*/
|
||||
function observeForm ($html, $script, $field_id, $options = array()) {
|
||||
if (!isset($options['with'])) {
|
||||
$options['with'] = 'Form.serialize(this.form)';
|
||||
}
|
||||
return $script->codeBlock($this->__buildObserver($html, 'Form.Observer', $field_id, $options));
|
||||
}
|
||||
function observeForm ($html, $script, $field_id, $options = array())
|
||||
{
|
||||
if (!isset($options['with']))
|
||||
{
|
||||
$options['with'] = 'Form.serialize(this.form)';
|
||||
}
|
||||
return $script->codeBlock($this->__buildObserver($html, 'Form.Observer', $field_id, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create a text field with Autocomplete.
|
||||
*
|
||||
* Creates an autocomplete field with the given ID and options
|
||||
* Creates an autocomplete field with the given ID and options.
|
||||
*
|
||||
* options['with'] defaults to "Form.Element.serialize('$field_id')",
|
||||
* but can be any valid javascript expression defining the
|
||||
*
|
||||
* @param HtmlHelper $html
|
||||
* @param JavascriptHelper $script
|
||||
* @param string $field_id DOM ID of field to observe
|
||||
* @param array $options ajax options
|
||||
* @return string ajax script
|
||||
* @param string $field_id DOM ID of field to observe
|
||||
* @param array $options ajax options
|
||||
* @return string ajax script
|
||||
*/
|
||||
function autoComplete ($html, $script, $field, $url = "", $options = array())
|
||||
{
|
||||
if (!isset($options['id'])) {
|
||||
$options['id'] = str_replace("/", "_", $field);
|
||||
}
|
||||
function autoComplete ($html, $script, $field, $url = "", $options = array())
|
||||
{
|
||||
if (!isset($options['id']))
|
||||
{
|
||||
$options['id'] = str_replace("/", "_", $field);
|
||||
}
|
||||
|
||||
$htmlOptions = $options;
|
||||
$ajaxOptions = array('with', 'asynchronous', 'synchronous', 'method', 'position', 'form');
|
||||
foreach($ajaxOptions as $key) {
|
||||
if(isset($htmlOptions[$key])) {
|
||||
unset($htmlOptions[$key]);
|
||||
}
|
||||
}
|
||||
$htmlOptions['autocomplete'] = "off";
|
||||
$htmlOptions = $options;
|
||||
$ajaxOptions = array('with', 'asynchronous', 'synchronous', 'method', 'position', 'form');
|
||||
foreach($ajaxOptions as $key)
|
||||
{
|
||||
if(isset($htmlOptions[$key]))
|
||||
{
|
||||
unset($htmlOptions[$key]);
|
||||
}
|
||||
}
|
||||
$htmlOptions['autocomplete'] = "off";
|
||||
|
||||
foreach($ajaxOptions as $key) {
|
||||
if(isset($options[$key])) {
|
||||
$ajaxOptions[$key] = $options[$key];
|
||||
} else {
|
||||
unset($ajaxOptions[$key]);
|
||||
}
|
||||
}
|
||||
foreach($ajaxOptions as $key)
|
||||
{
|
||||
if(isset($options[$key]))
|
||||
{
|
||||
$ajaxOptions[$key] = $options[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($ajaxOptions[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => "auto_complete");
|
||||
return $html->input($field, $htmlOptions) .
|
||||
$html->tag("div", $divOptions, true) . "</div>" .
|
||||
$script->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" . $divOptions['id'] . "', '" . $html->url($url) . "', " . $this->__optionsForAjax($ajaxOptions) . ");");
|
||||
}
|
||||
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => "auto_complete");
|
||||
return $html->input($field, $htmlOptions) .
|
||||
$html->tag("div", $divOptions, true) . "</div>" .
|
||||
$script->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" . $divOptions['id'] . "', '" . $html->url($url) . "', " . $this->__optionsForAjax($ajaxOptions) . ");");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function drag($script, $id, $options = array())
|
||||
{
|
||||
return $script->codeBlock("new Draggable('$id', " . $this->__optionsForDraggable($options) . ");");
|
||||
}
|
||||
function drag($script, $id, $options = array())
|
||||
{
|
||||
return $script->codeBlock("new Draggable('$id', " . $this->__optionsForDraggable($options) . ");");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* For a reference on the options for this function, check out
|
||||
* http://wiki.script.aculo.us/scriptaculous/show/Droppables.add
|
||||
*
|
||||
*/
|
||||
function drop($html, $script, $id, $options = array())
|
||||
{
|
||||
return $script->codeBlock("Droppables.add('$id', " . $this->__optionsForDroppable($options) . ");");
|
||||
}
|
||||
function drop($html, $script, $id, $options = array())
|
||||
{
|
||||
return $script->codeBlock("Droppables.add('$id', " . $this->__optionsForDroppable($options) . ");");
|
||||
}
|
||||
|
||||
|
||||
function dropRemote($html, $script, $id, $options = array(), $ajaxOptions = array())
|
||||
{
|
||||
$options['onDrop'] = "function(element){" . $this->remoteFunction($html, $ajaxOptions) . "}";
|
||||
}
|
||||
function dropRemote($html, $script, $id, $options = array(), $ajaxOptions = array())
|
||||
{
|
||||
$options['onDrop'] = "function(element){" . $this->remoteFunction($html, $ajaxOptions) . "}";
|
||||
}
|
||||
|
||||
function __optionsForDraggable ($options)
|
||||
{
|
||||
$opts = array("handle" => "", "revert" => "true", "constraint" => "", "change" => "");
|
||||
foreach($opts as $key => $val) {
|
||||
if(isset($options[$key])) {
|
||||
$opts[$key] = $options[$key];
|
||||
} else {
|
||||
if($val == "") { unset($opts[$key]); }
|
||||
}
|
||||
}
|
||||
if(isset($opts['handle'])) { $opts['handle'] = "'" . $opts['handle'] . "'"; }
|
||||
if(isset($opts['constraint'])) { $opts['constraint'] = "'" . $opts['constraint'] . "'"; }
|
||||
function __optionsForDraggable ($options)
|
||||
{
|
||||
$opts = array("handle" => "", "revert" => "true", "constraint" => "", "change" => "");
|
||||
foreach($opts as $key => $val)
|
||||
{
|
||||
if(isset($options[$key]))
|
||||
{
|
||||
$opts[$key] = $options[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($val == "") { unset($opts[$key]); }
|
||||
}
|
||||
}
|
||||
if(isset($opts['handle'])) { $opts['handle'] = "'" . $opts['handle'] . "'"; }
|
||||
if(isset($opts['constraint'])) { $opts['constraint'] = "'" . $opts['constraint'] . "'"; }
|
||||
|
||||
$out = array();
|
||||
foreach ($opts as $k => $v)
|
||||
{
|
||||
$out[] = "$k:$v";
|
||||
}
|
||||
$out = array();
|
||||
foreach ($opts as $k => $v)
|
||||
{
|
||||
$out[] = "$k:$v";
|
||||
}
|
||||
|
||||
$out = join(', ', $out);
|
||||
$out = '{' . $out . '}';
|
||||
return $out;
|
||||
}
|
||||
$out = join(', ', $out);
|
||||
$out = '{' . $out . '}';
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
function __optionsForDroppable ($options)
|
||||
{
|
||||
$opts = array("accept" => "", "containment" => "", "overlap" => "", "greedy" => "", "hoverclass" => "", "onHover" => "", "onDrop" => "");
|
||||
foreach($opts as $key => $val) {
|
||||
if(isset($options[$key])) {
|
||||
$opts[$key] = $options[$key];
|
||||
} else {
|
||||
if($val == "") { unset($opts[$key]); }
|
||||
}
|
||||
}
|
||||
if(isset($opts['accept'])) { $opts['accept'] = "'" . $opts['accept'] . "'"; }
|
||||
if(isset($opts['overlap'])) { $opts['overlap'] = "'" . $opts['overlap'] . "'"; }
|
||||
if(isset($opts['hoverclass'])) { $opts['hoverclass'] = "'" . $opts['hoverclass'] . "'"; }
|
||||
function __optionsForDroppable ($options)
|
||||
{
|
||||
$opts = array("accept" => "", "containment" => "", "overlap" => "", "greedy" => "", "hoverclass" => "", "onHover" => "", "onDrop" => "");
|
||||
foreach($opts as $key => $val)
|
||||
{
|
||||
if(isset($options[$key]))
|
||||
{
|
||||
$opts[$key] = $options[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($val == "") { unset($opts[$key]); }
|
||||
}
|
||||
}
|
||||
if(isset($opts['accept'])) { $opts['accept'] = "'" . $opts['accept'] . "'"; }
|
||||
if(isset($opts['overlap'])) { $opts['overlap'] = "'" . $opts['overlap'] . "'"; }
|
||||
if(isset($opts['hoverclass'])) { $opts['hoverclass'] = "'" . $opts['hoverclass'] . "'"; }
|
||||
|
||||
$out = array();
|
||||
foreach ($opts as $k => $v)
|
||||
{
|
||||
$out[] = "$k:$v";
|
||||
}
|
||||
$out = array();
|
||||
foreach ($opts as $k => $v)
|
||||
{
|
||||
$out[] = "$k:$v";
|
||||
}
|
||||
|
||||
$out = join(', ', $out);
|
||||
$out = '{' . $out . '}';
|
||||
return $out;
|
||||
}
|
||||
$out = join(', ', $out);
|
||||
$out = '{' . $out . '}';
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Javascript helper function (private).
|
||||
*
|
||||
*/
|
||||
function __optionsForAjax ($options)
|
||||
{
|
||||
$js_options = $this->__buildCallbacks($options);
|
||||
$js_options['asynchronous'] = 'true';
|
||||
if (isset($options['type'])) {
|
||||
if ($options['type'] == 'synchronous') {
|
||||
$js_options['asynchronous'] = 'false';
|
||||
}
|
||||
}
|
||||
function __optionsForAjax ($options)
|
||||
{
|
||||
$js_options = $this->__buildCallbacks($options);
|
||||
$js_options['asynchronous'] = 'true';
|
||||
if (isset($options['type']))
|
||||
{
|
||||
if ($options['type'] == 'synchronous')
|
||||
{
|
||||
$js_options['asynchronous'] = 'false';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['method'])) {
|
||||
$js_options['method'] = $this->__methodOptionToString($options['method']);
|
||||
}
|
||||
if (isset($options['method']))
|
||||
{
|
||||
$js_options['method'] = $this->__methodOptionToString($options['method']);
|
||||
}
|
||||
|
||||
if (isset($options['position']))
|
||||
{
|
||||
$js_options['insertion'] = "Insertion." . Inflector::camelize($options['position']);
|
||||
}
|
||||
|
||||
if (isset($options['position'])) {
|
||||
$js_options['insertion'] = "Insertion." . Inflector::camelize($options['position']);
|
||||
}
|
||||
if (isset($options['form']))
|
||||
{
|
||||
$js_options['parameters'] = 'Form.serialize(this)';
|
||||
}
|
||||
elseif (isset($options['with']))
|
||||
{
|
||||
$js_options['parameters'] = $options['with'];
|
||||
}
|
||||
|
||||
if (isset($options['form'])) {
|
||||
$js_options['parameters'] = 'Form.serialize(this)';
|
||||
} elseif (isset($options['with'])) {
|
||||
$js_options['parameters'] = $options['with'];
|
||||
}
|
||||
if (isset($options['evalScripts']))
|
||||
{
|
||||
$js_options['evalScripts'] = "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
$js_options['evalScripts'] = "false";
|
||||
}
|
||||
|
||||
if (isset($options['evalScripts'])) {
|
||||
$js_options['evalScripts'] = "true";
|
||||
} else {
|
||||
$js_options['evalScripts'] = "false";
|
||||
}
|
||||
$out = array();
|
||||
foreach ($js_options as $k => $v)
|
||||
{
|
||||
$out[] = "$k:$v";
|
||||
}
|
||||
|
||||
$out = array();
|
||||
foreach ($js_options as $k => $v)
|
||||
{
|
||||
$out[] = "$k:$v";
|
||||
}
|
||||
$out = join(', ', $out);
|
||||
$out = '{' . $out . '}';
|
||||
return $out;
|
||||
}
|
||||
|
||||
$out = join(', ', $out);
|
||||
$out = '{' . $out . '}';
|
||||
return $out;
|
||||
}
|
||||
function __methodOptionToString ($method)
|
||||
{
|
||||
return (is_string($method) && !$method[0]=="'") ? $method : "'$method'";
|
||||
}
|
||||
|
||||
function __methodOptionToString ($method)
|
||||
{
|
||||
return (is_string($method) && !$method[0]=="'") ? $method : "'$method'";
|
||||
}
|
||||
function __buildObserver ($html, $klass, $name, $options=null)
|
||||
{
|
||||
if(!isset($options['with']) && isset($options['update']))
|
||||
{
|
||||
$options['with'] = 'value';
|
||||
}
|
||||
|
||||
function __buildObserver ($html, $klass, $name, $options=null)
|
||||
{
|
||||
if(!isset($options['with']) && isset($options['update']))
|
||||
{
|
||||
$options['with'] = 'value';
|
||||
}
|
||||
|
||||
$callback = $this->remoteFunction($html, $options);
|
||||
$javascript = "new $klass('$name', ";
|
||||
$javascript .= (isset($options['frequency']) ? $options['frequency'] : 2) . ", function(element, value) {";
|
||||
$javascript .= "$callback})";
|
||||
return $javascript;
|
||||
}
|
||||
|
||||
function __buildCallbacks($options)
|
||||
{
|
||||
$actions = array('uninitialized', 'loading', 'loaded', 'interactive', 'complete');
|
||||
$callbacks = array();
|
||||
foreach($actions as $callback)
|
||||
{
|
||||
if(isset($options[$callback]))
|
||||
{
|
||||
$name = 'on' . ucfirst($callback);
|
||||
$code = $options[$callback];
|
||||
$callbacks[$name] = "function(request){".$code."}";
|
||||
}
|
||||
}
|
||||
return $callbacks;
|
||||
}
|
||||
$callback = $this->remoteFunction($html, $options);
|
||||
$javascript = "new $klass('$name', ";
|
||||
$javascript .= (isset($options['frequency']) ? $options['frequency'] : 2) . ", function(element, value) {";
|
||||
$javascript .= "$callback})";
|
||||
return $javascript;
|
||||
}
|
||||
|
||||
function __buildCallbacks($options)
|
||||
{
|
||||
$actions = array('uninitialized', 'loading', 'loaded', 'interactive', 'complete');
|
||||
$callbacks = array();
|
||||
foreach($actions as $callback)
|
||||
{
|
||||
if(isset($options[$callback]))
|
||||
{
|
||||
$name = 'on' . ucfirst($callback);
|
||||
$code = $options[$callback];
|
||||
$callbacks[$name] = "function(request){".$code."}";
|
||||
}
|
||||
}
|
||||
return $callbacks;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
* Automatic generation of HTML FORMs from given data.
|
||||
*
|
||||
* Long description for file
|
||||
* Used for scaffolding.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -60,7 +60,7 @@ define('TAG_FIELDSET', '<fieldset><legend>%s</legend>%s</label>');
|
|||
/**
|
||||
* Form helper library.
|
||||
*
|
||||
* Long description for class
|
||||
* Automatic generation of HTML FORMs from given data.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs.helpers
|
||||
|
@ -70,22 +70,22 @@ define('TAG_FIELDSET', '<fieldset><legend>%s</legend>%s</label>');
|
|||
class FormHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor which takes an instance of the HtmlHelper class.
|
||||
*
|
||||
* @param object $htmlHelper the HtmlHelper object to use as our helper.
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* Constructor which takes an instance of the HtmlHelper class.
|
||||
*
|
||||
* @param object $htmlHelper the HtmlHelper object to use as our helper.
|
||||
* @return void
|
||||
*/
|
||||
function FormHelper()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted error message for given FORM field, NULL if no errors.
|
||||
*
|
||||
* @param string $field If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @return bool If there are errors this method returns true, else false.
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted error message for given FORM field, NULL if no errors.
|
||||
*
|
||||
* @param string $field If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @return bool If there are errors this method returns true, else false.
|
||||
*/
|
||||
function isFieldError($html, $field )
|
||||
{
|
||||
$error = 1;
|
||||
|
@ -98,54 +98,54 @@ class FormHelper
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted LABEL tag for HTML FORMs.
|
||||
*
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $text Text that will appear in the label field.
|
||||
* @return string The formatted LABEL element
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted LABEL element for HTML FORMs.
|
||||
*
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $text Text that will appear in the label field.
|
||||
* @return string The formatted LABEL element
|
||||
*/
|
||||
function labelTag( $tagName, $text )
|
||||
{
|
||||
return sprintf( TAG_LABEL, $tagName, $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted DIV tag for HTML FORMs.
|
||||
*
|
||||
* @param string $class If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $text Text that will appear in the label field.
|
||||
* @return string The formatted DIV element
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted DIV tag for HTML FORMs.
|
||||
*
|
||||
* @param string $class If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $text Text that will appear in the label field.
|
||||
* @return string The formatted DIV element
|
||||
*/
|
||||
function divTag( $class, $text )
|
||||
{
|
||||
return sprintf( TAG_DIV, $class, $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted P tag with class for HTML FORMs.
|
||||
*
|
||||
* @param string $class If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $text Text that will appear in the label field.
|
||||
* @return string The formatted DIV element
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted P tag with class for HTML FORMs.
|
||||
*
|
||||
* @param string $class If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $text Text that will appear in the label field.
|
||||
* @return string The formatted DIV element
|
||||
*/
|
||||
function pTag( $class, $text )
|
||||
{
|
||||
return sprintf( TAG_P_CLASS, $class, $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted INPUT tag for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $errorMsg Text that will appear if an error has occurred.
|
||||
* @param int $size Size attribute for INPUT element
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted INPUT element
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted INPUT tag for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $errorMsg Text that will appear if an error has occurred.
|
||||
* @param int $size Size attribute for INPUT element
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted INPUT element
|
||||
*/
|
||||
function generateInputDiv($html, $tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null )
|
||||
{
|
||||
$str = $html->inputTag( $tagName, $size, $htmlOptions );
|
||||
|
@ -170,18 +170,18 @@ class FormHelper
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted INPUT tag for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $errorMsg Text that will appear if an error has occurred.
|
||||
* @param int $size Size attribute for INPUT element
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted INPUT element
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted CHECKBOX tag inside a DIV for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $errorMsg Text that will appear if an error has occurred.
|
||||
* @param int $size Size attribute for INPUT element
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted INPUT element
|
||||
*/
|
||||
function generateCheckboxDiv($html, $tagName, $prompt, $required=false, $errorMsg=null, $htmlOptions=null )
|
||||
{
|
||||
$htmlOptions['class'] = "inputCheckbox";
|
||||
|
@ -206,7 +206,19 @@ class FormHelper
|
|||
return $this->divTag( $divClass, $divTagInside );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a formatted date option element for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $errorMsg Text that will appear if an error has occurred.
|
||||
* @param int $size Size attribute for INPUT element
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted INPUT element
|
||||
*/
|
||||
function generateDate($html, $tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null )
|
||||
{
|
||||
$str = $html->dateTimeOptionTag( $tagName, 'MDY' , 'NONE' );
|
||||
|
@ -232,6 +244,18 @@ class FormHelper
|
|||
return $this->divTag("date", $requiredDiv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted datetime option element for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $errorMsg Text that will appear if an error has occurred.
|
||||
* @param int $size Size attribute for INPUT element
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted datetime option element
|
||||
*/
|
||||
function generateDateTime($html, $tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null )
|
||||
{
|
||||
$str = $html->dateTimeOptionTag( $tagName, 'MDY' , '12' );
|
||||
|
@ -256,19 +280,20 @@ class FormHelper
|
|||
|
||||
return $this->divTag("date", $requiredDiv);
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param HtmlHelper $html
|
||||
* @param unknown_type $tagName
|
||||
* @param unknown_type $prompt
|
||||
* @param unknown_type $required
|
||||
* @param unknown_type $errorMsg
|
||||
* @param unknown_type $cols
|
||||
* @param unknown_type $rows
|
||||
* @param unknown_type $htmlOptions
|
||||
* @return unknown
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a formatted TEXTAREA inside a DIV for use with HTML forms.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param boolean $required True if this field is required.
|
||||
* @param string $errorMsg ext that will appear if an error has occurred.
|
||||
* @param integer $cols Number of columns.
|
||||
* @param integer $rows Number of rows.
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted TEXTAREA element
|
||||
*/
|
||||
function generateAreaDiv($html, $tagName, $prompt, $required=false, $errorMsg=null, $cols=60, $rows=10, $htmlOptions=null )
|
||||
{
|
||||
$str = $html->areaTag( $tagName, $cols, $rows, $htmlOptions );
|
||||
|
@ -293,22 +318,20 @@ class FormHelper
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted SELECT tag for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field.
|
||||
* @param array $options Options to be contained in SELECT element
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $selected Text of the currently selected item
|
||||
* @param bool $required True if this field is required.
|
||||
* @param bool $required True if this field is required.
|
||||
* @param string $errorMsg Text that will appear if an error has occurred.
|
||||
* @param array $selectAttr
|
||||
* @param array $optionAttr
|
||||
* @return string The formatted INPUT element
|
||||
*/
|
||||
/**
|
||||
* Returns a formatted SELECT tag for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form
|
||||
* @param string $tagName If field is to be used for CRUD, this should be modelName/fieldName
|
||||
* @param string $prompt Text that will appear in the label field
|
||||
* @param array $options Options to be contained in SELECT element
|
||||
* @param string $selected Text of the currently selected item
|
||||
* @param array $selectAttr Array of HTML attributes for the SELECT element
|
||||
* @param array $optionAttr Array of HTML attributes for the OPTION elements
|
||||
* @param bool $required True if this field is required
|
||||
* @param string $errorMsg Text that will appear if an error has occurred
|
||||
* @return string The formatted INPUT element
|
||||
*/
|
||||
function generateSelectDiv($html, $tagName, $prompt, $options, $selected=null, $selectAttr=null, $optionAttr=null, $required=false, $errorMsg=null)
|
||||
{
|
||||
$str = $html->selectTag( $tagName, $options, $selected, $selectAttr, $optionAttr );
|
||||
|
@ -332,20 +355,29 @@ class FormHelper
|
|||
return $this->divTag( $divClass, $divTagInside );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a formatted submit widget for HTML FORMs.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form
|
||||
* @param string $prompt Text that will appear on the widget
|
||||
* @param array $htmlOptions
|
||||
* @return string The formatted submit widget
|
||||
*/
|
||||
function generateSubmitDiv($html, $displayText, $htmlOptions = null)
|
||||
{
|
||||
return $this->divTag( 'submit', $html->submitTag( $displayText, $htmlOptions) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an form to go onto a HtmlHelper object.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form.
|
||||
* @param array $fields An array of form field definitions.
|
||||
* @return string The completed form specified by the $fields praameter.
|
||||
*/
|
||||
/**
|
||||
* Generates an form to go onto a HtmlHelper object.
|
||||
*
|
||||
* @param HtmlHelper $html The HtmlHelper object which is creating this form
|
||||
* @param array $fields An array of form field definitions
|
||||
* @param boolean $readOnly True if the form should be rendered as READONLY
|
||||
* @return string The completed form specified by the $fields parameter
|
||||
*/
|
||||
function generateFields( $html, $fields, $readOnly = false )
|
||||
{
|
||||
$strFormFields = '';
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,9 +39,9 @@ if(!defined("TAG_JAVASCRIPT_INCLUDE")) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Javascript Helper class for easy use of javascript.
|
||||
* Javascript Helper class for easy use of JavaScript.
|
||||
*
|
||||
* JavascriptHelper encloses all methods needed while working with javascripts.
|
||||
* JavascriptHelper encloses all methods needed while working with JavaScript.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs.helpers
|
||||
|
@ -61,7 +61,7 @@ class JavascriptHelper extends Helper
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a JavaScript include tag
|
||||
* Returns a JavaScript include tag (LINK element)
|
||||
*
|
||||
* @param string $url URL to JavaScript file.
|
||||
* @return string
|
||||
|
@ -72,7 +72,7 @@ class JavascriptHelper extends Helper
|
|||
}
|
||||
|
||||
/**
|
||||
* Escape carrier returns and single and double quotes for Javascript segments.
|
||||
* Escape carriage returns and single and double quotes for JavaScript segments.
|
||||
*
|
||||
* @param string $script string that might have javascript elements
|
||||
* @return string escaped string
|
||||
|
@ -85,7 +85,7 @@ class JavascriptHelper extends Helper
|
|||
}
|
||||
|
||||
/**
|
||||
* Attach an event to an element
|
||||
* Attach an event to an element. Used with the Prototype library.
|
||||
*
|
||||
* @param string $object Object to be observed
|
||||
* @param string $event event to observe
|
||||
|
@ -100,7 +100,7 @@ class JavascriptHelper extends Helper
|
|||
|
||||
|
||||
/**
|
||||
* Includes the Prototype Javascript library (and anything else) inside a single script tag
|
||||
* Includes the Prototype Javascript library (and anything else) inside a single script tag.
|
||||
*
|
||||
* Note: The recommended approach is to copy the contents of
|
||||
* lib/javascripts/ into your application's
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
/**
|
||||
* Number Helper.
|
||||
*
|
||||
* Long description for file
|
||||
* Methods to make numbers more readable.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -36,6 +36,8 @@
|
|||
/**
|
||||
* Number helper library.
|
||||
*
|
||||
* Methods to make numbers more readable.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs.helpers
|
||||
* @since CakePHP v 0.9.2
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
/**
|
||||
* Text Helper
|
||||
*
|
||||
* Long description for file
|
||||
* Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -40,7 +40,7 @@ uses('flay', 'helpers/html');
|
|||
/**
|
||||
* Text helper library.
|
||||
*
|
||||
* Long description for class
|
||||
* Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs.helpers
|
||||
|
@ -50,7 +50,7 @@ uses('flay', 'helpers/html');
|
|||
class TextHelper extends Helper
|
||||
{
|
||||
/**
|
||||
* Highlights a given phrase in a text
|
||||
* Highlights a given phrase in a text.
|
||||
*
|
||||
* @param string $text Text to search the phrase in
|
||||
* @param string $phrase The phrase that will be searched
|
||||
|
@ -83,7 +83,7 @@ class TextHelper extends Helper
|
|||
}
|
||||
|
||||
/**
|
||||
* Strips all links(<a href=....) of a givent text
|
||||
* Strips given text of all links (<a href=....)
|
||||
*
|
||||
* @param string $text Text
|
||||
* @return string The text without links
|
||||
|
@ -94,7 +94,7 @@ class TextHelper extends Helper
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds links(<a href=....) to a given text
|
||||
* Adds links (<a href=....) to a given text.
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param array $htmlOptions Array of HTML options.
|
||||
|
@ -128,7 +128,7 @@ class TextHelper extends Helper
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds email links(<a href="mailto:....) to a givent text
|
||||
* Adds email links (<a href="mailto:....) to a given text.
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param array $htmlOptions Array of HTML options.
|
||||
|
@ -154,7 +154,7 @@ class TextHelper extends Helper
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert all links and email adresses to Html links.
|
||||
* Convert all links and email adresses to HTML links.
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param array $htmlOptions Array of HTML options.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* SVN FILE: $Id: html.php 578 2005-08-12 04:09:07Z phpnut $ */
|
||||
|
||||
/**
|
||||
* Html Helper class file.
|
||||
* Time Helper class file.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -30,9 +30,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Html Helper class for easy use of html widgets.
|
||||
* Time Helper class for easy use of time data.
|
||||
*
|
||||
* HtmlHelper encloses all methods needed while working with html pages.
|
||||
* Manipulation of time data.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs.helpers
|
||||
|
@ -55,28 +55,29 @@ class TimeHelper extends Helper
|
|||
|
||||
|
||||
/**
|
||||
* Returns a unix timestamp, given either a unix timestamp or a valid strtotime() date string.
|
||||
* Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
*
|
||||
* @param string $date_string Datetime string
|
||||
* @return string Formatted date string
|
||||
*/
|
||||
function fromString ($date_string) {
|
||||
function fromString ($date_string)
|
||||
{
|
||||
return is_integer($date_string)
|
||||
? $date_string
|
||||
: strtotime($date_string);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a nicely formatted date string for given Datetime string.
|
||||
*
|
||||
* @param string $date_string Datetime string or Unix timestamp
|
||||
* @param boolean $return Whether this method should return a value
|
||||
* or output it. This overrides AUTO_OUTPUT.
|
||||
* @return string Formatted date string
|
||||
* @param string $date_string Datetime string or Unix timestamp
|
||||
* @param boolean $return Whether this method should return a value
|
||||
* or output it. This overrides AUTO_OUTPUT.
|
||||
* @return string Formatted date string
|
||||
*/
|
||||
function nice ($date_string=null,$return = false) {
|
||||
function nice ($date_string=null, $return = false)
|
||||
{
|
||||
$date = $date_string? strtotime($date_string): time();
|
||||
$date = $date_string? $this->fromString($date_string): time();
|
||||
$ret = date("D, M jS Y, H:i", $date);
|
||||
|
@ -87,6 +88,7 @@ class TimeHelper extends Helper
|
|||
|
||||
/**
|
||||
* Returns a formatted descriptive date string for given datetime string.
|
||||
*
|
||||
* If the given date is today, the returned string could be "Today, 16:54".
|
||||
* If the given date was yesterday, the returned string could be "Yesterday, 16:54".
|
||||
* If $date_string's year is the current year, the returned string does not
|
||||
|
@ -103,12 +105,18 @@ class TimeHelper extends Helper
|
|||
|
||||
$y = $this->isThisYear($date)? '': ' Y';
|
||||
|
||||
if ($this->isToday($date))
|
||||
if ($this->isToday($date))
|
||||
{
|
||||
$ret = "Today, ".date("H:i", $date);
|
||||
}
|
||||
elseif ($this->wasYesterday($date))
|
||||
{
|
||||
$ret = "Yesterday, ".date("H:i", $date);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret = date("M jS{$y}, H:i", $date);
|
||||
}
|
||||
|
||||
return $this->output($ret, $return);
|
||||
}
|
||||
|
@ -136,6 +144,7 @@ class TimeHelper extends Helper
|
|||
*
|
||||
* @param string $date_string Datetime string or Unix timestamp
|
||||
* @param string $end Datetime string or Unix timestamp
|
||||
* @param string $field_name Name of database field to compare with
|
||||
* @param boolean $return Whether this method should return a value
|
||||
* or output it. This overrides AUTO_OUTPUT.
|
||||
* @return string Partial SQL string.
|
||||
|
@ -158,6 +167,7 @@ class TimeHelper extends Helper
|
|||
* occurring on the same day.
|
||||
*
|
||||
* @param string $date_string Datetime string or Unix timestamp
|
||||
* @param string $field_name Name of database field to compare with
|
||||
* @param boolean $return Whether this method should return a value
|
||||
* or output it. This overrides AUTO_OUTPUT.
|
||||
* @return string Partial SQL string.
|
||||
|
@ -204,7 +214,7 @@ class TimeHelper extends Helper
|
|||
|
||||
|
||||
/**
|
||||
* Returns a Unix timestamp from a textual datetime description. Wrapper for PHP function strtotime().
|
||||
* Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
|
||||
*
|
||||
* @param string $date_string Datetime string to be represented as a Unix timestamp
|
||||
* @param boolean $return Whether this method should return a value
|
||||
|
@ -285,27 +295,39 @@ class TimeHelper extends Helper
|
|||
$diff -= $minutes*60;
|
||||
$seconds = $diff;
|
||||
|
||||
if ($months>0) {
|
||||
if ($months>0)
|
||||
{
|
||||
// over a month old, just show date (mm/dd/yyyy format)
|
||||
$ret = 'on '.date("j/n/Y", $in_seconds);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$relative_date='';
|
||||
if ($weeks>0) {
|
||||
if ($weeks>0)
|
||||
{
|
||||
// weeks and days
|
||||
$relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks>1?'s':'');
|
||||
$relative_date .= $days>0?($relative_date?', ':'').$days.' day'.($days>1?'s':''):'';
|
||||
} elseif ($days>0) {
|
||||
}
|
||||
elseif ($days>0)
|
||||
{
|
||||
// days and hours
|
||||
$relative_date .= ($relative_date?', ':'').$days.' day'.($days>1?'s':'');
|
||||
$relative_date .= $hours>0?($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''):'';
|
||||
} elseif ($hours>0) {
|
||||
}
|
||||
elseif ($hours>0)
|
||||
{
|
||||
// hours and minutes
|
||||
$relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours>1?'s':'');
|
||||
$relative_date .= $minutes>0?($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''):'';
|
||||
} elseif ($minutes>0) {
|
||||
}
|
||||
elseif ($minutes>0)
|
||||
{
|
||||
// minutes only
|
||||
$relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':'');
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// seconds only
|
||||
$relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':'');
|
||||
}
|
||||
|
@ -352,7 +374,8 @@ class TimeHelper extends Helper
|
|||
$currentTime = floor(time());
|
||||
$seconds = ($currentTime - floor($date));
|
||||
|
||||
switch($textInterval) {
|
||||
switch($textInterval)
|
||||
{
|
||||
|
||||
case "seconds":
|
||||
case "second":
|
||||
|
@ -406,9 +429,12 @@ class TimeHelper extends Helper
|
|||
break;
|
||||
}
|
||||
|
||||
if ($timePeriod <= $numInterval) {
|
||||
if ($timePeriod <= $numInterval)
|
||||
{
|
||||
$ret = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
* Object-relational mapper.
|
||||
*
|
||||
* Long description for file
|
||||
* DBO-backed object data model, for mapping database tables to Cake objects.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -883,7 +883,7 @@ class Model extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->id? $this->find("id = '{$this->id}'", $fields): false;
|
||||
return $this->id? $this->find("$this->table.id = '{$this->id}'", $fields): false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1292,6 +1292,8 @@ class Model extends Object
|
|||
{
|
||||
foreach ($value1 as $key2 => $value2)
|
||||
{
|
||||
if($key2 === Inflector::singularize($this->table))
|
||||
{
|
||||
$oneToManySelect[$table] = $this->db->all("SELECT * FROM {$table} WHERE ($field) = '{$value2['id']}'");
|
||||
|
||||
if( !empty($oneToManySelect[$table]) && is_array($oneToManySelect[$table]))
|
||||
|
@ -1311,6 +1313,7 @@ class Model extends Object
|
|||
{
|
||||
$original[$count] = $newdata[$count];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$count++;
|
||||
|
@ -1337,41 +1340,40 @@ class Model extends Object
|
|||
{
|
||||
foreach ($value1 as $key2 => $value2)
|
||||
{
|
||||
if( 0 == strncmp($key2, $joinKey1, strlen($key2)) )
|
||||
{
|
||||
if(!empty ($value2['id']))
|
||||
{
|
||||
$tmpSQL = "SELECT * FROM {$table}
|
||||
JOIN {$joineTable} ON {$joineTable}.{$joinKey1} = '$value2[id]'
|
||||
AND {$joineTable}.{$JoinKey2} = {$table} .id";
|
||||
$manyToManySelect[$table] = $this->db->all($tmpSQL);
|
||||
}
|
||||
|
||||
if( !empty($manyToManySelect[$table]) && is_array($manyToManySelect[$table]))
|
||||
{
|
||||
$newKey = Inflector::singularize($table);
|
||||
foreach ($manyToManySelect[$table] as $key => $value)
|
||||
{
|
||||
$manyToManySelect1[$table][$key] = $value[$newKey];
|
||||
}
|
||||
|
||||
$merged = array_merge_recursive($data[$count],$manyToManySelect1);
|
||||
$newdata[$count] = $merged;
|
||||
unset( $manyToManySelect[$table] );
|
||||
}
|
||||
|
||||
|
||||
if(!empty($newdata[$count]))
|
||||
{
|
||||
$original[$count] = $newdata[$count];
|
||||
}
|
||||
}
|
||||
if($key2 === Inflector::singularize($this->table))
|
||||
{
|
||||
if( 0 == strncmp($key2, $joinKey1, strlen($key2)) )
|
||||
{
|
||||
if(!empty ($value2['id']))
|
||||
{
|
||||
$tmpSQL = "SELECT * FROM {$table}
|
||||
JOIN {$joineTable} ON {$joineTable}.{$joinKey1} = '$value2[id]'
|
||||
AND {$joineTable}.{$JoinKey2} = {$table} .id";
|
||||
$manyToManySelect[$table] = $this->db->all($tmpSQL);
|
||||
}
|
||||
|
||||
if( !empty($manyToManySelect[$table]) && is_array($manyToManySelect[$table]))
|
||||
{
|
||||
$newKey = Inflector::singularize($table);
|
||||
foreach ($manyToManySelect[$table] as $key => $value)
|
||||
{
|
||||
$manyToManySelect1[$table][$key] = $value[$newKey];
|
||||
}
|
||||
$merged = array_merge_recursive($data[$count],$manyToManySelect1);
|
||||
$newdata[$count] = $merged;
|
||||
unset( $manyToManySelect[$table] );
|
||||
}
|
||||
if(!empty($newdata[$count]))
|
||||
{
|
||||
$original[$count] = $newdata[$count];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
$this->joinedHasAndBelongs[] = new NeatArray($this->db->fields($table));
|
||||
}
|
||||
|
||||
if(!empty($original))
|
||||
{
|
||||
$data = $original;
|
||||
|
@ -1401,7 +1403,7 @@ class Model extends Object
|
|||
function findCount ($conditions)
|
||||
{
|
||||
list($data) = Model::findAll($conditions, 'COUNT(*) AS count');
|
||||
return isset($data['count'])? $data['count']: false;
|
||||
return isset($data[0]['count'])? $data[0]['count']: false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1573,6 +1575,11 @@ class Model extends Object
|
|||
|
||||
return $dispField;
|
||||
}
|
||||
|
||||
function getLastInsertID()
|
||||
{
|
||||
return $this->db->lastInsertId($this->table, 'id');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue