ed_classified module

tanyi - December 24, 2008 - 18:00
Project:Classified Ads
Version:5.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I am working on a classified sites with 8 different categories: For Sale, Housing, Personals etc.
When I go to the Submit ad page, I always have the same fields no matter what type of ad I would like to submit. For example the Price field is applicable to the For Sale category but not to the Personals. Is there a way I can make that field "go away" on the Submit ad page when a user selects Personals category for example. The only way I can think of is to use 8 different ed_classified modules for the 8 different categories and add the appropriate fields to the module. That way each category would have a seperate Submit ad page. So how where in the classified ad module do I need to make this changes? Thanks.

#1

triskelion - January 22, 2009 - 20:06

What you want is accomplished with a hack.

1. Create new content type 'for_sale' with a price field. Associate the 'Classified Ads' vocabulary with this content type.

2. In ed_classified.module (about line 530) modify hook node_info:

function ed_classified_node_info() {
  // beware: these must match nodeapi value; name must be same as $node->type for spam module to add spam reporting links
  return array(EDI_CLASSIFIED_MODULE_NAME =>
               array('name' => t('Classified Ads'), // cannot call node_get_types() since it ends up calling this code.
                     'module' => EDI_CLASSIFIED_MODULE_NAME,
                     'description' => t('Contains a title, a body, and an administrator-defined expiration date')),
               'for_sale' =>
               array('name' => t('For Sale'),
                     'module' => EDI_CLASSIFIED_MODULE_NAME,
                     'description' => t('Classified ad with a price field.')));
}

3. If you have direct access to your database, execute the following query:
UPDATE node_type SET module='ed_classified' WHERE type='for_sale';

If you do not have access, add it as an update in ed_classified.install, and run the database update script. Remember to REMOVE the update after you have run it.

Be aware that limiting the content type to particular terms may not be trivial, so you may end up with Personals using the For Sale format :-) Hope this helps.

EDIT:

It may be sufficient just to modify node_type, without hacking hook node_info. Once the content typ is defined in the node_type table, core node info loads it. You can edit the content type without the module field being reset.

Maybe as a feature request for the module -> An admin screen listing user-defined node types, with check boxes to associate them with the ed_classified module.

#2

triskelion - January 22, 2009 - 23:44

Two points:

1. I just confirmed that hook node_info must be changed. A more general solution to my previous is:

/**
* Implementation of hook_node_info().
*/
function ed_classified_node_info() {
  $info = array();
  // beware: these must match nodeapi value; name must be same as $node->type for spam module to add spam reporting links
  $sql = "SELECT type, name, description FROM {node_type} WHERE module = '%s'";
  $result = db_query($sql, EDI_CLASSIFIED_MODULE_NAME);
  while ($type = db_fetch_object($result)) {
    $info["$type->type"] = array( 'name' => t($type->name), 'module' => EDI_CLASSIFIED_MODULE_NAME, 'description' => t($type->description));
  }
  $info[EDI_CLASSIFIED_MODULE_NAME] =      
               array('name' => t('Classified Ads'), // cannot call node_get_types() since it ends up calling this code.
                     'module' => EDI_CLASSIFIED_MODULE_NAME,
                     'description' => t('Contains a title, a body, and an administrator-defined expiration date'));
  return $info;
}

2. If you do NOT associate the new node type with the Classified Ads vocabulary, you can associate a default term with the node using Taxonomy Defaults at http://drupal.org/project/taxonomy_defaults, and the user has no control over the taxonomy. Works like a charm with ed_classified.

#3

grateful_drupal_user - January 22, 2009 - 23:45

@triskelion:

What you want is accomplished with a hack.

Wow, thanks for that bit of effort.

#4

grateful_drupal_user - January 23, 2009 - 03:22

Maybe as a feature request for the module -> An admin screen listing
user-defined node types, with check boxes to associate them with the
ed_classified module.

That's kind of what I was thinking... thanks for the suggestion, I'll investigate (unless you have a patch ready to go, of course!)

#5

triskelion - January 23, 2009 - 03:28

