original_string: public static function setChangeFieldsByPrefix(\MUtil_Model_DatabaseModelAbstract $model, $prefix, $userid = null)
      {
          $changed_field    = $prefix . '_changed';
          $changed_by_field = $prefix . '_changed_by';
          $created_field    = $prefix . '_created';
          $created_by_field = $prefix . '_created_by';
  
          foreach (array($changed_field, $changed_by_field, $created_field, $created_by_field) as $field) {
              $model->set($field, 'elementClass', 'none');
          }
  
          $model->setOnSave($changed_field, new \MUtil_Db_Expr_CurrentTimestamp());
          $model->setSaveOnChange($changed_field);
          $model->setOnSave($created_field, new \MUtil_Db_Expr_CurrentTimestamp());
          $model->setSaveWhenNew($created_field);
  
          if (! $userid && self::$currentUserId) {
              $userid = self::$currentUserId;
          }
          
          if (! $userid) {
              $escort = \GemsEscort::getInstance();
  
              if ($escort) {
                  $currentUser = $escort->currentUser;
  
                  if ($currentUser instanceof Gems_User_User) {   // During some unit tests this will be null
                      $userid = $currentUser->getUserId();
                  }
  
                  if (!$userid) {
                      $userid = 1;
                  }
              }
          }
          if ($userid) {
              $model->setOnSave($changed_by_field, $userid);
              $model->setSaveOnChange($changed_by_field);
              $model->setOnSave($created_by_field, $userid);
              $model->setSaveWhenNew($created_by_field);
          }
      }
code: public static function setChangeFieldsByPrefix(\MUtil_Model_DatabaseModelAbstract $model, $prefix, $userid = null)
      {
          $changed_field    = $prefix . '_changed';
          $changed_by_field = $prefix . '_changed_by';
          $created_field    = $prefix . '_created';
          $created_by_field = $prefix . '_created_by';
  
          foreach (array($changed_field, $changed_by_field, $created_field, $created_by_field) as $field) {
              $model->set($field, 'elementClass', 'none');
          }
  
          $model->setOnSave($changed_field, new \MUtil_Db_Expr_CurrentTimestamp());
          $model->setSaveOnChange($changed_field);
          $model->setOnSave($created_field, new \MUtil_Db_Expr_CurrentTimestamp());
          $model->setSaveWhenNew($created_field);
  
          if (! $userid && self::$currentUserId) {
              $userid = self::$currentUserId;
          }
          
          if (! $userid) {
              $escort = \GemsEscort::getInstance();
  
              if ($escort) {
                  $currentUser = $escort->currentUser;
  
                  if ($currentUser instanceof Gems_User_User) {   // During some unit tests this will be null
                      $userid = $currentUser->getUserId();
                  }
  
                  if (!$userid) {
                      $userid = 1;
                  }
              }
          }
          if ($userid) {
              $model->setOnSave($changed_by_field, $userid);
              $model->setSaveOnChange($changed_by_field);
              $model->setOnSave($created_by_field, $userid);
              $model->setSaveWhenNew($created_by_field);
          }
      }
code_tokens: public static function setChangeFieldsByPrefix ( \ MUtil_Model_DatabaseModelAbstract $ model , $ prefix , $ userid = null ) { $ changed_field = $ prefix . '_changed' ; $ changed_by_field = $ prefix . '_changed_by' ; $ created_field = $ prefix . '_created' ; $ created_by_field = $ prefix . '_created_by' ; foreach ( array ( $ changed_field , $ changed_by_field , $ created_field , $ created_by_field ) as $ field ) { $ model -> set ( $ field , 'elementClass' , 'none' ) ; } $ model -> setOnSave ( $ changed_field , new \ MUtil_Db_Expr_CurrentTimestamp ( ) ) ; $ model -> setSaveOnChange ( $ changed_field ) ; $ model -> setOnSave ( $ created_field , new \ MUtil_Db_Expr_CurrentTimestamp ( ) ) ; $ model -> setSaveWhenNew ( $ created_field ) ; if ( ! $ userid && self :: $ currentUserId ) { $ userid = self :: $ currentUserId ; } if ( ! $ userid ) { $ escort = \ GemsEscort :: getInstance ( ) ; if ( $ escort ) { $ currentUser = $ escort -> currentUser ; if ( $ currentUser instanceof Gems_User_User ) { // During some unit tests this will be null $ userid = $ currentUser -> getUserId ( ) ; } if ( ! $ userid ) { $ userid = 1 ; } } } if ( $ userid ) { $ model -> setOnSave ( $ changed_by_field , $ userid ) ; $ model -> setSaveOnChange ( $ changed_by_field ) ; $ model -> setOnSave ( $ created_by_field , $ userid ) ; $ model -> setSaveWhenNew ( $ created_by_field ) ; } }
docstring: Function that automatically fills changed, changed_by, created and created_by fields with a certain prefix.
  
  @param \MUtil_Model_DatabaseModelAbstract $model
  @param string $prefix Three letter code
  @param int $userid Gems user id
docstring_tokens: Function that automatically fills changed changed_by created and created_by fields with a certain prefix .