Ejemplo n.º 1
0
 /**
  * @param User $user
  * @return bool
  */
 public function hasUserAdded($user)
 {
     if ($this->getUsers()->count()) {
         $categoryUser = new CLpCategoryUser();
         $categoryUser->setCategory($this);
         $categoryUser->setUser($user);
         return $this->hasUser($categoryUser);
     }
     return false;
 }
    $values = $formUsers->getSubmitValues();
    // Subscribing users
    $users = isset($values['users']) ? $values['users'] : [];
    if (!empty($users)) {
        $deleteUsers = [];
        if ($subscribedUsersInCategory) {
            /** @var CLpCategoryUser $user */
            foreach ($subscribedUsersInCategory as $user) {
                $userId = $user->getUser()->getId();
                if (!in_array($userId, $users)) {
                    $category->removeUsers($user);
                }
            }
        }
        foreach ($users as $userId) {
            $categoryUser = new CLpCategoryUser();
            $user = UserManager::getRepository()->find($userId);
            $categoryUser->setUser($user);
            $category->addUser($categoryUser);
        }
        $em->merge($category);
        $em->flush();
        Display::addFlash(Display::return_message(get_lang('Updated')));
    }
    header("Location: {$url}");
    exit;
} else {
    $headers = [get_lang('SubscribeUsersToLp'), get_lang('SubscribeGroupsToLp')];
    $tabs = $formUsers->toHtml();
    $tpl->assign('tabs', $tabs);
}