/** * Validates the form. * * @param array $data Data to validate. * @param bool $skipEntityCreation Skip entity creation. * * @return boolean */ public function isValid($data = null, $skipEntityCreation = true) { if (!$data) { $data = $this->getDI()->getRequest()->getPost(); } // Check package location. $packageManager = new Manager(); $path = $packageManager->getPackageLocation($data['type']); if (!is_writable($path)) { $this->addError('Can not create package. Package location isn\'t writable: ' . $path); $this->setValues($data); return false; } // Also check that config file is writable. if (!is_writable(ROOT_PATH . Config::CONFIG_PATH)) { $this->addError('Configuration file isn\'t writable...'); $this->setValues($data); return false; } if (isset($data['type']) && $data['type'] == 'widget' && !$this->hasEntity('widget')) { $this->addEntity(new WidgetModel(), 'widget'); } if (!parent::isValid($data, $skipEntityCreation)) { return false; } // Check package existence. $id = $this->getEntity()->id; $condition = "type='{$data['type']}' AND name='{$data['name']}'" . ($id ? " AND id!='{$id}'" : ''); if (Package::findFirst($condition)) { $this->addError('Package with that name already exist!'); return false; } // Check widget existence. if ($this->hasEntity('widget')) { $name = ucfirst($data['name']); $id = $this->getEntity('widget')->id; $condition = "module='{$data['module']}' AND name='{$name}'" . ($id ? " AND id!='{$id}'" : ''); if (WidgetModel::findFirst($condition)) { $this->addError('Widget with that name already exist!'); return false; } } return true; }