当前位置: 首页>>代码示例>>PHP>>正文


PHP User::setAvatar方法代码示例

本文整理汇总了PHP中AppBundle\Entity\User::setAvatar方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setAvatar方法的具体用法?PHP User::setAvatar怎么用?PHP User::setAvatar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AppBundle\Entity\User的用法示例。


在下文中一共展示了User::setAvatar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createUserAction

 /**
  * @Route("/api/createUser", name="createUser"), defaults={"_format"="xml"}, name="_createUser")
  */
 public function createUserAction(Request $request)
 {
     try {
         $verificationCode = $request->get('verificationcode', '');
         if ($verificationCode == '') {
             $oOperation = new Operation();
             $oOperation->setBSucceeded(false);
             $oOperation->setICode(409);
             $oOperation->setSMessage("Phone validation failed");
             return $this->xmlResponse($oOperation, SerializationContext::create()->setGroups(array('Error')), 409);
         }
         $username = $request->get('username', null);
         $phone = $request->get('phone', null);
         $deviceId = $request->get('deviceid', null);
         $contactsPhones = $request->get('contactsphones', null);
         $em = $this->getDoctrine()->getManager();
         //Get current device
         $deviceRepository = $em->getRepository('AppBundle:UserDevice');
         $device = $deviceRepository->findOneBy(array('deviceId' => $deviceId));
         if (!isset($device)) {
             $oOperation = new Operation();
             $oOperation->setBSucceeded(false);
             $oOperation->setICode(409);
             $oOperation->setSMessage("Device not found");
             return $this->xmlResponse($oOperation, SerializationContext::create()->setGroups(array('Error')), 409);
         }
         $userRepository = $em->getRepository('AppBundle:User');
         $user = $userRepository->findOneBy(array('phone' => $phone));
         if (!isset($user)) {
             $user = new User();
             $user->setCdate((new DateTime())->setTimezone(new \DateTimeZone('UTC')));
             $user->setTKey(sha1(date_format(new DateTime(), 'Y-m-d H:i:s') . $phone));
             $user->setAvatar(self::DEFAULT_AVATAR_URL);
         }
         /** TODO ensure normalized Phone */
         $user->setPhone($phone);
         $user->setUsername($username);
         //If we have a registered User append his already existing contacts
         //Store the new contact list $updatedContactsPhones
         $contactsPhonesArray = explode(',', $contactsPhones);
         if (empty($user->getContactsphones())) {
             $user->setContactsphones(json_encode(array_values($contactsPhonesArray)));
         }
         if (isset($device) && isset($user)) {
             $contactsPhonesArray = $this->appendUserContacts($user, $contactsPhonesArray);
         }
         $updatedContactsPhones = json_encode(array_values($contactsPhonesArray));
         //Get lastest contacts Users and store their ids via $contactsUserIds
         $contactsUserIds = array();
         if (isset($contactsPhones)) {
             $contactsUsers = $userRepository->findBy(array('phone' => $contactsPhonesArray));
             foreach ($contactsUsers as $contactsUser) {
                 $contactsUserIds[] = $contactsUser->getId();
                 if (!$user->getMyContacts()->Contains($contactsUser)) {
                     $user->addMyContact($contactsUser);
                 }
             }
         }
         $contactsUserIds = json_encode($contactsUserIds);
         $user->setConnections($contactsUserIds);
         $user->setContactsPhones($updatedContactsPhones);
         $user->setLastUpdate((new DateTime())->setTimezone(new \DateTimeZone('UTC')));
         $em->persist($user);
         $em->flush();
         //Update the device
         $device->setUser($user);
         $device->setIsUserRegistered(true);
         $em->persist($device);
         $em->flush();
         return $this->xmlResponse($device, SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('Device')));
     } catch (Exception $ex) {
         $oOperation = new Operation();
         $oOperation->setBSucceeded(false);
         $oOperation->setICode(409);
         $oOperation->setSMessage("Phone validation failed");
         $oError = new Error();
         $oError->setICode($ex->getCode());
         $oError->setSMessage($ex->getMessage());
         $oOperation->addError($oError);
         return $this->xmlResponse($oOperation, SerializationContext::create()->setGroups(array('Error')), 409);
     }
 }
