How create a list of existing categories?

  • Thread starter Thread starter Deleted member 10469
  • Start date Start date
D

Deleted member 10469

Guest
Hello, i would like know how create a list of existing categories for admin options please.

Can you help me please ?
It's for remplace this option:

2hwzb.jpg


Thanks :)
 
Hello, i would like know how create a list of existing categories for admin options please.

Can you help me please ?
It's for remplace this option:

2hwzb.jpg


Thanks :)
I don't have access to a development environment of work, but I've found an option that has a node-listing in a drop down. Checkout Options > Spam Management > Spam Cleaner Thread Action and look to see how XF has done that.
 
Hello, i would like know how create a list of existing categories for admin options please.

Can you help me please ?
It's for remplace this option:

2hwzb.jpg


Thanks :)

If I have correctly understood your question, I think I've done it in the ToogleMe addon:

Check this class Sedo_ToggleME_Option_Factory and this part of the code:
PHP:
    public static function render_nodes(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
    {
        $preparedOption['formatParams'] = XenForo_Model::create('Sedo_ToggleME_Model_GetNodes')->getNodesOptions($preparedOption['option_value']);
        return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal('option_list_option_checkbox', $view, $fieldPrefix, $preparedOption, $canEdit);
    }

Then check this class Sedo_ToggleME_Model_GetNodes (all of it)

Your XenForo option must use a callback. See in the addon or just check this part in the install xml:
Code:
    <option option_id="toggleME_Usergroups_Forumhome" edit_format="callback" data_type="array" can_backup="1">
      <default_value>a:4:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";i:3;s:1:"4";}</default_value>
      <edit_format_params>Sedo_ToggleME_Option_Factory::render_usergroups</edit_format_params>
      <sub_options>*</sub_options>
      <relation group_id="toggleME" display_order="200"/>
    </option>
 
Thank you, it's good :)

2hCqm.jpg


But how can I make it to display as dropdown please ? :)

Edit: j'ai essayé ça mais j'ai une erreur:
2hCyL.jpg


Please select a data type other than 'array' if you want to allow single selections only.

I would like the user to be able to select only one result in a dropdown.
 
Thank you, it's good :)

2hCqm.jpg


But how can I make it to display as dropdown please ? :)

Edit: j'ai essayé ça mais j'ai une erreur:
2hCyL.jpg




I would like the user to be able to select only one result in a dropdown.
change the template used within the callback to be option_list_option_select, and you should be good.
 
Thanks, it's ok:
2hDgw.jpg



But I have this errors:

