Joomla - how can I count all active instances of specific module type? - joomla

As the title suggests my question is pretty simple.
Is there a way to count the total number of active module instances of a specific type/kind in Joomla (with a specific module name)?
I know how to count modules in a specific module position using JModuleHelper::getModules, but that is not what I want.
I simply need to count all active modules instances of a specific type/kind.
Does anyone know how to do this (without having to do a manual MySQL query)?

I do not know if there is an official joomla way, but you can do it by having an sql query looking at
#__modules
table.
Check out this table and you will find out how easy it is.
An example sql would be:
select count(id) from #__modules where module = 'mod_login'

As far as i know there is no joomla method for this. I would recommend (if it has to be done) either
using a crawler to go through all pages of the site counting the instances.
or using a script which goes through the template php files and the database to find all active instances.
Both these methods might not be 100% reliable due to unexpected circumstances (like module being included in article or module included only after a button is clicked on) but could work if you know your site well enough.

Unfortunately there does not seem to be such a function in Joomla.
In my case I needed this to tell me whether or not a instances of this module was > 0 or not.. and my alternative solution was to simply make a module-specific function and then in the module php file check if function is already loaded.

Related

How do I get a count of the Shopify products in a collection using the Ruby API

I want to get the count of products in each collection in the shop as part of a Shopify App that I'm building.
I know that for a single collection Product.all(params: {collection_id: 29238895}).count will show me the count in the shopify console, but I'm not certain about how it is implemented.
The API document describes a call that counts all products that belong to a certain collection GET /admin/products/count.json?collection_id=841564295 but I have been unable to get a ruby expression that runs this.
Is there a more complete document on the Ruby API?
If you want to know exactly what is going on with the API, may I suggest the simple command: bundle open shopify_api
That will load the entire API into your text editor, allowing to quickly determine the answer to your question. The /lib/resources directory is especially rich, but do not forget to check the base class as well. In fact, I think the count option is declared right in the base itself. Nothing beats a few minutes of examining the code.

Kohana ORM Caching/Caching design approach

This questions is related to Kohana ORM AND Caching module. I use version 3.2 if it matters. I tried to research trust me, but I really couldn't find some good answer... so here it is:
What are the correct ways to use ORM::cached() and ORM::serialize() and ORM::$reload_on_wakeup?
I've seen many 2-line code examples but never anything really solid on the userguide/api...
What is the difference between enabling Cache module and 'caching' => true in Kohana::init?
Anyone has any recommended approach for the following specific situations? I have a catalogue page that upon profiling, I realized two very expensive actions:
I queried database each time for a currency model for each item, when the currency information can really be reused.
I queried database each time for each item's inventory item, this is an expensive query, which I wish I can cache until inventory level changes.
References that I found but couldn't answer fully my questions:
http://forum.kohanaframework.org/discussion/1782/tip-for-caching-orm-objects/p1
http://forum.kohanaframework.org/discussion/10600/does-kohana-orm-and-cache-work-together/p1
Just found your question, maybe too late, but maybe is useful to others:
cached, will force the Query builder to cache the DB query. It uses the KOhana:cache method (file cache) I am trying to find a workaround for this.
enables caching for the file search as says in the Kohana/Core.php file: Whether to use internal caching for [Kohana::find_file], does not apply to [Kohana::cache]. Set by [Kohana::init]
Enable caching true to speed up the file search, and enable the cache module, I am working on a way to cache the queries of DB using the instance used by the module. That would be better than using the file cache. Maybe I am missing something but stuck there right now.

How to make wp plugin auto-refreshing on the public side of view (auto load page)

First have to say that almost every time when searching on technical solutions.. search engine will direct me to this site here. I admit that i have learned such A LOT here just by searching through for answers..
but also have to say that not being a coder.. so don't understand much here at all ;)
Ok, the Problem:
Want to update wordpress tables or calendar within wp admin. These changes should become updated on the public side automatically and more or less instantly (~ few seconds is perfectly fine).
I found solutions about manipulating header.php, i found some ajax plugins I found -too much to count- info on how to implement ajax into wp
Sadly.. none of these could help me through as the plugins mostly either not work, are outdated or require countless file edits. Manipulating header.php seems odd.. as i don't want to loop-refresh the whole page, post etc.. but only get e.g. table or calendar data updated.
So maybe any of you coders know of something to e.g. get the plugin "All-in-One Event Calendar by Timely" to update the public visible part of the calendar once data edited in wp admin?
Greatly appreciate pointers in any direction to solve this.
P.S.: What would you think of plugins like "ajaxify everything" ? don't know if this really the way to go..
Again, thanks for your help, time and contribution!!
update
additional question:
I now found such plugin to let me chose which parts i want to "ajaxify".
Such plugin would ask me for a specific function name.
Now, where do i start to gather this information?
Below is the instruction from the plugin context inside wordpress admin
Generate Ajaxized DIV for your function
Ajaxize will allow you to ajaxize almost any php function on your
site.
It can be a plugin, a function you wrote, or even a core wordpress
function.
There are some (obvious or less obvious) limitations currently:
Functions must return valid HTML - this will be called in php and returned via the
Ajax call
Functions cannot accept any parameters (at least at the moment)
Enter a function name below.
Function Name: xxx input field xxx what put in here? xxx
The generated div can be inserted to any page/post on the site and
will ajaxize the call to the function automatically.
Please make sure you enter a valid function name, that the function
does not require any parameters, and that it returns valid HTML.
In your context you want to refresh the calendar automaticaly when there is a change in the WP_Admin;
but you can't exactly do this.
You can write a Js method which will check the time of lastest modification of the calendar at the load of the page, stock it in Var.
After you'll have a constant (each 10seconds) Js "daemon" which will get the time of lastest modification of the calendar and compare it to the stocked Var; If change you reload the calendar.
PS: Ajaxify everything is not really a solution due of the developpement you need To Ajaxify and to code for people who has disabled Javascript.
Hope it helps

