/**
  * Filter class constants by given prefixes and return the extracted constants.
  *
  * @param  string $strClass            The class that should be searched for constants in.
  * @param array   $arrPrefixes         An array of prefixes that should be used to filter the class constants.
  * @param         $blnReturnValueAsKey boolean Return the extracted array keys from its value, if true.
  *
  * @return array The extracted constants as array.
  */
 public static function getConstantsByPrefixes($strClass, array $arrPrefixes = array(), $blnReturnValueAsKey = true)
 {
     $arrExtract = array();
     if (!class_exists($strClass)) {
         return $arrExtract;
     }
     $objReflection = new \ReflectionClass($strClass);
     $arrConstants = $objReflection->getConstants();
     if (!is_array($arrConstants)) {
         return $arrExtract;
     }
     $arrExtract = Arrays::filterByPrefixes($arrConstants, $arrPrefixes);
     return $blnReturnValueAsKey ? array_combine($arrExtract, $arrExtract) : $arrExtract;
 }
 protected function transform()
 {
     // leave non-formhybrid data inside config
     $this->arrData = Arrays::filterOutByPrefixes($this->varConfig, array('formHybrid'));
     // never set context id from module id
     if (isset($this->arrData['id'])) {
         $this->arrData['moduleId'] = $this->arrData['id'];
         unset($this->arrData['id']);
     }
     // transform formhybrid prefixed attributes
     $arrData = Arrays::filterByPrefixes($this->varConfig, array('formHybrid'));
     foreach ($arrData as $strKey => $varValue) {
         $this->{$strKey} = $varValue;
     }
 }
 /**
  * Retrieve the subpalette by the field selector
  *
  * @param   string $strSelector
  * @param   array  $arrFields
  *
  * @return array Return the state, subpalette name, the filtered fields array and autosubmit state
  */
 protected function retrieveSubpaletteWithState($strSelector, array $arrFields)
 {
     $blnActive = null;
     $blnAutoSubmit = false;
     $strSubpalette = null;
     $arrSubPaletteFields = array();
     $blnToggleSubpalette = false;
     $varValue = $this->getFieldValue($strSelector);
     // skip arrays, they cant be array keys
     if (is_array($varValue)) {
         return array($blnActive, $strSubpalette, $arrFields, $blnAutoSubmit);
     }
     // checkbox: addImage for example
     if ($this->dca['fields'][$strSelector]['inputType'] == 'checkbox' && !$this->dca['fields'][$strSelector]['eval']['multiple']) {
         if (strlen($this->dca['subpalettes'][$strSelector])) {
             $blnActive = $varValue == true;
             $strSubpalette = $strSelector;
             $blnToggleSubpalette = true;
             $arrSubPaletteFields = FormHelper::getPaletteFields($this->strTable, $this->dca['subpalettes'][$strSubpalette]);
         }
     } else {
         // type selector
         if (isset($this->dca['subpalettes'][$varValue])) {
             $blnAutoSubmit = true;
             $blnActive = true;
             $strSubpalette = $varValue;
         } elseif (is_array($this->dca['subpalettes'])) {
             $arrSubpalettes = Arrays::filterByPrefixes($this->dca['subpalettes'], array($strSelector . '_'));
             if (!empty($arrSubpalettes)) {
                 $blnToggleSubpalette = true;
                 // also if no active type selector, cause no default value, toggleSubpalette
                 $blnActive = isset($arrSubpalettes[$strSelector . '_' . $varValue]);
                 if ($blnActive) {
                     $strSubpalette = $strSelector . '_' . $varValue;
                     $arrSubPaletteFields = FormHelper::getPaletteFields($this->strTable, $this->dca['subpalettes'][$strSubpalette]);
                 }
                 // remove concatenated type selector sibling subpalette fields that are not active
                 foreach ($arrSubpalettes as $strSubSiblingPalette => $strSubSiblingFields) {
                     // do not remove active concatenated type selector fields
                     if ($blnActive && $strSubSiblingPalette === $strSubpalette) {
                         continue;
                     }
                     $arrFields = array_diff($arrFields, FormHelper::getPaletteFields($this->strTable, $this->dca['subpalettes'][$strSubSiblingPalette]));
                 }
             }
         }
     }
     return array($blnActive, $strSubpalette, $arrFields, $arrSubPaletteFields, $blnAutoSubmit, $blnToggleSubpalette);
 }
 public function modifyPalette(\DataContainer $objDc, $blnFrontend = false)
 {
     // modify palette for backend view, based on archive submissionFields
     if (!$blnFrontend) {
         \Controller::loadDataContainer('tl_submission');
         $arrDca =& $GLOBALS['TL_DCA']['tl_submission'];
         if (($objSubmission = \HeimrichHannot\Submissions\SubmissionModel::findByPk($objDc->id)) === null) {
             return false;
         }
         if (($objSubmissionArchive = $objSubmission->getRelated('pid')) === null) {
             return false;
         }
         $arrDca['palettes']['defaultBackup'] = $arrDca['palettes']['default'];
         $arrSubmissionFields = deserialize($objSubmissionArchive->submissionFields, true);
         // remove subpalette fields from arrSubmissionFields
         if (is_array($arrDca['subpalettes'])) {
             foreach ($arrDca['subpalettes'] as $key => $value) {
                 $arrSubpaletteFields = \HeimrichHannot\FormHybrid\FormHelper::getPaletteFields($objDc->table, $value);
                 if (!is_array($arrSubpaletteFields)) {
                     continue;
                 }
                 $arrSubmissionFields = array_diff($arrSubmissionFields, $arrSubpaletteFields);
             }
         }
         $arrDca['palettes']['default'] = str_replace('submissionFields', implode(',', $arrSubmissionFields), \HeimrichHannot\Submissions\Submissions::PALETTE_DEFAULT);
     }
     // overwrite attachment config with archive
     if (isset($arrDca['fields']['attachments']) && $objSubmissionArchive->addAttachmentConfig) {
         $arrConfig = Arrays::filterByPrefixes($objSubmissionArchive->row(), array('attachment'));
         foreach ($arrConfig as $strKey => $value) {
             $strKey = lcfirst(str_replace('attachment', '', $strKey));
             $arrDca['fields']['attachments']['eval'][$strKey] = $value;
         }
     }
 }
 public function setModule(\Model $objModule)
 {
     $arrData = \HeimrichHannot\Haste\Util\Arrays::filterByPrefixes($objModule->row(), self::$arrayKeyPrefixes);
     $this->arrData = is_array($arrData) ? $arrData : $this->arrData;
     return $this;
 }
 /**
  * @dataProvider filterByPrefixesProvider
  * @test
  */
 public function testFilterByPrefixes($arrData, $arrPrefixes, $expectedResult)
 {
     $this->assertSame($expectedResult, Arrays::filterByPrefixes($arrData, $arrPrefixes));
 }
 public function getViewModes()
 {
     return array_values(Arrays::filterByPrefixes(get_defined_constants(), array('FORMHYBRID_VIEW_MODE_')));
 }