Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Getting Image URLS #41

Open
bradleylinger opened this issue Aug 1, 2017 · 0 comments
Open

Getting Image URLS #41

bradleylinger opened this issue Aug 1, 2017 · 0 comments

Comments

@bradleylinger
Copy link

This isn't actually an issue but more of a comment. I modified ExportService.php to get the URL of images. I'll leave it here and perhaps it will help someone else. Thanks for the code, bro.

public function parseFieldData($handle, $data)
{

    // Do we have any data at all
    if (!is_null($data)) {

        // Get field info
        $field = craft()->fields->getFieldByHandle($handle);

        // If it's a field ofcourse
        if (!is_null($field)) {

            // For some fieldtypes the're special rules
            switch ($field->type) {

                case ExportModel::FieldTypeAssets:
					// Show names
					if( $data instanceof ElementCriteriaModel)
					{
						//$imgSettings = array("mode"=> 'crop',
						//"width" => "1600",
						//"height"=> "230",
						//"position" =>  "center-center");

						$firstImage = $data->first();
						if(isset($firstImage)){
							$image =$firstImage->getUrl();
							$data =$image;
						}
					}

                    break;
                case ExportModel::FieldTypeEntries:
                case ExportModel::FieldTypeCategories:
                case ExportModel::FieldTypeUsers:
                case ExportModel::FieldTypeTags:
                    // Show names
                    $data = $data instanceof ElementCriteriaModel ? implode(', ', $data->find()) : $data;
                    break;

                case ExportModel::FieldTypeLightswitch:
                    // Make data human readable
                    switch ($data) {

                        case '0':
                            $data = Craft::t('No');
                            break;

                        case '1':
                            $data = Craft::t('Yes');
                            break;

                    }
                    break;

                case ExportModel::FieldTypeTable:
                    // Parse table checkboxes
                    $table = array();
                    if (is_array($data)) {
                        foreach ($data as $row) {

                            // Keep track of column #
                            $i = 1;

                            // Loop through columns
                            foreach ($row as $column => $value) {

                                // Get column
                                $column = isset($field->settings['columns'][$column]) ? $field->settings['columns'][$column] : (isset($field->settings['columns']['col'.$i]) ? $field->settings['columns']['col'.$i] : array('type' => 'dummy'));

                                // Keep track of column #
                                ++$i;

                                // Parse
                                $table[] = $column['type'] == 'checkbox' ? ($value == 1 ? Craft::t('Yes') : Craft::t('No')) : $value;
                            }
                        }
                    }

                    // Return parsed data as array
                    $data = $table;
                    break;

                case ExportModel::FieldTypeRichText:
                case ExportModel::FieldTypeDate:
                case ExportModel::FieldTypeRadioButtons:
                case ExportModel::FieldTypeDropdown:
                    // Resolve to string
                    $data = (string) $data;
                    break;

                case ExportModel::FieldTypeCheckboxes:
                case ExportModel::FieldTypeMultiSelect:
                    // Parse multi select values
                    $multi = array();
                    if (is_array($data)) {
                        foreach ($data as $row) {
                            $multi[] = $row->value;
                        }
                    }

                    // Return parsed data as array
                    $data = $multi;
                    break;

            }
        }

        // Get other operations
        craft()->plugins->call('registerExportOperation', array(&$data, $handle));
    } else {

        // Don't return null, return empty
        $data = '';
    }

    // If it's an object or an array, make it a string
    if (is_array($data)) {
        $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray($data)), ', ');
    }

    // If it's an object, make it a string
    if (is_object($data)) {
        $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray(get_object_vars($data))), ', ');
    }

    return $data;
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant