Admin_ClassController::objectbrickUpdateAction PHP Метод

objectbrickUpdateAction() публичный Метод

    public function objectbrickUpdateAction()
    {
        try {
            $key = $this->getParam("key");
            if ($this->getParam("task") == "add") {
                // check for existing brick with same name with different lower/upper cases
                $list = new Object\Objectbrick\Definition\Listing();
                $list = $list->load();
                foreach ($list as $item) {
                    if (strtolower($key) === strtolower($item->getKey())) {
                        throw new \Exception("Brick with the same name already exists (lower/upper cases may be different)");
                    }
                }
            }
            // now we create a new definition
            $fc = new Object\Objectbrick\Definition();
            $fc->setKey($key);
            if ($this->getParam("values")) {
                $values = \Zend_Json::decode($this->getParam("values"));
                $fc->setParentClass($values["parentClass"]);
                $fc->setClassDefinitions($values["classDefinitions"]);
            }
            if ($this->getParam("configuration")) {
                $configuration = \Zend_Json::decode($this->getParam("configuration"));
                $configuration["datatype"] = "layout";
                $configuration["fieldtype"] = "panel";
                $layout = Object\ClassDefinition\Service::generateLayoutTreeFromArray($configuration, true);
                $fc->setLayoutDefinitions($layout);
            }
            $fc->save();
            $this->_helper->json(["success" => true, "id" => $fc->getKey()]);
        } catch (\Exception $e) {
            Logger::error($e->getMessage());
            $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
        }
    }