liquid_feedback_frontend
view model/initiative.lua @ 124:f740026b1518
add initiator support in delegation
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Mon Sep 20 20:32:04 2010 +0200 (2010-09-20) | 
| parents | 88ac7798b562 | 
| children | f460555c9896 | 
 line source
     1 Initiative = mondelefant.new_class()
     2 Initiative.table = 'initiative'
     4 Initiative:add_reference{
     5   mode          = 'm1',
     6   to            = "Issue",
     7   this_key      = 'issue_id',
     8   that_key      = 'id',
     9   ref           = 'issue',
    10 }
    12 Initiative:add_reference{
    13   mode          = '1m',
    14   to            = "Draft",
    15   this_key      = 'id',
    16   that_key      = 'initiative_id',
    17   ref           = 'drafts',
    18   back_ref      = 'initiative',
    19   default_order = '"id" DESC'
    20 }
    22 Initiative:add_reference{
    23   mode          = '1m',
    24   to            = "Suggestion",
    25   this_key      = 'id',
    26   that_key      = 'initiative_id',
    27   ref           = 'suggestions',
    28   back_ref      = 'initiative',
    29 }
    31 Initiative:add_reference{
    32   mode          = '1m',
    33   to            = "Initiator",
    34   this_key      = 'id',
    35   that_key      = 'initiative_id',
    36   ref           = 'initiators',
    37   back_ref      = 'initiative'
    38 }
    40 Initiative:add_reference{
    41   mode          = '1m',
    42   to            = "Supporter",
    43   this_key      = 'id',
    44   that_key      = 'initiative_id',
    45   ref           = 'supporters',
    46   back_ref      = 'initiative',
    47   default_order = '"id"'
    48 }
    50 Initiative:add_reference{
    51   mode          = '1m',
    52   to            = "Opinion",
    53   this_key      = 'id',
    54   that_key      = 'initiative_id',
    55   ref           = 'opinions',
    56   back_ref      = 'initiative',
    57   default_order = '"id"'
    58 }
    60 Initiative:add_reference{
    61   mode          = '1m',
    62   to            = "Vote",
    63   this_key      = 'id',
    64   that_key      = 'initiative_id',
    65   ref           = 'votes',
    66   back_ref      = 'initiative',
    67   default_order = '"member_id"'
    68 }
    70 Initiative:add_reference{
    71   mode          = 'm1',
    72   to            = "Initiative",
    73   this_key      = 'suggested_initiative_id',
    74   that_key      = 'id',
    75   ref           = 'suggested_initiative',
    76 }
    78 Initiative:add_reference{
    79   mode                  = 'mm',
    80   to                    = "Member",
    81   this_key              = 'id',
    82   that_key              = 'id',
    83   connected_by_table    = '"initiator"',
    84   connected_by_this_key = 'initiative_id',
    85   connected_by_that_key = 'member_id',
    86   ref                   = 'initiating_members'
    87 }
    89 Initiative:add_reference{
    90   mode                  = 'mm',
    91   to                    = "Member",
    92   this_key              = 'id',
    93   that_key              = 'id',
    94   connected_by_table    = '"supporter"',
    95   connected_by_this_key = 'initiative_id',
    96   connected_by_that_key = 'member_id',
    97   ref                   = 'supporting_members'
    98 }
   100 Initiative:add_reference{
   101   mode                  = 'mm',
   102   to                    = "Member",
   103   this_key              = 'id',
   104   that_key              = 'id',
   105   connected_by_table    = 'direct_supporter_snapshot',
   106   connected_by_this_key = 'initiative_id',
   107   connected_by_that_key = 'member_id',
   108   ref                   = 'supporting_members_snapshot'
   109 }
   112 function Initiative:get_search_selector(search_string)
   113   return self:new_selector()
   114     :join("draft", nil, "draft.initiative_id = initiative.id")
   115     :add_field( {'"highlight"("initiative"."name", ?)', search_string }, "name_highlighted")
   116     :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?) OR "draft"."text_search_data" @@ "text_search_query"(?)', search_string, search_string }
   117     :add_group_by('"initiative"."id"')
   118     :add_group_by('"initiative"."issue_id"')
   119     :add_group_by('"initiative"."name"')
   120     :add_group_by('"initiative"."discussion_url"')
   121     :add_group_by('"initiative"."created"')
   122     :add_group_by('"initiative"."revoked"')
   123     :add_group_by('"initiative"."admitted"')
   124     :add_group_by('"initiative"."supporter_count"')
   125     :add_group_by('"initiative"."informed_supporter_count"')
   126     :add_group_by('"initiative"."satisfied_supporter_count"')
   127     :add_group_by('"initiative"."satisfied_informed_supporter_count"')
   128     :add_group_by('"initiative"."positive_votes"')
   129     :add_group_by('"initiative"."negative_votes"')
   130     :add_group_by('"initiative"."agreed"')
   131     :add_group_by('"initiative"."rank"')
   132     :add_group_by('"initiative"."suggested_initiative_id"')
   133     :add_group_by('"initiative"."text_search_data"')
   134     :add_group_by('"issue"."population"')
   135     :add_group_by("_initiator.member_id")
   136     :add_group_by("_supporter.member_id")
   137 end
   139 --function Member:get_search_selector(search_string)
   140 --  return self:new_selector()
   141 --    :add_where("active")
   142 --end
   145 function Initiative.object_get:current_draft()
   146   return Draft:new_selector()
   147     :add_where{ '"initiative_id" = ?', self.id }
   148     :add_order_by('"id" DESC')
   149     :single_object_mode()
   150     :exec()
   151 end
   153 function Initiative.object_get:shortened_name()
   154   local name = self.name
   155   if #name > 100 then
   156     name = name:sub(1,100) .. "..."
   157   end
   158   return name
   159 end
   161 function Initiative.object_get:initiator_names()
   162   local members = Member:new_selector()
   163     :join("initiator", nil, "initiator.member_id = member.id")
   164     :add_where{ "initiator.initiative_id = ?", self.id }
   165     :add_where{ "initiator.accepted" }
   166     :exec()
   168   local member_names = {}
   169   for i, member in ipairs(members) do
   170     member_names[#member_names+1] = member.name
   171   end
   172   return member_names
   173 end
