Пример #1
0
 /**
  * Evaluates 'group' or 'select' type values.
  *
  * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
  * @param string $value The value to set.
  * @param array $tcaFieldConf Field configuration from TCA
  * @param string $table Table name
  * @param int $id UID of record
  * @param mixed $curValue Current value of the field
  * @param string $status 'update' or 'new' flag
  * @param string $recFID Field identifier [table:uid:field] for flexforms
  * @param array $uploadedFiles
  * @param string $field Field name
  * @return array Modified $res array
  */
 protected function checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field)
 {
     // Detecting if value sent is an array and if so, implode it around a comma:
     if (is_array($value)) {
         $value = implode(',', $value);
     }
     // This converts all occurrences of '{' to the byte 123 in the string - this is needed in very rare cases where file names with special characters (e.g. ???, umlaut) gets sent to the server as HTML entities instead of bytes. The error is done only by MSIE, not Mozilla and Opera.
     // Anyway, this should NOT disturb anything else:
     $value = $this->convNumEntityToByteValue($value);
     // When values are sent as group or select they come as comma-separated values which are exploded by this function:
     $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
     // If multiple is not set, remove duplicates:
     if (!$tcaFieldConf['multiple']) {
         $valueArray = array_unique($valueArray);
     }
     // If an exclusive key is found, discard all others:
     if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['exclusiveKeys']) {
         $exclusiveKeys = GeneralUtility::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
         foreach ($valueArray as $index => $key) {
             if (in_array($key, $exclusiveKeys, true)) {
                 $valueArray = array($index => $key);
                 break;
             }
         }
     }
     // This could be a good spot for parsing the array through a validation-function which checks if the values are correct (except that database references are not in their final form - but that is the point, isn't it?)
     // NOTE!!! Must check max-items of files before the later check because that check would just leave out file names if there are too many!!
     $valueArray = $this->applyFiltersToValues($tcaFieldConf, $valueArray);
     // Checking for select / authMode, removing elements from $valueArray if any of them is not allowed!
     if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['authMode']) {
         $preCount = count($valueArray);
         foreach ($valueArray as $index => $key) {
             if (!$this->BE_USER->checkAuthMode($table, $field, $key, $tcaFieldConf['authMode'])) {
                 unset($valueArray[$index]);
             }
         }
         // During the check it turns out that the value / all values were removed - we respond by simply returning an empty array so nothing is written to DB for this field.
         if ($preCount && empty($valueArray)) {
             return array();
         }
     }
     // For group types:
     if ($tcaFieldConf['type'] == 'group') {
         switch ($tcaFieldConf['internal_type']) {
             case 'file_reference':
             case 'file':
                 $valueArray = $this->checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFiles, $status, $table, $id, $recFID);
                 break;
             case 'db':
                 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'group', $table, $field);
                 break;
         }
     }
     // For select types which has a foreign table attached:
     $unsetResult = false;
     if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['foreign_table']) {
         // check, if there is a NEW... id in the value, that should be substituted later
         if (strpos($value, 'NEW') !== false) {
             $this->remapStackRecords[$table][$id] = array('remapStackIndex' => count($this->remapStack));
             $this->addNewValuesToRemapStackChildIds($valueArray);
             $this->remapStack[] = array('func' => 'checkValue_group_select_processDBdata', 'args' => array($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field), 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5), 'field' => $field);
             $unsetResult = true;
         } else {
             $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field);
         }
     }
     if (!$unsetResult) {
         $newVal = $this->checkValue_checkMax($tcaFieldConf, $valueArray);
         $res['value'] = $this->castReferenceValue(implode(',', $newVal), $tcaFieldConf);
     } else {
         unset($res['value']);
     }
     return $res;
 }