@inactivist

Your welcome, and thanks for the feedback. Coming from the developer, it means a lot!

I just finished a patch for lm_paypal which will preserve its legacy API, and gives the site developer the choice of using node->status to control publication. #362438: Node->status implementation for LM PayPal I am now looking at your module to see if I can do the same.

I would like to find a way to associate lm_paypal subscriptions with paid classifieds, letting lm_paypal handle all the expiry stuff and user communication, while letting ed_classified continue to work on its own, as designed, for the free stuff.

If lyricnz finds the patch worthy and can be convinced to commit it to the D5 dev branch, this might be the beginning of the 'tighter integration with lm_paypal" you mention on the project page. I already have paid classifieds working well in the sandbox.

The only problems I see with the above issue is the 'Create New Add' link still goes to the generic content type. (I know that term-specific links are in your to-do list.) With multiple content types, in the short term, users can be directed to the different types using menu items, and it is not difficult to do a static change to the current link to take the user to a page which gives them a choice.

Thanks for the great module, and I hope you don't mind my fiddling with it.

#6

triskelion - January 25, 2009 - 02:03
Version:5.x-1.5-8» 5.x-1.x-dev
Component:Documentation» Code
Status:active» needs review

I have rolled an initial patch against the D5 dev version. Not quite ready for prime time, but it does everything discussed above.

I ran into a problem with validation using drupal_get_form as a menu callback, so I created callback functions at the top of ed_classified_settings.inc. This approach has the advantage of your being able to include additional page content without having to wrap it in form markup.

You will notice that I split your admin page in two. I wanted to make sure I was doing things correctly, and the result is a tabbed admin menu.

I have confirmed that adding a node using a user-defined content type adds the appropriate record to edi_classified_nodes, but I have not had a chance to make sure that the module handles the expiration properly.

I am currently looking at the 'Create New Ad' question. Would welcome your feedback.

AttachmentSize
ed_classified_content_types00.patch 9.13 KB

#7

triskelion - January 25, 2009 - 20:16

Done.

Menu items are now created for the user to add content for each user-defined content type. The Create a new ad link at the top now takes the user to a page similar to the administrators Create Content page, which gives them the choice of which ad type to use.

A couple of internal changes were required to allow all content types to be counted.

I have also added a section to README.txt explaining the use of the new functions.

Hope this proves useful.

AttachmentSize
ed_classified_content_types01.patch 17.59 KB

#8

triskelion - January 26, 2009 - 11:55

I extended the patch to include the disabling of the ed_classified scheduling and user notification for each selected content type, if required. The default remains to have ed_classified handle these functions.

The site designer can now use Taxonomy Defaults to associate user-defined content types with each term and associate different subscriptions with one or more content types. It is now possible to have different rates for paid ads like personals and items for sale, while retaining the free lost pet or public service ads.

The new functions have all been added without changing the legacy API of the module.

AttachmentSize
ed_classified_content_types02.patch 23.12 KB

#9

LeMale - July 24, 2009 - 13:13

Hi,

Can anyone tell me how to remove ed_classified copyright bouton from it's pages on my site ?

Regards,

#10

kirkhings - August 10, 2009 - 16:00

Has anyone tried the conditional fields module for display certain fields only for certain types? You should be able to tie the price field to only display when 'for sale' is chosen but not 'personals'. I've used it with other content types and it works awesome, no hacks required.

#11

ajzz - December 6, 2009 - 05:12

Will the above code work for Drupal 6.x? Its precisely what I need on a site that is being upgraded from D5-D6.
@triskelion: a patch for D6.x would be much appreciated!

The idea (as mentioned above) is to use the module to support posting for two separate taxonomies and content types to reduce the confusion for the users when posting. For e.g. user can create content of type "Job Listing" or "Classified Ad" (which would need two content-types), each linked to separate taxonomies with their independent vocabularies. Currently, although independent taxonomies can be created for Classified content, only one content type can be exposed to the user for content creation.

 
 

Drupal is a registered trademark of Dries Buytaert.