12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229 |
- <?php
- namespace Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Doctrine\Common\Collections\Criteria;
- use Doctrine\Common\Collections\ArrayCollection;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Symfony\Component\Security\Core\User\AdvancedUserInterface;
- use Symfony\Component\Security\Core\User\EquatableInterface;
- use Symfony\Component\Validator\Mapping\ClassMetadata;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Symfony\Component\Validator\Constraints\DateTime;
- use ChamiloLMS\Component\Auth;
- /**
- * User
- *
- * @ORM\Table(name="user")
- * @ORM\Entity(repositoryClass="Entity\Repository\UserRepository")
- */
- class User implements AdvancedUserInterface, \Serializable , EquatableInterface
- {
- /**
- * @var integer
- *
- * @ORM\Column(name="user_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="IDENTITY")
- */
- private $userId;
- /**
- * @var string
- *
- * @ORM\Column(name="lastname", type="string", length=60, precision=0, scale=0, nullable=true, unique=false)
- */
- private $lastname;
- /**
- * @var string
- *
- * @ORM\Column(name="firstname", type="string", length=60, precision=0, scale=0, nullable=true, unique=false)
- */
- private $firstname;
- /**
- * @var string
- *
- * @ORM\Column(name="username", type="string", length=100, precision=0, scale=0, nullable=false, unique=false)
- */
- private $username;
- /**
- * @var string
- *
- * @ORM\Column(name="password", type="string", length=50, precision=0, scale=0, nullable=false, unique=false)
- */
- private $password;
- /**
- * @var string
- *
- * @ORM\Column(name="auth_source", type="string", length=50, precision=0, scale=0, nullable=true, unique=false)
- */
- private $authSource;
- /**
- * @var string
- *
- * @ORM\Column(name="email", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
- */
- private $email;
- /**
- * @var boolean
- *
- * @ORM\Column(name="status", type="integer", precision=0, scale=0, nullable=false, unique=false)
- */
- private $status;
- /**
- * @var string
- *
- * @ORM\Column(name="official_code", type="string", length=40, precision=0, scale=0, nullable=true, unique=false)
- */
- private $officialCode;
- /**
- * @var string
- *
- * @ORM\Column(name="phone", type="string", length=30, precision=0, scale=0, nullable=true, unique=false)
- */
- private $phone;
- /**
- * @var string
- *
- * @ORM\Column(name="picture_uri", type="string", length=250, precision=0, scale=0, nullable=true, unique=false)
- */
- private $pictureUri;
- /**
- * @var integer
- *
- * @ORM\Column(name="creator_id", type="integer", precision=0, scale=0, nullable=true, unique=false)
- */
- private $creatorId;
- /**
- * @var string
- *
- * @ORM\Column(name="competences", type="text", precision=0, scale=0, nullable=true, unique=false)
- */
- private $competences;
- /**
- * @var string
- *
- * @ORM\Column(name="diplomas", type="text", precision=0, scale=0, nullable=true, unique=false)
- */
- private $diplomas;
- /**
- * @var string
- *
- * @ORM\Column(name="openarea", type="text", precision=0, scale=0, nullable=true, unique=false)
- */
- private $openarea;
- /**
- * @var string
- *
- * @ORM\Column(name="teach", type="text", precision=0, scale=0, nullable=true, unique=false)
- */
- private $teach;
- /**
- * @var string
- *
- * @ORM\Column(name="productions", type="string", length=250, precision=0, scale=0, nullable=true, unique=false)
- */
- private $productions;
- /**
- * @var integer
- *
- * @ORM\Column(name="chatcall_user_id", type="integer", precision=0, scale=0, nullable=false, unique=false)
- */
- private $chatcallUserId;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="chatcall_date", type="datetime", precision=0, scale=0, nullable=false, unique=false)
- */
- private $chatcallDate;
- /**
- * @var string
- *
- * @ORM\Column(name="chatcall_text", type="string", length=50, precision=0, scale=0, nullable=false, unique=false)
- */
- private $chatcallText;
- /**
- * @var string
- *
- * @ORM\Column(name="language", type="string", length=40, precision=0, scale=0, nullable=true, unique=false)
- */
- private $language;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="registration_date", type="datetime", precision=0, scale=0, nullable=false, unique=false)
- */
- private $registrationDate;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="expiration_date", type="datetime", precision=0, scale=0, nullable=false, unique=false)
- */
- private $expirationDate;
- /**
- * @var boolean
- *
- * @ORM\Column(name="active", type="boolean", precision=0, scale=0, nullable=false, unique=false)
- */
- private $active;
- /**
- * @var string
- *
- * @ORM\Column(name="openid", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
- */
- private $openid;
- /**
- * @var string
- *
- * @ORM\Column(name="theme", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
- */
- private $theme;
- /**
- * @var integer
- *
- * @ORM\Column(name="hr_dept_id", type="smallint", precision=0, scale=0, nullable=false, unique=false)
- */
- private $hrDeptId;
- /**
- * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="user")
- **/
- private $courses;
- /**
- * @ORM\OneToMany(targetEntity="CItemProperty", mappedBy="user")
- **/
- private $items;
- /**
- * @ORM\OneToMany(targetEntity="UsergroupRelUser", mappedBy="user")
- **/
- private $classes;
- /**
- * @var ArrayCollection
- * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
- * @ORM\JoinTable(
- * name="users_roles",
- * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="user_id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
- * )
- */
- private $roles;
- /**
- * @ORM\Column(type="string", length=255)
- */
- private $salt;
- private $isActive;
- /**
- * @ORM\OneToMany(targetEntity="CurriculumItemRelUser", mappedBy="user")
- **/
- private $curriculumItems;
- /**
- * @ORM\ManyToMany(targetEntity="AccessUrl")
- * @ORM\JoinTable(name="access_url_rel_user",
- * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="user_id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="access_url_id", referencedColumnName="id")}
- * )
- */
- private $portals;
- /**
- *
- */
- public function __construct()
- {
- $this->courses = new ArrayCollection();
- $this->items = new ArrayCollection();
- $this->classes = new ArrayCollection();
- $this->roles = new ArrayCollection();
- $this->curriculumItems = new ArrayCollection();
- $this->salt = sha1(uniqid(null, true));
- $this->isActive = true;
- $this->registrationDate = new \DateTime();
- $this->curriculumItems = new ArrayCollection();
- $this->portals = new ArrayCollection();
- }
- /**
- * @param ClassMetadata $metadata
- */
- public static function loadValidatorMetadata(ClassMetadata $metadata)
- {
- $metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
- $metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
- $metadata->addPropertyConstraint('email', new Assert\Email());
- $metadata->addConstraint(new UniqueEntity(array(
- 'fields' => 'username',
- 'message' => 'This value is already used.',
- )));
- $metadata->addPropertyConstraint('username', new Assert\Length(array(
- 'min' => 2,
- 'max' => 50,
- '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.',
- '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.',
- )));
- }
- /**
- * @inheritDoc
- */
- public function isEqualTo(UserInterface $user)
- {
- if (!$user instanceof User) {
- return false;
- }
- if ($this->password !== $user->getPassword()) {
- return false;
- }
- if ($this->getSalt() !== $user->getSalt()) {
- return false;
- }
- if ($this->username !== $user->getUsername()) {
- return false;
- }
- return true;
- }
- /**
- * @return ArrayCollection
- */
- public function getPortals()
- {
- return $this->portals;
- }
- /**
- * @param $portal
- */
- public function setPortal($portal)
- {
- $this->portals->add($portal);
- }
- /**
- * @return ArrayCollection
- */
- public function getCurriculumItems()
- {
- return $this->curriculumItems;
- }
- /**
- * @param $items
- */
- public function setCurriculumItems($items)
- {
- $this->curriculumItems = $items;
- }
- /**
- * @return bool
- */
- public function getIsActive()
- {
- return $this->active == 1;
- }
- /**
- * @inheritDoc
- */
- public function isAccountNonExpired()
- {
- return true;
- /*$now = new \DateTime();
- return $this->getExpirationDate() < $now;*/
- }
- /**
- * @inheritDoc
- */
- public function isAccountNonLocked()
- {
- return true;
- }
- /**
- * @inheritDoc
- */
- public function isCredentialsNonExpired()
- {
- return true;
- }
- /**
- * @inheritDoc
- */
- public function isEnabled()
- {
- return $this->getActive() == 1;
- }
- /**
- * @inheritDoc
- */
- public function eraseCredentials()
- {
- }
- /**
- *
- * @return ArrayCollection
- */
- public function getRolesObj()
- {
- return $this->roles;
- }
- /**
- * This function is needed in order to pass roles to the security component
- * @inheritDoc
- */
- public function getRoles()
- {
- $roles = $this->roles->toArray();
- //$roles[] = new Auth\Role($this);
- return $roles;
- }
- /**
- * @param $role
- * @return $this
- */
- public function setRoles($role)
- {
- $this->roles->add($role);
- return $this;
- }
- /**
- * @see https://github.com/symfony/symfony/issues/3691
- * @see \Serializable::serialize()
- */
- public function serialize()
- {
- /*
- * ! Don't serialize $roles field !
- */
- return \serialize(
- array(
- $this->userId,
- $this->username,
- $this->email,
- $this->salt,
- $this->password,
- $this->isActive
- )
- );
- }
- /**
- * @see \Serializable::unserialize()
- */
- public function unserialize($serialized)
- {
- list (
- $this->userId,
- $this->username,
- $this->email,
- $this->salt,
- $this->password,
- $this->isActive
- ) = \unserialize($serialized);
- }
- /**
- * Set salt
- *
- * @param string $salt
- *
- * @return User
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- return $this;
- }
- /**
- * Get salt
- *
- * @return string
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * @return ArrayCollection
- */
- public function getClasses()
- {
- return $this->classes;
- }
- /**
- *
- */
- public function getLps()
- {
- //return $this->lps;
- /*$criteria = Criteria::create()
- ->where(Criteria::expr()->eq("id", "666"))
- //->orderBy(array("username" => "ASC"))
- //->setFirstResult(0)
- //->setMaxResults(20)
- ;
- $lps = $this->lps->matching($criteria);*/
- /*return $this->lps->filter(
- function($entry) use ($idsToFilter) {
- return $entry->getId() == 1;
- });*/
- }
- /**
- * @return string
- */
- public function getCompleteName()
- {
- return $this->lastname .', '. $this->firstname;
- }
- /**
- * Returns the list of classes for the user
- * @return string
- */
- public function getCompleteNameWithClasses()
- {
- $classSubscription = $this->getClasses();
- $classList = array();
- foreach ($classSubscription as $subscription) {
- $class = $subscription->getClass();
- $classList[] = $class->getName();
- }
- $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
- return $this->getCompleteName().$classString;
- }
- /**
- * Get userId
- *
- * @return integer
- */
- public function getUserId()
- {
- return $this->userId;
- }
- /**
- * Set lastname
- *
- * @param string $lastname
- *
- * @return User
- */
- public function setLastname($lastname)
- {
- $this->lastname = $lastname;
- return $this;
- }
- /**
- * Get lastname
- *
- * @return string
- */
- public function getLastname()
- {
- return $this->lastname;
- }
- /**
- * Set firstname
- *
- * @param string $firstname
- *
- * @return User
- */
- public function setFirstname($firstname)
- {
- $this->firstname = $firstname;
- return $this;
- }
- /**
- * Get firstname
- *
- * @return string
- */
- public function getFirstname()
- {
- return $this->firstname;
- }
- /**
- * Set username
- *
- * @param string $username
- * @return User
- */
- public function setUsername($username)
- {
- $this->username = $username;
- return $this;
- }
- /**
- * Get username
- *
- * @return string
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * Set password
- *
- * @param string $password
- * @return User
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Set authSource
- *
- * @param string $authSource
- * @return User
- */
- public function setAuthSource($authSource)
- {
- $this->authSource = $authSource;
- return $this;
- }
- /**
- * Get authSource
- *
- * @return string
- */
- public function getAuthSource()
- {
- return $this->authSource;
- }
- /**
- * Set email
- *
- * @param string $email
- * @return User
- */
- public function setEmail($email)
- {
- $this->email = $email;
- return $this;
- }
- /**
- * Get email
- *
- * @return string
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Set status
- *
- * @param boolean $status
- * @return User
- */
- public function setStatus($status)
- {
- $this->status = $status;
- return $this;
- }
- /**
- * Get status
- *
- * @return boolean
- */
- public function getStatus()
- {
- return $this->status;
- }
- /**
- * Set officialCode
- *
- * @param string $officialCode
- * @return User
- */
- public function setOfficialCode($officialCode)
- {
- $this->officialCode = $officialCode;
- return $this;
- }
- /**
- * Get officialCode
- *
- * @return string
- */
- public function getOfficialCode()
- {
- return $this->officialCode;
- }
- /**
- * Set phone
- *
- * @param string $phone
- * @return User
- */
- public function setPhone($phone)
- {
- $this->phone = $phone;
- return $this;
- }
- /**
- * Get phone
- *
- * @return string
- */
- public function getPhone()
- {
- return $this->phone;
- }
- /**
- * Set pictureUri
- *
- * @param string $pictureUri
- * @return User
- */
- public function setPictureUri($pictureUri)
- {
- $this->pictureUri = $pictureUri;
- return $this;
- }
- /**
- * Get pictureUri
- *
- * @return string
- */
- public function getPictureUri()
- {
- return $this->pictureUri;
- }
- /**
- * Set creatorId
- *
- * @param integer $creatorId
- * @return User
- */
- public function setCreatorId($creatorId)
- {
- $this->creatorId = $creatorId;
- return $this;
- }
- /**
- * Get creatorId
- *
- * @return integer
- */
- public function getCreatorId()
- {
- return $this->creatorId;
- }
- /**
- * Set competences
- *
- * @param string $competences
- * @return User
- */
- public function setCompetences($competences)
- {
- $this->competences = $competences;
- return $this;
- }
- /**
- * Get competences
- *
- * @return string
- */
- public function getCompetences()
- {
- return $this->competences;
- }
- /**
- * Set diplomas
- *
- * @param string $diplomas
- * @return User
- */
- public function setDiplomas($diplomas)
- {
- $this->diplomas = $diplomas;
- return $this;
- }
- /**
- * Get diplomas
- *
- * @return string
- */
- public function getDiplomas()
- {
- return $this->diplomas;
- }
- /**
- * Set openarea
- *
- * @param string $openarea
- * @return User
- */
- public function setOpenarea($openarea)
- {
- $this->openarea = $openarea;
- return $this;
- }
- /**
- * Get openarea
- *
- * @return string
- */
- public function getOpenarea()
- {
- return $this->openarea;
- }
- /**
- * Set teach
- *
- * @param string $teach
- * @return User
- */
- public function setTeach($teach)
- {
- $this->teach = $teach;
- return $this;
- }
- /**
- * Get teach
- *
- * @return string
- */
- public function getTeach()
- {
- return $this->teach;
- }
- /**
- * Set productions
- *
- * @param string $productions
- * @return User
- */
- public function setProductions($productions)
- {
- $this->productions = $productions;
- return $this;
- }
- /**
- * Get productions
- *
- * @return string
- */
- public function getProductions()
- {
- return $this->productions;
- }
- /**
- * Set chatcallUserId
- *
- * @param integer $chatcallUserId
- * @return User
- */
- public function setChatcallUserId($chatcallUserId)
- {
- $this->chatcallUserId = $chatcallUserId;
- return $this;
- }
- /**
- * Get chatcallUserId
- *
- * @return integer
- */
- public function getChatcallUserId()
- {
- return $this->chatcallUserId;
- }
- /**
- * Set chatcallDate
- *
- * @param \DateTime $chatcallDate
- * @return User
- */
- public function setChatcallDate($chatcallDate)
- {
- $this->chatcallDate = $chatcallDate;
- return $this;
- }
- /**
- * Get chatcallDate
- *
- * @return \DateTime
- */
- public function getChatcallDate()
- {
- return $this->chatcallDate;
- }
- /**
- * Set chatcallText
- *
- * @param string $chatcallText
- * @return User
- */
- public function setChatcallText($chatcallText)
- {
- $this->chatcallText = $chatcallText;
- return $this;
- }
- /**
- * Get chatcallText
- *
- * @return string
- */
- public function getChatcallText()
- {
- return $this->chatcallText;
- }
- /**
- * Set language
- *
- * @param string $language
- * @return User
- */
- public function setLanguage($language)
- {
- $this->language = $language;
- return $this;
- }
- /**
- * Get language
- *
- * @return string
- */
- public function getLanguage()
- {
- return $this->language;
- }
- /**
- * Set registrationDate
- *
- * @param \DateTime $registrationDate
- * @return User
- */
- public function setRegistrationDate($registrationDate)
- {
- $this->registrationDate = $registrationDate;
- return $this;
- }
- /**
- * Get registrationDate
- *
- * @return \DateTime
- */
- public function getRegistrationDate()
- {
- return $this->registrationDate;
- }
- /**
- * Set expirationDate
- *
- * @param \DateTime $expirationDate
- * @return User
- */
- public function setExpirationDate($expirationDate)
- {
- $this->expirationDate = $expirationDate;
- return $this;
- }
- /**
- * Get expirationDate
- *
- * @return \DateTime
- */
- public function getExpirationDate()
- {
- return $this->expirationDate;
- }
- /**
- * Set active
- *
- * @param boolean $active
- * @return User
- */
- public function setActive($active)
- {
- $this->active = $active;
- return $this;
- }
- /**
- * Get active
- *
- * @return boolean
- */
- public function getActive()
- {
- return $this->active;
- }
- /**
- * Set openid
- *
- * @param string $openid
- * @return User
- */
- public function setOpenid($openid)
- {
- $this->openid = $openid;
- return $this;
- }
- /**
- * Get openid
- *
- * @return string
- */
- public function getOpenid()
- {
- return $this->openid;
- }
- /**
- * Set theme
- *
- * @param string $theme
- * @return User
- */
- public function setTheme($theme)
- {
- $this->theme = $theme;
- return $this;
- }
- /**
- * Get theme
- *
- * @return string
- */
- public function getTheme()
- {
- return $this->theme;
- }
- /**
- * Set hrDeptId
- *
- * @param integer $hrDeptId
- * @return User
- */
- public function setHrDeptId($hrDeptId)
- {
- $this->hrDeptId = $hrDeptId;
- return $this;
- }
- /**
- * Get hrDeptId
- *
- * @return integer
- */
- public function getHrDeptId()
- {
- return $this->hrDeptId;
- }
- /**
- * @todo use SUM
- * @return int
- */
- public function getCurriculumScore()
- {
- $items = $this->getCurriculumItems();
- $scorePerCategory = array();
- $maxPerCategory = array();
- /** @var \Entity\CurriculumItemRelUser $itemRelUser */
- $mainParentList = array();
- $parentList = array();
- foreach ($items as $itemRelUser) {
- $parentId = $itemRelUser->getItem()->getCategory()->getParent()->getId();
- $mainParent = $itemRelUser->getItem()->getCategory()->getParent()->getParent();
- $mainParentList[$mainParent->getId()] = $mainParent->getMaxScore();
- $parentList[$parentId] = $mainParent->getId();
- if (!isset($scorePerCategory[$parentId])) {
- $scorePerCategory[$parentId] = 0;
- }
- $scorePerCategory[$parentId] += $itemRelUser->getItem()->getScore();
- if (!isset($scorePerCategory[$parentId])) {
- $maxPerCategory[$parentId] = 0;
- }
- $maxPerCategory[$parentId] =
- $itemRelUser->getItem()->getCategory()->getParent()->getMaxScore();
- }
- $newScorePerCategory = array();
- foreach ($scorePerCategory as $categoryId => $scoreInCategory) {
- $mainParentId = $parentList[$categoryId];
- if ($scoreInCategory >= $maxPerCategory[$categoryId]) {
- $score = $maxPerCategory[$categoryId];
- } else {
- $score = $scoreInCategory;
- }
- if (!isset($newScorePerCategory[$categoryId])) {
- $newScorePerCategory[$mainParentId][$categoryId] = 0;
- }
- $newScorePerCategory[$mainParentId][$categoryId] += $score;
- }
- $finalScore = 0;
- foreach ($newScorePerCategory as $mainParentId => $scoreList) {
- $maxScore = $mainParentList[$mainParentId];
- $subScore = 0;
- foreach ($scoreList as $score) {
- $subScore += $score;
- }
- if ($subScore >= $maxScore) {
- $finalScore += $maxScore;
- } else {
- $finalScore += $score;
- }
- }
- return $finalScore;
- }
- }
|