Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Commit

  • Loading branch information...
commit a760585c0d3845717d9b081ec2aea84074bb6e82 0 parents
@k1LoW authored
2  .gitignore
@@ -0,0 +1,2 @@
+*~
+*#
71 Model/Behavior/AdditionalValidationPatternsBehavior.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * AdditionalValidationPatternsBehavior
+ *
+ * jpn: Cakeplus用のカスタムバリデーションパターン
+ */
+class AdditionalValidationPatternsBehavior extends ModelBehavior {
+
+ public $validationPatterns = array(
+ 'required' => array(
+ 'required' => array(
+ 'rule' => '/.*/',
+ 'required' => true,
+ 'last' => true,
+ ),
+ ),
+ 'notempty' => array(
+ 'notEmpty' => array('rule' => array('notEmpty'),
+ 'required' => false,
+ 'last' => true
+ ),
+ ),
+ // jpn: 数値チェック用
+ 'numeric' => array(
+ 'numeric' => array(
+ 'rule' => '/^[0-9]+$/',
+ 'last' => true,
+ ),
+ ),
+
+ // jpn:
+ 'zenkaku_only' => array(
+ 'zenkakuOnly' => array(
+ 'rule' => array('zenkakuOnly'),
+ 'allowEmpty' => true,
+ 'last' => true,
+ ),
+ ),
+ 'katakana_only' => array(
+ 'katakanaOnly' => array(
+ 'rule' => array('zenkakuOnly'),
+ 'allowEmpty' => true,
+ 'last' => true,
+ ),
+ ),
+ 'katakana_and_space' => array(
+ 'katakanaAndSpace' => array(
+ 'rule' => array('katakanaAndSpace'),
+ 'allowEmpty' => true,
+ 'last' => true,
+ ),
+ ),
+ );
+
+ /**
+ * setUp
+ *
+ */
+ public function setUp(Model $model){
+ $this->mergeValidationPatterns($model);
+ }
+
+ /**
+ * mergeValidationPatterns
+ *
+ */
+ private function mergeValidationPatterns(Model $model){
+ $model->validation_patterns = Hash::merge($this->validationPatterns, $model->validation_patterns);
+ }
+
+}
48 Model/Behavior/AdditionalValidationRulesBehavior.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * AdditionalValidationRulesBehavior
+ *
+ * jpn: 追加のバリデーションルール
+ */
+class AdditionalValidationRulesBehavior extends ModelBehavior {
+
+ /**
+ * setUp
+ *
+ * @param Model $model
+ */
+ public function setUp(Model $model){
+ }
+
+ /**
+ * notEmptyWith
+ * jpn: $withに指定されたフィールドに1つでも値が入っていたらnotEmptyを発動
+ *
+ */
+ public function notEmptyWith(Model $model, $field, $with = array()){
+ if (empty($with)) {
+ return true;
+ }
+ $key = key($field);
+ $value = array_shift($field);
+ $v = new Validation();
+ foreach ((array)$with as $withField) {
+ if($v->notEmpty($model->data[$model->alias][$withField])) {
+ return $v->notEmpty($value);
+ }
+ }
+ return true;
+ }
+
+ /**
+ * katakanaAndSpace
+ * jpn: 全角カタカナと全角スペースのみ
+ * @param Model $model, $field
+ */
+ public function katakanaAndSpace(Model $model, $field){
+ $key = key($field);
+ $value = array_shift($field);
+ $field = array($key => preg_replace('/ /','', $value));
+ return $model->katakanaOnly($field);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.