1: <?php
  2: 
  3:   4:   5: 
  6: class Quform_Element_Row extends Quform_Element_Container
  7: {
  8:       9:  10:  11:  12:  13: 
 14:     public function render(array $context = array())
 15:     {
 16:         $context = $this->prepareContext($context);
 17: 
 18:         $output = sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getContainerClasses($context))));
 19: 
 20:         foreach ($this->elements as $key => $element) {
 21:             $output .= $element->render($context);
 22:         }
 23: 
 24:         $output .= '</div>';
 25: 
 26:         return $output;
 27:     }
 28: 
 29:      30:  31:  32:  33:  34: 
 35:     protected function getContainerClasses(array $context = array())
 36:     {
 37:         $classes = array(
 38:             'quform-element',
 39:             'quform-element-row',
 40:             sprintf('quform-element-row-%s', $this->getIdentifier()),
 41:             sprintf('quform-%d-columns', count($this->elements)),
 42:             sprintf('quform-element-row-size-%s', $this->config('columnSize'))
 43:         );
 44: 
 45:         if (Quform::isNonEmptyString($context['responsiveColumns']) && $context['responsiveColumns'] != 'custom') {
 46:             $classes[] = sprintf('quform-responsive-columns-%s', $context['responsiveColumns']);
 47:         }
 48: 
 49:         $classes = apply_filters('quform_container_classes', $classes, $this);
 50:         $classes = apply_filters('quform_container_classes_' . $this->getIdentifier(), $classes, $this);
 51: 
 52:         return $classes;
 53:     }
 54: 
 55:      56:  57:  58:  59:  60: 
 61:     protected function renderCss(array $context = array())
 62:     {
 63:         $css = '';
 64: 
 65:         if ($context['responsiveColumns'] == 'custom' && Quform::isNonEmptyString($context['responsiveColumnsCustom'])) {
 66:             $css .= sprintf(
 67:                 '@media (max-width: %s) { .quform-element-row-%s > .quform-element-column { float: none; width: 100%% !important; } }',
 68:                 Quform::addCssUnit($context['responsiveColumnsCustom']),
 69:                 $this->getIdentifier()
 70:             );
 71:         }
 72: 
 73:         $css .= parent::renderCss($context);
 74: 
 75:         return $css;
 76:     }
 77: 
 78:      79:  80:  81:  82:  83: 
 84:     public static function getDefaultConfig($key = null)
 85:     {
 86:         $config = apply_filters('quform_default_config_row', array(
 87:             
 88:             'columnSize' => 'fixed',
 89:             'responsiveColumns' => 'inherit',
 90:             'responsiveColumnsCustom' => '',
 91: 
 92:             
 93:             'elements' => array()
 94:         ));
 95: 
 96:         $config['type'] = 'row';
 97: 
 98:         if (Quform::isNonEmptyString($key)) {
 99:             return Quform::get($config, $key);
100:         }
101: 
102:         return $config;
103:     }
104: 
105:     106: 107: 108: 109: 110: 
111:     protected function prepareContext(array $context = array())
112:     {
113:         $context = parent::prepareContext($context);
114: 
115:         $context['columnSize'] = $this->config('columnSize');
116: 
117:         if (is_string($this->config('responsiveColumns'))) {
118:             if ($this->config('responsiveColumns') != 'inherit') {
119:                 $context['responsiveColumns'] = $this->config('responsiveColumns');
120: 
121:                 if ($this->config('responsiveColumns') == 'custom' && Quform::isNonEmptyString($this->config('responsiveColumnsCustom'))) {
122:                     $context['responsiveColumnsCustom'] = $this->config('responsiveColumnsCustom');
123:                 }
124:             }
125:         }
126: 
127:         return $context;
128:     }
129: }
130: