Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-19829 - Attachment API: return icons #9714

Merged
merged 2 commits into from
Jan 24, 2017
Merged

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Jan 23, 2017

@colemanw colemanw force-pushed the CRM-19829 branch 2 times, most recently from 5188227 to d457daf Compare January 23, 2017 19:18
@totten
Copy link
Member

totten commented Jan 23, 2017

It has a test! :) By definition, it works.

Non-blocker issue: really tempted to put that in a data file?

## CRM/Utils/File/mime-icons.json
{
  "*/*": "fa-file-o",
  "image/*": "fa-file-image-o",
  "application/pdf": "fa-file-pdf-o",
  ...
}
  public static function getIconFromMimeType($mimeType) { 
    if (!isset(Civi::$statics[__CLASS__]['mimeIcons'])) {
      Civi::$statics[__CLASS__]['mimeIcons'] = json_decode(file_get_contents(__DIR__ . '/File/mime-icons.json'));
    }
    $icons = Civi::$statics[__CLASS__]['mimeIcons'];
    list ($left, $right) = explode('/', $mimeType):
    
    if (isset($icons["$left/$right"])) return $icons["$left/$right"];
    elseif (isset($icons["$left/*"])) return $icons["$left/*"];
    else return $icons["*/*"];
  }

@colemanw
Copy link
Member Author

@totten done moving it to a data file.

Your list() = explode() trick is clever but the foreach() loop is necessary to use the strpos() comparison, as some mimetypes contain extra dots and words at the end. The test covers that; mime-type application/vnd.openxmlformats-officedocument.wordprocessingml.document matches to the icon for application/vnd.openxmlformats-officedocument.wordprocessingml.

@totten
Copy link
Member

totten commented Jan 23, 2017

...the foreach() loop is necessary to...

Cool. Works for me.

@colemanw colemanw merged commit 35c9fd0 into civicrm:master Jan 24, 2017
@colemanw colemanw deleted the CRM-19829 branch January 24, 2017 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants