Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • AbstractElement
  • DefaultFilterElement
  • DefaultLimitElement
  • DefaultPanel
  • DefaultPanelContainer
  • DefaultSearchElement
  • DefaultSortElement
  • DefaultSubmitElement

Interfaces

  • FilterElementInterface
  • LimitElementInterface
  • PanelContainerInterface
  • PanelElementInterface
  • PanelInterface
  • SearchElementInterface
  • SortElementInterface
  • SubmitElementInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @author     Tristan Lins <tristan.lins@bit3.de>
  8:  * @copyright  The MetaModels team.
  9:  * @license    LGPL.
 10:  * @filesource
 11:  */
 12: 
 13: namespace DcGeneral\Panel;
 14: 
 15: use DcGeneral\Data\ConfigInterface;
 16: use DcGeneral\View\ViewTemplateInterface;
 17: 
 18: /**
 19:  * Default implementation of a search panel element.
 20:  *
 21:  * @package DcGeneral\Panel
 22:  */
 23: class DefaultSearchElement
 24:     extends AbstractElement
 25:     implements SearchElementInterface
 26: {
 27:     /**
 28:      * The properties to be allowed to be searched on.
 29:      *
 30:      * @var array
 31:      */
 32:     protected $arrProperties;
 33: 
 34:     /**
 35:      * The currently active property to be searched on.
 36:      *
 37:      * @var string
 38:      */
 39:     protected $strSelectedProperty;
 40: 
 41:     /**
 42:      * The current value to be searched.
 43:      *
 44:      * @var mixed
 45:      */
 46:     protected $mixValue;
 47: 
 48:     /**
 49:      * Retrieve the persistent value from the input provider.
 50:      *
 51:      * @return array
 52:      */
 53:     protected function getPersistent()
 54:     {
 55:         $arrValue = array();
 56:         if ($this->getInputProvider()->hasPersistentValue('search'))
 57:         {
 58:             $arrValue = $this->getInputProvider()->getPersistentValue('search');
 59:         }
 60: 
 61:         if (array_key_exists($this->getEnvironment()->getDataDefinition()->getName(), $arrValue))
 62:         {
 63:             return $arrValue[$this->getEnvironment()->getDataDefinition()->getName()];
 64:         }
 65: 
 66:         return array();
 67:     }
 68: 
 69:     /**
 70:      * Store the persistent value in the input provider.
 71:      *
 72:      * @param string $strProperty The property being searched on.
 73:      *
 74:      * @param string $strValue    The value being searched for.
 75:      *
 76:      * @return void
 77:      */
 78:     protected function setPersistent($strProperty, $strValue)
 79:     {
 80:         $arrValue       = array();
 81:         $definitionName = $this->getEnvironment()->getDataDefinition()->getName();
 82: 
 83:         if ($this->getInputProvider()->hasPersistentValue('search'))
 84:         {
 85:             $arrValue = $this->getInputProvider()->getPersistentValue('search');
 86:         }
 87: 
 88:         if (!empty($strValue))
 89:         {
 90:             if (!is_array($arrValue[$definitionName]))
 91:             {
 92:                 $arrValue[$definitionName] = array();
 93:             }
 94: 
 95:             if ($strValue)
 96:             {
 97:                 $arrValue[$definitionName]['field'] = $strProperty;
 98:                 $arrValue[$definitionName]['value'] = $strValue;
 99:             }
100:             else
101:             {
102:                 unset($arrValue[$definitionName]);
103:             }
104:         }
105:         else
106:         {
107:             unset($arrValue[$definitionName]);
108:         }
109: 
110:         $this->getInputProvider()->setPersistentValue('search', $arrValue);
111:     }
112: 
113:     /**
114:      * {@inheritDoc}
115:      */
116:     public function initialize(ConfigInterface $objConfig, PanelElementInterface $objElement = null)
117:     {
118:         $input = $this->getInputProvider();
119:         $value = null;
120:         $field = null;
121: 
122:         if ($this->getPanel()->getContainer()->updateValues() && $input->hasValue('tl_field'))
123:         {
124:             $field = $input->getValue('tl_field');
125:             $value = $input->getValue('tl_value');
126: 
127:             $this->setPersistent($field, $value);
128:         }
129:         elseif ($input->hasPersistentValue('search'))
130:         {
131:             $persistent = $this->getPersistent();
132:             if ($persistent)
133:             {
134:                 $field = $persistent['field'];
135:                 $value = $persistent['value'];
136:             }
137:         }
138: 
139:         $this->setSelectedProperty($field);
140:         $this->setValue($value);
141: 
142:         if (!($this->getSelectedProperty() && $this->getValue()))
143:         {
144:             return;
145:         }
146: 
147:         $arrCurrent = $objConfig->getFilter();
148:         if (!is_array($arrCurrent))
149:         {
150:             $arrCurrent = array();
151:         }
152: 
153:         $objConfig->setFilter(array_merge_recursive(
154:             $arrCurrent,
155:             array(
156:                 array(
157:                     'operation' => 'AND',
158:                     'children' => array(array(
159:                         'operation' => 'LIKE',
160:                         'property' => $this->getSelectedProperty(),
161:                         'value' => sprintf('*%s*', $this->getValue())
162:                     ))
163:                 )
164:             )
165:         ));
166:     }
167: 
168:     /**
169:      * {@inheritDoc}
170:      */
171:     public function render(ViewTemplateInterface $objTemplate)
172:     {
173:         $arrOptions = array();
174: 
175:         foreach ($this->getPropertyNames() as $field)
176:         {
177:             $arrLabel     = $this
178:                 ->getEnvironment()
179:                 ->getDataDefinition()
180:                 ->getPropertiesDefinition()
181:                 ->getProperty($field)
182:                 ->getLabel();
183:             $arrOptions[] = array
184:             (
185:                 'value'      => $field,
186:                 'content'    => is_array($arrLabel) ? $arrLabel[0] : $arrLabel,
187:                 'attributes' => ($field == $this->getSelectedProperty()) ? ' selected="selected"' : ''
188:             );
189:         }
190: 
191:         $objTemplate->class   = 'tl_select' . (!is_null($this->getValue()) ? ' active' : '');
192:         $objTemplate->options = $arrOptions;
193:         $objTemplate->value   = $this->getValue();
194: 
195:         return $this;
196:     }
197: 
198:     /**
199:      * {@inheritDoc}
200:      */
201:     public function addProperty($strProperty)
202:     {
203:         $this->arrProperties[] = $strProperty;
204: 
205:         return $this;
206:     }
207: 
208:     /**
209:      * {@inheritDoc}
210:      */
211:     public function getPropertyNames()
212:     {
213:         return $this->arrProperties;
214:     }
215: 
216:     /**
217:      * {@inheritDoc}
218:      */
219:     public function setSelectedProperty($strProperty = '')
220:     {
221:         $this->strSelectedProperty = $strProperty;
222: 
223:         return $this;
224:     }
225: 
226:     /**
227:      * {@inheritDoc}
228:      */
229:     public function getSelectedProperty()
230:     {
231:         return $this->strSelectedProperty;
232:     }
233: 
234:     /**
235:      * {@inheritDoc}
236:      */
237:     public function setValue($mixValue = null)
238:     {
239:         $this->mixValue = $mixValue;
240: 
241:         return $this;
242:     }
243: 
244:     /**
245:      * {@inheritDoc}
246:      */
247:     public function getValue()
248:     {
249:         return $this->mixValue;
250:     }
251: }
252: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0