Example #1
0
 public function getDataObject($name, $data)
 {
     $configuration = $this->loadConfiguration($name);
     if (!is_array($data) && !is_object($data)) {
         try {
             $data = Nette\Utils\Json::decode($data, Nette\Utils\Json::FORCE_ARRAY);
         } catch (Nette\Utils\JsonException $e) {
             throw new LogicException('Json::decode problem', Exception::JSON_DECODE, $e);
         }
     }
     $out = Factory::getItemObject(['type' => 'container', 'child' => $configuration], $data, $this->subTypes);
     $this->logObject($out->getRemovedItems(), $name);
     return $out;
 }
Example #2
0
 protected function sanitizeData($data, $first = false)
 {
     if (!isset($this->configuration['child'])) {
         throw new Contents\DomainException('Container has not defined child.', Contents\Exception::INCOMPLETE_CONFIGURATION);
     }
     $child = $this->configuration['child'];
     /** @var Base[] $out */
     $out = $this->data;
     foreach ($child as $k => $v) {
         if (isset($out[$k])) {
             $out[$k]->update(isset($data[$k]) ? $data[$k] : NULL);
         } else {
             $out[$k] = Contents\Factory::getItemObject($v, isset($data[$k]) ? $data[$k] : NULL, $this->subTypes);
         }
     }
     return $out;
 }
Example #3
0
 public function update($data)
 {
     if (isset($data[ListContainer::LIST_BOX])) {
         unset($data[ListContainer::LIST_BOX]);
     }
     if (isset($data[Base::NEW_ITEM_CONTENT])) {
         foreach ($data[Base::NEW_ITEM_CONTENT] as $newData) {
             $child = isset($this->configuration['child']) ? $this->configuration['child'] : (isset($this->configuration['listItem']) ? $this->configuration['listItem'] : NULL);
             $maxDataI = 0;
             for ($i = 0; $i < count($this->data); $i++) {
                 if (isset($this->data[$i]) && $i > $maxDataI) {
                     $maxDataI = $i;
                 }
             }
             $this->data[$maxDataI + 1] = Contents\Factory::getItemObject(['type' => 'container', 'child' => $child], NULL, $this->subTypes);
             $data[$maxDataI + 1] = $newData;
         }
         unset($data[Base::NEW_ITEM_CONTENT]);
     }
     if (isset($data[ListContainer::DELETE_ITEM])) {
         foreach ($data[ListContainer::DELETE_ITEM] as $k => $v) {
             if ($v) {
                 unset($data[$k]);
                 $this->removedData[$k] = $this->data[$k]->getRawContent();
                 $this->data[$k] = NULL;
             }
         }
         unset($data[ListContainer::DELETE_ITEM]);
     }
     parent::update($data);
     return;
 }