コード例 #1
0
 /**
  * Process submitted groups (and roles) for this contact and update the relationships
  *
  * @param IXP_Form_Contact $contact
  * @param \Entities\Contact $contact
  * @return boolean
  */
 private function _setContactGroups($form, $contact)
 {
     $groups = [];
     foreach (['role', 'group'] as $groupType) {
         if ($form->getValue($groupType)) {
             foreach ($form->getValue($groupType) as $cgid) {
                 if ($group = $this->getD2R("\\Entities\\ContactGroup")->find($cgid)) {
                     if ($group->getLimitedTo() != 0) {
                         $contactsWithGroupForCustomer = $this->getD2R("\\Entities\\ContactGroup")->countForCustomer($contact->getCustomer(), $cgid);
                         if (!$contact->getGroups()->contains($group) && $group->getLimitedTo() <= $contactsWithGroupForCustomer) {
                             $this->addMessage("Contact group {$group->getName()} has a limited membership and is full.", OSS_Message::WARNING);
                             return false;
                         }
                     }
                     if (!$contact->getGroups()->contains($group)) {
                         $contact->addGroup($group);
                         $group->addContact($contact);
                     }
                     $groups[] = $group;
                 }
             }
         }
     }
     foreach ($contact->getGroups() as $key => $group) {
         if (!in_array($group, $groups)) {
             $contact->getGroups()->remove($key);
         }
     }
     return true;
 }