Skip to content

Commit

Permalink
Draft of 10th.
Browse files Browse the repository at this point in the history
  • Loading branch information
hidenori-wasa committed Jan 21, 2015
1 parent 5ff5f40 commit 3b08ff8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 35 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -60,6 +60,6 @@ Configure::write('debug', WASA_DEBUG_LEVEL);
Change log
----------

* I added "\WasaCache" class feature to decrease disc access.
* I repaired "\WasaAppController" class.
* I created "\WasaAppModel" class for model validation.
* I added "\WasaAppModel::__construct()" class method.
* I repaired "\WasaCache::__write()" class method.
* I repaired "\WasaBootstrap030200FormHelper" class.
14 changes: 11 additions & 3 deletions app/Lib/Wasa/Cache/WasaCache.php
Expand Up @@ -110,7 +110,7 @@ private static function __read($key)
// Reads the cache without lock.
$array = \Cache::read($key, self::SETTING_NAME);
// If this is not array.
if (!\is_array($array)) {
if (!is_array($array)) {
// Returns an empty array.
return array ();
}
Expand Down Expand Up @@ -156,8 +156,16 @@ private static function __write($key, $nativeArray, $array)
if ($array !== $nativeArray) {
// Locks the cache.
\Cache::set(array ('lock' => true), self::SETTING_NAME);
// Writes to the cache.
$result = \Cache::write($key, $array, self::SETTING_NAME);
$result = true;
$currentArray = \Cache::read($key, self::SETTING_NAME);
if (!\is_array($currentArray)) {
$currentArray = array ();
}
// If other process has not written.
if ($currentArray === $nativeArray) {
// Writes to the cache.
$result = \Cache::write($key, $array, self::SETTING_NAME);
}
// Unlocks the cache.
\Cache::set(array ('lock' => false), self::SETTING_NAME);
if (WASA_DEBUG_LEVEL && $result === false) {
Expand Down
11 changes: 11 additions & 0 deletions app/Lib/Wasa/Model/WasaAppModel.php
Expand Up @@ -43,6 +43,7 @@
*/
\App::uses('AppModel', 'Model');
\App::uses('WasaAppController', 'Wasa/Controller');
\App::uses('WasaCache', 'Wasa/Cache');
/**
* Wasa's Application Model.
*
Expand All @@ -56,6 +57,16 @@
class WasaAppModel extends \AppModel
{

/**
* Sets "$validate" property for model validation.
*/
function __construct()
{
$this->validate = $this->_getModelValidation();

parent::__construct();
}

/**
* Gets the model validation.
*
Expand Down
43 changes: 21 additions & 22 deletions app/Lib/Wasa/View/Helper/WasaBootstrap030200FormHelper.php
Expand Up @@ -41,8 +41,7 @@
* @license http://www.opensource.org/licenses/bsd-license.php BSD 2-Clause
* @link https://github.com/hidenori-wasa/_CakePHP0204Lib/
*/
use \WasaBootstrap030200FormHelper as WBFH; // This is this file scope and priority is high.
use \WasaCache as WC;
use \WasaCache as WC; // This is this file scope and priority is high.

\App::uses('WasaCache', 'Wasa/Cache');
/**
Expand Down Expand Up @@ -266,14 +265,14 @@ static function displayTelForJP($params)
for ($count = 0;; $count++) {
$fieldName = $fieldNames[$count];
// エラーの場合、入力フォームをエラー色にする
echo '<span class="' . $hasErrors[$fieldName] . '" style="' . WBFH::INLINE_BLOCK_STYLE . ' width: 30%">';
echo '<span class="' . $hasErrors[$fieldName] . '" style="' . self::INLINE_BLOCK_STYLE . ' width: 30%">';
// 電話番号テキストボックス
echo $telHTML[$count];
echo '</span>';
if ($count === 2) {
break;
}
echo '<span class="wasa-tel-separator-margin" style="' . WBFH::INLINE_BLOCK_STYLE . '">―</span>';
echo '<span class="wasa-tel-separator-margin" style="' . self::INLINE_BLOCK_STYLE . '">―</span>';
}
echo '</div>';

Expand Down Expand Up @@ -330,7 +329,7 @@ static function displayCheckboxes($params)
array (
'type' => 'checkbox',
'value' => $value,
'style' => WBFH::INLINE_BLOCK_STYLE,
'style' => self::INLINE_BLOCK_STYLE,
)
);
preg_match('`<input [[:space:]]+ type [[:space:]]* = [[:space:]]* "checkbox" .* [[:space:]]+ id [[:space:]]* = [[:space:]]* "(.*)"`xXU', $checkboxElement, $matches);
Expand All @@ -339,14 +338,14 @@ static function displayCheckboxes($params)
echo '<label class="' . $class . ' wasa-checkbox" for="' . $id . '">';
if ($labelLocation === 'front') {
// Displays the front label.
echo '<span class="wasa-label" style="' . WBFH::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
echo '<span class="wasa-label" style="' . self::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
// Displays checkbox and keeps input value.
echo $checkboxElement;
} else {
// Displays checkbox and keeps input value.
echo $checkboxElement;
// Displays the rear label.
echo '<span class="wasa-label" style="' . WBFH::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
echo '<span class="wasa-label" style="' . self::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
}
echo '</label>';
}
Expand Down Expand Up @@ -381,7 +380,7 @@ static function displayRadioButtons($params)
$fieldName, //
array (
'type' => 'radio',
'style' => WBFH::INLINE_BLOCK_STYLE,
'style' => self::INLINE_BLOCK_STYLE,
'options' => $values2,
'legend' => false,
'label' => false
Expand Down Expand Up @@ -410,14 +409,14 @@ static function displayRadioButtons($params)
echo '<label class="' . $class . ' wasa-radio" for="' . $id . '">';
if ($labelLocation === 'front') {
// Displays the front label.
echo '<span class="wasa-label" style="' . WBFH::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
echo '<span class="wasa-label" style="' . self::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
// Displays radio button and keeps input value.
echo $radioElement;
} else {
// Displays radio button and keeps input value.
echo $radioElement;
// Displays the rear label.
echo '<span class="wasa-label" style="' . WBFH::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
echo '<span class="wasa-label" style="' . self::INLINE_BLOCK_STYLE . '">' . $label . '</span>';
}
echo '</label>';
}
Expand Down Expand Up @@ -474,31 +473,31 @@ static function displayDateForJP($params)
// 画面サイズがエキストラスモール以外の場合のレイアウト
echo '<div style="padding: 0;" class="hidden-xs">';
// echo '<div style="padding: 0;">'; // For debug.
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . '">' . $yearHTML . '</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . '">年</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . '">' . $monthHTML . '</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . '">月</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . '">' . $dayHTML . '</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . '">日</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . '">' . $yearHTML . '</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . '">年</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . '">' . $monthHTML . '</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . '">月</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . '">' . $dayHTML . '</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . '">日</span>';
echo '</div>';

// 画面サイズがエキストラスモールの場合のレイアウト
echo '<div style="padding: 0;" class="visible-xs">';
// echo '<div style="padding: 0;">'; // For debug.
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . ' width: 90%">';
echo '<span style="' . self::INLINE_BLOCK_STYLE . ' width: 90%">';
echo $yearHTML;
echo '</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . ' margin-top: 0;">年</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . ' margin-top: 0;">年</span>';
echo '<div style="' . $centerBlockStyle . '">|</div>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . ' width: 90%">';
echo '<span style="' . self::INLINE_BLOCK_STYLE . ' width: 90%">';
echo $monthHTML;
echo '</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . ' margin-top: 0;">月</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . ' margin-top: 0;">月</span>';
echo '<div style="' . $centerBlockStyle . '">|</div>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . ' width: 90%">';
echo '<span style="' . self::INLINE_BLOCK_STYLE . ' width: 90%">';
echo $dayHTML;
echo '</span>';
echo '<span style="' . WBFH::INLINE_BLOCK_STYLE . ' margin-top: 0;">日</span>';
echo '<span style="' . self::INLINE_BLOCK_STYLE . ' margin-top: 0;">日</span>';
echo '</div>';

echo '</div>';
Expand Down
8 changes: 1 addition & 7 deletions app/Model/WasaBootstrap030200FormSample.php
Expand Up @@ -4,15 +4,9 @@
class WasaBootstrap030200FormSample extends \WasaAppModel
{

function __construct()
{
$this->validate = $this->_getModelValidation();

parent::__construct();
}
}

// \Validation:
}

/*
CREATE TABLE IF NOT EXISTS `wasa_bootstrap030200_form_samples` (
Expand Down

0 comments on commit 3b08ff8

Please sign in to comment.