/** * Decorates the user in the provided cell * @param zibo\library\html\table\Cell $cell Cell to decorate * @param zibo\library\html\table\Row $row Row of the cell to decorate * @param integer $rowNumber Number of the current row * @param array $remainingRows Array with the values of the remaining rows * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingRows) { $user = $cell->getValue(); if (!$user instanceof UserData) { $cell->setValue(''); return; } $html = $user->username; if ($this->action) { $anchor = new Anchor($html, $this->action . $user->id); $html = $anchor->getHtml(); } $userEmail = $user->getUserEmail(); $userRoles = $user->getUserRoles(); $html .= '<div class="info">'; if ($userEmail) { $html .= $userEmail . '<br />'; } if (!$user->isActive) { $html .= $this->translator->translate(self::TRANSLATION_INACTIVE) . '<br />'; } if ($userRoles) { $roles = array(); foreach ($userRoles as $role) { $roles[] = $role->getRoleName(); } $html .= $this->translator->translate(self::TRANSLATION_ROLES) . ': ' . implode(', ', $roles); } $html .= '</div>'; $cell->setValue($html); }
/** * Decorates the role in the provided cell * @param zibo\library\html\table\Cell $cell Cell to decorate * @param zibo\library\html\table\Row $row Row of the cell to decorate * @param integer $rowNumber Number of the current row * @param array $remainingRows Array with the values of the remaining rows * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingRows) { $role = $cell->getValue(); if (!$role instanceof RoleData) { $cell->setValue(''); return; } $html = $role->name; if ($this->action) { $anchor = new Anchor($html, $this->action . $role->id); $html = $anchor->getHtml(); } if ($role->permissions || $role->isSuperRole) { $html .= '<div class="info">'; if ($role->isSuperRole) { $html .= $this->translator->translate(self::TRANSLATION_SUPER_ROLE) . '<br />'; } if ($role->permissions) { $permissions = array(); foreach ($role->permissions as $permission) { $permissions[] = $permission->getPermissionCode(); } asort($permissions); $html .= $this->translator->translate(self::TRANSLATION_PERMISSIONS) . ': ' . implode(', ', $permissions); } $html .= '</div>'; } $cell->setValue($html); }
/** * Gets the information about the fields of the index * @param zibo\library\orm\definition\Index $index * @return string */ private function getFieldsInfo(Index $index) { $info = ''; $fields = array_keys($index->getFields()); $numFields = count($fields); if ($numFields == 1) { $field = array_pop($fields); $info .= $this->translator->translate('orm.label.index.field.in', array('field' => $field)) . '<br />'; } else { $last = array_pop($fields); $first = implode(', ', $fields); $info .= $this->translator->translate('orm.label.index.fields.in', array('first' => $first, 'last' => $last)) . '<br />'; } return $info; }
/** * Gets the translation of the message * @param mixed $value Value of the cell * @return string|null The translation of the message to use for the confirmation, null if no message was set while constructing */ protected function processMessage($value) { if (!$this->message) { return null; } return $this->translator->translate($this->message); }
/** * Decorates the data in the cell * @param zibo\library\html\table\Cell $cell Cell to decorate * @param zibo\library\html\table\Row $row Row containing the cell * @param int $rowNumber Number of the current row * @param array $remainingValues Array with the values of the remaining rows of the table * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $data = $cell->getValue(); $title = '#' . $data->id . ': ' . $data->getJobClassName(); $anchor = new Anchor($title, $this->action . $data->id); $translationVars = array('queue' => $data->queue, 'date' => $this->locale->formatDate($data->dateAdded, 'j F Y H:i:s')); if ($data->dateScheduled) { $translationKey = self::TRANSLATION_INFO_SCHEDULED; $translationVars['scheduled'] = $this->locale->formatDate($data->dateScheduled, 'j F Y H:i:s'); } else { $translationKey = self::TRANSLATION_INFO; } $value = $anchor->getHtml(); $value .= '<div class="info">' . $this->translator->translate($translationKey, $translationVars) . '</div>'; $cell->setValue($value); }
/** * Decorates a cell which contains an Advertisement object * @param zibo\library\html\table\Cell $cell * @param zibo\library\html\table\Row $row * @param int $rowNumber * @param array $remainingValues * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $advertisement = $cell->getValue(); if (!$advertisement instanceof AdvertisementData) { return; } $cell->appendToClass('advertisement'); try { $image = new Image($advertisement->image); $image->appendToClass('data'); $image->setThumbnailer('crop', 50, 50); $value = $image->getHtml(); } catch (Exception $e) { $value = 'Could not load image: ' . $e->getMessage(); } $anchor = new Anchor($advertisement->name, $this->action . $advertisement->id); $value .= $anchor->getHtml(); if (!$advertisement->clicks) { $advertisement->clicks = '0'; } $translateParams = array('from' => $this->locale->formatDate($advertisement->dateStart), 'till' => $this->locale->formatDate($advertisement->dateStop), 'clicks' => $advertisement->clicks); $value .= '<div class="info">'; $value .= $advertisement->website . '<br />'; $value .= $this->translator->translate(self::TRANSLATION_DISPLAY, $translateParams) . '<br />'; $value .= $this->translator->translate(self::TRANSLATION_CLICKS, $translateParams); $value .= '</div>'; $cell->setValue($value); }
/** * Decorates the cell * @param zibo\library\html\table\Cell $cell Cell of the value to decorate * @param zibo\library\html\table\Row $row Row containing the cell * @param int $rowNumber Number of the current row * @param array $remainingValues Array containing the values of the remaining rows of the table * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $field = $cell->getValue(); if (!$field instanceof ModelField) { return; } $fieldName = $field->getName(); if ($this->fieldAction) { $anchor = new Anchor($fieldName, $this->fieldAction . $fieldName); $value = $anchor->getHtml(); } else { $value = $fieldName; } $value .= '<div class="info">'; if ($field instanceof RelationField) { if ($field instanceof BelongsToField) { $relationType = 'belongsTo'; } elseif ($field instanceof HasOneField) { $relationType = 'hasOne'; } else { if ($field instanceof HasManyField) { $relationType = 'hasMany'; } } $relationModelName = $field->getRelationModelName(); $linkModelName = $field->getLinkModelName(); $foreignKeyName = $field->getForeignKeyName(); if ($this->modelAction) { $anchor = new Anchor($relationModelName, $this->modelAction . $relationModelName); $relationModelName = $anchor->getHtml(); if ($linkModelName) { $anchor = new Anchor($linkModelName, $this->modelAction . $linkModelName); $linkModelName = $anchor->getHtml(); } } $parameters = array('type' => $relationType, 'model' => $relationModelName, 'link' => $linkModelName, 'foreignKey' => $foreignKeyName); if ($linkModelName) { if ($foreignKeyName) { $value .= $this->translator->translate('orm.label.relation.type.link.fk', $parameters); } else { $value .= $this->translator->translate('orm.label.relation.type.link', $parameters); } } else { if ($foreignKeyName) { $value .= $this->translator->translate('orm.label.relation.type.fk', $parameters); } else { $value .= $this->translator->translate('orm.label.relation.type', $parameters); } } } else { $value .= $this->translator->translate('orm.label.field.type', array('type' => $field->getType())) . '<br />'; $defaultValue = $field->getDefaultValue(); if (!String::isEmpty($defaultValue)) { $value .= $this->translator->translate('orm.label.value.default') . ': ' . $defaultValue; } } $value .= '</div>'; $cell->setValue($value); }
/** * Gets the HTML for a file * @param zibo\library\filesystem\File $file The file to get the HTML for * @return string The HTML of the file */ private function getFileHtml(File $file) { $html = $this->getNameHtml($file->getName(), self::CLASS_FILE, $this->fileAction); $html .= '<div class="info">'; $html .= '<span class="size">' . $this->translator->translate(self::TRANSLATION_SIZE) . ': ' . $this->formatter->formatSize($this->fileBrowser->getSize($file)) . '</span>'; $html .= '</div>'; return $html; }
/** * Gets the HTML of the dependencies of the module * @param string $id CSS id for the dependencies container * @param array $dependencies Array with Module instances with version info * @return HTML of the dependencies */ protected function getDependenciesHtml($id, $dependencies) { $dependenciesCount = count($dependencies); if (!$dependenciesCount) { return ''; } $label = $this->translator->translatePlural($dependenciesCount, self::TRANSLATION_DEPENDS); $anchor = new Anchor($label, '#'); $jQueryEscapedId = str_replace('.', '\\\\.', $id); $anchor->setAttribute('onclick', '$("#' . $jQueryEscapedId . '").slideToggle("normal"); return false;'); $html = '<div class="info">' . PHP_EOL; $html .= $anchor->getHtml() . PHP_EOL; $html .= '<div id="' . $id . '" style="display:none;"><ul>' . PHP_EOL; foreach ($dependencies as $dependency) { $html .= '<li>' . $dependency->getNamespace() . '.' . $dependency->getName() . ' ' . $dependency->getVersion() . '</li>' . PHP_EOL; } $html .= '</ul></div></div>'; return $html; }
/** * Gets the HTML of the provided modules * @param array $modules Array with the data of the modules * @param string $id Style id for the containing ul * @param string $class Style class for the containing div * @param string $labelModule The translation key for 1 module * @param string $labelModules The translation key for multiple modules * @return string The HTML of the provided modules */ private function getModulesHtml($modules, $id, $class, $labelModule, $labelModules) { $numModules = count($modules); if ($numModules == 0) { return ''; } if ($numModules == 1) { $label = $this->translator->translate($labelModule); } else { $label = $this->translator->translate($labelModules, array('number' => $numModules)); } $id .= ucfirst($class); $anchor = new Anchor($label, '#'); $anchor->setAttribute('id', $id); $html = '<div class="' . $class . '">'; $html .= $anchor->getHtml() . '<ul id="' . $id . 'List">'; foreach ($modules as $module) { $html .= '<li>' . $this->getNameHtml($module) . '</li>'; } $html .= '</ul></div>'; return $html; }
/** * Decorates a table cell by setting an anchor to the cell based on the cell's value * @param zibo\library\html\table\Cell $cell Cell to decorate * @param zibo\library\html\table\Row $row Row which will contain the cell * @param int $rowNumber Number of the row in the table * @param array $remainingValues Array containing the values of the remaining rows of the table * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $module = $cell->getValue(); if (!$module instanceof Module) { $cell->setValue(''); return; } $namespace = $module->getNamespace(); $name = $module->getName(); $version = $module->getVersion(); $ziboVersion = $module->getZiboVersion(); if (version_compare(Zibo::VERSION, $ziboVersion) === -1) { $label = $this->translator->translate(self::TRANSLATION_DEPENDENCY_ZIBO, array('version' => $ziboVersion)); $label = '<span class="newerZiboRequired">' . $label . '</span>'; $cell->setValue($label); return; } $urlParams = $namespace . '/' . $name . '/' . $version; if (!$this->installer->hasModule($namespace, $name)) { $label = $this->translator->translate(self::TRANSLATION_INSTALL, array('version' => $version)); $anchor = new Anchor($label, $this->installAction . $urlParams); $anchor = $anchor->getHtml(); $cell->setValue($anchor); return; } $installedModule = $this->installer->getModule($namespace, $name); $installedVersion = $installedModule->getVersion(); $versionCompare = version_compare($installedVersion, $version); if ($versionCompare === 0) { $value = '<span class="installed">' . $this->translator->translate(self::TRANSLATION_INSTALLED) . '</span>'; } elseif ($versionCompare === -1) { $label = $this->translator->translate(self::TRANSLATION_UPGRADE, array('version' => $version)); $anchor = new Anchor($label, $this->upgradeAction . $urlParams); $value = $anchor->getHtml(); } else { $value = '<span class="installedNewer">' . $this->translator->translate(self::TRANSLATION_INSTALLED_NEWER) . '</span>'; } $value .= '<div class="info">' . $this->translator->translate(self::TRANSLATION_VERSION_CURRENT, array('version' => $installedVersion)) . '</div>'; $cell->setValue($value); }
/** * Gets the information about the unlinked models of the provided table * @param string $tableName The name of the table * @return string The information about the unlinked models of the provided table */ private function getUnlinkedModelsInfo($tableName) { $info = ''; $model = ModelManager::getInstance()->getModel($tableName); $unlinkedModels = $model->getMeta()->getUnlinkedModels(); $numUnlinkedModels = count($unlinkedModels); if ($this->action) { foreach ($unlinkedModels as $index => $modelName) { $anchor = new Anchor($modelName, $this->action . $modelName); $unlinkedModels[$index] = $anchor->getHtml(); } } if ($numUnlinkedModels == 1) { $model = array_pop($unlinkedModels); $info .= $this->translator->translate('orm.label.unlinked.model', array('model' => $model)) . '<br />'; } elseif ($numUnlinkedModels) { $last = array_pop($unlinkedModels); $first = implode(', ', $unlinkedModels); $info .= $this->translator->translate('orm.label.unlinked.models', array('first' => $first, 'last' => $last)) . '<br />'; } return $info; }
/** * Get the HTML of the page numbers * @return string */ private function getPagesHtml() { $gaps = $this->getGaps(); $gap = null; $currentGap = null; $html = ''; if ($gaps) { $gap = array_pop($gaps); } for ($i = 1; $i <= $this->pages; $i++) { if ($i == $this->page) { $html .= "\t" . '<span class="' . $this->pageClass . '">' . $i . '</span>' . "\n"; continue; } $display = true; if ($currentGap != null && $currentGap['stop'] == $i) { $currentGap = null; if ($gaps) { $gap = array_pop($gaps); } $html .= "\t" . $this->ellipsis . "\n"; } elseif ($currentGap != null && ($currentGap['start'] < $i && $i < $currentGap['stop'])) { $display = false; } else { if ($gap != null && $gap['start'] == $i) { $currentGap = $gap; $gap = null; $display = false; } } if ($display) { $anchor = $this->createAnchor($i, $this->pageClass, $i); $anchor->setAttribute('title', $this->translator->translate(self::TRANSLATION_TITLE_PAGE, array('number' => $i))); $html .= "\t" . $anchor->getHtml() . "\n"; } } return $html; }
/** * Get the html for an anchor * @param string $href the href of the anchor * @param string $label the label for the anchor * @param boolean $translate true to translate the label * @param string $class Style class for the anchor * @return string html of the anchor */ private function getAnchorHtml($href, $label, $translate, $class = null, $id = null, $title = null) { if ($translate) { $label = $this->translator->translate($label); } if ($href != '#') { $href = $this->baseUrl . Module::ROUTE_JOPPA . $href; } if (!$label) { $label = 'N/A'; } $anchor = new Anchor($label, $href); if ($id) { $anchor->setId($id); } if ($class) { $anchor->appendToClass($class); } if ($title) { $anchor->setAttribute('title', $title); } return $anchor->getHtml(); }
/** * Sets a failure message to the provided cell * @param zibo\library\html\table\Cell $cell Cell to set a failure message to * @return null */ private function setFailureValue(Cell $cell, Exception $e) { $value = $this->translator->translate(self::TRANSLATION_FAILURE, array('message' => $e->getMessage())); $this->setValue($cell, $value, self::STYLE_FAILURE); }