ad_library { Classified Ads Procs (Containers) @author Deds Castillo (deds@infiniteinfo.com) @creation-date 2002-10-08 @cvs-id $Id: ads-procs.tcl.old,v 1.1 2003/07/16 04:52:32 rmello Exp $ } namespace eval classified-ads::ads {} ad_proc -public ::classified-ads::ads::new { {-item_id_element:required} {-form_id:required} {-parent_id} } { Creates a new ad @author Deds Castillo @author Roberto Mello @param form_id The ID of the form that contains the name/value pairs @param item_id_element The name of the form element that should be used as the item id @param parent_id The parent of this ad (category) } { if { [empty_string_p $parent_id] } { set package_id [ad_conn package_id] set parent_id [get_folder_id -package_id $package_id] } return [classified-ads::create_ca_item -item_id_element $item_id_element \ -content_type "ca_ad" \ -form_id $form_id \ -parent_id $parent_id \ ] } ad_proc -public ::classified-ads::ads::edit { {-item_id_element:required} {-form_id:required} } { Edits properties of an existing ad @param form_id The ID of the form that contains the name/value pairs @param item_id_element The name of the form element that should be used as the item id } { return [classified-ads::edit_ca_item -item_id_element $item_id_element \ -form_id $form_id \ ] } ad_proc -public ::classified-ads::ads::delete { {-ad_id:required} } { delete an existing ad @param ad_id The item id of the ad to delete } { db_transaction { db_exec_plsql delete_ad {} db_exec_plsql delete_content {} } return 0 } ad_proc -public ::classified-ads::ads::get { {-ad_id:required} {-revision_id ""} {-array:required} } { Gets the data of a particular ad @param item_id The ID ad to get @param revisionid If present, then get the data for this revision. If not get the data for the latest revision @param array The array where the data is stored } { upvar $array row if {[empty_string_p $revision_id]} { set revision_id [classified-ads::get_latest_revision -item_id $ad_id] } db_1row select_data {} # DEDS: FIXME - you know what's wrong here right? set row(title) $title set row(description) $description set row(data) [classified-ads::get_content -revision_id $revision_id] return 0 } ad_proc -public ::classified-ads::ads::get_assigned_ads_by_category { {-category_id_list ""} } { Gets all the ads assigned to categories @param category_id_list A list of category ids. The system returns all ads mapped to these categories. } { # DEDS: FIXME - this uses a subselect. this will get inefficient # when faced with a large db. optimize this. set condition_stub "" if {[llength $category_id_list]} { set condition_stub "and keyword_id in ([join $category_id_list ", "])" } set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] return [db_list_of_ns_sets select_ads {}] } ad_proc -public ::classified-ads::ads::get_unassigned_ads_by_category { {-category_id_list ""} } { Gets all the ads NOT assigned to the categories passed. @param container_id_list A list of category ids. The system returns all ads not mapped to these categories. } { # DEDS: FIXME - this uses a subselect. this will get inefficient # when faced with a large db. optimize this. set condition_stub "" if {[llength $category_id_list]} { set condition_stub "where keyword_id in ([join $category_id_list ", "])" } set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] return [db_list_of_ns_sets select_ads {}] }