private function fieldFacetVote(FieldFacet $fieldFacet, TokenInterface $token, $attribute) { $fieldFacetsByRole = $this->container->get('claroline.manager.facet_manager')->getVisibleFieldFacets(); $canEdit = false; $canOpen = false; foreach ($fieldFacetsByRole as $field) { if ($field['id'] === $fieldFacet->getId()) { $canEdit = $field['canEdit']; $canOpen = $field['canOpen']; } } if (strtolower($attribute) === 'edit') { return $fieldFacet->getIsEditableByOwner() | $canEdit ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED; } if (strtolower($attribute) === 'open') { return $fieldFacet->getIsVisibleByOwner() | $canOpen ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED; } return VoterInterface::ACCESS_DENIED; }
/** * This function will allow to set on of the boolean property of FieldFacetRole * for a fieldFacet and an array of roles. * * @param FieldFacet $fieldFacet * @param array $roles * @param $property (canOpen | canEdit) */ public function setFieldBoolProperty(FieldFacet $fieldFacet, array $roles, $property) { //find each fields sharing the same role as $fieldFacet $fieldFacetsRole = $fieldFacet->getFieldFacetsRole(); //get the correct setter $setterFunc = 'set' . ucfirst($property); //initialize an array of roles wich are not linked to the field $unknownRoles = array(); //initialize an array of fieldFacetRoles wich are going to have their property to true $fieldFacetRolesToChange = array(); //initialize each of field facets property to false foreach ($fieldFacetsRole as $fieldFacetRole) { $fieldFacetRole->{$setterFunc}(false); } //find roles wich are not linked to a field foreach ($roles as $role) { $found = false; foreach ($fieldFacetsRole as $fieldFacetRole) { if ($fieldFacetRole->getRole()->getId() === $role->getId()) { $found = true; $fieldFacetRolesToChange[] = $fieldFacetRole; } } if (!$found) { $unknownRoles[] = $role; } } //create a new FieldFacetRole for each missing role foreach ($unknownRoles as $unknownRole) { $ffr = new FieldFacetRole(); $ffr->setRole($unknownRole); $ffr->setFieldFacet($fieldFacet); //add the new fieldFacetRole to the list of retrieved fieldFacetRoles at the beginning $fieldFacetRolesToChange[] = $ffr; } //set the property correctly foreach ($fieldFacetRolesToChange as $ffr) { $ffr->{$setterFunc}(true); $this->om->persist($ffr); } $this->om->flush(); }
public function setFieldFacet(FieldFacet $ff) { $this->fieldFacet = $ff; $ff->addFieldChoice($this); }
/** * Returns the field role edition in a modal * * @EXT\Route("/field/{field}/roles/form", * name="claro_admin_field_role_form", * options = {"expose"=true} * ) * * @EXT\Template() */ public function fieldRolesFormAction(FieldFacet $field) { $fieldFacetsRole = $field->getFieldFacetsRole(); $platformRoles = $this->roleManager->getPlatformNonAdminRoles(true); return array('fieldFacetsRole' => $fieldFacetsRole, 'field' => $field, 'platformRoles' => $platformRoles); }
public function reorderChoices(FieldFacet $field) { $choices = $field->getFieldFacetChoices(); $order = 0; foreach ($choices as $choice) { $field->setPosition($order); ++$order; $this->om->persist($choice); } $this->om->flush(); }