-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
P#56183 Optimize columns on list views for forms estates and addresses #139
Changes from 7 commits
d31dcf7
9994a40
f392f3b
401cb15
9ef6fe3
35b06b5
6444b38
68246c1
500acc0
b9a488f
6609639
5e5f6b1
d93dcbf
58f40d2
f3602d7
38668ef
893ac08
9117224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,9 +77,14 @@ private function fillData() | |
$pRecordRead->setOffset($offset); | ||
$pRecordRead->addColumn('listview_address_id', 'ID'); | ||
$pRecordRead->addColumn('name'); | ||
$pRecordRead->addColumn('template'); | ||
$pRecordRead->addColumn('name', 'shortcode'); | ||
$pRecordRead->addColumn('page_shortcode'); | ||
|
||
$this->setItems($pRecordRead->getRecordsSortedAlphabetically()); | ||
$pRecord = $pRecordRead->getRecords(); | ||
$pRecord = $this->handleRecord($pRecord); | ||
$this->setItems($pRecord); | ||
$itemsCount = $pRecordRead->getCountOverall(); | ||
|
||
$this->set_pagination_args([ | ||
|
@@ -89,6 +94,31 @@ private function fillData() | |
]); | ||
} | ||
|
||
private function handleRecord($listRecord) | ||
{ | ||
if (empty($listRecord)) | ||
{ | ||
return []; | ||
} | ||
foreach ($listRecord as &$record) | ||
{ | ||
if (!empty($record->page_shortcode)) | ||
{ | ||
$listPageID = explode(',',$record->page_shortcode); | ||
$page = ''; | ||
foreach ($listPageID as $pageID) | ||
{ | ||
if (!empty($page)) | ||
{ | ||
$page .= ','; | ||
} | ||
$page .= "<a href='".get_edit_post_link((int)$pageID)."' target='_blank'>".get_the_title((int)$pageID)."</a>"; | ||
} | ||
$record->page_shortcode = $page; | ||
} | ||
} | ||
return $listRecord; | ||
} | ||
|
||
/** | ||
* | ||
|
@@ -144,7 +174,9 @@ public function prepare_items() | |
$columns = [ | ||
'cb' => '<input type="checkbox" />', | ||
'name' => __('Name of View', 'onoffice-for-wp-websites'), | ||
'template' => __('Tempaltes', 'onoffice-for-wp-websites'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in "Templates". |
||
'shortcode' => __('Shortcode', 'onoffice-for-wp-websites'), | ||
'page_shortcode' => __('Page with Shortcode', 'onoffice-for-wp-websites'), | ||
]; | ||
|
||
$hidden = ['ID']; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,12 +104,17 @@ private function fillData() | |
$pRecordRead->addColumn('listview_id', 'ID'); | ||
$pRecordRead->addColumn('name'); | ||
$pRecordRead->addColumn('filterId'); | ||
$pRecordRead->addColumn('template'); | ||
$pRecordRead->addColumn('show_status'); | ||
$pRecordRead->addColumn('list_type'); | ||
$pRecordRead->addColumn('name', 'shortcode'); | ||
$pRecordRead->addColumn('page_shortcode'); | ||
$pRecordRead->addWhere("`list_type` IN('default', 'reference', 'favorites')"); | ||
|
||
$this->setItems($pRecordRead->getRecordsSortedAlphabetically()); | ||
$pRecord = $pRecordRead->getRecords(); | ||
$pRecord = $this->handleRecord($pRecord); | ||
$this->setItems($pRecord); | ||
$itemsCount = $pRecordRead->getCountOverall(); | ||
|
||
$this->set_pagination_args([ | ||
|
@@ -119,6 +124,31 @@ private function fillData() | |
]); | ||
} | ||
|
||
private function handleRecord($listRecord) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block was duplicated so often. Can it be factored out into something reusable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still open |
||
{ | ||
if (empty($listRecord)) | ||
{ | ||
return []; | ||
} | ||
foreach ($listRecord as &$record) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An array of new records would be cleaner than |
||
{ | ||
if (!empty($record->page_shortcode)) | ||
{ | ||
$listPageID = explode(',',$record->page_shortcode); | ||
$page = ''; | ||
foreach ($listPageID as $pageID) | ||
{ | ||
if (!empty($page)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is still open, too |
||
{ | ||
$page .= ','; | ||
} | ||
$page .= "<a href='".get_edit_post_link((int)$pageID)."' target='_blank'>".get_the_title((int)$pageID)."</a>"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
$record->page_shortcode = $page; | ||
} | ||
} | ||
return $listRecord; | ||
} | ||
|
||
/** | ||
* | ||
|
@@ -130,9 +160,11 @@ public function prepare_items() | |
'cb' => '<input type="checkbox" />', | ||
'name' => __('Name of View', 'onoffice-for-wp-websites'), | ||
'filtername' => __('Filter', 'onoffice-for-wp-websites'), | ||
'template' => __('Tempaltes', 'onoffice-for-wp-websites'), | ||
'show_status' => __('Show Status', 'onoffice-for-wp-websites'), | ||
'list_type' => __('Type of List', 'onoffice-for-wp-websites'), | ||
'shortcode' => __('Shortcode', 'onoffice-for-wp-websites'), | ||
'page_shortcode' => __('Page with Shortcode', 'onoffice-for-wp-websites'), | ||
]; | ||
|
||
$hidden = ['ID', 'filterId']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unstable. Better use
explode
, array functions. andimplode
.