Users Entity :
<?php
namespace App\Entity;
use App\Entity;
use Doctrine\ORM\Mapping;
/**
* @Entity
* @Table(name="users", options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"MyISAM"})
*/
class Users extends Entity {
/**
* One Users has One UserInformation. Inversed here.
* @OneToOne(targetEntity="UserInformation",mappedBy="users")
*/
protected $userInformation;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $email;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $encrypted_password;
/**
* @Column(type="string", length=10)
* @var string
*/
protected $salt;
/**
* @Column(type="smallint", options={"default":"0","comment":"0 : Doctor, 1 : Assistant, 2 : Student"}))
* @var smallint
*/
protected $type;
/**
* @Column(type="string", length=150)
* @var string
*/
protected $sef_link;
/**
* @return mixed
*/
public function getUserInformation() {
return $this->userInformation;
}
/**
* @param mixed $userInformation
*/
public function setUserInformation($userInformation) {
$this->userInformation = $userInformation;
}
/**
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* @param string $email
*/
public function setEmail($email) {
$this->email = $email;
}
/**
* @return string
*/
public function getEncryptedPassword() {
return $this->encrypted_password;
}
/**
* @param string $encrypted_password
*/
public function setEncryptedPassword($encrypted_password) {
$this->encrypted_password = $encrypted_password;
}
/**
* @return string
*/
public function getSalt() {
return $this->salt;
}
/**
* @param string $salt
*/
public function setSalt($salt) {
$this->salt = $salt;
}
/**
* @return integer
*/
public function getType() {
return $this->type;
}
/**
* @param integer $type
*/
public function setType($type) {
$this->type = $type;
}
/**
* @return string
*/
public function getSefLink() {
return $this->sef_link;
}
/**
* @param string $sef_link
*/
public function setSefLink($sef_link) {
$this->sef_link = $sef_link;
}
}
UserInformation Entity :
<?php
namespace App\Entity;
use App\Entity;
use Doctrine\ORM\Mapping;
/**
* @Entity
* @Table(name="user_information", options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"MyISAM"})
*/
class UserInformation extends Entity {
/**
* One UserInformation has One Uses. Mapped here.
* @OneToOne(targetEntity="Users")
* @JoinColumn(name="uid", referencedColumnName="id")
*/
protected $users;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $title;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $name;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $surname;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $born;
/**
* @Column(type="smallint", options={"default" : "0", "comment":"0 : Female, 1 : Male"}))
* @var smallint
*/
protected $gender;
/**
* @Column(type="text", length=65532, nullable=true)
* @var text
*/
protected $address;
/**
* @Column(type="integer", nullable=true)
* @var integer
*/
protected $country_id;
/**
* @Column(type="text", length=65532, nullable=true)
* @var text
*/
protected $about;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $institution;
/**
* @Column(type="text", length=65532, nullable=true)
* @var text
*/
protected $area_of_expertise;
/**
* @Column(type="string", length=100, nullable=true)
* @var string
*/
protected $cv_path;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $facebook_link;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $twitter_link;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $instagram_link;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $linkedin_link;
/**
* @Column(type="string", length=100)
* @var string
*/
protected $img_path;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $university;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $university_graduated_at;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $md;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $md_graduated_at;
/**
* @Column(type="string", length=50, nullable=true)
* @var string
*/
protected $associate_professor;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $associate_professor_graduated_at;
/**
* @return mixed
*/
public function getUsers() {
return $this->users;
}
/**
* @param mixed $users
*/
public function setUsers($users) {
$this->users = $users;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @param string $name
*/
public function setName($name) {
$this->name = $name;
}
/**
* @return string
*/
public function getSurname() {
return $this->surname;
}
/**
* @param string $surname
*/
public function setSurname($surname) {
$this->surname = $surname;
}
/**
* @return date
*/
public function getBorn() {
return $this->born;
}
/**
* @param date $born
*/
public function setBorn($born) {
$this->born = $born;
}
/**
* @return smallint
*/
public function getGender() {
return $this->gender;
}
/**
* @param smallint $gender
*/
public function setGender($gender) {
$this->gender = $gender;
}
/**
* @return text
*/
public function getAddress() {
return $this->address;
}
/**
* @param text $address
*/
public function setAddress($address) {
$this->address = $address;
}
/**
* @return int
*/
public function getCountryId() {
return $this->country_id;
}
/**
* @param int $country_id
*/
public function setCountryId($country_id) {
$this->country_id = $country_id;
}
/**
* @return text
*/
public function getAbout() {
return $this->about;
}
/**
* @param text $about
*/
public function setAbout($about) {
$this->about = $about;
}
/**
* @return string
*/
public function getInstitution() {
return $this->institution;
}
/**
* @param string $institution
*/
public function setInstitution($institution) {
$this->institution = $institution;
}
/**
* @return text
*/
public function getAreaOfExpertise() {
return $this->area_of_expertise;
}
/**
* @param text $area_of_expertise
*/
public function setAreaOfExpertise($area_of_expertise) {
$this->area_of_expertise = $area_of_expertise;
}
/**
* @return string
*/
public function getCvPath() {
return $this->cv_path;
}
/**
* @param string $cv_path
*/
public function setCvPath($cv_path) {
$this->cv_path = $cv_path;
}
/**
* @return string
*/
public function getFacebookLink() {
return $this->facebook_link;
}
/**
* @param string $facebook_link
*/
public function setFacebookLink($facebook_link) {
$this->facebook_link = $facebook_link;
}
/**
* @return string
*/
public function getTwitterLink() {
return $this->twitter_link;
}
/**
* @param string $twitter_link
*/
public function setTwitterLink($twitter_link) {
$this->twitter_link = $twitter_link;
}
/**
* @return string
*/
public function getInstagramLink() {
return $this->instagram_link;
}
/**
* @param string $instagram_link
*/
public function setInstagramLink($instagram_link) {
$this->instagram_link = $instagram_link;
}
/**
* @return string
*/
public function getLinkedinLink() {
return $this->linkedin_link;
}
/**
* @param string $linkedin_link
*/
public function setLinkedinLink($linkedin_link) {
$this->linkedin_link = $linkedin_link;
}
/**
* @return string
*/
public function getImgPath() {
return $this->img_path;
}
/**
* @param string $img_path
*/
public function setImgPath($img_path) {
$this->img_path = $img_path;
}
/**
* @return string
*/
public function getUniversity() {
return $this->university;
}
/**
* @param string $university
*/
public function setUniversity($university) {
$this->university = $university;
}
/**
* @return date
*/
public function getUniversityGraduatedAt() {
return $this->university_graduated_at;
}
/**
* @param date $university_graduated_at
*/
public function setUniversityGraduatedAt($university_graduated_at) {
$this->university_graduated_at = $university_graduated_at;
}
/**
* @return string
*/
public function getMd() {
return $this->md;
}
/**
* @param string $md
*/
public function setMd($md) {
$this->md = $md;
}
/**
* @return date
*/
public function getMdGraduatedAt() {
return $this->md_graduated_at;
}
/**
* @param date $md_graduated_at
*/
public function setMdGraduatedAt($md_graduated_at) {
$this->md_graduated_at = $md_graduated_at;
}
/**
* @return string
*/
public function getAssociateProfessor() {
return $this->associate_professor;
}
/**
* @param string $associate_professor
*/
public function setAssociateProfessor($associate_professor) {
$this->associate_professor = $associate_professor;
}
/**
* @return date
*/
public function getAssociateProfessorGraduatedAt() {
return $this->associate_professor_graduated_at;
}
/**
* @param date $associate_professor_graduated_at
*/
public function setAssociateProfessorGraduatedAt($associate_professor_graduated_at) {
$this->associate_professor_graduated_at = $associate_professor_graduated_at;
}
}
Service :
public function getUserByEmailAndPassword($email, $password, $ip, $user_agent) {
$repository = $this->getEntityManager()->getRepository('App\Entity\Users');
$user = $repository
->createQueryBuilder('u')
->addSelect('ui') // to limit queries when doing $user->getUserInformation()
->innerJoin('u.userInformation', 'ui')
->where('u.email = :email')->setParameter('email', $email)->getQuery()->getSingleResult();
if ($user == null)
return 0; // user not found
$salt = $user->getSalt();
$encrypted_password = $user->getEncryptedPassword();
$hash = $this->checkhashSSHA($salt, $password);
if ($hash == $encrypted_password) {
return array(
'id' => $user->getId(),
'email' => $user->getEmail(),
'type' => $user->getType(),
'information' => $user->getUserInformation(),
'created_at' => $user->getCreatedAt(),
'updated_at' => $user->getUpdatedAt(),
'is_deleted' => $user->getIsDeleted()
);
}
return 1; // wrong email or password
}
getUserInformation returns empty...
if i call getResultArray()
instead of getSingleResult()
, information returns with data. But this time, i can not use like this, $user->getId()
. I just return the $user
.
So, i want to call $user
as an object array. Information returns empty ?
{ "error": false, "user": { "id": 27, "email": "[email protected]", "type": 1, "information": {}, "created_at": { "date": "2017-01-01 21:05:45.000000", "timezone_type": 3, "timezone": "Europe/Berlin" }, "updated_at": { "date": "2017-01-01 21:05:45.000000", "timezone_type": 3, "timezone": "Europe/Berlin" }, "is_deleted": false } }
Here is if getQuery()->getArrayResult();
and return $user;
{ "error": false, "user": [ { "email": "[email protected]", "encrypted_password": "vjvyW2E9/MT7pll01S6uBeFIvO9lNzI1N2VjYjEx", "salt": "e7257ecb11", "type": 1, "sef_link": "test-test", "id": 27, "created_at": { "date": "2017-01-01 21:05:45.000000", "timezone_type": 3, "timezone": "Europe/Berlin" }, "updated_at": { "date": "2017-01-01 21:05:45.000000", "timezone_type": 3, "timezone": "Europe/Berlin" }, "is_deleted": false, "userInformation": { "title": "test1", "name": "test", "surname": "test", "born": null, "gender": 0, "address": null, "country_id": null, "about": null, "institution": null, "area_of_expertise": null, "cv_path": null, "facebook_link": null, "twitter_link": null, "instagram_link": null, "linkedin_link": null, "img_path": "default-profile-female.png", "university": null, "university_graduated_at": null, "md": null, "md_graduated_at": null, "associate_professor": null, "associate_professor_graduated_at": null, "id": 16, "created_at": { "date": "2017-01-01 21:05:45.000000", "timezone_type": 3, "timezone": "Europe/Berlin" }, "updated_at": { "date": "2017-01-01 21:05:45.000000", "timezone_type": 3, "timezone": "Europe/Berlin" }, "is_deleted": false } } ] }