Using Services to get all the Categories related to an Entry? In a plugin, I've been advised to try to use craft built-in services instead of direct db queries. So can anyone help with this:  For an entry type that includes a categories field, how to get all the categories related to an entry?

I found this:

$entry = craft()-&gt;entries-&gt;getEntryById($entryId);


So I suppose this might work as well:

$category = craft()-&gt;categories-&gt;getCategoryById($categoryId);


But I can't find anything intelligible to me under the relations service. 

Thanks for any help.

EDIT: On a related note, I see here that in twig you can do this:

{% for entry in craft.entries.section('news').limit(10) %}
&lt;article&gt;
    &lt;h1&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h1&gt;
    {{ entry.summary }}
    &lt;a href="{{ entry.url }}"&gt;Continue reading&lt;/a&gt;
&lt;/article&gt;
{% endfor %}


Whereby Craft/Twig does all the work to find and return the 'summary' field related to each entry. Is there any php statement like this next confused one, following which I could get the categories related to each event?

$events = craft()-&gt;entries.section('events').start('&lt;=$toDateYmd').end('OR', '&gt;=$fromDateYmd', '').status('publish');
foreach ($events as $event)
   $categories = $event.category;


Thank you!
If you have an EntryModel and know the category field's handle, you don't really need a service:

$categories = $entry-&gt;categoryFieldHandle;


In other cases, you can construct an ElementCriteriaModel to search for related elements (categories, entries, users or assets), using a number of different variables. Easy example to get related categories from an entry ID:

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
$criteria-&gt;relatedTo = array($entryId);
$categories = craft()-&gt;elements-&gt;findElements($criteria);