Json::entries_assets PHP Method

entries_assets() protected method

protected entries_assets ( $entry_id, $field, $field_data, $entry )
  protected function entries_assets($entry_id, $field, $field_data, $entry)
  {
    $field_data = $this->entries_custom_field($entry_id, $field, $field_data, $entry);

    if ( ! is_array($field_data))
    {
      $field_data = array();
    }

    if (isset($field_data['absolute_total_files']) && $field_data['absolute_total_files'] === 0)
    {
      return array();
    }

    $fields = array(
      'file_id',
      'url',
      'subfolder',
      'filename',
      'extension',
      'date_modified',
      'kind',
      'width',
      'height',
      'size',
      'title',
      'date',
      'alt_text',
      'caption',
      'author',
      'desc',
      'location',
    );

    foreach ($field_data as &$row)
    {
      $source_type = $row['source_type'];
      $filedir_id = $row['filedir_id'];
      //excise any other fields from this row
      $row = array_intersect_key($row, array_flip($fields));
      $row['file_id'] = (int) $row['file_id'];
      $row['date'] = $this->date_format($row['date']);
      $row['date_modified'] = $this->date_format($row['date_modified']);

      $row['manipulations'] = array();

      if ($source_type === 'ee')
      {
        if ( ! isset($this->image_manipulations[$filedir_id]))
        {
          ee()->load->model('file_model');

          $query = ee()->file_model->get_dimensions_by_dir_id($filedir_id);

          $this->image_manipulations[$filedir_id] = $query->result();

          $query->free_result();
        }

        foreach ($this->image_manipulations[$filedir_id] as $manipulation)
        {
          $row['manipulations'][$manipulation->short_name] = pathinfo($row['url'], PATHINFO_DIRNAME).'/_'.$manipulation->short_name.'/'.basename($row['url']);
        }
      }
    }

    return $field_data;
  }