Re: [development] Accessing CCK field data (single, multiple, or shared) from another module
To find the right table for a field for a SQL query, use the API, like this: $db_info = content_database_info($field); $table = $db_info['table']; That will always return the right table for the requested field. $field needs to be the complete field array, not just the field name, so if you only have the field name, you would do: $field = content_fields(my_field_name); $db_info = content_database_info($field); $table = $db_info['table']; content_database_info($field) also contains info about the columns declared by the field so you know what field names to use in a SQL query. It returns an array that looks like: Array ( [table] => content_type_story [columns] => Array ( [value] => Array ( [type] => varchar [length] => 50 [not null] => 1 [default] => '' [sortable] => 1 [column] => field_phone_value ) [value2] => Array ( [type] => int [length] => 10 [unsigned] => 1 [not null] => 1 [default] => 0 [column] => field_phone_type ) ) ) ----- Original Message ---- From: Rob Barreca <rob@electronicinsight.com> To: development@drupal.org Sent: Thursday, March 22, 2007 7:55:31 PM Subject: Re: [development] Accessing CCK field data (single, multiple, or shared) from another module
Is there a function for getting the data that you can just give a node type and a field name and it handles the rest?
This is something I've just run into as well. I have a hardcoded to query the DB for the multiple field table, but have a TODO in there to find the right API call. Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com Benjamin Melançon wrote:
Gracious developers, CCK people especially...
I wrote an access control module that works with the node relativity module to cascade permissions to all nodes lower in a hierarchy. I hard-coded a query for a userreference field on a custom content type as one way to give a user access to a node (and its descendants).
In generalizing this, the current stumbling block is the way CCK stores single instances in the content data table and shared instances of a field in a separate table.
Is there a function for getting the data that you can just give a node type and a field name and it handles the rest?
Or is there a place to check what the case is for a particular field? (Even a "column_exists()" function would do it for me, but haven't found one in PHP...)
It's being developed in Drupal 5 and fixing this (as well as saving explicitly permitted users when creating a new node) is all that's needed for posting the project for general use.
Many thanks,
ben
Agaric Design Collective Open Source Web Development http://AgaricDesign.com/
People Who Give a Damn building the infrastructure of a network for everyone http://pwgd.org/
$db_info = content_database_info($field); $table = $db_info['table'];
Karen, You rock! Thanks for enlightening us. Take care, Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com Karen Stevenson wrote:
To find the right table for a field for a SQL query, use the API, like this:
$db_info = content_database_info($field); $table = $db_info['table'];
That will always return the right table for the requested field.
$field needs to be the complete field array, not just the field name, so if you only have the field name, you would do:
$field = content_fields(my_field_name); $db_info = content_database_info($field); $table = $db_info['table'];
content_database_info($field) also contains info about the columns declared by the field so you know what field names to use in a SQL query. It returns an array that looks like:
Array ( [table] => content_type_story [columns] => Array ( [value] => Array ( [type] => varchar [length] => 50 [not null] => 1 [default] => '' [sortable] => 1 [column] => field_phone_value ) [value2] => Array ( [type] => int [length] => 10 [unsigned] => 1 [not null] => 1 [default] => 0 [column] => field_phone_type ) ) )
----- Original Message ---- From: Rob Barreca <rob@electronicinsight.com> To: development@drupal.org Sent: Thursday, March 22, 2007 7:55:31 PM Subject: Re: [development] Accessing CCK field data (single, multiple, or shared) from another module
Is there a function for getting the data that you can just give a node type and a field name and it handles the rest?
This is something I've just run into as well. I have a hardcoded to query the DB for the multiple field table, but have a TODO in there to find the right API call.
Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com
Benjamin Melançon wrote:
Gracious developers, CCK people especially...
I wrote an access control module that works with the node relativity module to cascade permissions to all nodes lower in a hierarchy. I hard-coded a query for a userreference field on a custom content type as one way to give a user access to a node (and its descendants).
In generalizing this, the current stumbling block is the way CCK stores single instances in the content data table and shared instances of a field in a separate table.
Is there a function for getting the data that you can just give a node type and a field name and it handles the rest?
Or is there a place to check what the case is for a particular field? (Even a "column_exists()" function would do it for me, but haven't found one in PHP...)
It's being developed in Drupal 5 and fixing this (as well as saving explicitly permitted users when creating a new node) is all that's needed for posting the project for general use.
Many thanks,
ben
Agaric Design Collective Open Source Web Development http://AgaricDesign.com/
People Who Give a Damn building the infrastructure of a network for everyone http://pwgd.org/
Sorry for the slowest response time ever, let me also say thank you very much Karen for the enlightenment, which made this module fit for public consumption, http://drupal.org/project/relativity_access ben ~ In living, loving memory: http://melanconent.com/john-melancon-life ~ On 3/24/07, Rob Barreca <rob@electronicinsight.com> wrote:
$db_info = content_database_info($field); $table = $db_info['table'];
Karen,
You rock! Thanks for enlightening us.
Take care, Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com
Karen Stevenson wrote: To find the right table for a field for a SQL query, use the API, like this:
$db_info = content_database_info($field); $table = $db_info['table'];
That will always return the right table for the requested field.
$field needs to be the complete field array, not just the field name, so if you only have the field name, you would do:
$field = content_fields(my_field_name); $db_info = content_database_info($field); $table = $db_info['table'];
content_database_info($field) also contains info about the columns declared by the field so you know what field names to use in a SQL query. It returns an array that looks like:
Array ( [table] => content_type_story [columns] => Array ( [value] => Array ( [type] => varchar [length] => 50 [not null] => 1 [default] => '' [sortable] => 1 [column] => field_phone_value ) [value2] => Array ( [type] => int [length] => 10 [unsigned] => 1 [not null] => 1 [default] => 0 [column] => field_phone_type ) ) )
----- Original Message ---- From: Rob Barreca <rob@electronicinsight.com> To: development@drupal.org Sent: Thursday, March 22, 2007 7:55:31 PM Subject: Re: [development] Accessing CCK field data (single, multiple, or shared) from another module
Is there a function for getting the data that you can just give a node type and a field name and it handles the rest?
This is something I've just run into as well. I have a hardcoded to query the DB for the multiple field table, but have a TODO in there to find the right API call.
Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com
Benjamin Melançon wrote:
Gracious developers, CCK people especially...
I wrote an access control module that works with the node relativity module to cascade permissions to all nodes lower in a hierarchy. I hard-coded a query for a userreference field on a custom content type as one way to give a user access to a node (and its descendants).
In generalizing this, the current stumbling block is the way CCK stores single instances in the content data table and shared instances of a field in a separate table.
Is there a function for getting the data that you can just give a node type and a field name and it handles the rest?
Or is there a place to check what the case is for a particular field? (Even a "column_exists()" function would do it for me, but haven't found one in PHP...)
It's being developed in Drupal 5 and fixing this (as well as saving explicitly permitted users when creating a new node) is all that's needed for posting the project for general use.
Many thanks,
ben
Agaric Design Collective Open Source Web Development http://AgaricDesign.com/
People Who Give a Damn building the infrastructure of a network for everyone http://pwgd.org/
I hope this post is appropriate in this list. If not please accept my apology. As Drupal newbie I was hoping to get some advise on how to accomplish what I feel is something very simple, yet being unfamiliar with Drupal seems very difficult for me. I'd like to be able to add several form fields to an article (node) that would allow an administrator/author to specify if it is exclusive to a specific role. If so I'd like a pulldown menu that allows me to select which role it should be exclusive to. Then I'd like start date and end date fields to specify when this article should remain exclusive (the idea being that once it's past the end date it will no longer be exclusive and therefore be available to everyone). So far I've tried using CCK along with the Date module and JsTools (jscalendar). First off I cannot get jscalendar to work at all. no calendar is visible when you click on the text field, even though it is specified. Secondly, there doesn't seem to be any way of requring that if the exclusive checkbox is checked that the Role pulldown and startdate and enddate fields are completed. I appear to only be able to say that the start date and end date are required, even though they should not be if the exclusive checkbox is not checked. Third, I'm not sure how using CCK I would add a pulldown menu that dynamically gets filled with all roles. Is this possible? Last, how does one go about adding special validation to a node so that if specific fields are checked that other fields are required, if they're not checked then the other fields are not required, etc.? Is this beyond the scope of CCK? If so, how would you recommend accomplishing this? Any advice, insight, reference links would be GREATLY appreciated. best regards, brian
Hello, Brian, First, welcome to Drupal -- Second, the dev list is for concerns centered around development issues -- your question is more appropriate for the support list, or for the post-installation questions forum on drupal.org -- Third, if I understand you correctly, the content access module will meet your needs. Cheers, Bill Brian Tully wrote:
I hope this post is appropriate in this list. If not please accept my apology.
As Drupal newbie I was hoping to get some advise on how to accomplish what I feel is something very simple, yet being unfamiliar with Drupal seems very difficult for me.
I'd like to be able to add several form fields to an article (node) that would allow an administrator/author to specify if it is exclusive to a specific role.
If so I'd like a pulldown menu that allows me to select which role it should be exclusive to.
Then I'd like start date and end date fields to specify when this article should remain exclusive (the idea being that once it's past the end date it will no longer be exclusive and therefore be available to everyone).
So far I've tried using CCK along with the Date module and JsTools (jscalendar).
First off I cannot get jscalendar to work at all. no calendar is visible when you click on the text field, even though it is specified.
Secondly, there doesn't seem to be any way of requring that if the exclusive checkbox is checked that the Role pulldown and startdate and enddate fields are completed. I appear to only be able to say that the start date and end date are required, even though they should not be if the exclusive checkbox is not checked.
Third, I'm not sure how using CCK I would add a pulldown menu that dynamically gets filled with all roles. Is this possible?
Last, how does one go about adding special validation to a node so that if specific fields are checked that other fields are required, if they're not checked then the other fields are not required, etc.? Is this beyond the scope of CCK? If so, how would you recommend accomplishing this?
Any advice, insight, reference links would be GREATLY appreciated.
best regards, brian
-- Bill Fitzgerald http://www.funnymonkey.com Tools for Teachers 503.897.7160
participants (5)
-
Benjamin Melançon -
Bill Fitzgerald -
Brian Tully -
Karen Stevenson -
Rob Barreca