Changing Views in a Module pops me into the Admin Skin

This question has probably been the most covered question in all of DotNetNuke's lifetime but I'm going to ask it here in StackOverflow because I need an answer, a really good one that doesn't make me look the other way. Thanks in advance to all DNN experts.
I've researched many ways of making this work for me and i've seen Michael Washington's solutions (Panels, MultiViews, ...) and Will's (Strohl) blog post on DotNetNuke's personalization engine through setting SkinSrc which is useful, as well as reading through Default.aspx's code which has given me more insight, however, i'm still faced with the problem that calling EditUrl()/NavigateUrl() brings me to a page with a single module in admin skin or a page with nothing respectively.
The specific version is DotNetNuke 6.0.1 (DNN). This Module has 4 other views in addition to the main view which I desire to navigate through sequentially. e.g.
Begin Checkout -> Collection of Delivery Details -> Confim Order
Have you found a solution?
I want to achieve
1) Module loads with other modules around. No module isolation
2) Views in a module that don't Preload e.g. Page_Load in each view gets called when the Module loads up
Help!
Assuming you are asking this as the module developer, the solution is to not use DNN's mechanism for specifying a control. So, you can't use EditUrl or specify the ControlKey in the NavigateURL call (which both generate "ctl=mycontrol" in the URL). Instead you need to have your module display your various controls based on the Query String parameters. So, you'll generally have a control in your module who's primary purpose is to dynamically load other controls based on the query string. So, for instance:
You will start with your control that lists items. You'll have a "Buy Now" button for each item. The hyperlink for each item can be generated by calling
NavigateURL(TabID, "", "View=BeginCheckout", "itemid=" & id, "mid=" & mid)
2.) On the page load of the handler control, it looks to see if anything is specified for the "View" Querystring parameter. If not it displays the listing control, if so, it displays the corresponding control.
Dim controlPath As String
Dim path as String = "~/DesktopModules/MyModule/Controls"
Select Case Request("View")
Case "BeginCheckout"
ControlPath = path + "BeginCheckout.ascx"
Case "DeliveryDetails"
ControlPath = path + "DeliveryDetails.ascx"
Case "ConfirmOrder"
ControlPath = path + "ConfirmOrder.ascx"
Case Else
ControlPath = path + "ItemList.aspx"
End Select
If System.IO.File.Exists(Request.MapPath(controlPath)) Then
placeholder.LoadControl(controlPath)
Else
Throw New Exception("Unable to load selected template. Please go into module settings and select a list and details template.")
End If
Most of the advanced modules for DNN do something along these lines so there's plenty of sample code out there. I would guess some of the core modules do something similar. I adapted the code above from Efficon's Articles module for DotNetNuke.

how to add more simple products into configurable products using magento API

How can I simply add new simple products incrementally to configurable products?
or do I still need to retrieve the 2 original arrays of the pre-defined configurable product (getConfigurableAttributesData and getConfigurableProductsData) first, append the new arrays and set them again? Is it worked for my case just as the first-time creation?
And if the new simple product owns a new attribute / attribute options, do I also need to create /edit the attribute first before adding?
Thanks in advance!
The API as it stands does not have the functionality to do this.
Your options are:
Extend the API. (Hours of fun)
Do it with Magento methods in your own module or standalone code that includes Mage.php.
SQL script mixed in with your existing API code.
Buy someone's module - (Hope your German is good)
The approach you take also depends on your SKU naming scheme, if you have a simple BASECODE-SIZE-COLOUR type of scheme then the SQL option can work a treat, and in next to no time, but will be heavily scorned on by Magento evangelists.
That means you are probably going to have to write your own code. Here is a very useful site that should help get you started:
http://www.ayasoftware.com/
As well as being able to import configurables (by a variety of means including SQL) there are also snippets of code useful for updating superattribute price differentials. No readymade complete solution, but, you may need to roll your own anyway depending on your SKU naming scheme.
Whilst you are at it you may also want to write some code to find simple products that are not hooked up to anything when they should be, i,e. the ones with no visibility.

Resources