/** * Adds the confirmation message to the anchor * @param zibo\library\html\Anchor $anchor Generated anchor for the cell * @param mixed $value Value of the cell * @return null */ protected function processAnchor(Anchor $anchor, $value) { $message = $this->processMessage($value); if ($message) { $anchor->setAttribute('onclick', 'return confirm(\'' . $message . '\');'); } }
/** * 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); }
function smarty_function_link($params, &$smarty) { if (empty($params['name'])) { throw new Exception('No name parameter provided for the link'); } if (empty($params['href'])) { throw new Exception('No href parameter provided for the link'); } $name = $params['name']; $href = $params['href']; unset($params['name']); unset($params['href']); $title = $name; if (!empty($params['title'])) { $title = $params['title']; unset($params['title']); } $translator = I18n::getInstance()->getTranslator(); $name = $translator->translate($name); $title = $translator->translate($title); $anchor = new Anchor($name, $href); $anchor->setAttribute('title', $title); foreach ($params as $key => $value) { $anchor->setAttribute($key, $value); } return $anchor->getHtml(); }
/** * 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); }
/** * 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(); if (!$this->meta->isValidData($data)) { $cell->setValue(''); } $title = $this->meta->formatData($data, DataFormatter::FORMAT_TITLE); $teaser = ''; if ($this->hasTeaserFormat) { $teaser = $this->meta->formatData($data, DataFormatter::FORMAT_TEASER); } $value = $this->getImageHtml($data); if ($this->action) { if (!$title) { $title = $this->meta->getName() . ' ' . $data->id; } $anchor = new Anchor($title, $this->action . $data->id); $value .= $anchor->getHtml(); } else { $value .= $title; } if ($teaser) { $value .= '<div class="info">' . $teaser . '</div>'; } $cell->setValue($value); }
/** * Decorates the data into a locale overview * @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 all the values of the remaining rows of the table * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $data = $cell->getValue(); $value = ''; if (!$this->meta->isValidData($data)) { $cell->setValue($value); return; } if (isset($data->dataLocale) && $data->dataLocale != $this->currentLocale) { $row->appendToClass(self::STYLE_UNLOCALIZED); } $ids = $this->localizedModel->getLocalizedIds($data->id); foreach ($this->locales as $locale) { if (array_key_exists($locale, $ids)) { $localeString = '<strong>' . $locale . '</strong>'; } else { $localeString = $locale; } if ($this->action !== null) { $anchor = new Anchor($localeString, $this->action . '/' . $data->id . '/' . $locale); $localeString = $anchor->getHtml(); } $value .= ($value == '' ? '' : ' ') . $localeString; } $cell->setValue($value); }
/** * 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); }
public function testConstruct() { $label = 'label'; $href = '#'; $anchor = new Anchor($label); $this->assertEquals($label, $anchor->getLabel()); $this->assertEquals($href, $anchor->getHref()); }
/** * Decorates the cell containing a ForumRanking * @param Cell $cell * @param Row $row * @param integer $rowNumber * @param array $remainingValues * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $ranking = $cell->getValue(); $value = $ranking->name; if ($this->action) { $anchor = new Anchor($value, $this->action . $ranking->id); $value = $anchor->getHtml(); } $value .= '<div class="info">'; $value .= $this->translator->translate(self::TRANSLATION_POSTS, array('posts' => $ranking->numPosts, 'stars' => $ranking->stars)); $value .= '</div>'; $cell->setValue($value); }
/** * Gets the HTML to represent a namespace * @param zibo\repository\model\ModuleNamespace $namespace * @return string */ private function getNamespaceHtml(ModuleNamespace $namespace) { $value = $namespace->getName(); if ($this->action) { $action = $this->action . $value; $anchor = new Anchor($value, $action); $value = $anchor->getHtml(); } $value = $this->image . $value; $value .= '<div class="info">'; $value .= $this->translator->translatePlural($namespace->countModules(), self::TRANSLATION_MODULES); $value .= '</div>'; return $value; }
/** * Gets the HTML to represent a module * @param zibo\repository\model\Module $module * @return string */ private function getModuleHtml(Module $module) { $value = $module->getName(); if ($this->action) { $action = $this->action . $value; $anchor = new Anchor($value, $action); $value = $anchor->getHtml(); } $value = $this->image . $value; $value .= '<div class="info">'; $value .= $this->translator->translate(self::TRANSLATION_VERSION, array('version' => $module->getVersion())); $value .= '</div>'; return $value; }
/** * Decorates a connection with it's definition * @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 $remainingValues Array containing the values of the remaining rows of the table * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $connection = $cell->getValue(); $dsn = $connection->getDriver()->getDsn()->__toString(); $value = $connection->getName(); if ($value == $this->defaultConnection) { $value = '<strong>' . $value . '</strong>'; } if ($this->action) { $anchor = new Anchor($value, $this->action . $connection->getName()); $value = $anchor->getHtml(); } $value .= '<div class="info">' . $dsn . '</div>'; $cell->setValue($value); }
/** * 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 the permission 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) { $permission = $cell->getValue(); if (!$permission instanceof PermissionData) { $cell->setValue(''); return; } $html = $permission->getPermissionDescription(); if ($this->action) { $anchor = new Anchor($html, $this->action . $permission->id); $html = $anchor->getHtml(); } $html .= '<div class="info">'; $html .= $permission->getPermissionCode(); $html .= '</div>'; $cell->setValue($html); }
/** * Decorates the cell of a data format * @param zibo\library\html\table\Cell $cell Cell containing 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) { $dataFormat = $cell->getValue(); if (!$dataFormat instanceof DataFormat) { return; } $dataFormatName = $dataFormat->getName(); if ($this->action) { $anchor = new Anchor($dataFormatName, $this->action . $dataFormatName); $value = $anchor->getHtml(); } else { $value = $dataFormatName; } $value .= '<div class="info">'; $value .= $dataFormat->getFormat(); $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 $values) { $index = $cell->getValue(); if (!$index instanceof Index) { return; } $indexName = $index->getName(); if ($this->action) { $anchor = new Anchor($indexName, $this->action . $indexName); $value = $anchor->getHtml(); } else { $value = $indexName; } $value .= '<div class="info">'; $value .= $this->getFieldsInfo($index); $value .= '</div>'; $cell->setValue($value); }
/** * 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 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 containing the values of the remaining rows of the table * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $log = $cell->getValue(); $value = $log->dataModel . ' #' . $log->dataId; if ($this->action) { $anchor = new Anchor($value, $this->action . $log->id); $value = $anchor->getHtml(); } $data = null; try { $model = $this->modelManager->getModel($log->dataModel); $data = $this->logModel->getDataByVersion($log->dataModel, $log->dataId, $log->dataVersion); $data = $model->getMeta()->formatData($data); } catch (Exception $exception) { Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1); } if (!$data) { $data = '---'; } $value .= '<div class="info">' . $data . '</div>'; $cell->setValue($value); }
/** * 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); }
/** * Create a new page anchor * @param string $label label for the anchor * @param string $class style class for the anchor * @param int $page page number to link to * @return zibo\library\html\Anchor */ private function createAnchor($label, $class, $page) { $anchor = new Anchor($label); if ($this->onclick) { $anchor->setAttribute('onclick', str_replace('%page%', $page, $this->onclick)); } if ($this->href) { $anchor->setAttribute('href', str_replace('%page%', $page, $this->href)); } $anchor->setClass($class); return $anchor; }
/** * 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(); }
/** * 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 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; }