setUser() public method

Set user
public setUser ( User $user ) : Newscoop\Entity\Comment\Commenter
$user Newscoop\Entity\User
return Newscoop\Entity\Comment\Commenter
示例#1
0
 /**
  * Method for geting a commenter
  *
  * @param Newscoop\Entity\Comment\Commenter $p_entity
  * @param array $p_values
  * @return Newscoop\Entity\Comment\Commenter $p_entity
  */
 public function save($p_entity, array $p_values)
 {
     $keys = array('user', 'name', 'email');
     $set = false;
     for ($i = 0; $i < count($keys); $i++) {
         $set = $set || isset($p_values[$keys[$i]]) && !empty($p_values[$keys[$i]]);
     }
     if (!$set) {
         throw new InvalidArgumentException();
     }
     $em = $this->getEntityManager();
     if (!empty($p_values['user'])) {
         if (is_numeric($p_values['user'])) {
             $userRepository = $em->getRepository('Newscoop\\Entity\\User');
             $p_values['user'] = $userRepository->find($p_values['user']);
         }
         if ($p_values['user']) {
             $p_entity->setUser($p_values['user']);
             if (empty($p_values['name'])) {
                 $p_values['name'] = $p_values['user']->getName();
             }
             if (empty($p_values['email'])) {
                 $p_values['email'] = $p_values['user']->getEmail();
             }
         }
     }
     $commenters = $this->findBy(array('email' => $p_values['email'], 'name' => $p_values['name']));
     if (count($commenters) == 1) {
         $p_entity = $commenters[0];
     }
     /*
     $acceptanceRepository = $em->getRepository('Newscoop\Entity\Comment\Acceptance');
     $acceptanceRepository->isBanned($p_entity);
     */
     if (!isset($p_values['url'])) {
         $p_values['url'] = '';
     }
     $p_entity->setName($p_values['name'])->setEmail($p_values['email'])->setUrl($p_values['url'])->setIp($p_values['ip'])->setTimeCreated($p_values['time_created']);
     $em->persist($p_entity);
     return $p_entity;
 }
 public function setUser(\Newscoop\Entity\User $user)
 {
     $this->__load();
     return parent::setUser($user);
 }