本文整理汇总了PHP中Nette\Utils\Strings::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::truncate方法的具体用法?PHP Strings::truncate怎么用?PHP Strings::truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Strings
的用法示例。
在下文中一共展示了Strings::truncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValue
/**
* Sets selected items (by keys).
* @param array
* @return self
*/
public function setValue($values)
{
if (is_scalar($values) || $values === NULL) {
$values = (array) $values;
} elseif (!is_array($values)) {
throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
}
$flip = [];
foreach ($values as $value) {
if (!is_scalar($value) && !method_exists($value, '__toString')) {
throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
}
$flip[(string) $value] = TRUE;
}
$values = array_keys($flip);
if ($this->checkAllowedValues && ($diff = array_diff($values, array_keys($this->items)))) {
$set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
return var_export($s, TRUE);
}, array_keys($this->items))), 70, '...');
$vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed set [{$set}] in field '{$this->name}'.");
}
$this->value = $values;
return $this;
}
示例2: render
/**
* Format text column cell
* @param mixed $value
* @param mixed $rowData
* @return mixed|string
*/
public function render($value, $rowData)
{
$value = parent::render($value, $rowData);
// Truncate content
$value = $this->maxLength > 0 ? Strings::truncate($value, $this->maxLength) : $value;
return $value;
}
示例3: generateTree
/**
* Generate dir structure tree
*
* @param string $dir Path to root dir
* @param boolean $showFiles Show files
*
* @return \Nette\Utils\Html
*/
private function generateTree($dir, $showFiles = true)
{
if (!is_dir($dir)) {
throw new \Exception("Directory '{$dir}' does not exist!");
}
if ($showFiles) {
$files = Finder::find("*")->in($dir);
} else {
$files = Finder::findDirectories("*")->in($dir);
}
$list = Html::el("ul");
foreach ($files as $file) {
// Create file link
$link = Html::el("a")->href($file->getRealPath())->title($file->getRealPath());
if ($file->isDir()) {
$link[0] = Html::el("i")->class("icon-folder-open");
} else {
$link[0] = Html::el("i")->class("icon-file");
}
$link[1] = Html::el("span", Strings::truncate($file->getFileName(), 30));
// Create item in list
$item = Html::el("li");
$item[0] = $link;
if ($file->isDir()) {
$item[1] = $this->generateTree($file->getPathName(), $showFiles);
}
$list->add($item);
}
return $list;
}
示例4: setTruncate
/**
* @param string $maxLen UTF-8 encoding
* @param string $append UTF-8 encoding
* @return Column
*/
public function setTruncate($maxLen, $append = "…")
{
$this->truncate = function ($string) use($maxLen, $append) {
return \Nette\Utils\Strings::truncate($string, $maxLen, $append);
};
return $this;
}
示例5: setValue
public function setValue($values)
{
if (is_scalar($values) || $values === NULL) {
$values = (array) $values;
} elseif (!is_array($values)) {
throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
}
$flip = array();
foreach ($values as $value) {
if (!is_scalar($value) && !method_exists($value, '__toString')) {
throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
}
$flip[(string) $value] = TRUE;
}
$values = array_keys($flip);
$items = $this->items;
$nestedKeys = array();
array_walk_recursive($items, function ($value, $key) use(&$nestedKeys) {
$nestedKeys[] = $key;
});
if ($diff = array_diff($values, $nestedKeys)) {
$range = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
return var_export($s, TRUE);
}, $nestedKeys)), 70, '...');
$vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed range [{$range}] in field '{$this->name}'.");
}
$this->value = $values;
return $this;
}
示例6: formatContent
/**
* Formats cell's content.
* @param mixed
* @param \DibiRow|array
* @return string
*/
public function formatContent($value, $data = NULL)
{
$value = htmlSpecialChars($value);
if (is_array($this->replacement) && !empty($this->replacement)) {
if (in_array($value, array_keys($this->replacement))) {
$value = $this->replacement[$value];
}
}
foreach ($this->formatCallback as $callback) {
if (is_callable($callback)) {
$value = call_user_func($callback, $value, $data);
}
}
// translate & truncate
if ($value instanceof Nette\Utils\Html) {
$text = $this->dataGrid->translate($value->getText());
if ($this->maxLength != 0) {
$text = Nette\Utils\Strings::truncate($text, $this->maxLength);
}
$value->setText($text);
$value->title = $this->dataGrid->translate($value->title);
} else {
if ($this->maxLength != 0) {
$value = Nette\Utils\Strings::truncate($value, $this->maxLength);
}
}
return $value;
}
示例7: renderDefault
public function renderDefault()
{
$trips = $this->mapModel->loadTrips($this->user->id);
$categories = $this->mapModel->loadCategories($this->user->id);
$newTrips = [];
foreach ($trips as $trip) {
// if ($trip->duration == 1) {
// $duration = $trip->duration.' den';
// } elseif ($trip->duration < 5) {
// $duration = $trip->duration.' dny';
// } else {
// $duration = $trip->duration.' dní';
// }
if ($trip->category_id) {
$color = ['red' => $categories[$trip->category_id]->red, 'green' => $categories[$trip->category_id]->green, 'blue' => $categories[$trip->category_id]->blue];
} else {
$color = ['red' => 0, 'green' => 0, 'blue' => 0];
}
$lol = Utils\Strings::truncate($trip->name, 20);
$newTrips[] = ['id' => $trip->id, 'polygon' => $trip->polygon, 'color' => $color, 'info' => ['name' => $trip->name, 'date' => $trip->date->format('d. m. Y'), 'length' => $trip->lenght, 'duration' => $trip->duration, 'text' => $trip->text, 'category' => $trip->category_id ? $categories[$trip->category_id]->name : NULL, 'categoryId' => $trip->category_id ? $trip->category_id : NULL]];
}
$this->template->trips = $newTrips;
$this->template->showModal = FALSE;
$this['newTripForm']->setDefaults(['name' => ' ', 'text' => ' ', 'lenght' => ' ']);
$this->redrawControl("newTrip");
}
示例8: StringTruncate
/**
* Truncate value to $max character and return string or null
*
* @param string $value
* @param integer $max
*
* @return string|null
*/
protected function StringTruncate($value, $max = 255)
{
if ($value) {
return (string) Strings::truncate($value, $max, "");
} else {
return null;
}
}
示例9: getPanel
public function getPanel()
{
$this->disabled = TRUE;
$s = '';
$h = 'htmlSpecialChars';
foreach ($this->queries as $i => $query) {
list($sql, $params, $time, $rows, $connection, $source) = $query;
$explain = NULL;
// EXPLAIN is called here to work SELECT FOUND_ROWS()
if ($this->explain && preg_match('#\\s*\\(?\\s*SELECT\\s#iA', $sql)) {
try {
$cmd = is_string($this->explain) ? $this->explain : 'EXPLAIN';
$explain = $connection->queryArgs("{$cmd} {$sql}", $params)->fetchAll();
} catch (\PDOException $e) {
}
}
$s .= '<tr><td>' . sprintf('%0.3f', $time * 1000);
if ($explain) {
static $counter;
$counter++;
$s .= "<br /><a href='#' class='nette-toggler' rel='#nette-DbConnectionPanel-row-{$counter}'>explain ►</a>";
}
$s .= '</td><td class="nette-DbConnectionPanel-sql">' . Helpers::dumpSql(self::$maxLength ? Nette\Utils\Strings::truncate($sql, self::$maxLength) : $sql);
if ($explain) {
$s .= "<table id='nette-DbConnectionPanel-row-{$counter}' class='nette-collapsed'><tr>";
foreach ($explain[0] as $col => $foo) {
$s .= "<th>{$h($col)}</th>";
}
$s .= "</tr>";
foreach ($explain as $row) {
$s .= "<tr>";
foreach ($row as $col) {
$s .= "<td>{$h($col)}</td>";
}
$s .= "</tr>";
}
$s .= "</table>";
}
if ($source) {
$s .= Nette\Diagnostics\Helpers::editorLink($source[0], $source[1])->class('nette-DbConnectionPanel-source');
}
$s .= '</td><td>';
foreach ($params as $param) {
$s .= Debugger::dump($param, TRUE);
}
$s .= '</td><td>' . $rows . '</td></tr>';
}
return empty($this->queries) ? '' : '<style> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important }
#nette-debug .nette-DbConnectionPanel-source { color: #BBB !important }
#nette-debug nette-DbConnectionPanel tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
<h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1>
<div class="nette-inner nette-DbConnectionPanel">
<table>
<tr><th>Time ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
</table>
</div>';
}
示例10: setValue
/**
* Sets selected item (by key).
* @param scalar
* @return self
*/
public function setValue($value)
{
if ($value !== NULL && !array_key_exists((string) $value, $this->items)) {
$set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');
throw new Nette\InvalidArgumentException("Value '$value' is out of allowed set [$set] in field '{$this->name}'.");
}
$this->value = $value === NULL ? NULL : key(array((string) $value => NULL));
return $this;
}
示例11: parseMedia
private static function parseMedia($word)
{
$parts = explode(':\'', $word);
if (!isset($parts[1])) {
$parts = explode(':"', $word);
}
$media = $parts[1];
$media = Strings::truncate($media, strlen($media) - 1, null);
return $media;
}
示例12: getArticles
public function getArticles($menuId, $fullArticleId = NULL)
{
$sql = "SELECT a.id,[text] AS html FROM article a\n\t\t\tJOIN name_has_text nht ON a.name_id=nht.name_id AND language_id=%i\n\t\t\tJOIN text t ON t.id=nht.text_id\n\t\t\tWHERE menu_id=%i\n\t\t\tORDER BY a.sort ASC,a.id DESC";
$rows = $this->db->query($sql, $this->getLanguageId(), $menuId)->fetchAll();
foreach ($rows as &$row) {
if ($row['id'] != $fullArticleId) {
$row['html'] = strip_tags($row['html'], '<h2>');
$row['html'] = \Nette\Utils\Strings::truncate($row['html'], 1024);
}
}
return $rows;
}
示例13: processUpdate
/**
* @param \NetteAddons\Model\Importers\IAddonVersionsImporter
* @param string
* @param int
*/
private function processUpdate(IAddonVersionsImporter $addonVersionImporter, $url, $id)
{
try {
$this->db->beginTransaction();
$addon = $addonVersionImporter->getAddon($url);
/** @var \Nette\Database\Table\ActiveRow $row */
$row = $this->db->table('addons')->get($id);
if (!$row) {
$this->db->rollBack();
return;
}
$row->update(array('composerVendor' => $addon->getComposerVendor(), 'composerName' => $addon->getComposerName(), 'shortDescription' => Strings::truncate($addon->getPerex(), 250), 'stars' => $addon->getStars()));
$this->db->table('addons_versions')->where('addonId = ?', $id)->delete();
$row = $this->db->table('addons_resources')->where('addonId = ? AND type = ?', $id, AddonResources::RESOURCE_PACKAGIST)->fetch();
if ($row) {
if ($addon->getPackagist() === null) {
$row->delete();
} else {
$row->update(array('resource' => $addon->getPackagist()));
}
} elseif ($addon->getPackagist() !== null) {
$this->db->table('addons_resources')->insert(array('addonId' => $id, 'type' => AddonResources::RESOURCE_PACKAGIST, 'resource' => $addon->getPackagist()));
}
$row = $this->db->table('addons_resources')->where('addonId = ? AND type = ?', $id, AddonResources::RESOURCE_GITHUB)->fetch();
if ($row) {
if ($addon->getGithub() === null) {
$row->delete();
} else {
$row->update(array('resource' => $addon->getGithub()));
}
} elseif ($addon->getGithub() !== null) {
$this->db->table('addons_resources')->insert(array('addonId' => $id, 'type' => AddonResources::RESOURCE_GITHUB, 'resource' => $addon->getGithub()));
}
foreach ($addon->getVersions() as $version) {
/** @var \Nette\Database\Table\ActiveRow $row */
$row = $this->db->table('addons_versions')->insert(array('addonId' => $id, 'version' => $version->getVersion(), 'license' => implode(', ', $version->getLicenses()), 'distType' => 'zip', 'distUrl' => 'https://nette.org', 'updatedAt' => new DateTime(), 'composerJson' => ''));
if (!$row) {
$this->db->rollBack();
return;
}
foreach ($version->getDependencies() as $dependency) {
// @todo addon link
$this->db->table('addons_dependencies')->insert(array('versionId' => $row->id, 'packageName' => $dependency->getDependencyName(), 'version' => $dependency->getDependencyVersion(), 'type' => $dependency->getType()));
}
}
$this->db->commit();
} catch (\Exception $e) {
Debugger::log($e);
$this->db->rollBack();
}
}
示例14: addNewQueries
public function addNewQueries($description, $queries)
{
// create new file and save queries there
$time = time();
$filename = $time . '_' . Strings::webalize(Strings::truncate($description, 30)) . '.sql';
file_put_contents($this->changelogPath . $filename, $queries);
// save queries into database table changelog
$queries = explode(';', $queries);
foreach ($queries as $query) {
$query = trim($query);
if (empty($query)) {
continue;
}
$data = array('file' => $filename, 'description' => $description, 'query' => $query, 'executed' => 1, 'ins_timestamp' => $time, 'ins_dt' => new \DateTime(), 'ins_process_id' => 'DbChangelog::addNewQueries');
$this->changelogTable->insert($data);
}
return TRUE;
}
示例15: configure
protected function configure($presenter)
{
$this->selection->select("error.id, title, message, error_dt, project_id.name AS project_name, error_status_id.status AS status");
$source = new \NiftyGrid\DataSource\NDataSource($this->selection);
$self = $this;
$this->setDataSource($source);
$this->setDefaultOrder("error_dt DESC");
$this->addColumn("project_name", "Project")->setTableName("project_id")->setSortable()->setSelectFilter($this->projectEntity->findAll()->fetchPairs("id", "name"));
$this->addColumn("title", "Title")->setTextFilter()->setSortable();
$this->addColumn("message", "Message")->setSortable()->setTextFilter()->setRenderer(function ($row) use($presenter) {
return \Nette\Utils\Html::el("a")->setText(trim($row["message"]) ? Strings::truncate($row["message"], 60) : $row["id"])->addAttributes(array("target" => "_blank"))->href($presenter->link("ErrorList:display", $row["id"]));
});
$this->addColumn("status", "Status")->setTableName("error_status_id")->setSelectFilter($this->lstErrorStatus->findAll()->fetchPairs("id", "status"))->setRenderer(function ($row) use($presenter) {
$label = "";
if ($row["status"] == "New") {
$label = "label-important";
}
return \Nette\Utils\Html::el("span")->setText($row["status"])->addAttributes(array("class" => "label {$label}"));
});
if (!isset($this->filter['status'])) {
$this->filter['status'] = '1';
}
$this->addColumn("error_dt", "Date", "150px")->setDateFilter()->setSortable()->setRenderer(function ($row) {
return $row["error_dt"]->format("j.n.Y H:i:s");
});
$this->addButton("archive", "Archive")->setText("Archive")->setAjax()->setLink(function ($row) use($presenter) {
return $presenter->link("archive!", $row['id']);
})->setClass("btn-success btn-solve");
/*
$this->addButton("createTask", "Create Task")
->setText('Create task')
->setAjax()
->setLink(function($row) use ($presenter){return $presenter->link("createTask!", $row['id']);})
->setClass("btn-info");
*/
$this->addAction("archive", "Archive")->setAjax(true)->setCallback(function ($selectedItems) use($self) {
$self->handleArchive($selectedItems);
});
$this->addAction("unarchive", "Unarchive")->setAjax(true)->setCallback(function ($selectedItems) use($self) {
$self->handleUnArchive($selectedItems);
});
}