Getting valuelists/vocabularies ia php (was Editable List View)

26 views
Skip to first unread message

Edward Spiegel

unread,
Nov 22, 2016, 4:28:15 AM11/22/16
to xata...@googlegroups.com
Hi,

Thanks for the feedback. But, I think perhaps you misunderstand the question (or I am misunderstanding your code). I have defined valuelists/vocabularies in valuelists.ini. I am trying to figure out how to retrieve the valuelists/vocabularies -- as I prefer to use valuelists.ini to edit the valuelists.

I have looked through the library and tried accessing Dataface_Valuelisttool and Dataface_Vocabulary, but I haven't been able to make it work. Probably something ignorant on my side.

Have you or anyone else, succeeded in using them to retrieve an existing valuelist?

Thanks,
Edward

On Sun, Nov 20, 2016 at 1:07 PM, Ti Tou <patachou...@gmail.com> wrote:
Hi,

1.
I don't know how works the function xxx__getAddableValues(Dataface_Record $record){}
With xxx is a name field followed by two underscores.

I think it's a good start to check documentation or the code-source
 ./Dataface/DelegateClass.php

2.
For my part, I use function valuelist__xxx
With xxx is a valuelist name declared in valuelists.ini (don't forget, there is two underscores).

  function valuelist__xxx(){
      $query = Dataface_Application::getInstance()->getQuery();
      // you can mix both vocabulary defined in valuelists.ini and an other valuelist for only records edited on relationship
      // if you want to change the value only when the user edited related records on relationship relABC
      if ( array_key_exists('-relationship', $query) && $query['-relationship'] == 'relABC' ){
        $app =& Dataface_Application::getInstance();
        $currentrecord =& $app->getRecord();
        if (! isset($currentrecord)) { return null; }

        // you can add filter
       // for example, you want all the values of the columnV (v as values) from the table tableXYZ only where a column columnC (c as condition) have the exact value valueEV (ev as exact value)
        $newlist = df_get_records_array('tableXYZ', array('columnC'=>'=valueEV'')); // note the "=" after "=>"
        $out = array();
        foreach ( $newlist as $li){
            $out[$li->val('id')] = $li->val('columnV'); // note : in the fields.ini : [columnV] widget:type = select
        }

        return $out;
      }
  }


Try the simpliest (without filter, without check relationship) and adapt gradually.

-
Ti

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at https://groups.google.com/group/xataface.
To view this discussion on the web visit https://groups.google.com/d/msgid/xataface/e66c5dff-8d7c-48b8-9abb-069cd76557b4%40googlegroups.com.

Edward Spiegel

unread,
Nov 23, 2016, 6:40:25 PM11/23/16
to xata...@googlegroups.com
Answering my own question in case it helps someone else in the future.

After digging through the various docs and the Xataface source code, I found a way that works.

If you have a reference to a database record ($record) and want to get a vocabulary named "mylistname", the following will work

$options = $record->_table->getValuelist("mylistname");

You can also grab a field's valuelist without knowing the vocabulary name with this code:

$options =& $table->getValuelist($field['vocabulary']);

Best,

Edward

p.s. Sorry for the duplicate post. I asked this question in two threads and want to make sure that someone finds the answer if they find the question.
Reply all
Reply to author
Forward
0 new messages