Skip to content

Commit

Permalink
Merge pull request #6530 from laboro/fix/calendar_bundle_code_clear
Browse files Browse the repository at this point in the history
Code clear in CalendarBundle
  • Loading branch information
iklymenko committed Jan 15, 2016
2 parents 4688506 + 81d1847 commit c984724
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 62 deletions.
Expand Up @@ -138,11 +138,13 @@ protected function fixFormData(array &$data, $entity)
{
parent::fixFormData($data, $entity);

unset($data['calendarName']);
unset($data['removable']);
unset($data['canAddEvent']);
unset($data['canEditEvent']);
unset($data['canDeleteEvent']);
unset(
$data['calendarName'],
$data['removable'],
$data['canAddEvent'],
$data['canEditEvent'],
$data['canDeleteEvent']
);

return true;
}
Expand Down
Expand Up @@ -91,7 +91,7 @@ public function getItems($calendarId)
$result = $qb->getQuery()->getArrayResult();

// normalize integer foreign keys due Doctrine IDENTITY function always returns a string
if (!empty($intCasts)) {
if ($intCasts) {
foreach ($result as &$item) {
foreach ($intCasts as $fieldName) {
if (isset($item[$fieldName]) && is_string($item[$fieldName])) {
Expand Down
Expand Up @@ -45,16 +45,11 @@ public function __construct(
*/
public function getCalendarDefaultValues($organizationId, $userId, $calendarId, array $calendarIds)
{
$result = [];

if (!$this->calendarConfig->isPublicCalendarEnabled()) {
foreach ($calendarIds as $id) {
$result[$id] = null;
}

return $result;
return array_fill_keys($calendarIds, null);
}

$result = [];
/** @var SystemCalendarRepository $repo */
$repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:SystemCalendar');
$qb = $repo->getPublicCalendarsQueryBuilder();
Expand Down
Expand Up @@ -45,18 +45,13 @@ public function __construct(
*/
public function getCalendarDefaultValues($organizationId, $userId, $calendarId, array $calendarIds)
{
$result = [];

if (!$this->calendarConfig->isSystemCalendarEnabled()
|| !$this->securityFacade->isGranted('oro_system_calendar_view')
) {
foreach ($calendarIds as $id) {
$result[$id] = null;
}

return $result;
return array_fill_keys($calendarIds, null);
}

$result = [];
/** @var SystemCalendarRepository $repo */
$repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:SystemCalendar');

Expand Down Expand Up @@ -130,7 +125,7 @@ public function getCalendarEvents(
$invisibleIds[] = $id;
}
}
if (!empty($invisibleIds)) {
if ($invisibleIds) {
$qb
->andWhere('c.id NOT IN (:invisibleIds)')
->setParameter('invisibleIds', $invisibleIds);
Expand Down
Expand Up @@ -102,7 +102,7 @@ protected function serializeCalendarEvent(CalendarEvent $event, array $extraFiel
protected function applyAdditionalData(&$items, $calendarId)
{
$parentEventIds = $this->getParentEventIds($items);
if (!empty($parentEventIds)) {
if ($parentEventIds) {
/** @var CalendarEventRepository $repo */
$repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:CalendarEvent');
$invitees = $repo->getInvitedUsersByParentsQueryBuilder($parentEventIds)
Expand Down
11 changes: 2 additions & 9 deletions src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php
Expand Up @@ -57,8 +57,6 @@ public function getCalendarDefaultValues($organizationId, $userId, $calendarId,
// prohibit to remove the current calendar from the list of connected calendars
if ($calendar->getId() === $calendarId) {
$resultItem['removable'] = false;
}
if ($calendarId === $calendar->getId()) {
$resultItem['canAddEvent'] = true;
$resultItem['canEditEvent'] = true;
$resultItem['canDeleteEvent'] = true;
Expand Down Expand Up @@ -92,7 +90,7 @@ public function getCalendarEvents(
$visibleIds[] = $id;
}
}
if (!empty($visibleIds)) {
if ($visibleIds) {
$qb
->andWhere('c.id IN (:visibleIds)')
->setParameter('visibleIds', $visibleIds);
Expand All @@ -111,11 +109,6 @@ public function getCalendarEvents(
*/
protected function buildCalendarName(Calendar $calendar)
{
$name = $calendar->getName();
if (!$name) {
$name = $this->entityNameResolver->getName($calendar->getOwner());
}

return $name;
return $calendar->getName() ?: $this->entityNameResolver->getName($calendar->getOwner());
}
}
Expand Up @@ -36,11 +36,9 @@ protected function getProviders()
if (null === $this->sorted) {
ksort($this->providers);

if (empty($this->providers)) {
$this->sorted = [];
} else {
$this->sorted = call_user_func_array('array_merge', $this->providers);
}
$this->sorted = $this->providers
? call_user_func_array('array_merge', $this->providers)
: [];
}

return $this->sorted;
Expand Down
Expand Up @@ -35,7 +35,6 @@ public function processConfigs(DatagridConfiguration $config)
throw new \LogicException('Entity pagination is not boolean');
}

$pagination = $pagination ? true : false;
$config->offsetSetByPath(self::ENTITY_PAGINATION_PATH, $pagination);
$config->offsetSetByPath(self::ENTITY_PAGINATION_PATH, (bool)$pagination);
}
}
Expand Up @@ -58,15 +58,11 @@ public static function getPermission($scope)
{
switch ($scope) {
case self::VIEW_SCOPE:
$permission = 'VIEW';
break;
return 'VIEW';
case self::EDIT_SCOPE:
$permission = 'EDIT';
break;
default:
throw new \LogicException(sprintf('Scope "%s" is not available.', $scope));
return 'EDIT';
}

return $permission;
throw new \LogicException(sprintf('Scope "%s" is not available.', $scope));
}
}
10 changes: 3 additions & 7 deletions src/Oro/Bundle/EntityPaginationBundle/Manager/MessageManager.php
Expand Up @@ -150,19 +150,15 @@ protected function getStatsMessage($scope)
{
switch ($scope) {
case EntityPaginationManager::VIEW_SCOPE:
$message =
return
'oro.entity_pagination.message.' .
'stats_number_view_%count%_record|stats_number_view_%count%_records';
break;
case EntityPaginationManager::EDIT_SCOPE:
$message =
return
'oro.entity_pagination.message.' .
'stats_number_edit_%count%_record|stats_number_edit_%count%_records';
break;
default:
throw new \LogicException(sprintf('Scope "%s" is not available.', $scope));
}

return $message;
throw new \LogicException(sprintf('Scope "%s" is not available.', $scope));
}
}
8 changes: 3 additions & 5 deletions src/Oro/Bundle/UserBundle/Entity/AbstractRole.php
Expand Up @@ -25,11 +25,9 @@ abstract public function getPrefix();
*/
public function setRole($role, $generateUnique = true)
{
if ($generateUnique) {
$this->role = $this->generateUniqueRole($role);
} else {
$this->role = $this->addPrefix($this->normalize($role));
}
$this->role = $generateUnique
? $this->generateUniqueRole($role)
: $this->addPrefix($this->normalize($role));

return $this;
}
Expand Down
6 changes: 1 addition & 5 deletions src/Oro/Bundle/UserBundle/Entity/Group.php
Expand Up @@ -246,11 +246,7 @@ public function removeRole($role)
public function setRoles($roles)
{
if ($roles instanceof Collection) {
$this->roles->clear();

foreach ($roles as $role) {
$this->addRole($role);
}
$this->roles = new ArrayCollection($roles->toArray());
} elseif (is_array($roles)) {
$this->roles = new ArrayCollection($roles);
} else {
Expand Down

0 comments on commit c984724

Please sign in to comment.