daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 183 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class contacts
  2. {
  3. /**
  4.  * @var int
  5.  */
  6. private $id;
  7.  
  8.  /**
  9.  * @var string
  10.  * @AssertNotBlank()
  11.  *      )
  12.  *     @AssertRegex(
  13.  *     pattern="/d/",
  14.  *     match=false,
  15.  *     message="Your first name cannot contain a number"
  16.  * )
  17.  */
  18. private $firstName;
  19.  
  20. /**
  21.  * @var string
  22.  * @AssertNotBlank()
  23.  * @Asserttype(
  24.  *      type="string"
  25.  * )
  26.  *     @AssertRegex(
  27.  *     pattern="/d/",
  28.  *     match=false,
  29.  *     message="Your last name cannot contain a number"
  30.  * )
  31.  */
  32. private $lastName;
  33.  
  34. /**
  35.  * @var string
  36.  * @AssertRegex(
  37.  *     pattern="/d/",
  38.  *     match=true,
  39.  *     message="Your phone number cannot contain a character"
  40.  * )
  41.  * @AssertRegex(
  42.  *     pattern="/d{11}/",
  43.  *     match=true,
  44.  *     message="Your phone number should have 11 digits no more no less :)"
  45.  * )
  46.  */
  47. private $phoneNumber;
  48.  
  49. /**
  50.  * @var string
  51.  *     @AssertEmail(
  52.  *     message = "The email '{{ value }}' is not a valid email.",
  53.  *     checkMX = true
  54.  * )
  55.  */
  56. private $emailAddress;
  57.  
  58. /**
  59.  * @var integer
  60.  */
  61. private $User;
  62.  
  63. /**
  64.  * @return mixed
  65.  */
  66. public function getUser()
  67. {
  68.     return $this->User;
  69. }
  70.  
  71. /**
  72.  * @param mixed $user
  73.  */
  74. public function setUser($user)
  75. {
  76.     $this->User = $user;
  77. }
  78.  
  79.  
  80.  
  81. /**
  82.  * Get id
  83.  *
  84.  * @return int
  85.  */
  86. public function getId()
  87. {
  88.     return $this->id;
  89. }
  90.  
  91. /**
  92.  * Set firstName
  93.  *
  94.  * @param string $firstName
  95.  *
  96.  * @return contacts
  97.  */
  98. public function setFirstName($firstName)
  99. {
  100.     $this->firstName = $firstName;
  101.  
  102.     return $this;
  103. }
  104.  
  105. /**
  106.  * Get firstName
  107.  *
  108.  * @return string
  109.  */
  110. public function getFirstName()
  111. {
  112.     return $this->firstName;
  113. }
  114.  
  115. /**
  116.  * Set lastName
  117.  *
  118.  * @param string $lastName
  119.  *
  120.  * @return contacts
  121.  */
  122. public function setLastName($lastName)
  123. {
  124.     $this->lastName = $lastName;
  125.  
  126.     return $this;
  127. }
  128.  
  129. /**
  130.  * Get lastName
  131.  *
  132.  * @return string
  133.  */
  134. public function getLastName()
  135. {
  136.     return $this->lastName;
  137. }
  138.  
  139. /**
  140.  * Set phoneNumber
  141.  *
  142.  * @param string $phoneNumber
  143.  *
  144.  * @return contacts
  145.  */
  146. public function setPhoneNumber($phoneNumber)
  147. {
  148.     $this->phoneNumber = $phoneNumber;
  149.  
  150.     return $this;
  151. }
  152.  
  153. /**
  154.  * Get phoneNumber
  155.  *
  156.  * @return string
  157.  */
  158. public function getPhoneNumber()
  159. {
  160.     return $this->phoneNumber;
  161. }
  162.  
  163. /**
  164.  * Set emailAddress
  165.  *
  166.  * @param string $emailAddress
  167.  *
  168.  * @return string
  169.  */
  170. public function setEmailAddress($emailAddress)
  171. {
  172.     $this->emailAddress = $emailAddress;
  173.  
  174.     return $this;
  175. }
  176.  
  177. /**
  178.  * Get emailAddress
  179.  *
  180.  * @return string
  181.  */
  182. public function getEmailAddress()
  183. {
  184.     return $this->emailAddress;
  185. }
  186.  
  187. }
  188.    
  189. /**
  190.  * User
  191.  */
  192.  class User implements UserInterface , Serializable
  193. {
  194. /**
  195.  * @var int
  196.  */
  197. private $id;
  198.  
  199. /**
  200.  * @var string
  201.  *      * @AssertNotBlank()
  202.  *      * )
  203.  *      * @AssertRegex(
  204.  *     pattern="/d/",
  205.  *     match=false,
  206.  *     message="Your first name cannot contain a number"
  207.  * )
  208.  */
  209. private $firstName;
  210.  
  211. /**
  212.  * @var string
  213.  *      * @AssertNotBlank()
  214.  * @Asserttype(
  215.  *      type="string"
  216.  * )
  217.  *      * @AssertRegex(
  218.  *     pattern="/d/",
  219.  *     match=false,
  220.  *     message="Your last name cannot contain a number"
  221.  * )
  222.  */
  223. private $lastName;
  224.  
  225. /**
  226.  * @var string
  227.  *      * @var string
  228.  *      * @AssertEmail(
  229.  *     message = "The email '{{ value }}' is not a valid email.",
  230.  *     checkMX = true
  231.  * )
  232.  */
  233. public $email;
  234.  
  235. /**
  236.  * @var string
  237.  */
  238. private $password;
  239.  
  240. /**
  241.  * @var string
  242.  */
  243. private $Role;
  244.  
  245.  
  246.  
  247. /**
  248.  * Get id
  249.  *
  250.  * @return integer
  251.  */
  252. public function getId()
  253. {
  254.     return $this->id;
  255. }
  256.  
  257. /**
  258.  * Set firstName
  259.  *
  260.  * @param string $firstName
  261.  *
  262.  * @return User
  263.  */
  264. public function setFirstName($firstName)
  265. {
  266.     $this->firstName = $firstName;
  267.  
  268.     return $this;
  269. }
  270.  
  271. /**
  272.  * Get firstName
  273.  *
  274.  * @return string
  275.  */
  276. public function getFirstName()
  277. {
  278.     return $this->firstName;
  279. }
  280.  
  281. /**
  282.  * Set lastName
  283.  *
  284.  * @param string $lastName
  285.  *
  286.  * @return User
  287.  */
  288. public function setLastName($lastName)
  289. {
  290.     $this->lastName = $lastName;
  291.  
  292.     return $this;
  293. }
  294.  
  295. /**
  296.  * Get lastName
  297.  *
  298.  * @return string
  299.  */
  300. public function getLastName()
  301. {
  302.     return $this->lastName;
  303. }
  304.  
  305. /**
  306.  * Set email
  307.  *
  308.  * @param string $email
  309.  *
  310.  * @return User
  311.  */
  312. public function setEmail($email)
  313. {
  314.     $this->email = $email;
  315.  
  316.     return $this;
  317. }
  318.  
  319. /**
  320.  * Get email
  321.  *
  322.  * @return string
  323.  */
  324. public function getEmail()
  325. {
  326.     return $this->email;
  327. }
  328.  
  329. /**
  330.  * Set password
  331.  *
  332.  * @param string $password
  333.  *
  334.  * @return User
  335.  */
  336. public function setPassword($password)
  337. {
  338.     $this->password = $password;
  339.  
  340.     return $this;
  341. }
  342.  
  343. /**
  344.  * Get password
  345.  *
  346.  * @return string
  347.  */
  348. public function getPassword()
  349. {
  350.     return $this->password;
  351. }
  352.  
  353.  
  354.  
  355.  
  356. public function setRole($Role = null)
  357. {
  358.     $this->Role = $Role;
  359.     return $this;
  360. }
  361.  
  362. /**
  363.  * Get Role
  364.  *
  365.  * @return string
  366.  */
  367. public function getRole()
  368. {
  369.     return $this->Role;
  370. }
  371.  
  372. public function getRoles()
  373. {
  374.     return [ $this->getRole()];
  375. }
  376.  
  377. public function getSalt()
  378. {
  379.     return null;
  380. }
  381.  
  382. public function getUsername()
  383. {
  384.     return $this->email;
  385. }
  386.  
  387. public function eraseCredentials()
  388. {
  389.     return null;
  390. }
  391.  
  392. public function serialize()
  393. {
  394.     return serialize(array(
  395.         $this->id,
  396.         $this->email,
  397.         $this->password,
  398.     ));
  399. }
  400.  
  401. public function unserialize($serialized)
  402. {
  403.     list (
  404.         $this->id,
  405.         $this->email,
  406.         $this->password,
  407.         ) = unserialize($serialized);
  408. }
  409. }
  410.    
  411. manyToOne:
  412.         User:
  413.             targetEntity: UserBundleEntityUser
  414.             inversedBy: contacts
  415.             joinColumn:
  416.                 name: user_Id
  417.                 nullable: true
  418.                 referencedColumnName: id
  419. uniqueConstraints:
  420.         idx:
  421.             columns: phone_number,user_Id
  422.    
  423. public function addAction(Request $request)
  424.     {
  425.         $contact = new contacts();
  426.  
  427.         $userses = $this->get("security.token_storage")->getToken()
  428.         ->getUser()->getid();
  429.         $form = $this->createForm(addForm::class, $contact);
  430.             $form->handleRequest($request);
  431.             if ($form->isSubmitted() && $form->isValid()) {
  432.                 $data = $form->getData();
  433.                 $data->setUser($userses);
  434.                 $em = $this->getDoctrine()->getManager();
  435.                 $em->persist($data);
  436.                 $em->flush();
  437.                 return $this->render('/add/index.html.twig', array(
  438.                     'form' => $form->createView(),
  439.                 ));
  440.             } else return $this->render('/add/index.html.twig', array(
  441.                 'form' => $form->createView(),
  442.             ));
  443.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top