Skip to content

Commit

Permalink
Merge pull request #834 from intelliants/sorting_by_url_in_pages
Browse files Browse the repository at this point in the history
#829  Sorting by url in pages
  • Loading branch information
AleksandrPanarin committed May 2, 2019
2 parents 9a79288 + 8ce7912 commit 67ae36b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
11 changes: 8 additions & 3 deletions includes/classes/ia.base.controller.admin.php
Expand Up @@ -138,7 +138,7 @@ final public function process()
$entry = [];
$this->_setDefaultValues($entry);

// intentionally missing BREAK stmt
// intentionally missing BREAK stmt

case iaCore::ACTION_EDIT:
if (iaCore::ACTION_EDIT == $iaView->get('action')) {
Expand Down Expand Up @@ -314,6 +314,7 @@ public function getTable()
{
return $this->_table;
}

public function setTable($tableName)
{
$this->_table = $tableName;
Expand All @@ -323,6 +324,7 @@ public function getHelper()
{
return $this->_helper;
}

public function setHelper($helperClassInstance)
{
$this->_helper = &$helperClassInstance;
Expand Down Expand Up @@ -376,6 +378,9 @@ protected function _gridGetSorting(array $params)
? $this->_gridSorting[$params['sort']][1] . '.'
: $this->_gridQueryMainTableAlias;

if ($column == 'url') {
return sprintf(' ORDER BY `%s` %s', $column, $direction);
}
return sprintf(' ORDER BY %s`%s` %s', $tableAlias, $column, $direction);
}

Expand Down Expand Up @@ -491,10 +496,10 @@ protected function _gridUnpackColumnsArray()
$this->_gridColumns = array_merge($persistentColumns, $this->_gridColumns);

foreach ($this->_gridColumns as $key => $field) {
$result.= is_int($key)
$result .= is_int($key)
? $this->_gridQueryMainTableAlias . '`' . $field . '`'
: sprintf('%s `%s`', is_numeric($field) ? $field : $this->_gridQueryMainTableAlias . '`' . $field . '`', $key);
$result.= ', ';
$result .= ', ';
}

$result = substr($result, 0, -2);
Expand Down
41 changes: 24 additions & 17 deletions includes/classes/ia.core.field.php
Expand Up @@ -194,8 +194,8 @@ public function filter($itemName, array &$itemData, $pageName = null, $where = n
is_null($pageName) && $pageName = $this->iaView->name();
is_null($where) && $where = iaDb::EMPTY_CONDITION;

$where.= iaDb::printf(" && f.status = ':status'", ['status' => iaCore::STATUS_ACTIVE]);
$where.= !empty($itemData['sponsored_plan_id']) && !empty($itemData['sponsored'])
$where .= iaDb::printf(" && f.status = ':status'", ['status' => iaCore::STATUS_ACTIVE]);
$where .= !empty($itemData['sponsored_plan_id']) && !empty($itemData['sponsored'])
? " && (f.plans = '' || FIND_IN_SET('{$itemData['sponsored_plan_id']}', f.plans))"
: " && f.plans = ''";

Expand All @@ -209,7 +209,7 @@ public function filter($itemName, array &$itemData, $pageName = null, $where = n

foreach ($rows as $row) {
$iaAcl->checkAccess('field', $itemName . '_' . $row['name'])
&& $result[$row['id']] = $row;
&& $result[$row['id']] = $row;
}

self::_unpackValues($result);
Expand Down Expand Up @@ -320,7 +320,7 @@ protected static function _unpackValues(array &$fields)
$field['class'] = 'fieldzone';
if ($field['plans']) {
foreach (explode(',', $field['plans']) as $p) {
$field['class'].= sprintf(' plan_%d ', $p);
$field['class'] .= sprintf(' plan_%d ', $p);
}
}

Expand Down Expand Up @@ -566,7 +566,7 @@ public function parsePost($itemName, array &$itemData)
case self::CHECKBOX:
is_array($value) && $value = implode(',', $value);

// BREAK stmt omitted intentionally
// BREAK stmt omitted intentionally

case self::COMBO:
case self::SWITCHER:
Expand Down Expand Up @@ -711,6 +711,10 @@ public function parsePost($itemName, array &$itemData)
? str_replace($validProtocols, '', $value['url'])
: $value['title'];

if ($url === 'http://') {
$url = '';
}

$item[$fieldName] = $url . '|' . $title;
} else {
$errors[$fieldName] = iaLanguage::get('error_url') . ': ' . self::getFieldTitle($field['item'], $fieldName);
Expand Down Expand Up @@ -1104,18 +1108,21 @@ private function _alterCmdBody(array $fieldData)

switch ($fieldData['type']) {
case self::DATE:
$result.= 'DATETIME ';
$result .= 'DATETIME ';
break;
case self::NUMBER:
$result.= 'DOUBLE ';
$result .= 'DOUBLE ';
break;
case self::TEXT:
$result.= 'VARCHAR(' . $fieldData['length'] . ') '
$result .= 'VARCHAR(' . $fieldData['length'] . ') '
. ($fieldData['default'] ? "DEFAULT '{$fieldData['default']}' " : '');
break;
case self::ICONPICKER:
case self::URL:
$result.= 'TINYTEXT ';
$result .= 'TINYTEXT ';
break;
case self::SWITCHER:
$result .= 'TINYINT(1) ';
break;
case self::SWITCHER:
$result.= 'TINYINT(1) ';
Expand All @@ -1124,28 +1131,28 @@ private function _alterCmdBody(array $fieldData)
case self::IMAGE:
case self::STORAGE:
case self::PICTURES:
$result.= 'TEXT ';
$result .= 'TEXT ';
break;
case self::TEXTAREA:
$result.= 'MEDIUMTEXT ';
$result .= 'MEDIUMTEXT ';
break;
case self::CURRENCY:
$result.= 'DECIMAL(' . ($fieldData['length'] + 2) . ',2) unsigned ';
$result .= 'DECIMAL(' . ($fieldData['length'] + 2) . ',2) unsigned ';
break;
default:
if (isset($fieldData['values'])) {
$values = explode(',', $fieldData['values']);

$result.= ($fieldData['type'] == self::CHECKBOX) ? 'SET' : 'ENUM';
$result.= "('" . implode("','", $values) . "')";
$result .= ($fieldData['type'] == self::CHECKBOX) ? 'SET' : 'ENUM';
$result .= "('" . implode("','", $values) . "')";

if (!empty($fieldData['default'])) {
$result.= " DEFAULT '{$fieldData['default']}' ";
$result .= " DEFAULT '{$fieldData['default']}' ";
}
}
}

$result.= $fieldData['allow_null'] ? 'NULL' : 'NOT NULL';
$result .= $fieldData['allow_null'] ? 'NULL' : 'NOT NULL';

return $result;
}
Expand Down Expand Up @@ -1394,7 +1401,7 @@ public function deleteUploadedFile($fieldName, $itemName, $itemId, $fileName = n
// check if image removed from the entry of currently logged in user
// and reload his identity if so
iaUsers::getItemName() == $itemName && iaUsers::hasIdentity()
&& $itemId == iaUsers::getIdentity()->id && iaUsers::reloadIdentity();
&& $itemId == iaUsers::getIdentity()->id && iaUsers::reloadIdentity();

return true;
}
Expand Down
22 changes: 18 additions & 4 deletions templates/_common/field-type-content-view.tpl
Expand Up @@ -84,11 +84,25 @@
{else}
<div class="field field-{$type}" id="{$name}_fieldzone">
{if !isset($excludedTitles) || !in_array($name, $excludedTitles)}
<div class="field__header">{lang key=$fieldName}</div>
{if isset($value)}
{if !empty($value[0])}
<div class="field__header">{lang key=$fieldName}</div>
{/if}
{else}
<div class="field__header">{lang key=$fieldName}</div>
{/if}
{/if}
{if isset($value)}
{if !empty($value[0])}
<div class="field__content">
{$_field_text}
</div>
{/if}
{else}
<div class="field__content">
{$_field_text}
</div>
{/if}
<div class="field__content">
{$_field_text}
</div>
</div>
{/if}
{elseif empty($item.$name) && $field.empty_field}
Expand Down

0 comments on commit 67ae36b

Please sign in to comment.