/**
  * {@inheritdoc}
  */
 public function match(ModelInterface $model = null, PropertyValueBag $input = null, PropertyInterface $property = null, LegendInterface $legend = null)
 {
     if (!$legend) {
         return false;
     }
     if ($legend->getPalette()) {
         $property = $legend->getPalette()->getProperty($this->propertyName);
     } else {
         $property = $legend->getProperty($this->propertyName);
     }
     return $property->isEditable($model, $input, $legend);
 }
Exemplo n.º 2
0
 /**
  * Finish the current property or set of properties.
  *
  * @param PropertyInterface|PropertyInterface[] $property Return the final property or set of properties.
  *
  * @return PaletteBuilder
  *
  * @throws DcGeneralRuntimeException When no property is stored in the builder.
  */
 public function finishProperty(&$property = null)
 {
     if (!$this->property) {
         throw new DcGeneralRuntimeException('Property is missing, please create a property first');
     }
     if ($this->condition) {
         $this->finishCondition();
     }
     $properties = is_object($this->property) ? array($this->property) : $this->property;
     foreach ($properties as $index => $tempProperty) {
         $event = new FinishPropertyEvent($tempProperty, $this);
         $this->dispatchEvent($event);
         $properties[$index] = $event->getProperty();
     }
     if ($this->legend) {
         $this->legend->addProperties($properties);
     }
     $property = $properties;
     $this->property = null;
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Determine if the passed legend is visible or collapsed.
  *
  * @param LegendInterface $legend       The legend.
  *
  * @param bool[]          $legendStates The states from the session.
  *
  * @return bool
  */
 private function isLegendVisible($legend, $legendStates)
 {
     if (array_key_exists($legend->getName(), $legendStates)) {
         return $legendStates[$legend->getName()];
     }
     return $legend->isInitialVisible();
 }
Exemplo n.º 4
0
 /**
  * Retrieve a property from a legend or create a new one.
  *
  * @param string          $name   The legend name.
  *
  * @param LegendInterface $legend The legend instance.
  *
  * @return PropertyInterface
  */
 protected function getProperty($name, $legend)
 {
     foreach ($legend->getProperties() as $property) {
         if ($property->getName() == $name) {
             return $property;
         }
     }
     $property = new Property($name);
     $legend->addProperty($property);
     return $property;
 }
Exemplo n.º 5
0
 /**
  * Fill a legend from a multidimensional array of properties.
  *
  * @param LegendInterface $legend     The legend.
  *
  * @param array           $properties The properties.
  *
  * @return void
  *
  * @throws DcGeneralInvalidArgumentException When an invalid property is encountered.
  */
 public static function fillLegend(LegendInterface $legend, array $properties)
 {
     foreach ($properties as $property) {
         if ($property instanceof PropertyInterface) {
             $legend->addProperty($property);
         } elseif (is_array($property)) {
             static::fillLegend($legend, $property);
         } else {
             $type = is_object($property) ? get_class($property) : gettype($property);
             throw new DcGeneralInvalidArgumentException('Property [' . $type . '] does not implement PropertyInterface');
         }
     }
 }