Template Errors: option_list_option_select

  1. htmlspecialchars() expects parameter 1 to be string, array givenin /home/zephyr62/www/XenCreaDemo/Forum/library/XenForo/Template/Abstract.php(265) : eval()'d code, line 9:
    8: ';
    9: $__output .= XenForo_Template_Helper_Admin::selectUnit(htmlspecialchars($preparedOption['title']), htmlspecialchars($fieldPrefix) . '[' . htmlspecialchars($preparedOption['option_id']) . ']', htmlspecialchars($preparedOption['option_value']), $__compilerVar1, array(
    10: 'hint' => htmlspecialchars($preparedOption['hint']),
 
Thanks, it's ok:
2hDgw.jpg



But I have this errors:

Template Errors: option_list_option_select

  1. htmlspecialchars() expects parameter 1 to be string, array givenin /home/zephyr62/www/XenCreaDemo/Forum/library/XenForo/Template/Abstract.php(265) : eval()'d code, line 9:
    8: ';
    9: $__output .= XenForo_Template_Helper_Admin::selectUnit(htmlspecialchars($preparedOption['title']), htmlspecialchars($fieldPrefix) . '[' . htmlspecialchars($preparedOption['option_id']) . ']', htmlspecialchars($preparedOption['option_value']), $__compilerVar1, array(
    10: 'hint' => htmlspecialchars($preparedOption['hint']),

Change your data type from "Array" to string (or integer).
 
String or Integer =>
An exception occurred: in_array() expects parameter 2 to be array, string given in /home/zephyr62/www/XenCreaDemo/Forum/library/XenCrea/Colorize/Model/GetNodes.php on line 14

:S
 
String or Integer =>
An exception occurred: in_array() expects parameter 2 to be array, string given in /home/zephyr62/www/XenCreaDemo/Forum/library/XenCrea/Colorize/Model/GetNodes.php on line 14

:S
I don't have enouhg information to help you. I need to see XenCrea_Colorize_Model_GetNodes to help you out there. But without looking, its most likely you need to get rid of an in_array() and just pull in the options.
 
Oups sorry ^^

HTML:
<?php
 
class XenCrea_Colorize_Model_GetNodes extends XenForo_Model
{
    public function getNodesOptions($selectedNodesIds)
    {
 
        $nodes = array();
        foreach ($this->getDbNodes() AS $node)
        {
            $nodes[] = array(
            'label' => $node['title'],
            'value' => $node['node_id'],
            'selected' => in_array($node['node_id'], $selectedNodesIds)
            );
        }
 
        return $nodes;
    }
 
    public function getDbNodes()
    {
 
        return $this->_getDb()->fetchAll('
        SELECT node_id, title, node_type_id
        FROM xf_node
        WHERE node_type_id = ?
        ORDER BY node_id
        ', 'Category');
 
    }
}

I have remplaced:
'selected' => in_array($node['node_id'], $selectedNodesIds)

by
'selected' => $selectedNodesIds

But no work :S
 
Oups sorry ^^

HTML:
<?php
 
class XenCrea_Colorize_Model_GetNodes extends XenForo_Model
{
    public function getNodesOptions($selectedNodesIds)
    {
 
        $nodes = array();
        foreach ($this->getDbNodes() AS $node)
        {
            $nodes[] = array(
            'label' => $node['title'],
            'value' => $node['node_id'],
            'selected' => in_array($node['node_id'], $selectedNodesIds)
            );
        }
 
        return $nodes;
    }
 
    public function getDbNodes()
    {
 
        return $this->_getDb()->fetchAll('
        SELECT node_id, title, node_type_id
        FROM xf_node
        WHERE node_type_id = ?
        ORDER BY node_id
        ', 'Category');
 
    }
}

I have remplaced:
'selected' => in_array($node['node_id'], $selectedNodesIds)

by
'selected' => $selectedNodesIds

But no work :S
You most likely want:
PHP:
'selected' => ($node['node_id'] == $selectedNodesIds)
 
There are many things you need to modify if you want a list and according to the type of list you want, but are you sure you really want that? I mean do you want to use a list with a single selection (string) or with several selections (array) ?

If it's a single selection, XenForo has a pre-made template for this
1) Do what King Kovifor told you
PHP:
    public function getNodesOptions($selectedNodesId)
    {
 
        $nodes = array();
        foreach ($this->getDbNodes() AS $node)
        {
            $nodes[] = array(
            'label' => $node['title'],
            'value' => $node['node_id'],
            'selected' => ($node['node_id'] == $selectedNodesId)
            );
        }
 
        return $nodes;
    }

2) Change the template rendering name in this code
PHP:
        return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal('option_list_option_select', $view, $fieldPrefix, $preparedOption, $canEdit);
The template name is here "option_list_option_select"

3) Edit the option in XenOptions, change array to boolean (forum id will be booleans) and delete the sub-array "*"

It will work

If you want a multi selection list:
1) Create a new admin template
For example: "option_list_option_youraddon_multiselect"

Here's the code Jaxel already used for XenPorta:
HTML:
<xen:selectunit label="{$preparedOption.title}" name="{$fieldPrefix}[{$preparedOption.option_id}]" value="{xen:raw $preparedOption.option_value}"
hint="{$preparedOption.hint}" size="10" multiple="true">
    <xen:options source="$formatParams" />
    <xen:explain>{xen:raw $preparedOption.explain}</xen:explain>
    <xen:html>
        <input type="hidden" name="{$listedFieldName}" value="{$preparedOption.option_id}" />
        {xen:raw $editLink}
    </xen:html>
</xen:selectunit>

2) Change the template rendering name in this code
PHP:
        return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal('option_list_option_youraddon_multiselect', $view, $fieldPrefix, $preparedOption, $canEdit);

3) That's all (it's still an array)
 
Thanks, I have no errors but I still have problems.

List is ok, I do not have a null value possible, I need one.

2i2Zk.jpg


Then I have no errors, but when I agree, it is always the category which has id 1 which is stored in the database (I checked by displaying the variables in my views).

Finally, do you know where I can add code to load a javascript/jquery and css to my page options please?
I tried to add it in the description of an option, but no work even though the code seems to load, It's functional (tested in a view).

Anyway thank you for your help, I would offer you the style (premium style) that will work with the addon when it will be ready in a few days it should please you, It's very colorful, flexible and lovely at the same time! ^^
 
List is ok, I do not have a null value possible, I need one.Then I have no errors, but when I agree, it is always the category which has id 1 which is stored in the database (I checked by displaying the variables in my views).
Hey, that's a basic array, you just need to add an element in it;)
I don't know which system you've chosen, but replace "$nodes = array();" with something like this:
Code:
            $nodes[] = array(
            'label' => 'yourLabel',
            'value' => 'yourBlankValue',
            'selected' => in_array('yourBlankValue', $selectedNodesIds)
            );

Finally, do you know where I can add code to load a javascript/jquery and css to my page options please?
Nobody can reply to that question. All depends what you want to do, if the JS must be load on every page on not, etc. Just find the best template hook listeners (or post template listener) to add your own template (after to have cached it) with your JS code or CSS. Or use TMS. It's your decision. If you choose the listener option, try to add a timestamp to your JS file (what I often forgot to do). You can find an example in the ToggleMe addon.

