Skip to content
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

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified languages/onoffice-for-wp-websites-de_DE.mo
Binary file not shown.
4 changes: 2 additions & 2 deletions languages/onoffice-for-wp-websites-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ msgstr "Absteigend"
#: plugin/Model/FormModelBuilder/FormModelBuilderDB.php:193
#: plugin/Model/FormModelBuilder/FormModelBuilderEstateDetailSettings.php:245
#: plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php:215
msgid "Template"
msgstr "Template"
msgid "Templates"
msgstr "Templates"

#: plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php:94
#: plugin/Model/FormModelBuilder/FormModelBuilderDBEstateListSettings.php:119
Expand Down
Binary file modified languages/onoffice-for-wp-websites-es_ES.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion languages/onoffice-for-wp-websites-es_ES.po
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ msgstr "Descendente"
#: plugin/Model/FormModelBuilder/FormModelBuilderDB.php:193
#: plugin/Model/FormModelBuilder/FormModelBuilderEstateDetailSettings.php:245
#: plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php:215
msgid "Template"
msgid "Templates"
msgstr "Plantilla"

#: plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php:94
Expand Down
Binary file modified languages/onoffice-for-wp-websites-it_IT.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion languages/onoffice-for-wp-websites-it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ msgstr "Scendendo"
#: plugin/Model/FormModelBuilder/FormModelBuilderDB.php:193
#: plugin/Model/FormModelBuilder/FormModelBuilderEstateDetailSettings.php:245
#: plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php:215
msgid "Template"
msgid "Templates"
msgstr "Modello"

#: plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php:94
Expand Down
Binary file modified languages/onoffice-for-wp-websites-nl_NL.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion languages/onoffice-for-wp-websites-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ msgstr "Aflopend"
#: plugin/Model/FormModelBuilder/FormModelBuilderDB.php:193
#: plugin/Model/FormModelBuilder/FormModelBuilderEstateDetailSettings.php:245
#: plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php:215
msgid "Template"
msgid "Templates"
msgstr "Sjabloon"

#: plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php:94
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
}, 11);
add_action('admin_init', [$pAdminViewController, 'add_ajax_actions']);
add_action('admin_init', [CaptchaDataChecker::class, 'addHook']);

