/**
  * adds image property with image url like this:
  *  'index.php?method=Tinebase.getImage&application=Tinebase&location=vfs&id=e4b7de34e229672c0d5e22be0912779441e6e051'
  *
  * @param $records
  */
 public static function resolveAttachmentImage($records)
 {
     // get all images from attachments and set 'image' properties
     // TODO find an additional condition to better detect the attachments that should be the record image(s)
     /** @var Tinebase_Record_Interface $record */
     foreach ($records as $record) {
         if ($record->has('image') && $record->attachments instanceof Tinebase_Record_RecordSet) {
             foreach ($record->attachments as $attachment) {
                 if (in_array($attachment->contenttype, Tinebase_ImageHelper::getSupportedImageMimeTypes())) {
                     $record->image = Tinebase_Model_Image::getImageUrl('Tinebase', $attachment->getId(), 'vfs');
                     break;
                 }
             }
         }
     }
 }
 /**
  * returns a image link
  * 
  * @param  array $contactArray
  * @return string
  */
 protected function _getImageLink($contactArray)
 {
     $link = 'images/empty_photo_blank.png';
     if (!empty($contactArray['jpegphoto'])) {
         $link = Tinebase_Model_Image::getImageUrl('Addressbook', $contactArray['id'], '');
     } else {
         if (isset($contactArray['salutation']) && !empty($contactArray['salutation'])) {
             $salutations = Addressbook_Config::getInstance()->get(Addressbook_Config::CONTACT_SALUTATION, NULL);
             if ($salutations && $salutations->records instanceof Tinebase_Record_RecordSet) {
                 $salutationRecord = $salutations->records->getById($contactArray['salutation']);
                 if ($salutationRecord && $salutationRecord->image) {
                     $link = $salutationRecord->image;
                 }
             }
         }
     }
     return $link;
 }
 /**
  * saveRecordWithImage
  */
 public function testSaveRecordWithImage()
 {
     // create TEMPFILE and save in inv item
     $imageFile = dirname(dirname(dirname(dirname(__FILE__)))) . '/tine20/images/cancel.gif';
     $tempImage = Tinebase_TempFile::getInstance()->createTempFile($imageFile);
     $imageUrl = Tinebase_Model_Image::getImageUrl('Tinebase', $tempImage->getId(), 'tempFile');
     $invItem = $this->_getInventoryItem()->toArray();
     $invItem['image'] = $imageUrl;
     $savedInvItem = $this->_json->saveInventoryItem($invItem);
     //$savedInvItem = $this->_json->getInventoryItem($savedInvItem['id']);
     $this->assertTrue(!empty($savedInvItem['image']), 'image url is empty');
     $this->assertTrue(preg_match('/location=vfs&id=([a-z0-9]*)/', $savedInvItem['image']) == 1, print_r($savedInvItem, true));
     // check if favicon is delivered
     $image = Tinebase_Model_Image::getImageFromImageURL($savedInvItem['image']);
     $this->assertEquals(52, $image->width);
 }