iCal icon indicating copy to clipboard operation
iCal copied to clipboard

Implement HTML description

Open markuspoerschke opened this issue 3 years ago • 4 comments

See #55

markuspoerschke avatar Mar 24 '21 16:03 markuspoerschke

Hi Markus, can you please merge / restore this feature? Thank you so much!

If needed, I can help you with some other things like documentation, test etc.

giorginogreg avatar Sep 24 '21 07:09 giorginogreg

Is this coming back?

benjivm avatar Feb 08 '22 19:02 benjivm

I looked into the code, and happily do a PR, but can't get my head around it.

I'm assuming I would need to have the attribute $descriptionHTML below this line https://github.com/markuspoerschke/iCal/blob/30f7277757024debcb839ad033ca73a0b6e3d30e/src/Domain/Entity/Event.php#L30

Then create the GET, SET and UNSET methods in there.

Then in the eventFactory, have something like this https://github.com/markuspoerschke/iCal/blob/30f7277757024debcb839ad033ca73a0b6e3d30e/src/Presentation/Factory/EventFactory.php#L93

but built more like this

https://github.com/markuspoerschke/iCal/blob/30f7277757024debcb839ad033ca73a0b6e3d30e/src/Presentation/Factory/EventFactory.php#L196

Again, this is a wild guess. :)

PJFonseca avatar Feb 22 '23 09:02 PJFonseca

Hey guys, I don't have time to create a pull request for this right now. But here is a little workaround that will rewrite the description as an HTML description.

use Eluceo\iCal\Domain\Entity\Event;
use Eluceo\iCal\Presentation\Component;
use Eluceo\iCal\Presentation\Factory\EventFactory;

// Create a custom event factory that can be passed to the CalendarFactory
class CustomEventFactory extends EventFactory
{
    public function createComponent(Event $event): Component
    {
        $description = $event->getDescription();
        $event->unsetDescription();

        $component = parent::createComponent($event);

        return $component->withProperty(
            new Component\Property(
                'X-ALT-DESC',
                new Component\Property\Value\TextValue($description),
                [new Component\Property\Parameter('FMTTYPE', new Component\Property\Value\TextValue('text/html'))]
            )
        );
    }
}

Now you can create a CalendarFactory and pass it an instance of the CustomEventFactory:

// Pass a new instance of the CustomEventFactory to the CalendarFactory
$componentFactory = new CalendarFactory(new CustomEventFactory());

The CustomEventFactory will unset the description and add the HTML description instead. So using this workaround you cannot set both the description and the HTML description.

hakla avatar Jan 28 '24 23:01 hakla