Jump to content

Customizing sidebar below By Month under announcements to show Japanese date format


asiams

Recommended Posts

Hello

 

I am trying to localize the sidebar in By Month section on announcement page.

 

Currently it shows Feb 2016. I want to change that to 2016-02 to make it simple.

 

When I show the element for the site, the href="announcements.php?view=2016-02". I just want to show the menu to use exactly this numbers 2016-02.

 

I am using 6.2.2 WHMCS.

 

I tried put setlocale(LC_TIME, "ja-JP"); in configuration.php file, but it did not change.

Some suggested setlocale(LC_TIME, "ja-JP.utf-8");, but it did not affect to show in Japanese date format.

 

From admin, all of the general settings were done as follow:

 

system char-set: utf-8

date format: YYYY-MM-DD

Client Dateformat: same as above

 

I wasn't quite sure what this date format do the whole WHMCS.

 

Hook was suggested to be used. The example files did not show the title of the menu change by dateformat change.

 

I was able to change the date format for the announcements.tpl and viewannouncement.tpl since it has smarty codes section to change the date format as time stamp.

 

Any help would be appreciated.

 

Thank you.

 

Abraham

Link to comment
Share on other sites

Abraham,

 

I am trying to localize the sidebar in By Month section on announcement page.

Currently it shows Feb 2016. I want to change that to 2016-02 to make it simple.

When I show the element for the site, the href="announcements.php?view=2016-02". I just want to show the menu to use exactly this numbers 2016-02.

I am using 6.2.2 WHMCS.

I tried put setlocale(LC_TIME, "ja-JP"); in configuration.php file, but it did not change.

Some suggested setlocale(LC_TIME, "ja-JP.utf-8");, but it did not affect to show in Japanese date format.

From admin, all of the general settings were done as follow:

system char-set: utf-8

date format: YYYY-MM-DD

Client Dateformat: same as above

I wasn't quite sure what this date format do the whole WHMCS.

Hook was suggested to be used. The example files did not show the title of the menu change by dateformat change

it's going to have to be an action hook - I can think of three possible ways to do it... the basic method, a complicated method and an alternate route.

 

i'll give you the basic method first (as it's the most simplest!) - the important thing to realise is that all you are really wanting to do is to change the label of a sidebar item... it will currently be a string hard-coded by WHMCS - though i'm sure if they had wanted to, they could have made it use the Client date format.

 

http://docs.whmcs.com/Client_Area_Sidebars_Cheatsheet#Changing_the_Text_Label_of_a_Sidebar_Item

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if (!is_null($primarySidebar->getChild('Announcements Months'))) {
               $primarySidebar->getChild('Announcements Months')
                               ->getChild('Feb 2016')
                                    ->setLabel('2016-02');
   }
});

and let's say you want to do a similar think for January 2016...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if (!is_null($primarySidebar->getChild('Announcements Months'))) {
               $primarySidebar->getChild('Announcements Months')
                               ->getChild('Feb 2016')
                                   ->setLabel('2016-02');
               $primarySidebar->getChild('Announcements Months')                                
                               ->getChild('Jan 2016')
                                   ->setLabel('2016-01');
   }
});

you always need to remember that the sidebar item *must* exist before you can try to change it - for example, if you don't have any announcements for January 2016, the above hook will fail; if you try to add similar code in for March 2016 today, the hook will fail if there are no announcements for March 2016... but as long as the item exists, you should be able to modify it's label using the above method...

 

the complicated way would be to either cycle through the months and years, check the item exists and if so, adjust the labels accordingly... or possibly to use getChildren as an array, manipulate it's labels and then use setChildren to add them back... though I wouldn't fancy trying to get either method to work. :?:

 

the alternate route would be to just remove that particular sidebar and recreate it from scratch - e.g by querying the tblannouncements database table, getting the months from it and then using them for the labels and links... but even that seems like a lot of hassle when all you want to do is change the labels of an existing sidebar! :roll:

 

I said during the v6 beta period that WHMCS should have left these existing sidebars open source for us to edit - that would have been far easier than trying to figure out how to manipulate them with only flaky documentation for guidance.

 

unless someone can find a solution to do this programmatically, i'd suggest using the first method for now and update it for future months as and when the need arises.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated