src/Observers/CleanUpEmptyColumnsTrait.php
/**
     * Remove all the empty values from the row and return the cleared row.
     *
     * @return array The cleared row
     */
Remove all the empty values from the row and return the cleared row.
@return array The cleared row
Remove all the empty values from the row and return the cleared row . @return array The cleared row
protected function clearRow()
    {
        if ($this->cleanUpEmptyColumnKeys === null) {
            $this->cleanUpEmptyColumnKeys = array();
            if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS)
                && ($this->getSubject() instanceof CleanUpColumnsSubjectInterface)) {
                $cleanUpEmptyColumns = $this->getSubject()->getCleanUpColumns();
                foreach ($cleanUpEmptyColumns as $cleanUpEmptyColumn) {
                    if ($this->hasHeader($cleanUpEmptyColumn)) {
                        $this->cleanUpEmptyColumnKeys[] = $this->getHeader($cleanUpEmptyColumn);
                    }
                }
            }
        }
        $this->defaultColumnValues = array();
        $defaultColumnValues = $this->getSubject()->getDefaultColumnValues();
        foreach ($defaultColumnValues as $columnName => $defaultColumnValue) {
            if ($defaultColumnValue === '') {
                $this->defaultColumnValues[$columnName] = $this->getHeader($columnName);
            }
        }
        $emptyValueDefinition = $this->getEmptyAttributeValueConstant();
        $headers = in_array($emptyValueDefinition, $this->row, true) ? array_flip($this->getHeaders()) : [];
        foreach ($this->row as $key => $value) {
            if ($value === $emptyValueDefinition) {
                $this->cleanUpEmptyColumnKeys[$headers[$key]] = $key;
                $this->row[$key] = '';
            }
            if (($value === null || $value === '') &&
                in_array($key, $this->cleanUpEmptyColumnKeys) === false &&
                in_array($key, $this->defaultColumnValues) === false
            ) {
                unset($this->row[$key]);
            }
        }
        return $this->row;
    }
protected function clearRow ( ) { if ( $ this -> cleanUpEmptyColumnKeys === null ) { $ this -> cleanUpEmptyColumnKeys = array ( ) ; if ( $ this -> getSubject ( ) -> getConfiguration ( ) -> hasParam ( ConfigurationKeys :: CLEAN_UP_EMPTY_COLUMNS ) && ( $ this -> getSubject ( ) instanceof CleanUpColumnsSubjectInterface ) ) { $ cleanUpEmptyColumns = $ this -> getSubject ( ) -> getCleanUpColumns ( ) ; foreach ( $ cleanUpEmptyColumns as $ cleanUpEmptyColumn ) { if ( $ this -> hasHeader ( $ cleanUpEmptyColumn ) ) { $ this -> cleanUpEmptyColumnKeys [ ] = $ this -> getHeader ( $ cleanUpEmptyColumn ) ; } } } } $ this -> defaultColumnValues = array ( ) ; $ defaultColumnValues = $ this -> getSubject ( ) -> getDefaultColumnValues ( ) ; foreach ( $ defaultColumnValues as $ columnName => $ defaultColumnValue ) { if ( $ defaultColumnValue === '' ) { $ this -> defaultColumnValues [ $ columnName ] = $ this -> getHeader ( $ columnName ) ; } } $ emptyValueDefinition = $ this -> getEmptyAttributeValueConstant ( ) ; $ headers = in_array ( $ emptyValueDefinition , $ this -> row , true ) ? array_flip ( $ this -> getHeaders ( ) ) : [ ] ; foreach ( $ this -> row as $ key => $ value ) { if ( $ value === $ emptyValueDefinition ) { $ this -> cleanUpEmptyColumnKeys [ $ headers [ $ key ] ] = $ key ; $ this -> row [ $ key ] = '' ; } if ( ( $ value === null || $ value === '' ) && in_array ( $ key , $ this -> cleanUpEmptyColumnKeys ) === false && in_array ( $ key , $ this -> defaultColumnValues ) === false ) { unset ( $ this -> row [ $ key ] ) ; } } return $ this -> row ; }
Remove all the empty values from the row and return the cleared row.
Remove all the empty values from the row and return the cleared row .
// query whether or not the column keys has been initialized // initialize the array with the column keys that has to be cleaned-up // query whether or not column names that has to be cleaned up have been configured // if yes, load the column names // translate the column names into column keys // initialize the array with the default column values // iterate over the default column values to figure out whether or not the column exists // prepare the array with the default column values, BUT we only take // care of default columns WITHOUT any value, because in only in this // case the default EAV value from the DB should be used when a empty // column value has been found to create a NEW attribute value // load the header keys // remove all the empty values from the row, expected the columns has to be cleaned-up // query whether or not to cleanup complete attribute // query whether or not the value is empty AND the column has NOT to be cleaned-up // finally return the clean row