add_action('admin_init', [$pDetailViewPostSaveController, 'getAllPost']);
add_action('plugins_loaded', function() {
load_plugin_textdomain('onoffice-for-wp-websites', false, basename(ONOFFICE_PLUGIN_DIR) . '/languages');
// Check 'onoffice-personalized' Folder exists
Expand Down
177 changes: 176 additions & 1 deletion plugin/Controller/DetailViewPostSaveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

use onOffice\WPlugin\DataView\DataDetailViewHandler;
use onOffice\WPlugin\Utility\__String;
use onOffice\WPlugin\Record\RecordManagerReadListViewEstate;
use onOffice\WPlugin\Record\RecordManagerReadListViewAddress;
use onOffice\WPlugin\Record\RecordManagerReadForm;

use WP_Post;

/**
Expand Down Expand Up @@ -91,6 +95,18 @@ public function onSavePost($postId) {
flush_rewrite_rules();
}
}
$this->addPageUseShortCode($pPost);
}

}
public function getAllPost() {
$args = array(
'post_status' => 'publish',
);
$posts = get_pages($args);
foreach ($posts as $post)
{
$this->addPageUseShortCode($post);
}
}

Expand All @@ -114,6 +130,8 @@ public function onMoveTrash($postId) {
$pDataDetailViewHandler->saveDetailView($pDetailView);
flush_rewrite_rules();
}
$pPost = get_post($postId);
$this->deletePageUseShortCode($pPost);
}


Expand All @@ -128,7 +146,36 @@ private function generateDetailViewCode($detailViewName) {
return 'view="'.$detailViewName.'"';
}


private function generateDetailCode($detailViewName,$option) {
return $option.'="'.$detailViewName.'"';
}
private function getListView()
{
$pRecordReadListView = new RecordManagerReadListViewEstate();
$pRecordReadListView->addColumn('listview_id');
$pRecordReadListView->addColumn('name');
$pRecordReadListView->addColumn('page_shortcode');
$listView = $pRecordReadListView->getRecords();
return $listView;
}
private function getListViewAddress()
{
$pRecordReadListViewAddress = new RecordManagerReadListViewAddress();
$pRecordReadListViewAddress->addColumn('listview_address_id');
$pRecordReadListViewAddress->addColumn('name');
$pRecordReadListViewAddress->addColumn('page_shortcode');
$listViewAddress = $pRecordReadListViewAddress->getRecords();
return $listViewAddress;
}
private function getListForm()
{
$pRecordReadForm = new RecordManagerReadForm();
$pRecordReadForm->addColumn('form_id');
$pRecordReadForm->addColumn('name');
$pRecordReadForm->addColumn('page_shortcode');
$listForm = $pRecordReadForm->getRecords();
return $listForm;
}
/**
*
* @param string $post
Expand Down Expand Up @@ -156,4 +203,132 @@ private function postContainsViewName($post, $viewName) {

return false;
}

private function postContains($post, $viewName, $element,$option) {
$matches = array();
$regex = get_shortcode_regex(array($element));
preg_match_all('/'.$regex.'/ism', $post, $matches);

$detailviewCode = $this->generateDetailCode($viewName,$option);
if (!array_key_exists(3, $matches)) {
return false;
}

foreach ($matches[3] as $tagParams) {
if (__String::getNew($tagParams)->contains($detailviewCode)) {
return true;
}
}

return false;
}

private function addPageUseShortCode($post)
{
$listView = $this->getListView();
$listViewAddress = $this->getListViewAddress();
$listForm = $this->getListForm();
$isRevision = wp_is_post_revision($post);
if (!$isRevision) {
$postContent = $post->post_content;
$postID = $post->ID;
if (empty($postID))
{
return;
}
if (strpos($postContent,'oo_estate') !== false)
{
$this->addPageShortCode($listView,$post,'oo_estate','view',"oo_plugin_listviews","listview_id","listview_id");
}
if (strpos($postContent,'oo_address') !== false)
{
$this->addPageShortCode($listViewAddress,$post,'oo_address','view',"oo_plugin_listviews_address","listview_address_id","listview_address_id");
}
if (strpos($postContent,'oo_form') !== false)
{
$this->addPageShortCode($listForm,$post,'oo_form','form',"oo_plugin_forms","form_id","form_id");
}

}
}
private function deletePageUseShortCode($post)
{
$listView = $this->getListView();
$listViewAddress = $this->getListViewAddress();
$listForm = $this->getListForm();
$isRevision = wp_is_post_revision($post);
if (!$isRevision) {
$postContent = $post->post_content;
$postID = $post->ID;
if (empty($postID))
{
return;
}
if (strpos($postContent,'oo_estate') !== false)
{
$this->deletePageShortCode($listView,$post,"oo_plugin_listviews","listview_id","listview_id");
}
if (strpos($postContent,'oo_address') !== false)
{
$this->deletePageShortCode($listViewAddress,$post,"oo_plugin_listviews_address","listview_address_id","listview_address_id");
}
if (strpos($postContent,'oo_form') !== false)
{
$this->deletePageShortCode($listForm,$post,"oo_plugin_forms","form_id","form_id");
}

}
}
private function addPageShortCode($listView,$post,$element,$option,$tableName,$column,$primaKey)
{
$pRecordReadListView = new RecordManagerReadListViewEstate();
$postID = $post->ID;
$postContent = $post->post_content;
foreach($listView as $view)
{
$pageID = [];
if (!empty($view->page_shortcode))
{
$pageID = explode(',',$view->page_shortcode);
}
if (in_array($postID,$pageID))
{
break;
}
$viewContained = $this->postContains($postContent, $view->name,$element,$option);
if ($viewContained) {
if (empty($pageID))
{
$pageID = $postID;
}else {
$pageID[] = $postID;
$pageID = implode(",",$pageID);
}
$pRecordReadListView->updateColumnPageShortCode($pageID,$view->$primaKey,$tableName,$column);
}
}
}
private function deletePageShortCode($listView,$post,$tableName,$column,$primaKey)
{
$pRecordReadListView = new RecordManagerReadListViewEstate();
$postID = $post->ID;
foreach($listView as $view)
{
$pageID = '';
if (empty($view->page_shortcode))
{
break;
}
if (strpos($view->page_shortcode,(string)$postID)!== false)
{
$pageShortCode = explode(",",$view->page_shortcode);
if (($keyPageDelete = array_search($postID, $pageShortCode)) !== false) {
unset($pageShortCode[$keyPageDelete]);
}
$pageID = implode(",",$pageShortCode);
$pRecordReadListView->updateColumnPageShortCode($pageID,$view->$primaKey,$tableName,$column);
jayay marked this conversation as resolved.
Show resolved Hide resolved
}

}
}
}
43 changes: 40 additions & 3 deletions plugin/Gui/Table/AddressListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

use onOffice\WPlugin\Gui\Table\WP\ListTable;
use onOffice\WPlugin\Record\RecordManagerReadListViewAddress;
use onOffice\WPlugin\Controller\Exception\UnknownFilterException;
use onOffice\WPlugin\API\APIClientCredentialsException;
use onOffice\WPlugin\FilterCall;
use onOffice\SDK\onOfficeSDK;
use function __;
use function admin_url;
use function esc_html;
Expand All @@ -43,6 +47,8 @@ class AddressListTable
/** @var int */
private $_itemsPerPage = null;

/** @var FilterCall */
private $_pFilterCall = null;

/**
*
Expand All @@ -59,6 +65,7 @@ public function __construct($args = [])
]);

$this->_itemsPerPage = $this->get_items_per_page('onoffice-address-listview_per_page', 10);
$this->_pFilterCall = new FilterCall(onOfficeSDK::MODULE_ADDRESS);
}


Expand All @@ -77,9 +84,14 @@ private function fillData()
$pRecordRead->setOffset($offset);
$pRecordRead->addColumn('listview_address_id', 'ID');
$pRecordRead->addColumn('name');
$pRecordRead->addColumn('filterId');
$pRecordRead->addColumn('template');
$pRecordRead->addColumn('name', 'shortcode');
$pRecordRead->addColumn('page_shortcode');

$this->setItems($pRecordRead->getRecordsSortedAlphabetically());
$pRecord = $pRecordRead->getRecordsSortedAlphabetically();
$pRecord = $this->handleRecord($pRecord);
$this->setItems($pRecord);
$itemsCount = $pRecordRead->getCountOverall();

$this->set_pagination_args([
Expand All @@ -88,8 +100,29 @@ private function fillData()
'total_pages' => ceil($itemsCount / 10)
]);
}
/**
*
* @param object $pItem
* @return string
*
*/


protected function column_filtername($pItem)
{
$filterName = '';
try {
if ($pItem->filterId != 0) {
$filterName = $this->_pFilterCall->getFilternameById($pItem->filterId);
}
} catch (APIClientCredentialsException $pCredentialsException) {
$filterName = __('(Needs valid API credentials)', 'onoffice-for-wp-websites');
} catch (UnknownFilterException $pFilterException) {
/* translators: %s will be replaced with a number. */
$filterName = sprintf(__('(Unknown Filter (ID: %s))', 'onoffice-for-wp-websites'),
$pFilterException->getFilterId());
}
return $filterName;
}
/**
*
* @return array
Expand All @@ -101,6 +134,7 @@ public function get_columns()
return [
'cb' => '<input type="checkbox" />',
'name' => __('Name of View', 'onoffice-for-wp-websites'),
'filtername' => __('Filter', 'onoffice-for-wp-websites'),
'shortcode' => __('Shortcode', 'onoffice-for-wp-websites'),
];
}
Expand Down Expand Up @@ -144,10 +178,13 @@ public function prepare_items()
$columns = [
'cb' => '<input type="checkbox" />',
'name' => __('Name of View', 'onoffice-for-wp-websites'),
'filtername' => __('Filter', 'onoffice-for-wp-websites'),
'template' => __('Templates', 'onoffice-for-wp-websites'),
'shortcode' => __('Shortcode', 'onoffice-for-wp-websites'),
'page_shortcode' => __('Page with Shortcode', 'onoffice-for-wp-websites'),
];

$hidden = ['ID'];
$hidden = ['ID','filterId'];
$sortable = [];

$this->_column_headers = [$columns, $hidden, $sortable,
Expand Down
11 changes: 7 additions & 4 deletions plugin/Gui/Table/EstateListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ private function fillData()
$pRecordRead->addColumn('listview_id', 'ID');
$pRecordRead->addColumn('name');
$pRecordRead->addColumn('filterId');
$pRecordRead->addColumn('show_status');
$pRecordRead->addColumn('template');
$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->getRecordsSortedAlphabetically();
$pRecord = $this->handleRecord($pRecord);
$this->setItems($pRecord);
$itemsCount = $pRecordRead->getCountOverall();

$this->set_pagination_args([
Expand All @@ -119,7 +122,6 @@ private function fillData()
]);
}


/**
*
*/
Expand All @@ -130,9 +132,10 @@ public function prepare_items()
'cb' => '<input type="checkbox" />',
'name' => __('Name of View', 'onoffice-for-wp-websites'),
'filtername' => __('Filter', 'onoffice-for-wp-websites'),
'show_status' => __('Show Status', 'onoffice-for-wp-websites'),
'template' => __('Templates', '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'];
Expand Down
Loading