本文整理汇总了PHP中Sintattica\Atk\Core\Tools::atkArrayNvl方法的典型用法代码示例。如果您正苦于以下问题:PHP Tools::atkArrayNvl方法的具体用法?PHP Tools::atkArrayNvl怎么用?PHP Tools::atkArrayNvl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sintattica\Atk\Core\Tools
的用法示例。
在下文中一共展示了Tools::atkArrayNvl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_atktext
/**
* function to get multilanguage strings.
*
* This is actually a wrapper for ATK's Tools::atktext() method, for
* use in templates.
*
* @author Ivo Jansch <ivo@achievo.org>
*
* Example: {atktext id="users.userinfo.description"}
* {atktext id="userinfo.description" module="users"}
* {atktext id="description" module="users" node="userinfo"}
*/
function smarty_function_atktext($params, $smarty)
{
if (!isset($params['id'])) {
$params['id'] = $params[0];
}
switch (substr_count($params['id'], '.')) {
case 1:
list($module, $id) = explode('.', $params['id']);
$str = Tools::atktext($id, $module, isset($params['node']) ? $params['node'] : '');
break;
case 2:
list($module, $node, $id) = explode('.', $params['id']);
$str = Tools::atktext($id, $module, $node);
break;
default:
$str = Tools::atktext($params['id'], Tools::atkArrayNvl($params, 'module', ''), Tools::atkArrayNvl($params, 'node', ''), Tools::atkArrayNvl($params, 'lng', ''));
}
if (isset($params['filter'])) {
$fn = $params['filter'];
$str = $fn($str);
}
// parse the rest of the params in the string
$parser = new StringParser($str);
return $parser->parse($params);
}
示例2: buildTree
/**
* Build the tree.
*
* @return TreeToolsTree Tree object
*/
public function buildTree()
{
Tools::atkdebug('treenode::buildtree() ' . $this->m_parent);
$recordset = $this->select(Tools::atkArrayNvl($this->m_postvars, 'atkfilter', ''))->excludes($this->m_listExcludes)->mode('admin')->getAllRows();
$treeobject = new TreeToolsTree();
for ($i = 0; $i < count($recordset); ++$i) {
$treeobject->addNode($recordset[$i][$this->m_primaryKey[0]], $recordset[$i], $recordset[$i][$this->m_parent][$this->m_primaryKey[0]]);
}
return $treeobject;
}
示例3: export
/**
* Export data to a download file.
*
* BROWSER BUG:
* IE has problems with the use of attachment; needs atachment (someone at MS can't spell) or none.
* however ns under version 6 accepts this also.
* NS 6+ has problems with the absense of attachment; and the misspelling of attachment;
* at present ie 5 on mac gives wrong filename and NS 6+ gives wrong filename.
*
* @todo Currently supports only csv/excel mimetypes.
*
* @param string $data The content
* @param string $fileName Filename for the download
* @param string $type The type (csv / excel / xml)
* @param string $ext Extension of the file
* @param string $compression Compression method (bzip / gzip)
*/
public function export($data, $fileName, $type, $ext = '', $compression = '')
{
ob_end_clean();
if ($compression == 'bzip') {
$mime_type = 'application/x-bzip';
$ext = 'bz2';
} elseif ($compression == 'gzip') {
$mime_type = 'application/x-gzip';
$ext = 'gz';
} elseif ($type == 'csv') {
$mime_type = 'text/x-csv';
$ext = 'csv';
} elseif ($type == 'excel') {
$mime_type = 'application/octet-stream';
$ext = 'xls';
} elseif ($type == 'xml') {
$mime_type = 'text/xml';
$ext = 'xml';
} else {
$mime_type = 'application/octet-stream';
}
header('Content-Type: ' . $mime_type);
header('Content-Disposition: filename="' . $fileName . '.' . $ext . '"');
// Fix for downloading (Office) documents using an SSL connection in
// combination with MSIE.
if (($_SERVER['SERVER_PORT'] == '443' || Tools::atkArrayNvl($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https') && preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT'])) {
header('Pragma: public');
} else {
header('Pragma: no-cache');
}
header('Expires: 0');
// 1. as a bzipped file
if ($compression == 'bzip') {
if (@function_exists('bzcompress')) {
echo bzcompress($data);
}
} else {
if ($compression == 'gzip') {
if (@function_exists('gzencode')) {
// without the optional parameter level because it bug
echo gzencode($data);
}
} else {
if ($type == 'csv' || $type == 'excel') {
// in order to output UTF-8 content that Excel both on Windows and OS X will be able to successfully read
echo mb_convert_encoding($data, 'Windows-1252', 'UTF-8');
}
}
}
flush();
exit;
}
示例4: edit
/**
* Returns a piece of html code that can be used in a form to edit this
* attribute's value. (hours, minutes and seconds will be a dropdownbox).
*
* @param array $record The record that holds the value for this attribute.
* @param string $fieldprefix The fieldprefix to put in front of the name
* of any html form element for this attribute.
* @param string $mode The mode we're in ('add' or 'edit')
*
* @return string Piece a of HTML Code
*/
public function edit($record, $fieldprefix, $mode)
{
$id = $this->getHtmlId($fieldprefix);
$fieldvalue = Tools::atkArrayNvl($record, $this->fieldName(), '');
if (!$this->hasFlag(self::AF_DURATION_STRING)) {
$curminutes = null;
$result = '<div class="form-inline">';
if ($this->m_maxtime_min >= 60) {
$curhours = $this->_getHourPart($fieldvalue);
$curminutes = $this->_getMinutePart($fieldvalue);
$result .= '<select id="' . $id . '_hours" name="' . $this->getHtmlName($fieldprefix) . '[hours]" class="form-control select-standard">';
for ($h = 0; $h <= $this->m_maxtime_min / 60;) {
$result .= '<option value="' . $h . '" ';
if ($curhours == $h) {
$result .= 'selected';
}
$result .= '>' . $h . ' ' . Tools::atktext('hours', 'atk');
if ($this->m_resolution_min <= 60) {
++$h;
} else {
$h = floor($h + $this->m_resolution_min / 60);
}
}
$result .= '</select>';
}
if ($this->m_maxtime_min >= 1 && $this->m_resolution_min < 60) {
$result .= ' <select id="' . $id . '_minutes" name="' . $this->getHtmlName($fieldprefix) . '[minutes]" class="form-control select-standard">';
for ($m = 0; $m < 60 || $this->m_maxtime_min < 60 && $m < $this->m_maxtime_min;) {
$result .= '<option value="' . $m . '" ';
if ($curminutes == $m) {
$result .= 'selected';
}
$result .= '>' . $m . ' ' . Tools::atktext('minutes', 'atk');
if ($this->m_resolution_min <= 1) {
++$m;
} else {
$m = $m + $this->m_resolution_min;
}
}
$result .= '</select>';
}
$result .= '</div>';
} else {
$curval = $fieldvalue > 0 ? $this->_minutes2string($fieldvalue) : '';
$result = '<input type="text" name="' . $this->getHtmlName($fieldprefix) . '" value="' . $curval . '"' . ($this->m_size > 0 ? ' size="' . $this->m_size . '"' : '') . '>';
}
return $result;
}
示例5: getAllValuesAssoc
/**
* Get rows in an associative array with the given key column used as
* key and the given value column used as value.
*
* NOTE:
* This is not an efficient way to retrieve records, as this will load all
* records into an array in memory. If you retrieve a lot of records, you
* are better of using Statement::getIterator which only retrieves one
* row at a time.
*
* Depending on the database driver, using this method multiple times might
* result in the query to be executed multiple times.
*
* @param int|string $keyColumn column index / name (default first column) to be used as key
* @param int|string $valueColumn column index / name (default first column) to be used as value
*
* @return array rows
*/
public function getAllValuesAssoc($keyColumn = 0, $valueColumn = 1)
{
$rows = $this->getAllRowsAssoc($keyColumn);
foreach ($rows as $key => &$value) {
if (is_numeric($valueColumn)) {
$value = Tools::atkArrayNvl(array_values($value), $valueColumn);
} else {
$value = $value[$valueColumn];
}
}
return $rows;
}
示例6: needsUpdate
/** Due to the new storeType functions
* password field is not allways saved from within the password attrib.
*
* Added a "dynamic" needsUpdate to cancel updates if no password fields where used
* to alter the password. This overcomes the overwriting with an empty password.
*
* @param array $record The record that contains this attribute's value
*
* @return bool
*/
public function needsUpdate($record)
{
$value = $record[$this->fieldName()];
// new is set from an update using the password attrib edit() function
if (Tools::atkArrayNvl($value, 'new', '') != '' || Tools::atkArrayNvl($value, 'hash', '') != '') {
return true;
}
return false;
}
示例7: _doDeleteSession
/**
* Delete the database in the session.
*
* @return bool Results, true or false
*/
protected function _doDeleteSession()
{
$selector = Tools::atkArrayNvl($this->m_postvars, 'atkselector', '');
return SessionStore::getInstance()->deleteDataRowForSelector($selector);
}
示例8: fetchValue
/**
* Convert values from an HTML form posting to an internal value for
* this attribute.
*
* For the regular Attribute, this means getting the field with the
* same name as the attribute from the html posting.
*
* @param array $postvars The array with html posted values ($_POST, for
* example) that holds this attribute's value.
*
* @return string The internal value
*/
public function fetchValue($postvars)
{
$vars = Tools::atkArrayNvl($postvars, $this->fieldName());
if (!is_array($vars)) {
$result = [];
foreach ($this->m_values as $value) {
if (Tools::hasFlag($vars, $value)) {
$result[] = $value;
}
}
return $result;
} else {
return $vars;
}
}
示例9: atkGetUser
/**
* Retrieve all known information about the currently logged-in user.
*
* @param $key string
*
* @return array Array with userinfo, or "" if no user is logged in.
*/
public static function atkGetUser($key = '')
{
$sm = SessionManager::getInstance();
$session = SessionManager::getSession();
$user = '';
$session_auth = is_object($sm) ? $sm->getValue('authentication', 'globals') : [];
if (Config::getGlobal('authentication_session') && Tools::atkArrayNvl($session, 'login', 0) == 1 && $session_auth['authenticated'] == 1 && !empty($session_auth['user'])) {
$user = $session_auth['user'];
if (!isset($user['access_level']) || empty($user['access_level'])) {
$user['access_level'] = 0;
}
}
if ($key) {
return $user[$key];
}
return $user;
}
示例10: getRecordFromSession
/**
* Get the current record from the database with the current selector.
*
* @return array
*/
protected function getRecordFromSession()
{
$selector = Tools::atkArrayNvl($this->m_node->m_postvars, 'atkselector', '');
return SessionStore::getInstance()->getDataRowForSelector($selector);
}
示例11: draw
/**
* Returns a piece of html code that can be used in a form to edit this
* attribute's value. (Month will be a dropdownbox, year and day text fields).
*
* @todo We can't show a calendar when we have a year dropdown?
* @todo The calendar doesn't use the min/max values?
*
* @param array $record Array with 3 fields (year, month, day)
* @param string $id html id
* @param string $name html name
* @param string $fieldprefix The fieldprefix
* @param string $postfix
* @param string $mode The mode ('add' or 'edit')
* @param bool $obligatory Is this field obligatory or not
*
* @return string Piece a of HTML Code
*/
public function draw($record = [], $id, $name, $fieldprefix = '', $postfix = '', $mode = '', $obligatory = false)
{
$result = '';
// go in simplemode when a pda is detected
if (BrowserInfo::detectPDA()) {
$this->setSimpleMode(true);
}
$this->m_yeardropdown = false;
if (!$this->m_simplemode) {
self::registerScriptsAndStyles(!$this->hasFlag(self::AF_DATE_NO_CALENDAR));
}
$fieldname = $name . $postfix;
/* text mode? */
if ($this->hasFlag(self::AF_DATE_STRING) || $mode == 'list') {
$value =& $record[$this->fieldName()];
if (is_array($value)) {
$value = adodb_date($this->m_date_format_edit, adodb_mktime(0, 0, 0, $value['month'], $value['day'], $value['year']));
} elseif ($obligatory) {
$value = adodb_date($this->m_date_format_edit);
} else {
$value = '';
}
$fieldname = $fieldname . '[date]';
$result = '<input type="text" id="' . $id . '" class="atkdateattribute form-control" name="' . $fieldname . '" value="' . $value . '">';
if (!$this->hasFlag(self::AF_DATE_NO_CALENDAR) && $mode != 'list') {
$format = str_replace(array('y', 'Y', 'm', 'n', 'j', 'd'), array('yy', 'y', 'mm', 'm', 'd', 'dd'), $this->m_date_format_edit);
$mondayFirst = 'false';
if (is_bool(Tools::atktext('date_monday_first'))) {
$mondayFirst = Tools::atktext('date_monday_first') === true ? 'true' : $mondayFirst;
}
$result .= ' <input ' . $this->getCSSClassAttribute(['btn', 'btn-default', 'button', 'atkbutton', 'form-control']) . ' type="button" value="..." onclick="return showCalendar(\'' . $id . '\', \'' . $id . '\', \'' . $format . '\', false, ' . $mondayFirst . ');">';
}
return $result;
}
/* this field */
$field = Tools::atkArrayNvl($record, $this->fieldName());
$str_format = $this->m_date_format_edit;
/* currently selected date */
if (is_array($field) && $field['year'] == 0 && $field['month'] == 0 && $field['day'] == 0) {
$current = null;
} elseif (!is_array($field) && empty($field)) {
$current = null;
} elseif (is_array($field)) {
if ($this->checkDateArray($field)) {
$current = adodb_mktime(0, 0, 0, $field['month'], $field['day'], $field['year']);
} else {
$current = null;
Tools::triggerError($record, $this->fieldName(), 'error_date_invalid');
}
} else {
$date = self::dateArray($field);
if ($this->checkDateArray($date)) {
$current = adodb_mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
} else {
$current = null;
}
}
/* minimum date */
$minimum = $mode != 'search' ? $this->m_date_min : 0;
if ($minimum != 0) {
$str_min = adodb_date('Ymd', $minimum);
} else {
$str_min = 0;
}
/* maximum date */
$maximum = $mode != 'search' ? $this->m_date_max : 0;
if ($maximum != 0) {
$str_max = adodb_date('Ymd', $maximum);
} else {
$str_max = 0;
}
$current = $this->getValidCurrentDate($current, $minimum, $maximum, $mode);
/* get dates in array format */
if ($current !== null) {
$current = adodb_getdate($current);
}
if (!empty($minimum)) {
$minimum = adodb_getdate($minimum);
}
if (!empty($maximum)) {
$maximum = adodb_getdate($maximum);
}
/* minimum and maximum */
//.........这里部分代码省略.........
示例12: fetchValue
/**
* Convert values from an HTML form posting to an internal value for
* this attribute.
*
* If the user entered a number in his native language, he may have used
* a different decimal separator, which we first convert to the '.'
* standard separator (ATK uses the regular dot notation internally)
*
* @param array $postvars The array with html posted values ($_POST, for
* example) that holds this attribute's value.
*
* @return string The internal value
*/
public function fetchValue($postvars)
{
if ($this->isPosted($postvars)) {
return $this->removeSeparators(Tools::atkArrayNvl($postvars, $this->fieldName(), ''));
}
}
示例13: updateRecordInSession
/**
* Update a record in the session.
*
* @param array $record Record to update
*
* @return mixed Result of the update, true or false
*/
private function updateRecordInSession($record)
{
$selector = Tools::atkArrayNvl($this->m_postvars, 'atkselector', '');
return SessionStore::getInstance()->updateDataRowForSelector($selector, $record) !== false;
}
示例14: getValuesAssoc
/**
* Get rows in an associative array with the given key column used as
* key and the given value column used as value.
*
* NOTE:
* This is not an efficient way to retrieve records, as this
* will load all records into one array into memory. If you
* retrieve a lot of records, you might hit the memory_limit
* and your script will die.
*
* @param string $query query
* @param int|string $keyColumn column index / name (default first column) to be used as key
* @param int|string $valueColumn column index / name (default first column) to be used as value
* @param int $offset offset
* @param int $limit limit
*
* @return array rows
*/
public function getValuesAssoc($query, $keyColumn = 0, $valueColumn = 1, $offset = -1, $limit = -1)
{
$rows = $this->getRowsAssoc($query, $keyColumn, $offset, $limit);
foreach ($rows as $key => &$value) {
if (is_numeric($valueColumn)) {
$value = Tools::atkArrayNvl(array_values($value), $valueColumn);
} else {
$value = $value[$valueColumn];
}
}
return $rows;
}
示例15: edit
/**
* Returns a piece of html code that can be used in a form to edit this
* attribute's value.
*
* @param array $record The record that holds the value for this attribute.
* @param string $fieldprefix The fieldprefix to put in front of the name
* of any html form element for this attribute.
* @param string $mode The mode we're in ('add' or 'edit')
*
* @return string A piece of htmlcode for editing this attribute
*/
public function edit($record, $fieldprefix, $mode)
{
if ($this->m_default == "NOW" && $this->m_ownerInstance->m_action == "add" || $this->m_default == "" && $this->hasFlag(self::AF_OBLIGATORY) && !$this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
$this->m_default = date("H:i:s");
}
$default = explode(":", $this->m_default);
$id = $this->getHtmlId($fieldprefix);
$name = $this->getHtmlName($fieldprefix);
$field = Tools::atkArrayNvl($record, $this->fieldName());
if ($field && !is_array($field)) {
$field = self::parseTime($field);
}
$onChangeCode = '';
if (count($this->m_onchangecode)) {
$this->_renderChangeHandler($fieldprefix);
$onChangeCode = ' onChange="' . $this->getHtmlId($fieldprefix) . '_onChange(this);"';
}
$m_hourBox = '<select id="' . $id . '[hours]" name="' . $name . "[hours]\" class=\"atktimeattribute form-control select-standard\"{$onChangeCode}>\n";
$m_minBox = '<select id="' . $id . '[minutes]" name="' . $name . "[minutes]\" class=\"atktimeattribute form-control select-standard\"{$onChangeCode}>\n";
$m_secBox = '<select id="' . $id . '[seconds]" name="' . $name . "[seconds]\" class=\"atktimeattribute form-control select-standard\"{$onChangeCode}>\n";
if (is_array($field)) {
$m_defHour = $field['hours'];
$m_defMin = $field['minutes'];
$m_defSec = $field['seconds'];
} else {
$m_defHour = $default[0];
$m_defMin = $default[1];
$m_defSec = $default[2];
}
Tools::atkdebug("defhour={$m_defHour} defmin={$m_defMin}");
// generate hour dropdown
if (!$this->hasFlag(self::AF_OBLIGATORY) || $this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
$m_hourBox .= '<option value=""' . ($m_defHour === '' ? ' selected' : '') . '></option>';
}
for ($i = $this->m_beginTime; $i <= $this->m_endTime; ++$i) {
if ($m_defHour !== '' && $i == $m_defHour) {
$sel = ' selected';
} else {
$sel = '';
}
$m_hourBox .= sprintf("<option value='%02d'%s>%02d</option>\n", $i, $sel, $i);
}
// generate minute dropdown
if (!$this->hasFlag(self::AF_OBLIGATORY) || $this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
$m_minBox .= '<option value=""' . ($m_defMin === '' ? ' selected' : '') . '></option>';
}
if ($this->hasFlag(self::AF_TIME_SECONDS)) {
$minute_steps = range(00, 59);
} else {
$minute_steps = $this->m_steps;
}
for ($i = 0; $i <= count($minute_steps) - 1; ++$i) {
if ($i != 0) {
$prev = $minute_steps[$i - 1];
} else {
$prev = -1;
}
if ($minute_steps[$i] >= $m_defMin && $prev < $m_defMin && $m_defMin != '') {
$sel = ' selected';
} else {
$sel = '';
}
$m_minBox .= sprintf("<option value='%02d'%s>%02d</option>\n", $minute_steps[$i], $sel, $minute_steps[$i]);
}
// generate second dropdown
if (!$this->hasFlag(self::AF_OBLIGATORY) || $this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
$m_secBox .= '<option value""' . ($m_defSec === '' ? ' selected' : '') . '></option>';
}
for ($i = 0; $i <= count($this->m_steps) - 1; ++$i) {
if ($i != 0) {
$prev = $this->m_steps[$i - 1];
} else {
$prev = -1;
}
if ($this->m_steps[$i] >= $m_defSec && $prev < $m_defSec && $m_defSec != '') {
$sel = ' selected';
} else {
$sel = '';
}
$m_secBox .= sprintf("<option value='%02d' %s>%02d</option>\n", $this->m_steps[$i], $sel, $this->m_steps[$i]);
}
// close dropdown structures
$m_hourBox .= '</select>';
$m_minBox .= '</select>';
if ($this->hasFlag(self::AF_TIME_SECONDS)) {
$m_secBox .= '</select>';
$m_secBox = ':' . $m_secBox;
} else {
$m_secBox = '<input type="hidden" id="' . $fieldprefix . $this->fieldName() . '[seconds]" name="' . $fieldprefix . $this->fieldName() . "[seconds]\" value=\"00\">\n";
//.........这里部分代码省略.........