/**
  * Get the Singleton Object
  *
  * @return tx_caretaker_ContactRepository
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new tx_caretaker_ContactRepository();
     }
     return self::$instance;
 }
 /**
  * Constructor
  * reads the service configuration
  */
 public function __construct()
 {
     parent::__construct('simple_mail');
     $contactRepository = tx_caretaker_ContactRepository::getInstance();
     $this->mail_from = $this->getConfigValue('mail_from');
     $this->mail_subject = $this->getConfigValue('mail_subject');
     $this->mail_link = $this->getConfigValue('mail_link');
     $this->mail_link = $this->getConfigValue('mail_link');
     $this->mail_roles = array();
     $role_ids = explode(',', $this->getConfigValue('role_ids'));
     foreach ($role_ids as $role_id) {
         $role = $contactRepository->getContactRoleById(trim($role_id));
         if (!$role && is_numeric($role_id)) {
             $role = $contactRepository->getContactRoleByUid(intval($role_id));
         }
         if ($role) {
             $this->mail_roles[] = $role;
         }
     }
 }
 /**
  * Get the contacts for the node
  *
  * @param string|tx_caretaker_ContactRole|array<tx_caretaker_ContactRole> $roles
  * @return array
  */
 public function getContacts($roles = NULL)
 {
     $contactRepository = tx_caretaker_ContactRepository::getInstance();
     if ($roles instanceof tx_caretaker_ContactRole) {
         $roles = array($roles);
     } else {
         if (is_string($roles)) {
             $roleIds = $roles;
             $roles = array();
             foreach (\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $roleIds) as $roleId) {
                 if ($roleId === '*') {
                     $roles = NULL;
                     break;
                 }
                 $role = $contactRepository->getContactRoleById($roleId);
                 if (!$role instanceof tx_caretaker_ContactRole) {
                     $role = $contactRepository->getContactRoleByUid(intval($roleId));
                 }
                 if ($role instanceof tx_caretaker_ContactRole) {
                     $roles[] = $role;
                 }
             }
         }
     }
     $contacts = array();
     if ($roles === NULL) {
         if ($this->contacts['__all__'] === NULL) {
             $this->contacts['__all__'] = $contactRepository->getContactsByNode($this);
         }
         $contacts = $this->contacts['__all__'];
     } else {
         /** @var tx_caretaker_ContactRole $role */
         foreach ($roles as $role) {
             if ($this->contacts[$role->getId()] === NULL) {
                 $this->contacts[$role->getId()] = $contactRepository->getContactsByNodeAndRole($this, $role);
             }
             $contacts = array_merge($this->contacts[$role->getId()], $contacts);
         }
     }
     if ($this->getParent()) {
         $contacts = array_merge($this->getParent()->getContacts($roles), $contacts);
     }
     // TODO return a list with only unique entries
     return $contacts;
 }