| Total Complexity | 218 |
| Total Lines | 2456 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like User often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use User, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 76 | class User extends BaseUser implements ThemeUser //implements ParticipantInterface, ThemeUser |
||
| 77 | { |
||
| 78 | const COURSE_MANAGER = 1; |
||
| 79 | const TEACHER = 1; |
||
| 80 | const SESSION_ADMIN = 3; |
||
| 81 | const DRH = 4; |
||
| 82 | const STUDENT = 5; |
||
| 83 | const ANONYMOUS = 6; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var integer |
||
| 87 | * |
||
| 88 | * @ORM\Column(name="id", type="integer") |
||
| 89 | * @ORM\Id |
||
| 90 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 91 | */ |
||
| 92 | protected $id; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var integer |
||
| 96 | * |
||
| 97 | * @ORM\Column(name="user_id", type="integer", nullable=true) |
||
| 98 | */ |
||
| 99 | protected $userId; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var string |
||
| 103 | * |
||
| 104 | * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true) |
||
| 105 | */ |
||
| 106 | //protected $username; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var string |
||
| 110 | * |
||
| 111 | * @ORM\Column(name="username_canonical", type="string", length=100, nullable=false) |
||
| 112 | */ |
||
| 113 | //protected $usernameCanonical; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var string |
||
| 117 | * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=false) |
||
| 118 | */ |
||
| 119 | //protected $emailCanonical; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var string |
||
| 123 | * |
||
| 124 | * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false) |
||
| 125 | */ |
||
| 126 | //protected $email; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var boolean |
||
| 130 | * @ORM\Column(name="locked", type="boolean") |
||
| 131 | */ |
||
| 132 | protected $locked; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var boolean |
||
| 136 | * @ORM\Column(name="enabled", type="boolean") |
||
| 137 | */ |
||
| 138 | //protected $enabled; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var boolean |
||
| 142 | * @ORM\Column(name="expired", type="boolean") |
||
| 143 | */ |
||
| 144 | protected $expired; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @var boolean |
||
| 148 | * @ORM\Column(name="credentials_expired", type="boolean") |
||
| 149 | */ |
||
| 150 | protected $credentialsExpired; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var \DateTime |
||
| 154 | * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false) |
||
| 155 | */ |
||
| 156 | protected $credentialsExpireAt; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var \DateTime |
||
| 160 | * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false) |
||
| 161 | */ |
||
| 162 | protected $expiresAt; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var string |
||
| 166 | * |
||
| 167 | * @ORM\Column(name="lastname", type="string", length=60, nullable=true, unique=false) |
||
| 168 | */ |
||
| 169 | //protected $lastname; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var string |
||
| 173 | * |
||
| 174 | * @ORM\Column(name="firstname", type="string", length=60, nullable=true, unique=false) |
||
| 175 | */ |
||
| 176 | //protected $firstname; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var string |
||
| 180 | * |
||
| 181 | * @ORM\Column(name="password", type="string", length=255, nullable=false, unique=false) |
||
| 182 | */ |
||
| 183 | //protected $password; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @var string |
||
| 187 | * |
||
| 188 | * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false) |
||
| 189 | */ |
||
| 190 | private $authSource; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @var int |
||
| 194 | * |
||
| 195 | * @ORM\Column(name="status", type="integer", nullable=false) |
||
| 196 | */ |
||
| 197 | private $status; |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @var string |
||
| 201 | * |
||
| 202 | * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false) |
||
| 203 | */ |
||
| 204 | private $officialCode; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @var string |
||
| 208 | * |
||
| 209 | * @ORM\Column(name="phone", type="string", length=30, nullable=true, unique=false) |
||
| 210 | */ |
||
| 211 | //protected $phone; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var string |
||
| 215 | * |
||
| 216 | * @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false) |
||
| 217 | */ |
||
| 218 | protected $address; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Vich\UploadableField(mapping="user_image", fileNameProperty="picture_uri") |
||
| 222 | * |
||
| 223 | * note This is not a mapped field of entity metadata, just a simple property. |
||
| 224 | * |
||
| 225 | * @var File $imageFile |
||
| 226 | */ |
||
| 227 | protected $imageFile; |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @var string |
||
| 231 | * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false) |
||
| 232 | */ |
||
| 233 | private $pictureUri; |
||
| 234 | |||
| 235 | /** |
||
| 236 | * ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", cascade={"all"} ) |
||
| 237 | * @ORM\JoinColumn(name="picture_uri", referencedColumnName="id") |
||
| 238 | */ |
||
| 239 | //protected $pictureUri; |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @var integer |
||
| 243 | * |
||
| 244 | * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false) |
||
| 245 | */ |
||
| 246 | private $creatorId; |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @var string |
||
| 250 | * |
||
| 251 | * @ORM\Column(name="competences", type="text", nullable=true, unique=false) |
||
| 252 | */ |
||
| 253 | private $competences; |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @var string |
||
| 257 | * |
||
| 258 | * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false) |
||
| 259 | */ |
||
| 260 | private $diplomas; |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @var string |
||
| 264 | * |
||
| 265 | * @ORM\Column(name="openarea", type="text", nullable=true, unique=false) |
||
| 266 | */ |
||
| 267 | private $openarea; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @var string |
||
| 271 | * |
||
| 272 | * @ORM\Column(name="teach", type="text", nullable=true, unique=false) |
||
| 273 | */ |
||
| 274 | private $teach; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @var string |
||
| 278 | * |
||
| 279 | * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false) |
||
| 280 | */ |
||
| 281 | private $productions; |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @var string |
||
| 285 | * |
||
| 286 | * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false) |
||
| 287 | */ |
||
| 288 | private $language; |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @var \DateTime |
||
| 292 | * |
||
| 293 | * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false) |
||
| 294 | */ |
||
| 295 | private $registrationDate; |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @var \DateTime |
||
| 299 | * |
||
| 300 | * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false) |
||
| 301 | */ |
||
| 302 | private $expirationDate; |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @var boolean |
||
| 306 | * |
||
| 307 | * @ORM\Column(name="active", type="boolean", nullable=false, unique=false) |
||
| 308 | */ |
||
| 309 | private $active; |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @var string |
||
| 313 | * |
||
| 314 | * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false) |
||
| 315 | */ |
||
| 316 | private $openid; |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @var string |
||
| 320 | * |
||
| 321 | * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false) |
||
| 322 | */ |
||
| 323 | private $theme; |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @var integer |
||
| 327 | * |
||
| 328 | * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false) |
||
| 329 | */ |
||
| 330 | private $hrDeptId; |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @var AccessUrl |
||
| 334 | **/ |
||
| 335 | protected $currentUrl; |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @ORM\Column(type="string", length=255) |
||
| 339 | */ |
||
| 340 | //protected $salt; |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @var \DateTime |
||
| 344 | * |
||
| 345 | * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false) |
||
| 346 | */ |
||
| 347 | //protected $lastLogin; |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @var \DateTime |
||
| 351 | * @ORM\Column(name="created_at", type="datetime", nullable=true, unique=false) |
||
| 352 | */ |
||
| 353 | //protected $createdAt; |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @var \DateTime |
||
| 357 | * @ORM\Column(name="updated_at", type="datetime", nullable=true, unique=false) |
||
| 358 | */ |
||
| 359 | //protected $updatedAt; |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Random string sent to the user email address in order to verify it |
||
| 363 | * |
||
| 364 | * @var string |
||
| 365 | * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true) |
||
| 366 | */ |
||
| 367 | //protected $confirmationToken; |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @var \DateTime |
||
| 371 | * |
||
| 372 | * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false) |
||
| 373 | */ |
||
| 374 | //protected $passwordRequestedAt; |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user") |
||
| 378 | **/ |
||
| 379 | protected $courses; |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="user") |
||
| 383 | **/ |
||
| 384 | //protected $items; |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user") |
||
| 388 | **/ |
||
| 389 | protected $classes; |
||
| 390 | |||
| 391 | /** |
||
| 392 | * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user") |
||
| 393 | **/ |
||
| 394 | protected $dropBoxReceivedFiles; |
||
| 395 | |||
| 396 | /** |
||
| 397 | * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent") |
||
| 398 | **/ |
||
| 399 | protected $dropBoxSentFiles; |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @ORM\Column(type="array") |
||
| 403 | */ |
||
| 404 | //protected $roles; |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @var boolean |
||
| 408 | * |
||
| 409 | * @ORM\Column(name="profile_completed", type="boolean", nullable=true) |
||
| 410 | */ |
||
| 411 | protected $profileCompleted; |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user") |
||
| 415 | **/ |
||
| 416 | //protected $jurySubscriptions; |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @ORM\ManyToMany(targetEntity="Chamilo\UserBundle\Entity\Group") |
||
| 420 | * @ORM\JoinTable(name="fos_user_user_group", |
||
| 421 | * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, |
||
| 422 | * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} |
||
| 423 | * ) |
||
| 424 | */ |
||
| 425 | protected $groups; |
||
| 426 | |||
| 427 | //private $isActive; |
||
| 428 | |||
| 429 | /** |
||
| 430 | * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user") |
||
| 431 | **/ |
||
| 432 | protected $curriculumItems; |
||
| 433 | |||
| 434 | /* |
||
| 435 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser", mappedBy="user") |
||
| 436 | * |
||
| 437 | */ |
||
| 438 | protected $portals; |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @var ArrayCollection |
||
| 442 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach") |
||
| 443 | **/ |
||
| 444 | protected $sessionAsGeneralCoach; |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @var ArrayCollection |
||
| 448 | * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UserFieldValues", mappedBy="user", orphanRemoval=true, cascade={"persist"}) |
||
| 449 | **/ |
||
| 450 | protected $extraFields; |
||
| 451 | |||
| 452 | /** |
||
| 453 | * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="creator") |
||
| 454 | **/ |
||
| 455 | protected $resourceNodes; |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser", mappedBy="user", cascade={"persist"}) |
||
| 459 | **/ |
||
| 460 | protected $sessionCourseSubscriptions; |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="user", cascade={"persist"}) |
||
| 464 | */ |
||
| 465 | protected $achievedSkills; |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment", mappedBy="feedbackGiver") |
||
| 469 | */ |
||
| 470 | protected $commentedUserSkills; |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Constructor |
||
| 474 | */ |
||
| 475 | public function __construct() |
||
| 476 | { |
||
| 477 | $this->status = self::STUDENT; |
||
| 478 | parent::__construct(); |
||
| 479 | $this->salt = sha1(uniqid(null, true)); |
||
| 480 | $this->active = true; |
||
| 481 | $this->registrationDate = new \DateTime(); |
||
| 482 | $this->authSource = 'platform'; |
||
| 483 | $this->courses = new ArrayCollection(); |
||
| 484 | //$this->items = new ArrayCollection(); |
||
| 485 | $this->classes = new ArrayCollection(); |
||
| 486 | $this->curriculumItems = new ArrayCollection(); |
||
| 487 | $this->portals = new ArrayCollection(); |
||
| 488 | $this->dropBoxSentFiles = new ArrayCollection(); |
||
| 489 | $this->dropBoxReceivedFiles = new ArrayCollection(); |
||
| 490 | //$this->extraFields = new ArrayCollection(); |
||
| 491 | //$this->userId = 0; |
||
| 492 | //$this->createdAt = new \DateTime(); |
||
| 493 | //$this->updatedAt = new \DateTime(); |
||
| 494 | |||
| 495 | $this->enabled = false; |
||
| 496 | $this->locked = false; |
||
| 497 | $this->expired = false; |
||
| 498 | $this->roles = []; |
||
| 499 | $this->credentialsExpired = false; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @return string |
||
| 504 | */ |
||
| 505 | public function __toString() |
||
| 506 | { |
||
| 507 | return $this->getCompleteName(); |
||
| 508 | } |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Updates the id with the user_id |
||
| 512 | * @ORM\PostPersist() |
||
| 513 | */ |
||
| 514 | public function postPersist(LifecycleEventArgs $args) |
||
| 515 | { |
||
| 516 | //parent::postPersist(); |
||
| 517 | // Updates the user_id field |
||
| 518 | $user = $args->getEntity(); |
||
| 519 | $this->setUserId($user->getId()); |
||
| 520 | /*$em = $args->getEntityManager(); |
||
| 521 | $em->persist($user); |
||
| 522 | $em->flush();*/ |
||
| 523 | } |
||
| 524 | |||
| 525 | /** |
||
| 526 | * @param int $userId |
||
| 527 | */ |
||
| 528 | public function setId($userId) |
||
| 529 | { |
||
| 530 | $this->id = $userId; |
||
| 531 | } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @param int $userId |
||
| 535 | */ |
||
| 536 | public function setUserId($userId) |
||
| 537 | { |
||
| 538 | if (!empty($userId)) { |
||
| 539 | $this->userId = $userId; |
||
| 540 | } |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @return int |
||
| 545 | */ |
||
| 546 | public function getId() |
||
| 547 | { |
||
| 548 | return $this->id; |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * @return string |
||
| 553 | */ |
||
| 554 | public function getEncoderName() |
||
| 555 | { |
||
| 556 | return "legacy_encoder"; |
||
| 557 | } |
||
| 558 | |||
| 559 | /** |
||
| 560 | * @return ArrayCollection |
||
| 561 | */ |
||
| 562 | public function getDropBoxSentFiles() |
||
| 563 | { |
||
| 564 | return $this->dropBoxSentFiles; |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * @return ArrayCollection |
||
| 569 | */ |
||
| 570 | public function getDropBoxReceivedFiles() |
||
| 571 | { |
||
| 572 | return $this->dropBoxReceivedFiles; |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * @return ArrayCollection |
||
| 577 | */ |
||
| 578 | public function getCourses() |
||
| 579 | { |
||
| 580 | return $this->courses; |
||
| 581 | } |
||
| 582 | |||
| 583 | /** |
||
| 584 | * @return array |
||
| 585 | */ |
||
| 586 | public static function getPasswordConstraints() |
||
| 587 | { |
||
| 588 | return |
||
| 589 | [ |
||
| 590 | new Assert\Length(['min' => 5]), |
||
| 591 | // Alpha numeric + "_" or "-" |
||
| 592 | new Assert\Regex( |
||
| 593 | [ |
||
| 594 | 'pattern' => '/^[a-z\-_0-9]+$/i', |
||
| 595 | 'htmlPattern' => '/^[a-z\-_0-9]+$/i'] |
||
| 596 | ), |
||
| 597 | // Min 3 letters - not needed |
||
| 598 | /*new Assert\Regex(array( |
||
| 599 | 'pattern' => '/[a-z]{3}/i', |
||
| 600 | 'htmlPattern' => '/[a-z]{3}/i') |
||
| 601 | ),*/ |
||
| 602 | // Min 2 numbers |
||
| 603 | new Assert\Regex( |
||
| 604 | [ |
||
| 605 | 'pattern' => '/[0-9]{2}/', |
||
| 606 | 'htmlPattern' => '/[0-9]{2}/'] |
||
| 607 | ), |
||
| 608 | ] |
||
| 609 | ; |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @param ClassMetadata $metadata |
||
| 614 | */ |
||
| 615 | public static function loadValidatorMetadata(ClassMetadata $metadata) |
||
|
|
|||
| 616 | { |
||
| 617 | //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank()); |
||
| 618 | //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank()); |
||
| 619 | //$metadata->addPropertyConstraint('email', new Assert\Email()); |
||
| 620 | /* |
||
| 621 | $metadata->addPropertyConstraint('password', |
||
| 622 | new Assert\Collection(self::getPasswordConstraints()) |
||
| 623 | );*/ |
||
| 624 | |||
| 625 | /*$metadata->addConstraint(new UniqueEntity(array( |
||
| 626 | 'fields' => 'username', |
||
| 627 | 'message' => 'This value is already used.', |
||
| 628 | )));*/ |
||
| 629 | |||
| 630 | /*$metadata->addPropertyConstraint( |
||
| 631 | 'username', |
||
| 632 | new Assert\Length(array( |
||
| 633 | 'min' => 2, |
||
| 634 | 'max' => 50, |
||
| 635 | 'minMessage' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.', |
||
| 636 | 'maxMessage' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.', |
||
| 637 | )) |
||
| 638 | );*/ |
||
| 639 | } |
||
| 640 | |||
| 641 | /** |
||
| 642 | * @inheritDoc |
||
| 643 | */ |
||
| 644 | public function isEqualTo(UserInterface $user) |
||
| 645 | { |
||
| 646 | if (!$user instanceof User) { |
||
| 647 | return false; |
||
| 648 | } |
||
| 649 | |||
| 650 | /*if ($this->password !== $user->getPassword()) { |
||
| 651 | return false; |
||
| 652 | }*/ |
||
| 653 | |||
| 654 | /*if ($this->getSalt() !== $user->getSalt()) { |
||
| 655 | return false; |
||
| 656 | }*/ |
||
| 657 | |||
| 658 | /*if ($this->username !== $user->getUsername()) { |
||
| 659 | return false; |
||
| 660 | }*/ |
||
| 661 | |||
| 662 | return true; |
||
| 663 | } |
||
| 664 | |||
| 665 | /** |
||
| 666 | * @return ArrayCollection |
||
| 667 | */ |
||
| 668 | public function getPortals() |
||
| 669 | { |
||
| 670 | return $this->portals; |
||
| 671 | } |
||
| 672 | |||
| 673 | /** |
||
| 674 | * @param $portal |
||
| 675 | */ |
||
| 676 | public function setPortal($portal) |
||
| 677 | { |
||
| 678 | $this->portals->add($portal); |
||
| 679 | } |
||
| 680 | |||
| 681 | /** |
||
| 682 | * @return ArrayCollection |
||
| 683 | */ |
||
| 684 | public function getCurriculumItems() |
||
| 685 | { |
||
| 686 | return $this->curriculumItems; |
||
| 687 | } |
||
| 688 | |||
| 689 | /** |
||
| 690 | * @param $items |
||
| 691 | */ |
||
| 692 | public function setCurriculumItems($items) |
||
| 693 | { |
||
| 694 | $this->curriculumItems = $items; |
||
| 695 | } |
||
| 696 | |||
| 697 | /** |
||
| 698 | * @return bool |
||
| 699 | */ |
||
| 700 | public function getIsActive() |
||
| 701 | { |
||
| 702 | return $this->active == 1; |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * @return bool |
||
| 707 | */ |
||
| 708 | public function isActive() |
||
| 709 | { |
||
| 710 | return $this->getIsActive(); |
||
| 711 | } |
||
| 712 | |||
| 713 | /** |
||
| 714 | * @inheritDoc |
||
| 715 | */ |
||
| 716 | public function isEnabled() |
||
| 717 | { |
||
| 718 | return $this->getActive() == 1; |
||
| 719 | } |
||
| 720 | |||
| 721 | /** |
||
| 722 | * |
||
| 723 | * @return ArrayCollection |
||
| 724 | */ |
||
| 725 | /*public function getRolesObj() |
||
| 726 | { |
||
| 727 | return $this->roles; |
||
| 728 | }*/ |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Set salt |
||
| 732 | * |
||
| 733 | * @param string $salt |
||
| 734 | * |
||
| 735 | * @return User |
||
| 736 | */ |
||
| 737 | public function setSalt($salt) |
||
| 738 | { |
||
| 739 | $this->salt = $salt; |
||
| 740 | |||
| 741 | return $this; |
||
| 742 | } |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Get salt |
||
| 746 | * |
||
| 747 | * @return string |
||
| 748 | */ |
||
| 749 | public function getSalt() |
||
| 750 | { |
||
| 751 | return $this->salt; |
||
| 752 | } |
||
| 753 | |||
| 754 | /** |
||
| 755 | * @return ArrayCollection |
||
| 756 | */ |
||
| 757 | public function getClasses() |
||
| 758 | { |
||
| 759 | return $this->classes; |
||
| 760 | } |
||
| 761 | |||
| 762 | /** |
||
| 763 | * |
||
| 764 | */ |
||
| 765 | public function getLps() |
||
| 766 | { |
||
| 767 | //return $this->lps; |
||
| 768 | /*$criteria = Criteria::create() |
||
| 769 | ->where(Criteria::expr()->eq("id", "666")) |
||
| 770 | //->orderBy(array("username" => "ASC")) |
||
| 771 | //->setFirstResult(0) |
||
| 772 | //->setMaxResults(20) |
||
| 773 | ; |
||
| 774 | $lps = $this->lps->matching($criteria);*/ |
||
| 775 | /*return $this->lps->filter( |
||
| 776 | function($entry) use ($idsToFilter) { |
||
| 777 | return $entry->getId() == 1; |
||
| 778 | });*/ |
||
| 779 | } |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Return Complete Name with the Username |
||
| 783 | * |
||
| 784 | * @return string |
||
| 785 | */ |
||
| 786 | public function getCompleteNameWithUsername() |
||
| 787 | { |
||
| 788 | return api_get_person_name($this->firstname, $this->lastname).' ('.$this->username.')'; |
||
| 789 | } |
||
| 790 | |||
| 791 | /** |
||
| 792 | * @todo don't use api_get_person_name |
||
| 793 | * @return string |
||
| 794 | */ |
||
| 795 | public function getCompleteName() |
||
| 796 | { |
||
| 797 | return api_get_person_name($this->firstname, $this->lastname); |
||
| 798 | } |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Returns the list of classes for the user |
||
| 802 | * @return string |
||
| 803 | */ |
||
| 804 | public function getCompleteNameWithClasses() |
||
| 805 | { |
||
| 806 | $classSubscription = $this->getClasses(); |
||
| 807 | $classList = []; |
||
| 808 | /** @var UsergroupRelUser $subscription */ |
||
| 809 | foreach ($classSubscription as $subscription) { |
||
| 810 | $class = $subscription->getUsergroup(); |
||
| 811 | $classList[] = $class->getName(); |
||
| 812 | } |
||
| 813 | $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null; |
||
| 814 | |||
| 815 | return $this->getCompleteName().$classString; |
||
| 816 | } |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Get userId |
||
| 820 | * |
||
| 821 | * @return integer |
||
| 822 | */ |
||
| 823 | public function getUserId() |
||
| 824 | { |
||
| 825 | return $this->userId; |
||
| 826 | } |
||
| 827 | |||
| 828 | /** |
||
| 829 | * Set lastname |
||
| 830 | * |
||
| 831 | * @param string $lastname |
||
| 832 | * |
||
| 833 | * @return User |
||
| 834 | */ |
||
| 835 | public function setLastname($lastname) |
||
| 836 | { |
||
| 837 | $this->lastname = $lastname; |
||
| 838 | |||
| 839 | return $this; |
||
| 840 | } |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Set firstname |
||
| 844 | * |
||
| 845 | * @param string $firstname |
||
| 846 | * |
||
| 847 | * @return User |
||
| 848 | */ |
||
| 849 | public function setFirstname($firstname) |
||
| 850 | { |
||
| 851 | $this->firstname = $firstname; |
||
| 852 | |||
| 853 | return $this; |
||
| 854 | } |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Set password |
||
| 858 | * |
||
| 859 | * @param string $password |
||
| 860 | * @return User |
||
| 861 | */ |
||
| 862 | public function setPassword($password) |
||
| 863 | { |
||
| 864 | $this->password = $password; |
||
| 865 | |||
| 866 | return $this; |
||
| 867 | } |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Get password |
||
| 871 | * |
||
| 872 | * @return string |
||
| 873 | */ |
||
| 874 | public function getPassword() |
||
| 875 | { |
||
| 876 | return $this->password; |
||
| 877 | } |
||
| 878 | |||
| 879 | /** |
||
| 880 | * Set authSource |
||
| 881 | * |
||
| 882 | * @param string $authSource |
||
| 883 | * @return User |
||
| 884 | */ |
||
| 885 | public function setAuthSource($authSource) |
||
| 886 | { |
||
| 887 | $this->authSource = $authSource; |
||
| 888 | |||
| 889 | return $this; |
||
| 890 | } |
||
| 891 | |||
| 892 | /** |
||
| 893 | * Get authSource |
||
| 894 | * |
||
| 895 | * @return string |
||
| 896 | */ |
||
| 897 | public function getAuthSource() |
||
| 898 | { |
||
| 899 | return $this->authSource; |
||
| 900 | } |
||
| 901 | |||
| 902 | /** |
||
| 903 | * Set email |
||
| 904 | * |
||
| 905 | * @param string $email |
||
| 906 | * @return User |
||
| 907 | */ |
||
| 908 | public function setEmail($email) |
||
| 909 | { |
||
| 910 | $this->email = $email; |
||
| 911 | |||
| 912 | return $this; |
||
| 913 | } |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Get email |
||
| 917 | * |
||
| 918 | * @return string |
||
| 919 | */ |
||
| 920 | public function getEmail() |
||
| 921 | { |
||
| 922 | return $this->email; |
||
| 923 | } |
||
| 924 | |||
| 925 | /** |
||
| 926 | * Set status |
||
| 927 | * |
||
| 928 | * @param int $status |
||
| 929 | * |
||
| 930 | * @return User |
||
| 931 | */ |
||
| 932 | public function setStatus($status) |
||
| 933 | { |
||
| 934 | $this->status = $status; |
||
| 935 | |||
| 936 | return $this; |
||
| 937 | } |
||
| 938 | |||
| 939 | /** |
||
| 940 | * Get status |
||
| 941 | * |
||
| 942 | * @return int |
||
| 943 | */ |
||
| 944 | public function getStatus() |
||
| 945 | { |
||
| 946 | return $this->status; |
||
| 947 | } |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Set officialCode |
||
| 951 | * |
||
| 952 | * @param string $officialCode |
||
| 953 | * @return User |
||
| 954 | */ |
||
| 955 | public function setOfficialCode($officialCode) |
||
| 956 | { |
||
| 957 | $this->officialCode = $officialCode; |
||
| 958 | |||
| 959 | return $this; |
||
| 960 | } |
||
| 961 | |||
| 962 | /** |
||
| 963 | * Get officialCode |
||
| 964 | * |
||
| 965 | * @return string |
||
| 966 | */ |
||
| 967 | public function getOfficialCode() |
||
| 968 | { |
||
| 969 | return $this->officialCode; |
||
| 970 | } |
||
| 971 | |||
| 972 | /** |
||
| 973 | * Set phone |
||
| 974 | * |
||
| 975 | * @param string $phone |
||
| 976 | * @return User |
||
| 977 | */ |
||
| 978 | public function setPhone($phone) |
||
| 979 | { |
||
| 980 | $this->phone = $phone; |
||
| 981 | |||
| 982 | return $this; |
||
| 983 | } |
||
| 984 | |||
| 985 | /** |
||
| 986 | * Get phone |
||
| 987 | * |
||
| 988 | * @return string |
||
| 989 | */ |
||
| 990 | public function getPhone() |
||
| 991 | { |
||
| 992 | return $this->phone; |
||
| 993 | } |
||
| 994 | |||
| 995 | /** |
||
| 996 | * Set address |
||
| 997 | * |
||
| 998 | * @param string $address |
||
| 999 | * @return User |
||
| 1000 | */ |
||
| 1001 | public function setAddress($address) |
||
| 1002 | { |
||
| 1003 | $this->address = $address; |
||
| 1004 | |||
| 1005 | return $this; |
||
| 1006 | } |
||
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Get address |
||
| 1010 | * |
||
| 1011 | * @return string |
||
| 1012 | */ |
||
| 1013 | public function getAddress() |
||
| 1014 | { |
||
| 1015 | return $this->address; |
||
| 1016 | } |
||
| 1017 | |||
| 1018 | /** |
||
| 1019 | * Set pictureUri |
||
| 1020 | * |
||
| 1021 | * @param string $pictureUri |
||
| 1022 | * @return User |
||
| 1023 | */ |
||
| 1024 | public function setPictureUri($pictureUri) |
||
| 1025 | { |
||
| 1026 | $this->pictureUri = $pictureUri; |
||
| 1027 | |||
| 1028 | return $this; |
||
| 1029 | } |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Get pictureUri |
||
| 1033 | * |
||
| 1034 | * @return Media |
||
| 1035 | */ |
||
| 1036 | public function getPictureUri() |
||
| 1037 | { |
||
| 1038 | return $this->pictureUri; |
||
| 1039 | } |
||
| 1040 | |||
| 1041 | /** |
||
| 1042 | * Set creatorId |
||
| 1043 | * |
||
| 1044 | * @param integer $creatorId |
||
| 1045 | * @return User |
||
| 1046 | */ |
||
| 1047 | public function setCreatorId($creatorId) |
||
| 1048 | { |
||
| 1049 | $this->creatorId = $creatorId; |
||
| 1050 | |||
| 1051 | return $this; |
||
| 1052 | } |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Get creatorId |
||
| 1056 | * |
||
| 1057 | * @return integer |
||
| 1058 | */ |
||
| 1059 | public function getCreatorId() |
||
| 1060 | { |
||
| 1061 | return $this->creatorId; |
||
| 1062 | } |
||
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Set competences |
||
| 1066 | * |
||
| 1067 | * @param string $competences |
||
| 1068 | * @return User |
||
| 1069 | */ |
||
| 1070 | public function setCompetences($competences) |
||
| 1071 | { |
||
| 1072 | $this->competences = $competences; |
||
| 1073 | |||
| 1074 | return $this; |
||
| 1075 | } |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * Get competences |
||
| 1079 | * |
||
| 1080 | * @return string |
||
| 1081 | */ |
||
| 1082 | public function getCompetences() |
||
| 1083 | { |
||
| 1084 | return $this->competences; |
||
| 1085 | } |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Set diplomas |
||
| 1089 | * |
||
| 1090 | * @param string $diplomas |
||
| 1091 | * @return User |
||
| 1092 | */ |
||
| 1093 | public function setDiplomas($diplomas) |
||
| 1094 | { |
||
| 1095 | $this->diplomas = $diplomas; |
||
| 1096 | |||
| 1097 | return $this; |
||
| 1098 | } |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * Get diplomas |
||
| 1102 | * |
||
| 1103 | * @return string |
||
| 1104 | */ |
||
| 1105 | public function getDiplomas() |
||
| 1106 | { |
||
| 1107 | return $this->diplomas; |
||
| 1108 | } |
||
| 1109 | |||
| 1110 | /** |
||
| 1111 | * Set openarea |
||
| 1112 | * |
||
| 1113 | * @param string $openarea |
||
| 1114 | * @return User |
||
| 1115 | */ |
||
| 1116 | public function setOpenarea($openarea) |
||
| 1117 | { |
||
| 1118 | $this->openarea = $openarea; |
||
| 1119 | |||
| 1120 | return $this; |
||
| 1121 | } |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Get openarea |
||
| 1125 | * |
||
| 1126 | * @return string |
||
| 1127 | */ |
||
| 1128 | public function getOpenarea() |
||
| 1129 | { |
||
| 1130 | return $this->openarea; |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Set teach |
||
| 1135 | * |
||
| 1136 | * @param string $teach |
||
| 1137 | * @return User |
||
| 1138 | */ |
||
| 1139 | public function setTeach($teach) |
||
| 1140 | { |
||
| 1141 | $this->teach = $teach; |
||
| 1142 | |||
| 1143 | return $this; |
||
| 1144 | } |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * Get teach |
||
| 1148 | * |
||
| 1149 | * @return string |
||
| 1150 | */ |
||
| 1151 | public function getTeach() |
||
| 1152 | { |
||
| 1153 | return $this->teach; |
||
| 1154 | } |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Set productions |
||
| 1158 | * |
||
| 1159 | * @param string $productions |
||
| 1160 | * @return User |
||
| 1161 | */ |
||
| 1162 | public function setProductions($productions) |
||
| 1163 | { |
||
| 1164 | $this->productions = $productions; |
||
| 1165 | |||
| 1166 | return $this; |
||
| 1167 | } |
||
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Get productions |
||
| 1171 | * |
||
| 1172 | * @return string |
||
| 1173 | */ |
||
| 1174 | public function getProductions() |
||
| 1175 | { |
||
| 1176 | return $this->productions; |
||
| 1177 | } |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Set language |
||
| 1181 | * |
||
| 1182 | * @param string $language |
||
| 1183 | * @return User |
||
| 1184 | */ |
||
| 1185 | public function setLanguage($language) |
||
| 1186 | { |
||
| 1187 | $this->language = $language; |
||
| 1188 | |||
| 1189 | return $this; |
||
| 1190 | } |
||
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Get language |
||
| 1194 | * |
||
| 1195 | * @return string |
||
| 1196 | */ |
||
| 1197 | public function getLanguage() |
||
| 1198 | { |
||
| 1199 | return $this->language; |
||
| 1200 | } |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Set registrationDate |
||
| 1204 | * |
||
| 1205 | * @param \DateTime $registrationDate |
||
| 1206 | * @return User |
||
| 1207 | */ |
||
| 1208 | public function setRegistrationDate($registrationDate) |
||
| 1209 | { |
||
| 1210 | $this->registrationDate = $registrationDate; |
||
| 1211 | |||
| 1212 | return $this; |
||
| 1213 | } |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Get registrationDate |
||
| 1217 | * |
||
| 1218 | * @return \DateTime |
||
| 1219 | */ |
||
| 1220 | public function getRegistrationDate() |
||
| 1221 | { |
||
| 1222 | return $this->registrationDate; |
||
| 1223 | } |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Set expirationDate |
||
| 1227 | * |
||
| 1228 | * @param \DateTime $expirationDate |
||
| 1229 | * |
||
| 1230 | * @return User |
||
| 1231 | */ |
||
| 1232 | public function setExpirationDate($expirationDate) |
||
| 1233 | { |
||
| 1234 | $this->expirationDate = $expirationDate; |
||
| 1235 | |||
| 1236 | return $this; |
||
| 1237 | } |
||
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Get expirationDate |
||
| 1241 | * |
||
| 1242 | * @return \DateTime |
||
| 1243 | */ |
||
| 1244 | public function getExpirationDate() |
||
| 1245 | { |
||
| 1246 | return $this->expirationDate; |
||
| 1247 | } |
||
| 1248 | |||
| 1249 | /** |
||
| 1250 | * Set active |
||
| 1251 | * |
||
| 1252 | * @param boolean $active |
||
| 1253 | * @return User |
||
| 1254 | */ |
||
| 1255 | public function setActive($active) |
||
| 1256 | { |
||
| 1257 | $this->active = $active; |
||
| 1258 | |||
| 1259 | return $this; |
||
| 1260 | } |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Get active |
||
| 1264 | * |
||
| 1265 | * @return boolean |
||
| 1266 | */ |
||
| 1267 | public function getActive() |
||
| 1268 | { |
||
| 1269 | return $this->active; |
||
| 1270 | } |
||
| 1271 | |||
| 1272 | /** |
||
| 1273 | * Set openid |
||
| 1274 | * |
||
| 1275 | * @param string $openid |
||
| 1276 | * @return User |
||
| 1277 | */ |
||
| 1278 | public function setOpenid($openid) |
||
| 1279 | { |
||
| 1280 | $this->openid = $openid; |
||
| 1281 | |||
| 1282 | return $this; |
||
| 1283 | } |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * Get openid |
||
| 1287 | * |
||
| 1288 | * @return string |
||
| 1289 | */ |
||
| 1290 | public function getOpenid() |
||
| 1291 | { |
||
| 1292 | return $this->openid; |
||
| 1293 | } |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Set theme |
||
| 1297 | * |
||
| 1298 | * @param string $theme |
||
| 1299 | * @return User |
||
| 1300 | */ |
||
| 1301 | public function setTheme($theme) |
||
| 1302 | { |
||
| 1303 | $this->theme = $theme; |
||
| 1304 | |||
| 1305 | return $this; |
||
| 1306 | } |
||
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Get theme |
||
| 1310 | * |
||
| 1311 | * @return string |
||
| 1312 | */ |
||
| 1313 | public function getTheme() |
||
| 1314 | { |
||
| 1315 | return $this->theme; |
||
| 1316 | } |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Set hrDeptId |
||
| 1320 | * |
||
| 1321 | * @param integer $hrDeptId |
||
| 1322 | * @return User |
||
| 1323 | */ |
||
| 1324 | public function setHrDeptId($hrDeptId) |
||
| 1325 | { |
||
| 1326 | $this->hrDeptId = $hrDeptId; |
||
| 1327 | |||
| 1328 | return $this; |
||
| 1329 | } |
||
| 1330 | |||
| 1331 | /** |
||
| 1332 | * Get hrDeptId |
||
| 1333 | * |
||
| 1334 | * @return integer |
||
| 1335 | */ |
||
| 1336 | public function getHrDeptId() |
||
| 1337 | { |
||
| 1338 | return $this->hrDeptId; |
||
| 1339 | } |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * @return Media |
||
| 1343 | */ |
||
| 1344 | public function getAvatar() |
||
| 1345 | { |
||
| 1346 | return $this->getPictureUri(); |
||
| 1347 | } |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * @return string |
||
| 1351 | */ |
||
| 1352 | public function getAvatarOrAnonymous($size = 22) |
||
| 1353 | { |
||
| 1354 | $avatar = $this->getAvatar(); |
||
| 1355 | |||
| 1356 | if (empty($avatar)) { |
||
| 1357 | return "img/icons/$size/unknown.png"; |
||
| 1358 | } |
||
| 1359 | |||
| 1360 | return $avatar; |
||
| 1361 | } |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * @return \DateTime |
||
| 1365 | */ |
||
| 1366 | public function getMemberSince() |
||
| 1367 | { |
||
| 1368 | return $this->registrationDate; |
||
| 1369 | } |
||
| 1370 | |||
| 1371 | /** |
||
| 1372 | * @return bool |
||
| 1373 | */ |
||
| 1374 | public function isOnline() |
||
| 1375 | { |
||
| 1376 | return false; |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | /** |
||
| 1380 | * @return int |
||
| 1381 | */ |
||
| 1382 | public function getIdentifier() |
||
| 1383 | { |
||
| 1384 | return $this->getId(); |
||
| 1385 | } |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * If manually uploading a file (i.e. not using Symfony Form) ensure an instance |
||
| 1389 | * of 'UploadedFile' is injected into this setter to trigger the update. If this |
||
| 1390 | * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter |
||
| 1391 | * must be able to accept an instance of 'File' as the bundle will inject one here |
||
| 1392 | * during Doctrine hydration. |
||
| 1393 | * |
||
| 1394 | * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image |
||
| 1395 | */ |
||
| 1396 | public function setImageFile(File $image) |
||
| 1397 | { |
||
| 1398 | $this->imageFile = $image; |
||
| 1399 | |||
| 1400 | if ($image) { |
||
| 1401 | // It is required that at least one field changes if you are using doctrine |
||
| 1402 | // otherwise the event listeners won't be called and the file is lost |
||
| 1403 | $this->updatedAt = new \DateTime('now'); |
||
| 1404 | } |
||
| 1405 | } |
||
| 1406 | |||
| 1407 | /** |
||
| 1408 | * @return File |
||
| 1409 | */ |
||
| 1410 | public function getImageFile() |
||
| 1411 | { |
||
| 1412 | return $this->imageFile; |
||
| 1413 | } |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * @param string $imageName |
||
| 1417 | */ |
||
| 1418 | public function setImageName($imageName) |
||
| 1419 | { |
||
| 1420 | $this->imageName = $imageName; |
||
| 1421 | } |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * @return string |
||
| 1425 | */ |
||
| 1426 | public function getImageName() |
||
| 1427 | { |
||
| 1428 | return $this->imageName; |
||
| 1429 | } |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * @return string |
||
| 1433 | */ |
||
| 1434 | public function getSlug() |
||
| 1435 | { |
||
| 1436 | return $this->getUsername(); |
||
| 1437 | } |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * @param $slug |
||
| 1441 | * @return User |
||
| 1442 | */ |
||
| 1443 | public function setSlug($slug) |
||
| 1444 | { |
||
| 1445 | return $this->setUsername($slug); |
||
| 1446 | } |
||
| 1447 | |||
| 1448 | /** |
||
| 1449 | * Set lastLogin |
||
| 1450 | * |
||
| 1451 | * @param \DateTime $lastLogin |
||
| 1452 | * |
||
| 1453 | * @return User |
||
| 1454 | */ |
||
| 1455 | public function setLastLogin(\DateTime $lastLogin = null) |
||
| 1456 | { |
||
| 1457 | $this->lastLogin = $lastLogin; |
||
| 1458 | |||
| 1459 | return $this; |
||
| 1460 | } |
||
| 1461 | |||
| 1462 | /** |
||
| 1463 | * Get lastLogin |
||
| 1464 | * |
||
| 1465 | * @return \DateTime |
||
| 1466 | */ |
||
| 1467 | public function getLastLogin() |
||
| 1468 | { |
||
| 1469 | return $this->lastLogin; |
||
| 1470 | } |
||
| 1471 | |||
| 1472 | /** |
||
| 1473 | * {@inheritdoc} |
||
| 1474 | */ |
||
| 1475 | public function getExtraFields() |
||
| 1476 | { |
||
| 1477 | return $this->extraFields; |
||
| 1478 | } |
||
| 1479 | |||
| 1480 | /** |
||
| 1481 | * {@inheritdoc} |
||
| 1482 | */ |
||
| 1483 | public function setExtraFields($extraFields) |
||
| 1484 | { |
||
| 1485 | $this->extraFields = new ArrayCollection(); |
||
| 1486 | foreach ($extraFields as $extraField) { |
||
| 1487 | $this->addExtraFields($extraField); |
||
| 1488 | } |
||
| 1489 | |||
| 1490 | return $this; |
||
| 1491 | } |
||
| 1492 | |||
| 1493 | /** |
||
| 1494 | * {@inheritdoc} |
||
| 1495 | */ |
||
| 1496 | /*public function addExtraFields(ExtraFieldValues $extraFieldValue) |
||
| 1497 | { |
||
| 1498 | $extraFieldValue->setUser($this); |
||
| 1499 | $this->extraFields[] = $extraFieldValue; |
||
| 1500 | |||
| 1501 | return $this; |
||
| 1502 | }*/ |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * {@inheritdoc} |
||
| 1506 | */ |
||
| 1507 | public function addExtraFields(ExtraFieldValues $extraFieldValue) |
||
| 1508 | { |
||
| 1509 | //if (!$this->hasExtraField($attribute)) { |
||
| 1510 | $extraFieldValue->setUser($this); |
||
| 1511 | $this->extraFields[] = $extraFieldValue; |
||
| 1512 | //} |
||
| 1513 | |||
| 1514 | return $this; |
||
| 1515 | } |
||
| 1516 | |||
| 1517 | /** |
||
| 1518 | * {@inheritdoc} |
||
| 1519 | */ |
||
| 1520 | public function removeExtraField(ExtraFieldValues $attribute) |
||
| 1521 | { |
||
| 1522 | //if ($this->hasExtraField($attribute)) { |
||
| 1523 | //$this->extraFields->removeElement($attribute); |
||
| 1524 | //$attribute->setUser($this); |
||
| 1525 | //} |
||
| 1526 | |||
| 1527 | return $this; |
||
| 1528 | } |
||
| 1529 | |||
| 1530 | /** |
||
| 1531 | * {@inheritdoc} |
||
| 1532 | */ |
||
| 1533 | /*public function hasExtraField($attribute) |
||
| 1534 | { |
||
| 1535 | if (!$this->extraFields) { |
||
| 1536 | return false; |
||
| 1537 | } |
||
| 1538 | return $this->extraFields->contains($attribute); |
||
| 1539 | }*/ |
||
| 1540 | |||
| 1541 | /** |
||
| 1542 | * {@inheritdoc} |
||
| 1543 | */ |
||
| 1544 | public function hasExtraFieldByName($attributeName) |
||
| 1545 | { |
||
| 1546 | foreach ($this->extraFields as $attribute) { |
||
| 1547 | if ($attribute->getName() === $attributeName) { |
||
| 1548 | return true; |
||
| 1549 | } |
||
| 1550 | } |
||
| 1551 | |||
| 1552 | return false; |
||
| 1553 | } |
||
| 1554 | |||
| 1555 | /** |
||
| 1556 | * {@inheritdoc} |
||
| 1557 | */ |
||
| 1558 | public function getExtraFieldByName($attributeName) |
||
| 1559 | { |
||
| 1560 | foreach ($this->extraFields as $attribute) { |
||
| 1561 | if ($attribute->getName() === $attributeName) { |
||
| 1562 | return $attribute; |
||
| 1563 | } |
||
| 1564 | } |
||
| 1565 | |||
| 1566 | return null; |
||
| 1567 | } |
||
| 1568 | |||
| 1569 | /** |
||
| 1570 | * Get sessionCourseSubscription |
||
| 1571 | * @return ArrayCollection |
||
| 1572 | */ |
||
| 1573 | public function getSessionCourseSubscriptions() |
||
| 1574 | { |
||
| 1575 | return $this->sessionCourseSubscriptions; |
||
| 1576 | } |
||
| 1577 | |||
| 1578 | /** |
||
| 1579 | * @return string |
||
| 1580 | */ |
||
| 1581 | public function getConfirmationToken() |
||
| 1582 | { |
||
| 1583 | return $this->confirmationToken; |
||
| 1584 | } |
||
| 1585 | |||
| 1586 | /** |
||
| 1587 | * @param string $confirmationToken |
||
| 1588 | * |
||
| 1589 | * @return User |
||
| 1590 | */ |
||
| 1591 | public function setConfirmationToken($confirmationToken) |
||
| 1592 | { |
||
| 1593 | $this->confirmationToken = $confirmationToken; |
||
| 1594 | |||
| 1595 | return $this; |
||
| 1596 | } |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * @return \DateTime |
||
| 1600 | */ |
||
| 1601 | public function getPasswordRequestedAt() |
||
| 1602 | { |
||
| 1603 | return $this->passwordRequestedAt; |
||
| 1604 | } |
||
| 1605 | |||
| 1606 | |||
| 1607 | /** |
||
| 1608 | * @param int $ttl |
||
| 1609 | * @return bool |
||
| 1610 | */ |
||
| 1611 | public function isPasswordRequestNonExpired($ttl) |
||
| 1612 | { |
||
| 1613 | return $this->getPasswordRequestedAt() instanceof \DateTime && |
||
| 1614 | $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time(); |
||
| 1615 | } |
||
| 1616 | |||
| 1617 | public function getUsername() |
||
| 1618 | { |
||
| 1619 | return $this->username; |
||
| 1620 | } |
||
| 1621 | |||
| 1622 | /** |
||
| 1623 | * Returns the creation date. |
||
| 1624 | * |
||
| 1625 | * @return \DateTime|null |
||
| 1626 | */ |
||
| 1627 | public function getCreatedAt() |
||
| 1628 | { |
||
| 1629 | return $this->createdAt; |
||
| 1630 | } |
||
| 1631 | |||
| 1632 | /** |
||
| 1633 | * Sets the last update date. |
||
| 1634 | * |
||
| 1635 | * @param \DateTime|null $updatedAt |
||
| 1636 | * |
||
| 1637 | * @return User |
||
| 1638 | */ |
||
| 1639 | public function setUpdatedAt(\DateTime $updatedAt = null) |
||
| 1640 | { |
||
| 1641 | $this->updatedAt = $updatedAt; |
||
| 1642 | |||
| 1643 | return $this; |
||
| 1644 | } |
||
| 1645 | |||
| 1646 | /** |
||
| 1647 | * Returns the last update date. |
||
| 1648 | * |
||
| 1649 | * @return \DateTime|null |
||
| 1650 | */ |
||
| 1651 | public function getUpdatedAt() |
||
| 1652 | { |
||
| 1653 | return $this->updatedAt; |
||
| 1654 | } |
||
| 1655 | |||
| 1656 | /** |
||
| 1657 | * Returns the expiration date. |
||
| 1658 | * |
||
| 1659 | * @return \DateTime|null |
||
| 1660 | */ |
||
| 1661 | public function getExpiresAt() |
||
| 1662 | { |
||
| 1663 | return $this->expiresAt; |
||
| 1664 | } |
||
| 1665 | |||
| 1666 | /** |
||
| 1667 | * Returns the credentials expiration date. |
||
| 1668 | * |
||
| 1669 | * @return \DateTime |
||
| 1670 | */ |
||
| 1671 | public function getCredentialsExpireAt() |
||
| 1672 | { |
||
| 1673 | return $this->credentialsExpireAt; |
||
| 1674 | } |
||
| 1675 | |||
| 1676 | /** |
||
| 1677 | * Sets the credentials expiration date. |
||
| 1678 | * |
||
| 1679 | * @param \DateTime|null $date |
||
| 1680 | * |
||
| 1681 | * @return User |
||
| 1682 | */ |
||
| 1683 | public function setCredentialsExpireAt(\DateTime $date = null) |
||
| 1684 | { |
||
| 1685 | $this->credentialsExpireAt = $date; |
||
| 1686 | |||
| 1687 | return $this; |
||
| 1688 | } |
||
| 1689 | |||
| 1690 | /** |
||
| 1691 | * Sets the user groups. |
||
| 1692 | * |
||
| 1693 | * @param array $groups |
||
| 1694 | * |
||
| 1695 | * @return User |
||
| 1696 | */ |
||
| 1697 | public function setGroups($groups) |
||
| 1698 | { |
||
| 1699 | foreach ($groups as $group) { |
||
| 1700 | $this->addGroup($group); |
||
| 1701 | } |
||
| 1702 | |||
| 1703 | return $this; |
||
| 1704 | } |
||
| 1705 | |||
| 1706 | /** |
||
| 1707 | * Sets the two-step verification code. |
||
| 1708 | * |
||
| 1709 | * @param string $twoStepVerificationCode |
||
| 1710 | * |
||
| 1711 | * @return User |
||
| 1712 | */ |
||
| 1713 | public function setTwoStepVerificationCode($twoStepVerificationCode) |
||
| 1714 | { |
||
| 1715 | $this->twoStepVerificationCode = $twoStepVerificationCode; |
||
| 1716 | |||
| 1717 | return $this; |
||
| 1718 | } |
||
| 1719 | |||
| 1720 | /** |
||
| 1721 | * Returns the two-step verification code. |
||
| 1722 | * |
||
| 1723 | * @return string |
||
| 1724 | */ |
||
| 1725 | public function getTwoStepVerificationCode() |
||
| 1726 | { |
||
| 1727 | return $this->twoStepVerificationCode; |
||
| 1728 | } |
||
| 1729 | |||
| 1730 | /** |
||
| 1731 | * @param string $biography |
||
| 1732 | * |
||
| 1733 | * @return User |
||
| 1734 | */ |
||
| 1735 | public function setBiography($biography) |
||
| 1736 | { |
||
| 1737 | $this->biography = $biography; |
||
| 1738 | |||
| 1739 | return $this; |
||
| 1740 | } |
||
| 1741 | |||
| 1742 | /** |
||
| 1743 | * @return string |
||
| 1744 | */ |
||
| 1745 | public function getBiography() |
||
| 1746 | { |
||
| 1747 | return $this->biography; |
||
| 1748 | } |
||
| 1749 | |||
| 1750 | /** |
||
| 1751 | * @param \DateTime $dateOfBirth |
||
| 1752 | * |
||
| 1753 | * @return User |
||
| 1754 | */ |
||
| 1755 | public function setDateOfBirth($dateOfBirth) |
||
| 1756 | { |
||
| 1757 | $this->dateOfBirth = $dateOfBirth; |
||
| 1758 | |||
| 1759 | return $this; |
||
| 1760 | } |
||
| 1761 | |||
| 1762 | /** |
||
| 1763 | * @return \DateTime |
||
| 1764 | */ |
||
| 1765 | public function getDateOfBirth() |
||
| 1766 | { |
||
| 1767 | return $this->dateOfBirth; |
||
| 1768 | } |
||
| 1769 | |||
| 1770 | /** |
||
| 1771 | * @param string $facebookData |
||
| 1772 | * |
||
| 1773 | * @return User |
||
| 1774 | */ |
||
| 1775 | public function setFacebookData($facebookData) |
||
| 1776 | { |
||
| 1777 | $this->facebookData = $facebookData; |
||
| 1778 | |||
| 1779 | return $this; |
||
| 1780 | } |
||
| 1781 | |||
| 1782 | /** |
||
| 1783 | * @return string |
||
| 1784 | */ |
||
| 1785 | public function getFacebookData() |
||
| 1786 | { |
||
| 1787 | return $this->facebookData; |
||
| 1788 | } |
||
| 1789 | |||
| 1790 | /** |
||
| 1791 | * @param string $facebookName |
||
| 1792 | * |
||
| 1793 | * @return User |
||
| 1794 | */ |
||
| 1795 | public function setFacebookName($facebookName) |
||
| 1796 | { |
||
| 1797 | $this->facebookName = $facebookName; |
||
| 1798 | |||
| 1799 | return $this; |
||
| 1800 | } |
||
| 1801 | |||
| 1802 | /** |
||
| 1803 | * @return string |
||
| 1804 | */ |
||
| 1805 | public function getFacebookName() |
||
| 1806 | { |
||
| 1807 | return $this->facebookName; |
||
| 1808 | } |
||
| 1809 | |||
| 1810 | /** |
||
| 1811 | * @param string $facebookUid |
||
| 1812 | * |
||
| 1813 | * @return User |
||
| 1814 | */ |
||
| 1815 | public function setFacebookUid($facebookUid) |
||
| 1816 | { |
||
| 1817 | $this->facebookUid = $facebookUid; |
||
| 1818 | |||
| 1819 | return $this; |
||
| 1820 | } |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * @return string |
||
| 1824 | */ |
||
| 1825 | public function getFacebookUid() |
||
| 1826 | { |
||
| 1827 | return $this->facebookUid; |
||
| 1828 | } |
||
| 1829 | |||
| 1830 | /** |
||
| 1831 | * @return string |
||
| 1832 | */ |
||
| 1833 | public function getFirstname() |
||
| 1834 | { |
||
| 1835 | return $this->firstname; |
||
| 1836 | } |
||
| 1837 | |||
| 1838 | /** |
||
| 1839 | * @param string $gender |
||
| 1840 | * |
||
| 1841 | * @return User |
||
| 1842 | */ |
||
| 1843 | public function setGender($gender) |
||
| 1844 | { |
||
| 1845 | $this->gender = $gender; |
||
| 1846 | |||
| 1847 | return $this; |
||
| 1848 | } |
||
| 1849 | |||
| 1850 | /** |
||
| 1851 | * @return string |
||
| 1852 | */ |
||
| 1853 | public function getGender() |
||
| 1854 | { |
||
| 1855 | return $this->gender; |
||
| 1856 | } |
||
| 1857 | |||
| 1858 | /** |
||
| 1859 | * @param string $gplusData |
||
| 1860 | * |
||
| 1861 | * @return User |
||
| 1862 | */ |
||
| 1863 | public function setGplusData($gplusData) |
||
| 1864 | { |
||
| 1865 | $this->gplusData = $gplusData; |
||
| 1866 | |||
| 1867 | return $this; |
||
| 1868 | } |
||
| 1869 | |||
| 1870 | /** |
||
| 1871 | * @return string |
||
| 1872 | */ |
||
| 1873 | public function getGplusData() |
||
| 1874 | { |
||
| 1875 | return $this->gplusData; |
||
| 1876 | } |
||
| 1877 | |||
| 1878 | /** |
||
| 1879 | * @param string $gplusName |
||
| 1880 | * |
||
| 1881 | * @return User |
||
| 1882 | */ |
||
| 1883 | public function setGplusName($gplusName) |
||
| 1884 | { |
||
| 1885 | $this->gplusName = $gplusName; |
||
| 1886 | |||
| 1887 | return $this; |
||
| 1888 | } |
||
| 1889 | |||
| 1890 | /** |
||
| 1891 | * @return string |
||
| 1892 | */ |
||
| 1893 | public function getGplusName() |
||
| 1894 | { |
||
| 1895 | return $this->gplusName; |
||
| 1896 | } |
||
| 1897 | |||
| 1898 | /** |
||
| 1899 | * @param string $gplusUid |
||
| 1900 | * |
||
| 1901 | * @return User |
||
| 1902 | */ |
||
| 1903 | public function setGplusUid($gplusUid) |
||
| 1904 | { |
||
| 1905 | $this->gplusUid = $gplusUid; |
||
| 1906 | |||
| 1907 | return $this; |
||
| 1908 | } |
||
| 1909 | |||
| 1910 | /** |
||
| 1911 | * @return string |
||
| 1912 | */ |
||
| 1913 | public function getGplusUid() |
||
| 1914 | { |
||
| 1915 | return $this->gplusUid; |
||
| 1916 | } |
||
| 1917 | |||
| 1918 | /** |
||
| 1919 | * @return string |
||
| 1920 | */ |
||
| 1921 | public function getLastname() |
||
| 1922 | { |
||
| 1923 | return $this->lastname; |
||
| 1924 | } |
||
| 1925 | |||
| 1926 | /** |
||
| 1927 | * @param string $locale |
||
| 1928 | * |
||
| 1929 | * @return User |
||
| 1930 | */ |
||
| 1931 | public function setLocale($locale) |
||
| 1932 | { |
||
| 1933 | $this->locale = $locale; |
||
| 1934 | |||
| 1935 | return $this; |
||
| 1936 | } |
||
| 1937 | |||
| 1938 | /** |
||
| 1939 | * @return string |
||
| 1940 | */ |
||
| 1941 | public function getLocale() |
||
| 1942 | { |
||
| 1943 | return $this->locale; |
||
| 1944 | } |
||
| 1945 | |||
| 1946 | /** |
||
| 1947 | * @param string $timezone |
||
| 1948 | * |
||
| 1949 | * @return User |
||
| 1950 | */ |
||
| 1951 | public function setTimezone($timezone) |
||
| 1952 | { |
||
| 1953 | $this->timezone = $timezone; |
||
| 1954 | |||
| 1955 | return $this; |
||
| 1956 | } |
||
| 1957 | |||
| 1958 | /** |
||
| 1959 | * @return string |
||
| 1960 | */ |
||
| 1961 | public function getTimezone() |
||
| 1962 | { |
||
| 1963 | return $this->timezone; |
||
| 1964 | } |
||
| 1965 | |||
| 1966 | /** |
||
| 1967 | * @param string $twitterData |
||
| 1968 | * |
||
| 1969 | * @return User |
||
| 1970 | */ |
||
| 1971 | public function setTwitterData($twitterData) |
||
| 1972 | { |
||
| 1973 | $this->twitterData = $twitterData; |
||
| 1974 | |||
| 1975 | return $this; |
||
| 1976 | } |
||
| 1977 | |||
| 1978 | /** |
||
| 1979 | * @return string |
||
| 1980 | */ |
||
| 1981 | public function getTwitterData() |
||
| 1982 | { |
||
| 1983 | return $this->twitterData; |
||
| 1984 | } |
||
| 1985 | |||
| 1986 | /** |
||
| 1987 | * @param string $twitterName |
||
| 1988 | * |
||
| 1989 | * @return User |
||
| 1990 | */ |
||
| 1991 | public function setTwitterName($twitterName) |
||
| 1992 | { |
||
| 1993 | $this->twitterName = $twitterName; |
||
| 1994 | |||
| 1995 | return $this; |
||
| 1996 | } |
||
| 1997 | |||
| 1998 | /** |
||
| 1999 | * @return string |
||
| 2000 | */ |
||
| 2001 | public function getTwitterName() |
||
| 2002 | { |
||
| 2003 | return $this->twitterName; |
||
| 2004 | } |
||
| 2005 | |||
| 2006 | /** |
||
| 2007 | * @param string $twitterUid |
||
| 2008 | * |
||
| 2009 | * @return User |
||
| 2010 | */ |
||
| 2011 | public function setTwitterUid($twitterUid) |
||
| 2012 | { |
||
| 2013 | $this->twitterUid = $twitterUid; |
||
| 2014 | |||
| 2015 | return $this; |
||
| 2016 | } |
||
| 2017 | |||
| 2018 | /** |
||
| 2019 | * @return string |
||
| 2020 | */ |
||
| 2021 | public function getTwitterUid() |
||
| 2022 | { |
||
| 2023 | return $this->twitterUid; |
||
| 2024 | } |
||
| 2025 | |||
| 2026 | /** |
||
| 2027 | * @param string $website |
||
| 2028 | * |
||
| 2029 | * @return User |
||
| 2030 | */ |
||
| 2031 | public function setWebsite($website) |
||
| 2032 | { |
||
| 2033 | $this->website = $website; |
||
| 2034 | |||
| 2035 | return $this; |
||
| 2036 | } |
||
| 2037 | |||
| 2038 | /** |
||
| 2039 | * @return string |
||
| 2040 | */ |
||
| 2041 | public function getWebsite() |
||
| 2042 | { |
||
| 2043 | return $this->website; |
||
| 2044 | } |
||
| 2045 | |||
| 2046 | /** |
||
| 2047 | * @param string $token |
||
| 2048 | * |
||
| 2049 | * @return User |
||
| 2050 | */ |
||
| 2051 | public function setToken($token) |
||
| 2052 | { |
||
| 2053 | $this->token = $token; |
||
| 2054 | |||
| 2055 | return $this; |
||
| 2056 | } |
||
| 2057 | |||
| 2058 | /** |
||
| 2059 | * @return string |
||
| 2060 | */ |
||
| 2061 | public function getToken() |
||
| 2062 | { |
||
| 2063 | return $this->token; |
||
| 2064 | } |
||
| 2065 | |||
| 2066 | /** |
||
| 2067 | * @return string |
||
| 2068 | */ |
||
| 2069 | public function getFullname() |
||
| 2070 | { |
||
| 2071 | return sprintf('%s %s', $this->getFirstname(), $this->getLastname()); |
||
| 2072 | } |
||
| 2073 | |||
| 2074 | /** |
||
| 2075 | * @return array |
||
| 2076 | */ |
||
| 2077 | public function getRealRoles() |
||
| 2078 | { |
||
| 2079 | return $this->roles; |
||
| 2080 | } |
||
| 2081 | |||
| 2082 | /** |
||
| 2083 | * @param array $roles |
||
| 2084 | * |
||
| 2085 | * @return User |
||
| 2086 | */ |
||
| 2087 | public function setRealRoles(array $roles) |
||
| 2088 | { |
||
| 2089 | $this->setRoles($roles); |
||
| 2090 | |||
| 2091 | return $this; |
||
| 2092 | } |
||
| 2093 | |||
| 2094 | /** |
||
| 2095 | * Removes sensitive data from the user. |
||
| 2096 | */ |
||
| 2097 | public function eraseCredentials() |
||
| 2098 | { |
||
| 2099 | $this->plainPassword = null; |
||
| 2100 | } |
||
| 2101 | |||
| 2102 | /** |
||
| 2103 | * @return string |
||
| 2104 | */ |
||
| 2105 | public function getUsernameCanonical() |
||
| 2106 | { |
||
| 2107 | return $this->usernameCanonical; |
||
| 2108 | } |
||
| 2109 | |||
| 2110 | /** |
||
| 2111 | * @return string |
||
| 2112 | */ |
||
| 2113 | public function getEmailCanonical() |
||
| 2114 | { |
||
| 2115 | return $this->emailCanonical; |
||
| 2116 | } |
||
| 2117 | |||
| 2118 | /** |
||
| 2119 | * @return mixed |
||
| 2120 | */ |
||
| 2121 | public function getPlainPassword() |
||
| 2122 | { |
||
| 2123 | if (isset($this->plainPassword)) { |
||
| 2124 | return $this->plainPassword; |
||
| 2125 | } |
||
| 2126 | } |
||
| 2127 | |||
| 2128 | /** |
||
| 2129 | * Returns the user roles |
||
| 2130 | * |
||
| 2131 | * @return array The roles |
||
| 2132 | */ |
||
| 2133 | public function getRoles() |
||
| 2134 | { |
||
| 2135 | $roles = $this->roles; |
||
| 2136 | |||
| 2137 | foreach ($this->getGroups() as $group) { |
||
| 2138 | $roles = array_merge($roles, $group->getRoles()); |
||
| 2139 | } |
||
| 2140 | |||
| 2141 | // we need to make sure to have at least one role |
||
| 2142 | $roles[] = static::ROLE_DEFAULT; |
||
| 2143 | |||
| 2144 | return array_unique($roles); |
||
| 2145 | } |
||
| 2146 | |||
| 2147 | /** |
||
| 2148 | * Never use this to check if this user has access to anything! |
||
| 2149 | * |
||
| 2150 | * Use the SecurityContext, or an implementation of AccessDecisionManager |
||
| 2151 | * instead, e.g. |
||
| 2152 | * |
||
| 2153 | * $securityContext->isGranted('ROLE_USER'); |
||
| 2154 | * |
||
| 2155 | * @param string $role |
||
| 2156 | * |
||
| 2157 | * @return boolean |
||
| 2158 | */ |
||
| 2159 | public function hasRole($role) |
||
| 2160 | { |
||
| 2161 | return in_array(strtoupper($role), $this->getRoles(), true); |
||
| 2162 | } |
||
| 2163 | |||
| 2164 | public function isAccountNonExpired() |
||
| 2165 | { |
||
| 2166 | if (true === $this->expired) { |
||
| 2167 | return false; |
||
| 2168 | } |
||
| 2169 | |||
| 2170 | if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) { |
||
| 2171 | return false; |
||
| 2172 | } |
||
| 2173 | |||
| 2174 | return true; |
||
| 2175 | } |
||
| 2176 | |||
| 2177 | public function isAccountNonLocked() |
||
| 2178 | { |
||
| 2179 | return !$this->locked; |
||
| 2180 | } |
||
| 2181 | |||
| 2182 | public function isCredentialsNonExpired() |
||
| 2183 | { |
||
| 2184 | if (true === $this->credentialsExpired) { |
||
| 2185 | return false; |
||
| 2186 | } |
||
| 2187 | |||
| 2188 | if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) { |
||
| 2189 | return false; |
||
| 2190 | } |
||
| 2191 | |||
| 2192 | return true; |
||
| 2193 | } |
||
| 2194 | |||
| 2195 | public function isCredentialsExpired() |
||
| 2196 | { |
||
| 2197 | return !$this->isCredentialsNonExpired(); |
||
| 2198 | } |
||
| 2199 | |||
| 2200 | public function isExpired() |
||
| 2201 | { |
||
| 2202 | return !$this->isAccountNonExpired(); |
||
| 2203 | } |
||
| 2204 | |||
| 2205 | public function isLocked() |
||
| 2206 | { |
||
| 2207 | return !$this->isAccountNonLocked(); |
||
| 2208 | } |
||
| 2209 | |||
| 2210 | public function isSuperAdmin() |
||
| 2211 | { |
||
| 2212 | return $this->hasRole(static::ROLE_SUPER_ADMIN); |
||
| 2213 | } |
||
| 2214 | |||
| 2215 | public function isUser(UserInterface $user = null) |
||
| 2216 | { |
||
| 2217 | return null !== $user && $this->getId() === $user->getId(); |
||
| 2218 | } |
||
| 2219 | |||
| 2220 | public function removeRole($role) |
||
| 2221 | { |
||
| 2222 | if (false !== $key = array_search(strtoupper($role), $this->roles, true)) { |
||
| 2223 | unset($this->roles[$key]); |
||
| 2224 | $this->roles = array_values($this->roles); |
||
| 2225 | } |
||
| 2226 | |||
| 2227 | return $this; |
||
| 2228 | } |
||
| 2229 | |||
| 2230 | /** |
||
| 2231 | * @param boolean $boolean |
||
| 2232 | * |
||
| 2233 | * @return User |
||
| 2234 | */ |
||
| 2235 | public function setCredentialsExpired($boolean) |
||
| 2240 | } |
||
| 2241 | |||
| 2242 | public function setEnabled($boolean) |
||
| 2243 | { |
||
| 2244 | $this->enabled = (Boolean) $boolean; |
||
| 2245 | |||
| 2246 | return $this; |
||
| 2247 | } |
||
| 2248 | |||
| 2249 | /** |
||
| 2250 | * Sets this user to expired. |
||
| 2251 | * |
||
| 2252 | * @param Boolean $boolean |
||
| 2253 | * |
||
| 2254 | * @return User |
||
| 2255 | */ |
||
| 2256 | public function setExpired($boolean) |
||
| 2257 | { |
||
| 2258 | $this->expired = (Boolean) $boolean; |
||
| 2259 | |||
| 2260 | return $this; |
||
| 2261 | } |
||
| 2262 | |||
| 2263 | /** |
||
| 2264 | * @param \DateTime $date |
||
| 2265 | * |
||
| 2266 | * @return User |
||
| 2267 | */ |
||
| 2268 | public function setExpiresAt(\DateTime $date) |
||
| 2269 | { |
||
| 2270 | $this->expiresAt = $date; |
||
| 2271 | |||
| 2272 | return $this; |
||
| 2273 | } |
||
| 2274 | |||
| 2275 | public function setSuperAdmin($boolean) |
||
| 2276 | { |
||
| 2277 | if (true === $boolean) { |
||
| 2278 | $this->addRole(static::ROLE_SUPER_ADMIN); |
||
| 2279 | } else { |
||
| 2280 | $this->removeRole(static::ROLE_SUPER_ADMIN); |
||
| 2281 | } |
||
| 2282 | |||
| 2283 | return $this; |
||
| 2284 | } |
||
| 2285 | |||
| 2286 | public function setPlainPassword($password) |
||
| 2287 | { |
||
| 2288 | $this->plainPassword = $password; |
||
| 2289 | |||
| 2290 | return $this; |
||
| 2291 | } |
||
| 2292 | |||
| 2293 | public function setLocked($boolean) |
||
| 2294 | { |
||
| 2295 | $this->locked = $boolean; |
||
| 2296 | |||
| 2297 | return $this; |
||
| 2298 | } |
||
| 2299 | |||
| 2300 | public function setPasswordRequestedAt(\DateTime $date = null) |
||
| 2301 | { |
||
| 2302 | $this->passwordRequestedAt = $date; |
||
| 2303 | |||
| 2304 | return $this; |
||
| 2305 | } |
||
| 2306 | |||
| 2307 | |||
| 2308 | public function setRoles(array $roles) |
||
| 2309 | { |
||
| 2310 | $this->roles = []; |
||
| 2311 | |||
| 2312 | foreach ($roles as $role) { |
||
| 2313 | $this->addRole($role); |
||
| 2314 | } |
||
| 2315 | |||
| 2316 | return $this; |
||
| 2317 | } |
||
| 2318 | |||
| 2319 | /** |
||
| 2320 | * Gets the groups granted to the user. |
||
| 2321 | * |
||
| 2322 | * @return Collection |
||
| 2323 | */ |
||
| 2324 | public function getGroups() |
||
| 2325 | { |
||
| 2326 | return $this->groups ?: $this->groups = new ArrayCollection(); |
||
| 2327 | } |
||
| 2328 | |||
| 2329 | public function getGroupNames() |
||
| 2330 | { |
||
| 2331 | $names = []; |
||
| 2332 | foreach ($this->getGroups() as $group) { |
||
| 2333 | $names[] = $group->getName(); |
||
| 2334 | } |
||
| 2335 | |||
| 2336 | return $names; |
||
| 2337 | } |
||
| 2338 | |||
| 2339 | public function hasGroup($name) |
||
| 2340 | { |
||
| 2341 | return in_array($name, $this->getGroupNames()); |
||
| 2342 | } |
||
| 2343 | |||
| 2344 | public function addGroup(GroupInterface $group) |
||
| 2351 | } |
||
| 2352 | |||
| 2353 | public function removeGroup(GroupInterface $group) |
||
| 2354 | { |
||
| 2355 | if ($this->getGroups()->contains($group)) { |
||
| 2356 | $this->getGroups()->removeElement($group); |
||
| 2357 | } |
||
| 2358 | |||
| 2359 | return $this; |
||
| 2360 | } |
||
| 2361 | |||
| 2362 | public function addRole($role) |
||
| 2363 | { |
||
| 2364 | $role = strtoupper($role); |
||
| 2365 | if ($role === static::ROLE_DEFAULT) { |
||
| 2366 | return $this; |
||
| 2367 | } |
||
| 2368 | |||
| 2369 | if (!in_array($role, $this->roles, true)) { |
||
| 2370 | $this->roles[] = $role; |
||
| 2371 | } |
||
| 2372 | |||
| 2373 | return $this; |
||
| 2374 | } |
||
| 2375 | |||
| 2376 | /** |
||
| 2377 | * Serializes the user. |
||
| 2378 | * |
||
| 2379 | * The serialized data have to contain the fields used by the equals method and the username. |
||
| 2380 | * |
||
| 2381 | * @return string |
||
| 2382 | */ |
||
| 2383 | public function serialize() |
||
| 2384 | { |
||
| 2385 | return serialize([ |
||
| 2386 | $this->password, |
||
| 2387 | $this->salt, |
||
| 2388 | $this->usernameCanonical, |
||
| 2389 | $this->username, |
||
| 2390 | $this->expired, |
||
| 2391 | $this->locked, |
||
| 2392 | $this->credentialsExpired, |
||
| 2393 | $this->enabled, |
||
| 2394 | $this->id, |
||
| 2395 | ]); |
||
| 2396 | } |
||
| 2397 | |||
| 2398 | /** |
||
| 2399 | * Unserializes the user. |
||
| 2400 | * |
||
| 2401 | * @param string $serialized |
||
| 2402 | */ |
||
| 2403 | public function unserialize($serialized) |
||
| 2404 | { |
||
| 2405 | $data = unserialize($serialized); |
||
| 2406 | // add a few extra elements in the array to ensure that we have enough keys when unserializing |
||
| 2407 | // older data which does not include all properties. |
||
| 2408 | $data = array_merge($data, array_fill(0, 2, null)); |
||
| 2409 | |||
| 2410 | list( |
||
| 2411 | $this->password, |
||
| 2412 | $this->salt, |
||
| 2413 | $this->usernameCanonical, |
||
| 2414 | $this->username, |
||
| 2415 | $this->expired, |
||
| 2416 | $this->locked, |
||
| 2417 | $this->credentialsExpired, |
||
| 2418 | $this->enabled, |
||
| 2419 | $this->id |
||
| 2420 | ) = $data; |
||
| 2421 | } |
||
| 2422 | |||
| 2423 | /** |
||
| 2424 | * Get achievedSkills |
||
| 2425 | * @return ArrayCollection |
||
| 2426 | */ |
||
| 2427 | public function getAchievedSkills() |
||
| 2428 | { |
||
| 2429 | return $this->achievedSkills; |
||
| 2430 | } |
||
| 2431 | |||
| 2432 | /** |
||
| 2433 | * Check if the user has the skill |
||
| 2434 | * @param Skill $skill The skill |
||
| 2435 | * @return boolean |
||
| 2436 | */ |
||
| 2437 | public function hasSkill(Skill $skill) |
||
| 2438 | { |
||
| 2439 | $achievedSkills = $this->getAchievedSkills(); |
||
| 2440 | |||
| 2441 | foreach ($achievedSkills as $userSkill) { |
||
| 2442 | if ($userSkill->getSkill()->getId() !== $skill->getId()) { |
||
| 2443 | continue; |
||
| 2444 | } |
||
| 2445 | return true; |
||
| 2446 | } |
||
| 2447 | } |
||
| 2448 | |||
| 2449 | /** |
||
| 2450 | * @return bool |
||
| 2451 | */ |
||
| 2452 | public function isProfileCompleted() |
||
| 2453 | { |
||
| 2454 | return $this->profileCompleted; |
||
| 2455 | } |
||
| 2456 | |||
| 2457 | /** |
||
| 2458 | * @param mixed $profileCompleted |
||
| 2459 | * @return User |
||
| 2460 | */ |
||
| 2461 | public function setProfileCompleted($profileCompleted) |
||
| 2462 | { |
||
| 2463 | $this->profileCompleted = $profileCompleted; |
||
| 2464 | |||
| 2465 | return $this; |
||
| 2466 | } |
||
| 2467 | |||
| 2468 | /** |
||
| 2469 | * Sets the AccessUrl for the current user in memory |
||
| 2470 | * @param AccessUrl $url |
||
| 2471 | * |
||
| 2472 | * @return $this |
||
| 2473 | */ |
||
| 2474 | public function setCurrentUrl(AccessUrl $url) |
||
| 2475 | { |
||
| 2476 | $urlList = $this->getPortals(); |
||
| 2477 | /** @var AccessUrlRelUser $item */ |
||
| 2478 | foreach ($urlList as $item) { |
||
| 2479 | if ($item->getPortal()->getId() == $url->getId()) { |
||
| 2480 | $this->currentUrl = $url; |
||
| 2481 | break; |
||
| 2482 | } |
||
| 2483 | } |
||
| 2484 | |||
| 2485 | return $this; |
||
| 2486 | } |
||
| 2487 | |||
| 2488 | /** |
||
| 2489 | * @return AccessUrl |
||
| 2490 | */ |
||
| 2491 | public function getCurrentUrl() |
||
| 2492 | { |
||
| 2493 | return $this->currentUrl; |
||
| 2494 | } |
||
| 2495 | |||
| 2496 | |||
| 2497 | /** |
||
| 2498 | * Get sessionAsGeneralCoach |
||
| 2499 | * @return ArrayCollection |
||
| 2500 | */ |
||
| 2501 | public function getSessionAsGeneralCoach() |
||
| 2504 | } |
||
| 2505 | |||
| 2506 | /** |
||
| 2507 | * Get the list of HRM who have assigned this user |
||
| 2508 | * @return array |
||
| 2509 | */ |
||
| 2510 | public function getHrm() |
||
| 2511 | { |
||
| 2512 | $em = \Database::getManager(); |
||
| 2513 | $qb = $em->createQueryBuilder(); |
||
| 2514 | |||
| 2515 | $hrmList = $qb |
||
| 2516 | ->select('uru') |
||
| 2517 | ->from('ChamiloCoreBundle:UserRelUser', 'uru') |
||
| 2518 | ->innerJoin('ChamiloCoreBundle:AccessUrlRelUser', 'auru', Join::WITH, 'auru.userId = uru.friendUserId') |
||
| 2519 | ->where( |
||
| 2520 | $qb->expr()->eq('auru.accessUrlId', api_get_current_access_url_id()) |
||
| 2521 | ) |
||
| 2522 | ->andWhere( |
||
| 2523 | $qb->expr()->eq('uru.userId', $this->id) |
||
| 2524 | ) |
||
| 2525 | ->andWhere( |
||
| 2526 | $qb->expr()->eq('uru.relationType', USER_RELATION_TYPE_RRHH) |
||
| 2527 | ) |
||
| 2528 | ->getQuery() |
||
| 2529 | ->getResult(); |
||
| 2530 | |||
| 2531 | return $hrmList; |
||
| 2532 | } |
||
| 2533 | } |
||
| 2534 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.