lib/EigyoBundle/src/Entity/SystemSetting.php line 20

Open in your IDE?
  1. <?php
  2. namespace Times\EigyoBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\NotifyPropertyChanged,
  5.     Doctrine\Common\PropertyChangedListener;
  6. use Doctrine\Persistence\NotifyPropertyChanged as PersistenceNotifyPropertyChanged;
  7. use Doctrine\Persistence\PropertyChangedListener as PersistencePropertyChangedListener;
  8. use Kzl\BaseBundle\Common\KzlStatic;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Times\EigyoBundle\Repository\SystemSettingRepository;
  11. #use Kzl\JinjiKoukaBundle\Common\JinjiKoukaStatic;
  12. use Kzl\LogBundle\Entity\LogInterface;
  13. /**
  14.  * SystemSetting
  15.  */
  16. class SystemSetting implements PersistenceNotifyPropertyChanged LogInterface
  17. {
  18.     /**
  19.      * @var integer
  20.      */
  21.     private $id;
  22.     /**
  23.      * Get id
  24.      *
  25.      * @return integer 
  26.      */
  27.     public function getId()
  28.     {
  29.         return $this->id;
  30.     }
  31.     /**
  32.      * Set id
  33.      *
  34.      * @param integer $id
  35.      *
  36.      */
  37.     public function setId($id)
  38.     {
  39.         $this->id $id;
  40.         return $this;
  41.     }
  42.     
  43.     /**
  44.      * @var string
  45.      */
  46.     private $key_str;
  47.     /**
  48.      * @var integer
  49.      */
  50.     private $value_kbn;
  51.     /**
  52.      * @var integer
  53.      */
  54.     private $int_value;
  55.     /**
  56.      * @var string
  57.      */
  58.     private $string_value;
  59.     /**
  60.      * @var \DateTime
  61.      */
  62.     private $date_value;
  63.     /**
  64.      * @var string
  65.      */
  66.     private $name;
  67.     /**
  68.      * @var \DateTime
  69.      */
  70.     private $created_at;
  71.     /**
  72.      * @var \DateTime
  73.      */
  74.     private $updated_at;
  75.     /**
  76.      * Set key_str
  77.      *
  78.      * @param string $keyStr
  79.      * @return SystemSetting
  80.      */
  81.     public function setKeyStr($keyStr)
  82.     {
  83.         $this->key_str $keyStr;
  84.     
  85.         return $this;
  86.     }
  87.     /**
  88.      * Get key_str
  89.      *
  90.      * @return string 
  91.      */
  92.     public function getKeyStr()
  93.     {
  94.         return $this->key_str;
  95.     }
  96.     /**
  97.      * Set value_kbn
  98.      *
  99.      * @param integer $valueKbn
  100.      * @return SystemSetting
  101.      */
  102.     public function setValueKbn($valueKbn)
  103.     {
  104.         $this->value_kbn $valueKbn;
  105.     
  106.         return $this;
  107.     }
  108.     /**
  109.      * Get value_kbn
  110.      *
  111.      * @return integer 
  112.      */
  113.     public function getValueKbn()
  114.     {
  115.         return $this->value_kbn;
  116.     }
  117.     /**
  118.      * Set int_value
  119.      *
  120.      * @param integer $intValue
  121.      * @return SystemSetting
  122.      */
  123.     public function setIntValue($intValue)
  124.     {
  125.         $this->int_value $intValue;
  126.     
  127.         return $this;
  128.     }
  129.     /**
  130.      * Get int_value
  131.      *
  132.      * @return integer 
  133.      */
  134.     public function getIntValue()
  135.     {
  136.         return $this->int_value;
  137.     }
  138.     /**
  139.      * Set string_value
  140.      *
  141.      * @param string $stringValue
  142.      * @return SystemSetting
  143.      */
  144.     public function setStringValue($stringValue)
  145.     {
  146.         $this->string_value $stringValue;
  147.     
  148.         return $this;
  149.     }
  150.     /**
  151.      * Get string_value
  152.      *
  153.      * @return string 
  154.      */
  155.     public function getStringValue()
  156.     {
  157.         return $this->string_value;
  158.     }
  159.     /**
  160.      * Set date_value
  161.      *
  162.      * @param \DateTime $dateValue
  163.      * @return SystemSetting
  164.      */
  165.     public function setDateValue($dateValue)
  166.     {
  167.         $this->date_value $dateValue;
  168.     
  169.         return $this;
  170.     }
  171.     /**
  172.      * Get date_value
  173.      *
  174.      * @return \DateTime 
  175.      */
  176.     public function getDateValue()
  177.     {
  178.         return $this->date_value;
  179.     }
  180.     /**
  181.      * Set name
  182.      *
  183.      * @param string $name
  184.      * @return SystemSetting
  185.      */
  186.     public function setName($name)
  187.     {
  188.         $this->name $name;
  189.     
  190.         return $this;
  191.     }
  192.     /**
  193.      * Get name
  194.      *
  195.      * @return string 
  196.      */
  197.     public function getName()
  198.     {
  199.         return $this->name;
  200.     }
  201.     /**
  202.      * Set created_at
  203.      *
  204.      * @param \DateTime $createdAt
  205.      * @return SystemSetting
  206.      */
  207.     public function setCreatedAt($createdAt)
  208.     {
  209.         $this->created_at $createdAt;
  210.     
  211.         return $this;
  212.     }
  213.     /**
  214.      * Get created_at
  215.      *
  216.      * @return \DateTime 
  217.      */
  218.     public function getCreatedAt()
  219.     {
  220.         return $this->created_at;
  221.     }
  222.     /**
  223.      * Set updated_at
  224.      *
  225.      * @param \DateTime $updatedAt
  226.      * @return SystemSetting
  227.      */
  228.     public function setUpdatedAt($updatedAt)
  229.     {
  230.         $this->updated_at $updatedAt;
  231.     
  232.         return $this;
  233.     }
  234.     /**
  235.      * Get updated_at
  236.      *
  237.      * @return \DateTime 
  238.      */
  239.     public function getUpdatedAt()
  240.     {
  241.         return $this->updated_at;
  242.     }
  243.     // ------------------ 以下追加処理 ----------------------
  244.     /**
  245.      * 値区分によって、該当する項目へ値を設定する
  246.      * @param integer $valueKbn
  247.      * @param mixed $value
  248.      */
  249.     public function setValueByValueKbn($value$valueKbn null)
  250.     {
  251.         //値区分が渡されない場合は、自身の設定を利用する
  252.         if(!$valueKbn){
  253.             $valueKbn $this->getValueKbn();
  254.         }
  255.         // 値区分によってそれぞれの項目へ設定
  256.         switch ($valueKbn) {
  257.             case SystemSettingRepository::VALUE_KBN_NUM:
  258.                 $this->setIntValue($value);
  259.                 break;
  260.             case SystemSettingRepository::VALUE_KBN_STR:
  261.                 $this->setStringValue($value);
  262.                 break;
  263.             case SystemSettingRepository::VALUE_KBN_DATE:
  264.                 $this->setDateValue($value);
  265.                 break;
  266.             default:
  267.                 break;
  268.         }
  269.     }
  270.     /**
  271.      * 値区分によって、該当する項目から値を取得する
  272.      * @param integer $valueKbn
  273.      * @param mixed $value
  274.      */
  275.     public function getValueByValueKbn($valueKbn null)
  276.     {
  277.         //値区分が渡されない場合は、自身の設定を利用する
  278.         if(!$valueKbn){
  279.             $valueKbn $this->getValueKbn();
  280.         }
  281.         // 値区分によってそれぞれの項目を返す
  282.         switch ($valueKbn) {
  283.             case SystemSettingRepository::VALUE_KBN_NUM:
  284.                 return $this->getIntValue();
  285.             case SystemSettingRepository::VALUE_KBN_STR:
  286.                 return $this->getStringValue();
  287.             case SystemSettingRepository::VALUE_KBN_DATE:
  288.                 return $this->getDateValue();
  289.             default:
  290.                 throw new \LogicException(sprintf("不明な値区分「%s」です。"$setting->getValueKbn()));
  291.         }
  292.     }
  293.     /**
  294.      * 2014/9/13 mitsuanga バリデーションをわたす(コード設定用)
  295.      * @param type $key
  296.      */
  297.     /*
  298.     public function getValidationForCdSetting($key){
  299.         $validation = array();
  300.         // 種類は必須
  301.         if($key == SystemSettingRepository::CD_SETTING_KEY_KIND){
  302.             $validation[] = new Assert\NotBlank();
  303.         }
  304.         // すべて数値
  305.         // 14/11/07 sakamoto 社員設定に合わせてコードを10桁まで変更可能に
  306.         if($key == SystemSettingRepository::CD_SETTING_KEY_MAX){
  307. //            $maxMin = array('max' => 20, 'min' => 1);
  308.             $maxMin = array('max' => 10, 'min' => 1);
  309.         } else {
  310.             $maxMin = array('max' => 1, 'min' => 0);
  311.         }
  312.         $validation[] = new Assert\Range($maxMin);
  313.         return $validation;
  314.     }
  315. */
  316.     /**
  317.      * 種別ごとに必要な制約を返す。
  318.      * @param integer $valueKbn
  319.      */
  320.     public function getValidation($valueKbn null$keyStr null)
  321.     {
  322.         //値区分が渡されない場合は、自身の設定を利用する
  323.         if(!$valueKbn){
  324.             $valueKbn $this->getValueKbn();
  325.         }
  326.         //キー文字列も同様
  327.         if(!$keyStr){
  328.             $keyStr $this->getKeyStr();
  329.         }
  330.         $validation = array();
  331.         // 値区分での判定
  332.         switch ($valueKbn) {
  333.             case SystemSettingRepository::VALUE_KBN_NUM:
  334.                 // 最大11文字・integer
  335.                 // 第一期年度の場合は、最小・最大値を4桁へ
  336.                 if($keyStr == SystemSettingRepository::KEY_TERM_START_YEAR) {
  337.                     $validation[] = new Assert\Range(array('min'=>2010'max' => date_create('now')->format('Y')));
  338.                 } else if ($keyStr == SystemSettingRepository::KEY_NEW_INFO_DAY_AGO) {
  339.                     // 新着表示日数
  340.                     $validation[] = new Assert\Range(array('min'=>1'max' => 100));
  341.                     $validation[] = new Assert\Type(array('type'=>'digit''message' => 'This value should be a valid number.'));
  342.                 } else {
  343.                     $validation[] = new Assert\Range(array('max' => PHP_INT_MAX));
  344.                 }
  345.                 break;
  346.             case SystemSettingRepository::VALUE_KBN_STR:
  347.                 // 最大255(string初期値)
  348.                 if(strpos ($keyStr'MAIL_SEND_TIME') === 0) {
  349.                     $validation[] = new Assert\Regex(array('pattern' => '/^(0[0-9]{1}|1{1}[0-9]{1}|2{1}[0-3]{1}):(0[0-9]{1}|[1-5]{1}[0-9]{1})$/'));
  350.                 } elseif($keyStr == SystemSettingRepository::KEY_ADMIN_MAIL) {
  351.                     // 15/2/26 mitsunaga 追加
  352.                     $validation[] = new Assert\Email();
  353.                 } else {
  354.                     $validation[] = new Assert\Length(array('max' => 6));
  355.                 }
  356.                 break;
  357.             case SystemSettingRepository::VALUE_KBN_DATE:
  358.                 // 日付
  359.                 $validation[] = new Assert\DateTime();
  360.                 break;
  361.             default:
  362.                 break;
  363.         }
  364.         // キー文字列での判定
  365.         $requiredItems SystemSettingRepository::$required_items;
  366.         // 必須
  367.         if(in_array($keyStr$requiredItems)){
  368.             $validation[] = new Assert\NotBlank();
  369.         }
  370.         /*
  371.         // メールアドレス
  372.         if($keyStr == SystemSettingRepository::KEY_ADMIN_MAIL){
  373.             $validation[] = new Assert\Email();
  374.         }
  375.         */
  376.         return $validation;
  377.     }
  378.     /**
  379.      * 選択可能な値のリストを返す。
  380.      * 主に数値項目で利用
  381.      */
  382.     public function getSelectableValues($keyStr null)
  383.     {
  384.         //キー文字列の指定がなければ自分自身を使用
  385.         if(!$keyStr){
  386.             $keyStr $this->getKeyStr();
  387.         }
  388.         //if($keyStr == SystemSettingRepository::KEY_KOUKA_STAGE_COLOR_SELECT_INIT){
  389.         /*
  390.         switch($keyStr){
  391.             case SystemSettingRepository::KEY_SELF_HYOKA_FLG:
  392.                 // 自己評価設定
  393.             case SystemSettingRepository::KEY_AIM_FLG:
  394.                 // 個人目標設定
  395.             case SystemSettingRepository::KEY_MAIL_CHECK_FLG:
  396.                 // 2014/7/9 mitsunaga メールアドレス正当性チェック
  397.             case SystemSettingRepository::KEY_EMPLOYEE_OPTION_USE_FLG:
  398.                 // 個人目標機能使用設定
  399.             case SystemSettingRepository::KEY_EMPLOYEE_INFOMATION_FLG:
  400.                 // 面談機能使用設定
  401.             case SystemSettingRepository::KEY_EMPLOYEE_AIM_FLG:
  402.                 // 個人情報機能使用設定
  403.                 return SystemSettingRepository::$use_settings;
  404.             case SystemSettingRepository::KEY_LOGIN_SETTING:
  405.                 // ログイン設定
  406.                 return SystemSettingRepository::$login_settings;
  407.             case SystemSettingRepository::KEY_EMPLOYEE_AIM_EDIT_FLG:
  408.             case SystemSettingRepository::KEY_EMPLOYEE_AIM_PERCENTAGE_EDIT_FLG:
  409.                 // 14/12/1 mitsunaga employee_aim setting
  410.                 return SystemSettingRepository::$employee_aim_setting;
  411.         } */
  412.         return array();
  413.     }
  414.     /**
  415.      * @ORM\PostLoad
  416.      */
  417.     public function doPostLoad()
  418.     {
  419.         // Add your code here
  420.     }
  421.     private $_changeValues = array();
  422.     /**
  423.      * @ORM\PrePersist
  424.      */
  425.     public function doPreUpdate()
  426.     {
  427.         KzlStatic::setNewDNo($this);
  428.         // ** 変更された値をログへ記録
  429.         /*
  430.         // 1)変更値取得
  431.         if ($this->_listeners) {
  432.             foreach ($this->_listeners as $listener) {
  433.                 // 変更項目
  434.                 $changeSet = $listener->getEntityChangeSet($this);
  435.                 foreach ($changeSet as $item => $values) {
  436.                     // 監視対象なら変更値を保存
  437.                     if(SystemSettingRepository::isLogTargetItem($item)){
  438.                         foreach($values as $key => $value){
  439.                             if(is_null($value) || JinjiKoukaStatic::isNotValue($value)){
  440.                                 $values[$key] = JinjiKoukaStatic::LOG_EMPTT_STRING;
  441.                             }
  442.                         }
  443.                         //変更値を保持しておく
  444.                         $this->_changeValues[SystemSettingRepository::$log_target_list[$item]] = $values;
  445.                     }
  446.                 }//end foreach $changeSet
  447.             } // end foreach $_listeners
  448.         } //end if
  449.             */
  450.         // 新規の時は作成日を設定
  451.         if(null === $this->created_at){
  452.             $this->setCreatedAt(new \DateTime);
  453.         }
  454.         // 更新日を設定
  455.         $this->setUpdatedAt(new \DateTime);
  456.     }
  457.     public function writeLog()
  458.     {
  459.         /*
  460. //        var_dump( $this->_changeValues);
  461.         // 2)変更値があればログへ保存
  462.         if(count($this->_changeValues) > 0){
  463. //        var_dump( $this->_changeValues);
  464.             JinjiKoukaStatic::getLogger()->infoChange(JinjiKoukaStatic::getTrans('システム設定'), $this->getName(), $this->_changeValues);
  465.             // 初期化
  466.             $this->_changeValues = array();
  467.         } */
  468.     }
  469.     public function getChangeValues()
  470.     {
  471.         if(count($this->_changeValues) > 0){
  472.             return $this->_changeValues;
  473.         }
  474.         return false;
  475.     }
  476.      public function resetChangeValues(){
  477.          if(count($this->_changeValues = array()));
  478.      }
  479.     //-------------------------------------------------------------------
  480.     // NotifyPropertyChanged 実装
  481.     private $_listeners = array();
  482.     /**
  483.      * 値変更のイベントリスナー
  484.      * @param \Doctrine\Common\PropertyChangedListener $listener
  485.      */
  486.     public function addPropertyChangedListener(PersistencePropertyChangedListener $listener)
  487.     {
  488.         $this->_listeners[] = $listener;
  489.     }
  490.     /**
  491.      * 変更前・変更後の値をイベントリスナーに保存する
  492.      * @param type $propName
  493.      * @param type $oldValue
  494.      * @param type $newValue
  495.      */
  496.     protected function _onPropertyChanged($propName$oldValue$newValue)
  497.     {
  498.         if ($this->_listeners) {
  499.             foreach ($this->_listeners as $listener) {
  500.                 $listener->propertyChanged($this$propName$oldValue$newValue);
  501.             }
  502.         }
  503.     }
  504.     // -----------------------------------------
  505.     /**
  506.      * 値型が文字列かどうか
  507.      * @return bolean
  508.      */
  509.     private function isValueString()
  510.     {
  511.         return $this->value_kbn == SystemSettingRepository::VALUE_KBN_STR;
  512.     }
  513.     /**
  514.      * 2014/9/13 mitsunaga 文字列の値をJSON形式で返す
  515.      * @return type
  516.      */
  517.     /*
  518.     public function getStrValueByArray()
  519.     {
  520.         if(!$this->isValueString()) throw new \Exception('値処理が不正です');
  521.         if($this->string_value){
  522.             return JinjiKoukaStatic::getArrayByJson($this->string_value);
  523.         }else{
  524.             // 初期値で空が入っているので、値が無ければデフォルト値を返す
  525.             if(SystemSettingRepository::isCdSetting($this->key_str)){
  526.                 return SystemSettingRepository::$cd_setting_default_values;
  527.             }else{
  528.                 throw new \Exception('値処理が不正です');
  529.             }
  530.         }
  531.     } */
  532.     /**
  533.      * 2014/9/13 mitsunaga 文字列の値を配列で設定
  534.      * @return type
  535.      */
  536.     /*
  537.     public function setStrValueByArray($array)
  538.     {
  539.         if(!$this->isValueString()) throw new \Exception('値処理が不正です');
  540.         $this->string_value = JinjiKoukaStatic::getJsonByArray($array);
  541.     } */
  542. }