示例#1
0
 public function save(EditPostEvent $event)
 {
     $post = $event->getPost();
     $form = $event->getForm();
     $start = $form->get('calendarStartDate')->getData();
     $end = $form->get('calendarEndDate')->getData();
     $groups = $form->get('calendarGroups')->getData();
     $name = $form->get('calendarName')->getData();
     if (!empty($start) && !empty($end)) {
         $repo = $this->em->getRepository('SymbbExtensionCalendarBundle:Event');
         $event = $repo->findOneBy(array('post' => $post->getId()));
         if (!$event) {
             $event = new \Symbb\Extension\CalendarBundle\Entity\Event();
             $event->setPost($post);
             if (empty($name)) {
                 $name = $post->getName();
             }
         }
         $event->setStartDate($start);
         $event->setEndDate($end);
         $event->setName($name);
         $finalGroups = array();
         foreach ($groups as $groupId) {
             $finalGroups[] = $this->groupManager->find($groupId);
         }
         $event->setGroups($finalGroups);
         $this->em->persist($event);
         $this->em->flush();
     }
     //flush will be execute in the controller but only if main object are changed...
 }
示例#2
0
文件: UserApi.php 项目: symbb/symbb
 /**
  * save a Site
  * you can pass the Site object or an array with the fields
  * if you pass an array the keys must be with underscore and not with CamelCase
  * @param UserInterface|array $object
  * @return UserInterface
  */
 public function save($object)
 {
     if (is_array($object)) {
         $objectData = $object;
         $newPassword = "";
         if (isset($object['id']) && $object['id'] > 0) {
             $object = $this->find($object['id']);
         } else {
             $object = new User();
         }
         if (isset($objectData['password'])) {
             $newPassword = $objectData['password'];
         }
         if (isset($objectData['enabled']) && $objectData['enabled']) {
             $object->enable();
         } else {
             $object->disable();
         }
         unset($objectData['enabled']);
         if (isset($objectData['groups'])) {
             $groups = $objectData['groups'];
             $groups = array_unique($groups);
             $object->setGroups(array());
             foreach ($groups as $groupId) {
                 $group = $this->groupManager->find($groupId);
                 $object->addGroup($group);
             }
             unset($objectData['groups']);
         }
         $this->assignArrayToObject($object, $objectData);
     } else {
         if (!$object instanceof UserInterface) {
             $this->addErrorMessage(self::ERROR_WRONG_OBJECT);
         }
     }
     if (!$this->hasError()) {
         if (!empty($newPassword)) {
             $check = $this->userManager->changeUserPassword($object, $newPassword);
             if ($check !== true) {
                 foreach ($check as $pwError) {
                     $this->addErrorMessage($pwError);
                 }
                 $check = false;
             }
         } else {
             $check = $this->userManager->updateUser($object);
         }
         if ($check === true) {
             $this->addSuccessMessage(self::SUCCESS_SAVED);
         }
     }
     return $object;
 }
示例#3
0
文件: GroupApi.php 项目: symbb/symbb
 /**
  * @param int|GroupInterface $object
  * @return bool
  */
 public function delete($object)
 {
     if (is_numeric($object)) {
         $object = $this->find($object);
     } else {
         if (!$object instanceof GroupInterface) {
             $this->addErrorMessage(self::ERROR_WRONG_OBJECT);
         }
     }
     if (!$this->hasError()) {
         $check = $this->groupManager->remove($object);
         if ($check) {
             $this->addSuccessMessage(self::SUCCESS_DELETED);
         }
         return $check;
     }
     return false;
 }