Strange behaviour on custom package

Discussion in 'Subrion CMS Packages Discussions' started by ivanvieira, Jul 22, 2015.

  1. ivanvieira

    ivanvieira New Member

    After developing three fully functional packages , the fourth is giving me work for about a week with symptoms that do not appear in other packages:

    1. In the administration , the statistics block does not appear in the dashboard, or on the package statistics page (debug utility shows that ia.admin.item.php class is not being loaded).

    2. The template brief.item.tpl the title and your link does not appear , and the link " Continue reading " is also empty, indicating a problem with the code { ia_url ... . The call {$item.title} alone shows de data normally.

    Already remade the package using the Publishing as a base for a few times , coming at the same frustrating result. Any help will be very welcome.
  2. ivanvieira

    ivanvieira New Member

    To better ilustrate the question:

    1. Admin Statistics page

    [​IMG]

    2. Categories and item data OK

    [​IMG]

    3. Front fail on Title and Continue Reading, and all blocks that call { ia_url... into template

    [​IMG]

    4. Acess by RSS icon shows the item correctly

    [​IMG]

    The other three packages above City Hall (admin screens) are full functional.
  3. Vasily_B.

    Vasily_B. Project Manager

    Hi,

    Please check your item class for admin panel. I mean class that handles item operations in admin dashboard.

    packages/your_package/includes/classes/ia.admin.ITEM.php

    There is a public var that should be set to either true, or array with configs.
    Code (Text):

    // public $dashboardStatistics = array('icon' => 'cart');

    public $dashboardStatistics = true;
     
    This should help. It activates stats display. For more options please check method in class includes/classes/ia.base.package.admin.php class:
    Code (Text):
    public function getDashboardStatistics($defaultProcessing = true)
    I hope this information can help.

    Cheers
  4. ivanvieira

    ivanvieira New Member

    Vasily,

    My code was already in accordance with information you passed.

    I'm working on an item named "Agency" , this could be a reserved name ?
  5. ivanvieira

    ivanvieira New Member

    Problem solved: changing the item name to "Department" , the package behavior is normal.

    Thank you Vasily for all the support .
  6. Vasily_B.

    Vasily_B. Project Manager

    Ivan, there is one weird undocumented thing in the name conventions of our items :(( It was implemented many years ago, and we have not got rid of it.

    Please make your items ending with 's'. Example:
    Auto - autos
    Shop - shops
    Page - pages
    Product - products
    Coupon - coupons
    etc.

    We have one method in our system, load class based on substr that s symbol. Please check iaCore / factoryPackage method.
    Code (Text):

            if ('item' == $name && $params)
            {
                $name = substr($params, 0, -1);
                $class = self::CLASSNAME_PREFIX . ucfirst(strtolower($name));
                $params = null;
            }
            else
            {
                $class = self::CLASSNAME_PREFIX . ucfirst(strtolower($name));
            }
     
    See that substr in the first condition, it gets rid of last s and generate classname. Due to this code you might have that issue.

    To summarize let's imagine you need a new item called EXAMPLE:
    class controller filename would be: ia.admin.example.php
    class name would be: iaExample
    item name would be: examples

    If you follow these conventions you won't have any issues and common functionality will work as expected.
  7. ivanvieira

    ivanvieira New Member

    Vasily,

    Really a weird thing . Originally the package contained:
    - class controller: ia.admin.agency.php
    - class name: iaAgency
    - item name: agencies

    The iaCore / factoryPackage method fails removing the "s" getting "agecie". Maybe replace the line:

    Code (Text):
    $name = substr($params, 0, -1);
    By something like this:

    Code (Text):
    $name = depluralize($params);
    Using a function like this:

    Code (Text):
    function depluralize($word){
        // Here is the list of rules. To add a scenario,
        // Add the plural ending as the key and the singular
        // ending as the value for that key. This could be
        // turned into a preg_replace and probably will be
        // eventually, but for now, this is what it is.
        //
        // Note: The first rule has a value of false since
        // we don't want to mess with words that end with
        // double 's'. We normally wouldn't have to create
        // rules for words we don't want to mess with, but
        // the last rule (s) would catch double (ss) words
        // if we didn't stop before it got to that rule.
        $rules = array(
            'ss' => false,
            'os' => 'o',
            'ies' => 'y',
            'xes' => 'x',
            'oes' => 'o',
            'ies' => 'y',
            'ves' => 'f',
            's' => '');
        // Loop through all the rules and do the replacement.
        foreach(array_keys($rules) as $key){
            // If the end of the word doesn't match the key,
            // it's not a candidate for replacement. Move on
            // to the next plural ending.
            if(substr($word, (strlen($key) * -1)) != $key)
                continue;
            // If the value of the key is false, stop looping
            // and return the original version of the word.
            if($key === false)
                return $word;
            // We've made it this far, so we can do the
            // replacement.
            return substr($word, 0, strlen($word) - strlen($key)) . $rules[$key];
        }
        return $word;
    }
    Note: depluralize function referenced at https://sites.google.com/site/chrelad/notes-1/pluraltosingularwithphp (credits are unknown). Items will be mandatorily named in English for the function to be effective.

    It would be a way to solve the problem?
  8. Vasily_B.

    Vasily_B. Project Manager

    Not sure if this a good way also. We have started to add something like this
    '
    <item pages="advsearch" table_name="coupons_shops">shops</item>
    '
    So there is a reserved column for class_name so you would be able to use a better class name soon. For example you'd have agencies as item table, agency as filename, and iaAgency as a class name. Anyhow, now it's just better to use the conventions and it will work as expected :)

Share This Page