开发者ID:jparaskakis,项目名称:thesis_back,代码行数:85,代码来源:DefaultController.php

示例2: uploadFile

 /**
  * @param File $file
  * @param User $user
  */
 private function uploadFile(File $file, User $user)
 {
     $filename = 'emergya-' . $user->getNick() . '.' . $file->getClientOriginalExtension();
     $file->move($this->getParameter('uploads_directory'), $filename);
     $user->setAvatar($filename);
 }
开发者ID:JuanLuisGarciaBorrego,项目名称:emergya,代码行数:10,代码来源:TablonController.php

示例3: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $uri = $this->request->getUri();
     $isMailru = false;
     if (strpos($uri, '/login_mailru') !== false) {
         $isMailru = true;
     }
     if ($isMailru === false) {
         throw new \Exception("Invalid social network login attempt");
     }
     $social = "";
     if ($isMailru) {
         $social = "mailru";
     }
     //check to see if the user is logged in and if she is logged in with the same social network
     $isLoggedInAlready = $this->session->has('user');
     $isLoggedInAlreadyId = $this->session->get('user')['id'];
     if ($isLoggedInAlready && $this->session->get('user')['social'] == $social) {
         return $this->loadUserByUsername($isLoggedInAlreadyId);
     }
     $social_id = $response->getUsername();
     $username = $response->getUsername();
     $realName = $response->getRealName();
     $email = $response->getEmail();
     $avatar = $response->getProfilePicture();
     //set data in session. upon logging out we just erase the whole array.
     $sessionData = array();
     $sessionData['social_id'] = $social_id;
     $sessionData['username'] = $username;
     $sessionData['realName'] = $realName;
     $sessionData['email'] = $email;
     $sessionData['avatar'] = $avatar;
     $sessionData['social'] = $social;
     $user = null;
     if ($isLoggedInAlready) {
         $user = $this->doctrine->getRepository('AppBundle\\Entity\\User')->findOneById($isLoggedInAlreadyId);
     } else {
         if ($isMailru) {
             $user = $this->doctrine->getRepository('AppBundle\\Entity\\User')->findOneByMid($social_id);
         }
     }
     if ($user == null) {
         $user = new User();
         //change these only the user hasn't been registered before.
         $user->setUsername($username);
         $user->setRealname($realName);
         $user->setAvatar($avatar);
     }
     if ($isMailru) {
         $user->setMid($social_id);
     }
     $user->setLastLogin(new \DateTime('now'));
     $user->setSocial($social);
     // SET E-MAIL
     //if all emails are empty, set the first one to this one.
     if ($user->getEmail() == "") {
         $user->setEmail($email);
     } else {
         //if it really is an e-mail, try putting it in email2 or email3
         if ($email != "") {
             //is the e-mail different than the previous one?
             if ($email != $user->getEmail()) {
                 //if there an e-mail in email2? no:
                 if ($user->getEmail2() == "") {
                     $user->setEmail2($email);
                 } else {
                     //there is an e-mail in email2 and it's different. fall back to setting the user3 to w/e.
                     if ($user->getEmail2() != $email) {
                         $user->setEmail3($email);
                     }
                 }
             }
         }
     }
     //save all changes
     $em = $this->doctrine->getManager();
     $em->persist($user);
     $em->flush();
     $id = $user->getId();
     //set id
     $sessionData['id'] = $id;
     $sessionData['is_admin'] = $this->adminChecker->check($user);
     $this->session->set('user', $sessionData);
     return $this->loadUserByUsername($user->getId());
 }
开发者ID:busaev,项目名称:s3,代码行数:85,代码来源:Provider.php


注:本文中的AppBundle\Entity\User::setAvatar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。