public function saveGroupAccess($connection, $entity, $groupIds) { //todo verify relations $groupIds = array_values(array_unique($groupIds, SORT_REGULAR)); $entityTypeObj = ECP\EntityTypeQuery::create()->filterByName($this->entityType)->findOne(); $entityId = $entity->getId(); $groupAccessEntities = ECP\GroupAccessQuery::create()->filterByEntityId($entityId)->filterByEntityType($entityTypeObj)->find(); $existingGroups = array(); foreach ($groupAccessEntities as $groupAccessEntity) { $groupId = $groupAccessEntity->getGroupId(); if (in_array($groupId, $groupIds)) { $existingGroups[] = $groupId; } else { $groupAccessEntity->delete($connection); } } foreach ($groupIds as $groupId) { if (!in_array($groupId, $existingGroups)) { $groupAccessEntity = new ECP\GroupAccess(); $groupAccessEntity->setEntityType($entityTypeObj); $groupAccessEntity->setEntityId($entityId); $groupAccessEntity->setGroupId($groupId); $groupAccessEntity->save($connection); } } }
/** * @param ChildGroupAccess $groupAccess The ChildGroupAccess object to add. */ protected function doAddGroupAccess(ChildGroupAccess $groupAccess) { $this->collGroupAccesses[] = $groupAccess; $groupAccess->setEntityType($this); }
/** * Exclude object from result * * @param ChildGroupAccess $groupAccess Object to remove from the list of results * * @return $this|ChildGroupAccessQuery The current query, for fluid interface */ public function prune($groupAccess = null) { if ($groupAccess) { $this->addUsingAlias(GroupAccessTableMap::COL_ID, $groupAccess->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related \ECP\GroupAccess object * * @param \ECP\GroupAccess|ObjectCollection $groupAccess the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildGroupQuery The current query, for fluid interface */ public function filterByGroupAccess($groupAccess, $comparison = null) { if ($groupAccess instanceof \ECP\GroupAccess) { return $this->addUsingAlias(GroupTableMap::COL_ID, $groupAccess->getGroupid(), $comparison); } elseif ($groupAccess instanceof ObjectCollection) { return $this->useGroupAccessQuery()->filterByPrimaryKeys($groupAccess->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByGroupAccess() only accepts arguments of type \\ECP\\GroupAccess or Collection'); } }