The listener (simplified for the example):
PHP:
            case 'page_container_head':
                $viewParams = array(
                    'toggleme_js_version' => filemtime("js/sedo/toggleme/toggleME.js")
                );
 
                $contents .= $template->create('toggleme_page_container_js', $viewParams);
            break;

The template:
HTML:
<xen:require js="js/sedo/toggleme/toggleME.js?{$toggleme_js_version}" />
 
Parse error: syntax error, unexpected ',' in /home/zephyr62/www/XenCreaDemo/Forum/library/XenCrea/Colorize/Model/GetNodes.php on line 11

I'm not sure I understood what to do:

(Fr: Pour être sûr de se comprendre, je cherche juste à rajouter un champ null à ma liste de catégorie pour que par défaut il ne puisse pas y avoir deux fois la même catégorie de sélectionné et ne pas créer de problèmes tout en faisant disparaitre le bug qui définie toujours la catégorie 1, j'arrive à bien dev avec Symfony2 mais avec Zend c'est une torture quand on connais pas les bases et ça me ralentit dans certain webdesign qui fonctionnent avec addon :S N'à tu jamais pensé, eu l'envie ou même le temps de faire des tutoriels pour la communauté fr ? Je ne sait pas si cela t’intéresserait et même si ça aiderais beaucoup de monde, mais en tout cas je serait un fervent lecteur si tu te lancez la dedans ! ^^ )

HTML:
<?php
 
class XenCrea_Colorize_Model_GetNodes extends XenForo_Model
{
    public function getNodesOptions($selectedNodesId)
    {
 
        $nodes[] = array(
            'label' => $node['title'],
            'value' => 'yourBlankValue',
            'selected' => ('yourBlankValue', $selectedNodesIds)
            );
 
        foreach ($this->getDbNodes() AS $node)
        {
            $nodes[] = array(
            'label' => $node['title'],
            'value' => $node['node_id'],
            'selected' => ($node['node_id'] == $selectedNodesId)
            );
        }
 
        return $nodes;
    }
 
    public function getDbNodes()
    {
 
        return $this->_getDb()->fetchAll('
        SELECT node_id, title, node_type_id
        FROM xf_node
        WHERE node_type_id = ?
        ORDER BY node_id
        ', 'Category');
 
    }
}

For the listener I'll watch it once this problem is solved :)
 
Mais là il ne s'agit de Zend ou tout autre framework, mais juste d'un simple tableau... Tu utilises "$node['title']" alors que la variable $node n'est pas déclarée... tu n'es pas dans la boucle foreach. Ensuite ce code ne veut pas dire grand chose " ('yourBlankValue', $selectedNodesIds)". C'est supposé être une condition (au format court) à l'image de ce qui est fait plus bas.
 
J'ai réussi à afficher le champs, par-contre je ne sait pas si j'ai fait ça comme il le faillais pour que ça fonctionne avec xenforo, et mon 'selected' m'a l'air incorrecte, je ne sait pas à quoi il sert ni même quoi en faire :

2i67W.jpg


PHP:
    public function getNodesOptions($selectedNodesId)
    {
        $bool = false;
 
        foreach ($this->getDbNodes() AS $node)
        {
            if ( $bool == false )
            {
                $nodes[] = array(
                'label' => 'Disabled',
                'value' => 'null',
                'selected' => ('NoChoice' == $selectedNodesId)
                );
              $bool = true;
            }
 
            $nodes[] = array(
            'label' => $node['title'],
            'value' => $node['node_id'],
            'selected' => ($node['node_id'] == $selectedNodesId)
            );
        }
 
        return $nodes;
    }
 
It's good it works now, had to integer and not boolean :)

I'm looking for .js now.
 
Use this, it will be cleaner:
PHP:
    public function getNodesOptions($selectedNodesId)
    {
       $nodes[] = array(
            'label' => new XenForo_Phrase('yourAddon_admin_optionName'),
            'value' => 0,
            'selected' => (0 == $selectedNodesId)
            );
               
        foreach ($this->getDbNodes() AS $node)
        {
            $nodes[] = array(
                'label' => $node['title'],
                'value' => $node['node_id'],
                'selected' => ($node['node_id'] == $selectedNodesId)
                );
        }
 
        return $nodes;
    }
 
    public function getDbNodes()
    {
 
        return $this->_getDb()->fetchAll('
        SELECT node_id, title, node_type_id
        FROM xf_node
        WHERE node_type_id = ?
        ORDER BY node_id
        ', 'Category');
 
    }

Et un petit cours sur les tableaux (array) pour éviter tout problème à l'avenir ;)
 
Top Bottom