/** * * @param Entity $entity * @param ValidationState $validationState */ public function __construct(Entity $entity, ValidationState $validationState, Request $request) { $this->entity = $entity; $this->request = $request; $this->configurationHelper = new ConfigurationHelper(); $this->configurationHelper->setCurrentTable($this->entity->getModelTable()->getModelTableName()); $this->validationState = $validationState; if ($this->entity->getPrimaryKey() == null || $this->entity->getPrimaryKey() == '') { $this->isNewEntity = true; } else { $this->isNewEntity = false; } $this->presetValues = array(); }
/** * * @param string $fieldName * @param Entity $entity * @param ValidationState $validationState */ public function __construct($fieldName, Entity $entity, Request $request, ValidationState $validationState) { $this->fieldName = $fieldName; $this->entity = $entity; $this->modelTable = $this->entity->getModelTable(); $this->request = $request; $this->fieldDefinitionHelper = $this->modelTable->getFieldDefinitionHelper(); $this->configurationHelper = new \PvikAdminTools\Library\ConfigurationHelper(); $this->configurationHelper->setCurrentTable($this->modelTable->getModelTableName()); $this->validationState = $validationState; if ($this->entity->getPrimaryKey() == null || $this->entity->getPrimaryKey() == '') { $this->isNewEntity = true; } else { $this->isNewEntity = false; } $this->preset = ''; }
/** * Adds a table row to the html. * @param Entity $entity */ protected function addHtmlTableRow(Entity $entity) { $this->html .= '<tr>'; $modelTable = $entity->getModelTable(); foreach ($this->configurationHelper->getFieldList() as $fieldName) { if ($this->configurationHelper->showInOverView($fieldName) && !in_array($fieldName, $this->hiddenFields)) { $type = $this->configurationHelper->getFieldType($fieldName); $fieldClassName = 'PvikAdminTools\\Library\\Fields\\' . $type; if (!class_exists($fieldClassName)) { throw new \Exception('PvikAdminTools: The type ' . $type . ' does not exists. Used for the field ' . $fieldName); } $field = new $fieldClassName($fieldName, $entity, $this->request, new ValidationState()); /* @var $field PvikAdminToolsBaseField */ $this->html .= '<td>' . $field->htmlOverview() . '</td>'; } } if ($this->configurationHelper->hasForeignTables()) { foreach ($this->configurationHelper->getForeignTables() as $foreignTableName => $foreignTable) { if (isset($foreignTable['ShowCountInOverview']) && $foreignTable['ShowCountInOverview'] == true) { // much faster than accessing view $entity->$foreignTableName->count // this would load the entire entries $this->html .= '<td>' . count($entity->getKeys(lcfirst($foreignTableName))) . '</td>'; } } } // add options $this->html .= '<td class="options">['; $editButtonUrl = \Pvik\Core\Path::relativePath('~' . \Pvik\Core\Config::$config['PvikAdminTools']['Url'] . 'tables/' . strtolower($modelTable->getModelTableName()) . ':edit:' . $entity->getPrimaryKey() . '/'); if ($this->buttonRedirectBack != null) { $editButtonUrl .= '?redirect-back-url=' . urlencode($this->buttonRedirectBack); } $this->html .= '<a href="' . $editButtonUrl . '">edit</a>|'; $deleteButtonUrl = \Pvik\Core\Path::relativePath('~' . \Pvik\Core\Config::$config['PvikAdminTools']['Url'] . 'tables/' . strtolower($modelTable->getModelTableName()) . ':delete:' . $entity->getPrimaryKey() . '/'); if ($this->buttonRedirectBack != null) { $deleteButtonUrl .= '?redirect-back-url=' . urlencode($this->buttonRedirectBack); } $this->html .= '<a href="' . $deleteButtonUrl . '" onclick="return confirm(\'Do you really want to delete this entry?\')">delete</a>'; $this->html .= ']</td>'; $this->html .= '</tr>'; }