mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
merging changes from [683] [684] [685] [686] [688] [689] [690]
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@691 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e9358bacbe
commit
cdf8fd5812
10 changed files with 219 additions and 102 deletions
|
@ -46,6 +46,18 @@ class TestsController extends TestsHelper {
|
|||
$this->layout = null;
|
||||
require_once TESTS.'index.php';
|
||||
}
|
||||
|
||||
function groups ()
|
||||
{
|
||||
$this->layout = null;
|
||||
require_once TESTS.'index.php';
|
||||
}
|
||||
|
||||
function cases ()
|
||||
{
|
||||
$this->layout = null;
|
||||
require_once TESTS.'index.php';
|
||||
}
|
||||
/**
|
||||
* Runs all library and application tests
|
||||
*
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* Long description for file
|
||||
* Base controller class.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -32,7 +30,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Include files
|
||||
*/
|
||||
uses('model', 'inflector', 'folder', 'view', 'helper');
|
||||
|
||||
|
@ -115,7 +113,7 @@ class Controller extends Object
|
|||
var $_viewVars = array();
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Web page title
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
|
@ -140,7 +138,7 @@ class Controller extends Object
|
|||
var $base = null;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Layout file to use (see /app/views/layouts/default.thtml)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
|
@ -148,7 +146,7 @@ class Controller extends Object
|
|||
var $layout = 'default';
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Automatically render the view (the dispatcher checks for this variable before running render())
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
|
@ -164,7 +162,7 @@ class Controller extends Object
|
|||
var $autoLayout = true;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Database configuration to use (see /config/database.php)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
|
@ -329,7 +327,8 @@ class Controller extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Gets an instance of the view object & prepares it for rendering the output, then
|
||||
* asks the view to actualy do the job.
|
||||
*
|
||||
* @param unknown_type $action
|
||||
* @param unknown_type $layout
|
||||
|
@ -442,11 +441,12 @@ class Controller extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Shows a message to the user $time seconds, then redirects to $url
|
||||
* Uses flash.thtml as a layout for the messages
|
||||
*
|
||||
* @param unknown_type $message
|
||||
* @param unknown_type $url
|
||||
* @param unknown_type $time
|
||||
* @param string $message Message to display to the user
|
||||
* @param string $url Relative URL to redirect to after the time expires
|
||||
* @param int $time Time to show the message
|
||||
*/
|
||||
function flash($message, $url, $time=1)
|
||||
{
|
||||
|
@ -461,7 +461,12 @@ class Controller extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Shows a message to the user $time seconds, then redirects to $url
|
||||
* Uses flash.thtml as a layout for the messages
|
||||
*
|
||||
* @param string $message Message to display to the user
|
||||
* @param string $url URL to redirect to after the time expires
|
||||
* @param int $time Time to show the message
|
||||
*
|
||||
* @param unknown_type $message
|
||||
* @param unknown_type $url
|
||||
|
@ -601,6 +606,18 @@ class Controller extends Object
|
|||
}
|
||||
}
|
||||
break;
|
||||
case "tinyint":
|
||||
{
|
||||
if( $fieldLength > 1 )
|
||||
{
|
||||
$fieldNames[ $tabl['name']]['type'] = 'input';
|
||||
}
|
||||
else
|
||||
{
|
||||
$fieldNames[ $tabl['name']]['type'] = 'checkbox';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "int":
|
||||
case "decimal":
|
||||
case "float":
|
||||
|
|
|
@ -170,6 +170,43 @@ 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
|
||||
*/
|
||||
function generateCheckboxDiv($html, $tagName, $prompt, $required=false, $errorMsg=null, $htmlOptions=null )
|
||||
{
|
||||
$htmlOptions['class'] = "inputCheckbox";
|
||||
$str = $html->checkbox( $tagName, null, $htmlOptions );
|
||||
$strLabel = $this->labelTag( $tagName, $prompt );
|
||||
|
||||
$divClass = "optional";
|
||||
|
||||
if( $required )
|
||||
$divClass = "required";
|
||||
|
||||
$strError = ""; // initialize the error to empty.
|
||||
|
||||
if( $this->isFieldError( $html, $tagName ) )
|
||||
{
|
||||
// if it was an error that occured, then add the error message, and append " error" to the div tag.
|
||||
$strError = $this->pTag( 'error', $errorMsg );
|
||||
$divClass = sprintf( "%s error", $divClass );
|
||||
}
|
||||
$divTagInside = sprintf( "%s %s %s", $strError, $strLabel, $str );
|
||||
|
||||
return $this->divTag( $divClass, $divTagInside );
|
||||
|
||||
}
|
||||
|
||||
function generateDate($html, $tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null )
|
||||
{
|
||||
$str = $html->dateTimeOptionTag( $tagName, 'MDY' , 'NONE' );
|
||||
|
@ -339,6 +376,9 @@ class FormHelper
|
|||
}
|
||||
$strFormFields = $strFormFields.$this->generateInputDiv( $html, $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['size'], $field['htmlOptions'] );
|
||||
break;
|
||||
case "checkbox" :
|
||||
$strFormFields = $strFormFields.$this->generateCheckboxDiv( $html, $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['htmlOptions'] );
|
||||
break;
|
||||
case "select";
|
||||
case "selectMultiple";
|
||||
{
|
||||
|
|
|
@ -191,10 +191,20 @@ class HtmlHelper extends Helper
|
|||
function link($title, $url = null, $htmlAttributes = null, $confirmMessage = false,
|
||||
$return = false)
|
||||
{
|
||||
// prepare title for html display
|
||||
$title = htmlspecialchars($title, ENT_QUOTES);
|
||||
|
||||
$url = $url? $url: $title;
|
||||
|
||||
if ($confirmMessage)
|
||||
{
|
||||
// prepare for html display (fix everything except quotes)
|
||||
$confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES);
|
||||
// fix single quotes
|
||||
$confirmMessage = str_replace("'", "\'", $confirmMessage);
|
||||
// fix double quotes
|
||||
$confirmMessage = str_replace('"', '"', $confirmMessage);
|
||||
|
||||
$htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
|
||||
}
|
||||
|
||||
|
@ -393,7 +403,9 @@ class HtmlHelper extends Helper
|
|||
function hidden($fieldName, $htmlAttributes = null, $return = false)
|
||||
{
|
||||
$this->setFormTag($fieldName);
|
||||
$htmlAttributes['value'] = $value? $value: $this->tagValue($fieldName);
|
||||
if(!isset($htmlAttributes['value'])) {
|
||||
$htmlAttributes['value'] = $this->tagValue($fieldName);
|
||||
}
|
||||
return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field,
|
||||
$this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
|
||||
}
|
||||
|
@ -976,15 +988,20 @@ class HtmlHelper extends Helper
|
|||
*
|
||||
* @param string $fieldName Name attribute of the SELECT
|
||||
* @param array $option_elements Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element
|
||||
* @param boolean $show_empty Show/hide the empty select option
|
||||
* @param array $select_attr Array of HTML options for the opening SELECT element
|
||||
* @param array $optionAttr Array of HTML options for the enclosed OPTION elements
|
||||
* @return string Formatted SELECT element
|
||||
*/
|
||||
function selectTag($fieldName, $option_elements, $selected=null, $select_attr=null, $optionAttr=null)
|
||||
function selectTag($fieldName, $option_elements, $selected=null, $select_attr=null, $optionAttr=null, $show_empty=false)
|
||||
{
|
||||
$this->setFormTag($fieldName);
|
||||
if (!is_array($option_elements) || !count($option_elements))
|
||||
|
||||
// do not display the select tag if no option elements are avaible
|
||||
if (!is_array($option_elements) || count($option_elements) == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if( isset($select_attr) && array_key_exists( "multiple", $select_attr) )
|
||||
{
|
||||
|
@ -994,12 +1011,16 @@ class HtmlHelper extends Helper
|
|||
{
|
||||
$select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($select_attr));
|
||||
}
|
||||
|
||||
if($show_empty == true)
|
||||
{
|
||||
$select[] = sprintf($this->tags['selectempty'], $this->parseHtmlOptions($optionAttr));
|
||||
}
|
||||
|
||||
foreach ($option_elements as $name=>$title)
|
||||
{
|
||||
$options_here = $optionAttr;
|
||||
if ($selected == $name)
|
||||
if (!empty($selected) && ($selected == $name))
|
||||
{
|
||||
$options_here['selected'] = 'selected';
|
||||
} else if ( is_array($selected) && array_key_exists($name, $selected) )
|
||||
|
|
|
@ -967,7 +967,7 @@ class Model extends Object
|
|||
|
||||
foreach ($this->data as $n=>$v)
|
||||
{
|
||||
if(isset($weHaveMulti) && $count > 0)
|
||||
if(isset($weHaveMulti) && $count > 0 && !empty($this->_manyToMany))
|
||||
{
|
||||
$joined = array($v);
|
||||
}
|
||||
|
@ -1332,12 +1332,15 @@ class Model extends Object
|
|||
foreach ($datacheck as $key => $value1)
|
||||
{
|
||||
foreach ($value1 as $key2 => $value2)
|
||||
{
|
||||
if( 0 == strncmp($key2, $joinKey1, strlen($key2)) )
|
||||
{
|
||||
if(!empty ($value2['id']))
|
||||
{
|
||||
$select[$table] = $this->db->all("SELECT * FROM {$table}
|
||||
$tmpSQL = "SELECT * FROM {$table}
|
||||
JOIN {$joineTable} ON {$joineTable}.{$joinKey1} = '$value2[id]'
|
||||
AND {$joineTable}.{$JoinKey2} = {$table} .id");
|
||||
AND {$joineTable}.{$JoinKey2} = {$table} .id";
|
||||
$select[$table] = $this->db->all($tmpSQL);
|
||||
}
|
||||
if( is_array($select[$table]) && ($select[$table] != null))
|
||||
{
|
||||
|
@ -1350,6 +1353,7 @@ class Model extends Object
|
|||
$merged = array_merge_recursive($data[$count],$select1);
|
||||
$newdata[$count] = $merged;
|
||||
unset ($select1);
|
||||
unset( $select[$table] );
|
||||
}
|
||||
|
||||
if(!empty($newdata[$count]))
|
||||
|
@ -1357,6 +1361,7 @@ class Model extends Object
|
|||
$original[$count] = $newdata[$count];
|
||||
}
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
$this->joinedHasAndBelongs[] = new NeatArray($this->db->fields($table));
|
||||
|
|
|
@ -162,8 +162,9 @@ class Scaffold extends Object {
|
|||
*/
|
||||
function scaffoldList($params)
|
||||
{
|
||||
$model = $this->model;
|
||||
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames(null,false) );
|
||||
$this->controllerClass->set('data', $this->controllerClass->models[$this->model]->findAll());
|
||||
$this->controllerClass->set('data', $this->controllerClass->models[$model]->findAll());
|
||||
$this->controllerClass->render($this->actionView, '', LIBS.'controllers'.DS.'templates'.DS.'scaffolds'.DS.'list.thtml');
|
||||
}
|
||||
|
||||
|
@ -201,7 +202,7 @@ class Scaffold extends Object {
|
|||
function scaffoldCreate($params)
|
||||
{
|
||||
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames() );
|
||||
$this->cleanUpDateFields();
|
||||
$this->cleanUpFields();
|
||||
|
||||
if ($this->controllerClass->models[$this->model]->save($this->controllerClass->params['data']))
|
||||
{
|
||||
|
@ -223,7 +224,7 @@ class Scaffold extends Object {
|
|||
function scaffoldUpdate($params=array())
|
||||
{
|
||||
// clean up the date fields
|
||||
$this->cleanUpDateFields();
|
||||
$this->cleanUpFields();
|
||||
|
||||
$this->controllerClass->models[$this->model]->set($this->controllerClass->params['data']);
|
||||
if ( $this->controllerClass->models[$this->model]->save())
|
||||
|
@ -257,7 +258,7 @@ class Scaffold extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
function cleanUpDateFields()
|
||||
function cleanUpFields()
|
||||
{
|
||||
// clean up the date fields
|
||||
$objModel = $this->controllerClass->models[$this->model];
|
||||
|
@ -290,6 +291,18 @@ class Scaffold extends Object {
|
|||
$newDate = date( 'Y-m-d', $newDate );
|
||||
$this->controllerClass->params['data'][$this->model][$field['name']] = $newDate;
|
||||
}
|
||||
else if( 'tinyint(1)' == $field['type'] )
|
||||
{
|
||||
if( isset( $this->controllerClass->params['data'][$this->model][$field['name']]) &&
|
||||
"on" == $this->controllerClass->params['data'][$this->model][$field['name']] )
|
||||
{
|
||||
$this->controllerClass->params['data'][$this->model][$field['name']] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->controllerClass->params['data'][$this->model][$field['name']] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,12 +197,14 @@ form div input.inputCheckbox, form div input.inputRadio, input.inputCheckbox, in
|
|||
background-color: transparent;
|
||||
border-width: 0px;
|
||||
padding: 0px;
|
||||
margin: 0px 0px 0px 140px;
|
||||
margin: 0px 0px 0px 0px;
|
||||
}
|
||||
|
||||
form div.submit {
|
||||
width: 214px;
|
||||
padding: 0px 0px 0px 140px;
|
||||
clear:both;
|
||||
display:block;
|
||||
}
|
||||
|
||||
div.submit input {
|
||||
|
@ -327,6 +329,10 @@ div.date select {
|
|||
width:auto;
|
||||
}
|
||||
|
||||
select.autoWidth {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
option {
|
||||
padding-left:1em;
|
||||
}
|
|
@ -16,6 +16,7 @@ font-size:1.7em;
|
|||
color: #383;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size:1.4em;
|
||||
color: #553;
|
||||
|
|
|
@ -71,6 +71,9 @@ echo $header;
|
|||
|
||||
function CakePHPTestSuiteHeader()
|
||||
{
|
||||
$groups = class_exists('Object') ? 'groups' : $_SERVER['PHP_SELF'].'?show=groups';
|
||||
$cases = class_exists('Object') ? 'cases' : $_SERVER['PHP_SELF'].'?show=cases';
|
||||
|
||||
$suiteHeader = <<<EOD
|
||||
<div id="main">
|
||||
<div id="header">
|
||||
|
@ -79,11 +82,10 @@ echo $header;
|
|||
<h2>Test Suite v 1.0.0.0</h2>
|
||||
</div>
|
||||
</div>
|
||||
<p><a href='$_SERVER[PHP_SELF]?show=groups'>Test Groups</a> || <a href='$_SERVER[PHP_SELF]?show=cases'>Test Cases</a></p>
|
||||
<p><a href='$groups'>Test Groups</a> || <a href='$cases'>Test Cases</a></p>
|
||||
EOD;
|
||||
echo $suiteHeader;
|
||||
}
|
||||
|
||||
function CakePHPTestSuiteFooter()
|
||||
{
|
||||
$footer = <<<EOD
|
||||
|
@ -96,11 +98,11 @@ echo $footer;
|
|||
CakePHPTestHeader();
|
||||
CakePHPTestSuiteHeader();
|
||||
|
||||
if (isset($_GET['show']) && $_GET['show'] == 'cases')
|
||||
if (isset($_GET['cases']))
|
||||
{
|
||||
CakePHPTestCaseList();
|
||||
}
|
||||
elseif (isset($_GET['show']) && $_GET['show'] == 'groups')
|
||||
elseif (isset($_GET['groups']))
|
||||
{
|
||||
CakePHPTestGroupTestList();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue