Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Bricolage: users

Basic assistance with code selects

 

 

Bricolage users RSS feed   Index | Next | Previous | View Threaded


phillip at communitybandwidth

Jul 27, 2008, 1:56 PM

Post #1 of 5 (234 views)
Permalink
Basic assistance with code selects

Hi ho,

Have to admit, I've never explored codeselects before. And I'm not
finding any documentation or examples to work from. Any quick pointers?

I'd like to return a list of stories (by title) of a particular type
to the contributor screen (when creating / editing a contributor).
From there, I'd like the user to select a story, and for that story's
id to be available to me via something like:

% my @contribs = $story->get_contributors;
% foreach my $contrib (@contribs) {
% my $bio_id = $contrib->get_data('blog_bio_id');
% }

Many thanks in advance,

Phillip.

--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.communitybandwidth.ca


greg at node79

Jul 27, 2008, 2:29 PM

Post #2 of 5 (214 views)
Permalink
Re: Basic assistance with code selects [In reply to]

> Have to admit, I've never explored codeselects before. And I'm not
> finding any documentation or examples to work from. Any quick
> pointers?

The basic idea is to build a hash where the hash key will become the
"value" part of the <option> element, and the hash value will be
what's displayed. So { '1024' => 'My Story' } will be HTMLized as
<option value="1024">My Story</option>.

You'd probably need to do a story list and loop through to build the
hash:

my %bios_hash;
my @bios_list = Bric::Biz::Asset::Business::Story-
>list({element_key_name => 'bio_page'});

foreach (@bios_list) {
$bios_hash{$_->get_id} = $_->get_title;
}

return \%bios_hash;

Assuming "bio_page" is the key name of the story element type;
publish_status, order, etc. should be added to the Story->list() as
required too.

HTH,
-Greg


lannings at who

Jul 27, 2008, 2:33 PM

Post #3 of 5 (220 views)
Permalink
Re: Basic assistance with code selects [In reply to]

On Sun, 27 Jul 2008, Phillip Smith wrote:
> I'd like to return a list of stories (by title) of a particular type to the
> contributor screen (when creating / editing a contributor). From there, I'd
> like the user to select a story, and for that story's id to be available to
> me via something like:
>
> % my @contribs = $story->get_contributors;
> % foreach my $contrib (@contribs) {
> % my $bio_id = $contrib->get_data('blog_bio_id');
> % }

I'm not sure what you mean by returning the list
to the contributor screen. Code Select is a data field in a story,
just like Select lists but where the items are generated by code.
So when you go in the Element Type profile, you can add a custom field
with type Code Select at the bottom. Instead of putting value,label
on lines as you do with Select fields, you add Perl code there.
Greg added the $field object that you can access from this code.
That is a handle on the Code Select $field itself, so you can
use the methods of Bric::Biz::Element::Field (and base classes)
on it.
I don't think the $story object is defined there.
Offhand, I think you'd get the story object with something
like

my ($oiid) = $field->get_object_instance_id;
my ($story) = Bric::Biz::Asset::Business::Story->list({version_id => $oiid});


phillip at communitybandwidth

Jul 27, 2008, 3:01 PM

Post #4 of 5 (222 views)
Permalink
Re: Basic assistance with code selects [In reply to]

On 27-Jul-08, at 5:29 PM, Greg Heo wrote:

>> Have to admit, I've never explored codeselects before. And I'm not
>> finding any documentation or examples to work from. Any quick
>> pointers?
>
> The basic idea is to build a hash where the hash key will become the
> "value" part of the <option> element, and the hash value will be
> what's displayed. So { '1024' => 'My Story' } will be HTMLized as
> <option value="1024">My Story</option>.
>
> You'd probably need to do a story list and loop through to build the
> hash:
>
> my %bios_hash;
> my @bios_list = Bric::Biz::Asset::Business::Story-
> >list({element_key_name => 'bio_page'});
>
> foreach (@bios_list) {
> $bios_hash{$_->get_id} = $_->get_title;
> }
>
> return \%bios_hash;
>
> Assuming "bio_page" is the key name of the story element type;
> publish_status, order, etc. should be added to the Story->list() as
> required too.


Bingo! :-) Cookies for Greg.


On 27-Jul-08, at 5:33 PM, Scott Lanning wrote:

> I'm not sure what you mean by returning the list
> to the contributor screen. Code Select is a data field in a story,
> just like Select lists but where the items are generated by code.


Actually, the contributor type screen allows the addition of custom
fields too, and one of the options is codeselect.

In the scenario above, I'm providing a list of possible contributor
bios (which are actual stories) on the Contributor -> New or
Contributor -> Edit screen. In those stories, I'm storing a bunch of
information, including contributor photos, etc.

Working nicely now. Thanks!

:-)

Still working on this though:

3) If I use the roles option when looking up contributor data, how
does one get the value on role-specific custom fields, e.g.:

% my @contribs = $story->get_contributors;
% foreach my $contrib (@contribs) {
% my @roles = $contrib->get_roles;
% foreach my $role (@roles) {
% if ($role eq 'blogger') {
% my $name = $contrib->get_name('%f %l');
% my $bio = $contrib->get_data('Bio');
% my $bio_id = $contrib->get_data('blog_bio_id_temp');
% my $contrib_id = $contrib->get_id;
<% $role %>
<% $bio %>
<% $bio_id %>
<% $name %>
<% $contrib_id %>
% }
% }
% }

... does not return the value for the custom fields for the "blogger"
role; instead, it returns the values from the "default" role (with the
exception of the $role, which is correctly returned as "blogger").

Any thoughts appreciated.

--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.communitybandwidth.ca


david at kineticode

Jul 27, 2008, 5:23 PM

Post #5 of 5 (221 views)
Permalink
Re: Basic assistance with code selects [In reply to]

On Jul 27, 2008, at 13:56, Phillip Smith wrote:

> Have to admit, I've never explored codeselects before. And I'm not
> finding any documentation or examples to work from. Any quick
> pointers?

Could someone write some docs for it, perhaps to go into the context-
sensitive help?

Thanks,

David

Bricolage users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.