stephpy / timeline

Standalone library to make a timeline.
MIT License
89 stars 20 forks source link

Understanding the library #6

Closed pulse00 closed 11 years ago

pulse00 commented 11 years ago

I have a hard time understanding how this library is supposed to work ;)

Let's take the example from the docs:

1. Add an action

$chuck         = $actionManager->findOrCreateComponent('User', 'ChuckNorris');
$bruceLee      = $actionManager->findOrCreateComponent('User', 'BruceLee');

$action = $actionManager->create($chuck, 'kick', array('directComplement' => $bruceLee))
$actionManager->updateAction($action);

2. Fetch timeline of chuck norris

$chuck           = $actionManager->findOrCreateComponent('User', 'ChuckNorris');

$timeline = $timelineManager->getTimeline($chuck);

What should $timeline contain? ChuckNorris kick BruceLee ?

3. Fetch actions of chuck norris

$chuck           = $actionManager->findOrCreateComponent('User', 'ChuckNorris');

$timeline = $actionManager->getSubjectActions($chuck);

What should $timeline contain? ChuckNorris kick BruceLee as well?

I would have guessed that the subjectActions retrieves all actions the subject has taken.

But when i'm testing this, also the call to ->getTimeline() returns something like ChuckNorris kick BruceLee. So basically the timeline and the subject actions contain the same actions.

Am i missing something?

stephpy commented 11 years ago

You are right, in this case, it's normal.

$timelineManager->getSubjectActions($component); return all actions where $component is the subject.

$timelineManager->getTimeline($component); return all actions where component was a recipient (from a spread).

By default, all actions created by X are spread to X timeline, but you can change this via spread.on_subject option:

see it on ServiceLocator.

Imagine now:

Bruce Lee kick Chuck Norris

and you defined a spread to deploy each kick actions on Chuck Norris see spread section.

In this case, when you fetch $timelineManager->getTimeline($chuckComponent); you'll get the action where Bruce Lee kick Chuck norris.

You can compare it to facebook system.

I hope i'm clear. Feel free to ask another one question.

ps: I created a demo application which can help you: https://github.com/stephpy/timeline-app, but it is for TimelineBundle ORM Doctrine only, but system is identical.

pulse00 commented 11 years ago

Ahh, alright, thanks for the clarification. spread.on_subject was what i didn't know about. Now it makes sense!