forked from litecommerce/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profile.php
139 lines (119 loc) · 4.03 KB
/
Profile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
// vim: set ts=4 sw=4 sts=4 et:
/**
* LiteCommerce
*
* NOTICE OF LICENSE
*
* This source file is subject to the GNU General Pubic License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/gpl-2.0.html
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to licensing@litecommerce.com so we can send you a copy immediately.
*
* PHP version 5.3.0
*
* @category LiteCommerce
* @author Creative Development LLC <info@cdev.ru>
* @copyright Copyright (c) 2011-2012 Creative Development LLC <info@cdev.ru>. All rights reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Pubic License (GPL 2.0)
* @link http://www.litecommerce.com/
*/
namespace XLite\Module\CDev\DrupalConnector\Model;
/**
* \XLite\Module\CDev\DrupalConnector\Model\Profile
*
*/
class Profile extends \XLite\Model\Profile implements \XLite\Base\IDecorator
{
/**
* User roles defined on Drupal side
*
* @var \XLite\Module\CDev\DrupalConnector\Model\DrupalRole
*
* @OneToMany (targetEntity="XLite\Module\CDev\DrupalConnector\Model\DrupalRole", mappedBy="profile", cascade={"all"})
*/
protected $drupalRoles;
/**
* Get CMS profile
*
* @return object|void
*/
public function getCMSProfile()
{
return \XLite\Module\CDev\DrupalConnector\Handler::getInstance()->checkCurrentCMS() && $this->getCMSProfileId()
? user_load($this->getCMSProfileId())
: null;
}
/**
* Update user's Drupal roles
*
* @param array $newDrupalRoles Array of Drupal role IDs
*
* @return void
*/
public function updateDrupalRoles($newDrupalRoles)
{
$processedRoles = array();
$drupalRoles = $this->getDrupalRoles();
if ($drupalRoles) {
// Remove roles that is not in new roles array
foreach ($this->getDrupalRoles() as $key => $drupalRole) {
if (!in_array($drupalRole->getDrupalRoleId(), $newDrupalRoles)) {
$this->drupalRoles->remove($key);
\XLite\Core\Database::getEM()->remove($drupalRole);
} else {
$processedRoles[] = $drupalRole->getDrupalRoleId();
}
}
}
// Get roles to add
$rolesToAdd = array_diff($newDrupalRoles, $processedRoles);
// Create new roles
foreach ($rolesToAdd as $roleId) {
$newDrupalRole = new \XLite\Module\CDev\DrupalConnector\Model\DrupalRole();
$newDrupalRole->setProfile($this);
$newDrupalRole->setDrupalRoleId($roleId);
$this->addDrupalRoles($newDrupalRole);
}
}
/**
* Set CMS name property before profile updating
*
* @param boolean $cloneMode Flag which means that update is launched in clone mode OPTIONAL
*
* @return boolean
*/
public function update($cloneMode = false)
{
if (\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->checkCurrentCMS()) {
$this->setCmsName(\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->getCMSName());
}
return parent::update($cloneMode);
}
/**
* Set CMS name property before profile creation
*
* @return void
*/
protected function prepareCreate()
{
parent::prepareCreate();
if (\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->checkCurrentCMS()) {
$this->setCmsName(\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->getCMSName());
}
}
/**
* Allow to suppress 'email already exists...' message in some cases (e.g. in user sync process)
*
* @return void
*/
protected function addErrorEmailExists()
{
if (!defined('LC_SUPPRESS_EMAIL_ALREADY_EXISTS_MESSAGE')) {
parent::addErrorEmailExists();
}
}
}