Wtx ~ Wt Extension Library
WtxLib
Activity.cpp
1 
2 #include <Wtx/Dbo/QueryModel.h>
3 #include <Wtx/Core/Core.h>
4 
5 #include "Activity.h"
6 
7 void Wtx::Crm::Activity::mapClasses( Wtx::Dbo::Session & session )
8 {
9  Wtx::Crm::Activity::Item::MapClass( session );
10 }
11 
12 void Wtx::Crm::Activity::postCreateTables( Wtx::Dbo::Session & session )
13 {
15 
16 // Wt::Dbo::Transaction t(session);
17 // auto sysLookup = session.addNew< Wtx::Sys::Lookup::Item >( "" );
18 // sysLookup.modify()-> cfyField().setValue( "*" );
19 
20 }
21 
28 Wt::Dbo::ptr< Wtx::Crm::Activity::Item > Wtx::Crm::Activity::add( const std::string & key, const Wt::WDate & date, Wtx::Dbo::Session & session )
29 {
30  Wt::Dbo::ptr< Wtx::Crm::Activity::Item > retVal;
31 
32  if( key != "" )
33  {
34  Wt::Dbo::Transaction t(session);
35  retVal =
36  session.find<Wtx::Crm::Activity::Item>()
37  .where( "UPPER(\"keyField\") = UPPER(?)").bind( key )
38  .where( "\"dateStart\" = ?").bind( date )
39  .resultValue()
40  ;
41 
42  }
43 
44 #ifdef NEVER
45  std::cout << __FILE__ << ":" << __LINE__
46  << " " << retVal
47  << " " << date.toString()
48  << " " << retVal-> keyField().value()
49  << std::endl
50  ;
51 #endif
52 
57  if( !retVal )
58  {
59  Wt::Dbo::Transaction t(session);
60  retVal = session.addNew<Wtx::Crm::Activity::Item>( key );
61  retVal.modify()-> dateStart().setValue( date );
62  }
63 
64  return retVal;
65 
66 } // endWt::Dbo::ptr< Wtx::Crm::Activity::Item > Wtx::Crm::Activity::add( const std::string & key, const Wt::WDateTime & dateTime, Wtx::Dbo::Session & session )
67 
74 Wt::Dbo::ptr< Wtx::Crm::Activity::Item > Wtx::Crm::Activity::add( const std::string & key, const Wt::WDateTime & dateTime, Wtx::Dbo::Session & session )
75 {
76  Wt::Dbo::ptr< Wtx::Crm::Activity::Item > retVal;
77 
78  if( key != "" )
79  {
80  Wt::Dbo::Transaction t(session);
81  retVal =
82  session.find<Wtx::Crm::Activity::Item>()
83  .where( "UPPER(\"keyField\") = UPPER(?)").bind( key )
84  .where( "\"dateStart\" = ?").bind( dateTime.date() )
85  .where( "\"timeStart\" = ?").bind( dateTime.time() )
86  .resultValue()
87  ;
88 
89  }
90 
91 #ifdef NEVER
92  std::cout << __FILE__ << ":" << __LINE__
93  << " " << retVal << retVal-> keyField().value()
94  << " " << dateTime.toString()
95  << std::endl
96  ;
97 #endif
98 
103  if( !retVal )
104  {
105  Wt::Dbo::Transaction t(session);
106  retVal = session.addNew<Wtx::Crm::Activity::Item>( key );
107  retVal.modify()-> dateStart().setValue( dateTime.date() );
108  retVal.modify()-> timeStart().setValue( dateTime.time() );
109  }
110 
111  return retVal;
112 
113 } // endWt::Dbo::ptr< Wtx::Crm::Activity::Item > Wtx::Crm::Activity::add( const std::string & key, const Wt::WDateTime & dateTime, Wtx::Dbo::Session & session )
114 
115 // static std::map<std::string,Wt::Dbo::ptr<Wtx::Sys::Lookup::Item>> cache;
116 
117 #ifdef NEVER
118 Wt::Dbo::ptr< Wtx::Sys::Lookup::Item > Wtx::Sys::Lookup::find( const std::string & key, Wtx::Dbo::Session & session )
119 {
120  Wt::Dbo::ptr< Wtx::Sys::Lookup::Item > retVal;
121 
122  if( key != "" )
123  {
124  if( key.at(0) == '[' )
125  {
126  auto v = Wtx::Core::split( key, ':' );
127  int idVal = std::stoi(v.at(1));
128 
129  if( idVal != -1 )
130  {
131  Wt::Dbo::Transaction t(session);
132  retVal = session.template load<Wtx::Sys::Lookup::Item>(idVal);
133  }
134  }
135  else
136  {
137 // retVal = cache[key];
138 
139  if( !retVal )
140  {
141  Wt::Dbo::Transaction t(session);
142  retVal =
143  session.find<Wtx::Sys::Lookup::Item>()
144  .where( "\"keyField\" = ?")
145  .bind( key )
146  .resultValue()
147  ;
148 // cache[key] = retVal;
149  }
150  }
151 
152  }
153 
154  return retVal;
155 }
156 
157 Wt::Dbo::ptr< Wtx::Sys::Lookup::Item > Wtx::Sys::Lookup::ifind( const std::string & key, Wtx::Dbo::Session & session )
158 {
159  Wt::Dbo::ptr< Wtx::Sys::Lookup::Item > retVal;
160 
161  if( key != "" )
162  {
163 // retVal = cache[key];
164 
165  if( !retVal )
166  {
167  Wt::Dbo::Transaction t(session);
168  retVal =
169  session.find<Wtx::Sys::Lookup::Item>()
170  .where( "UPPER(\"keyField\") = UPPER(?)")
171  .bind( key )
172  .resultValue()
173  ;
174 // cache[key] = retVal;
175  }
176 
177  }
178 
179  return retVal;
180 }
181 
196 std::shared_ptr<Wt::WAbstractItemModel> Wtx::Sys::Lookup::getComboBoxModel( int tid, const std::string & group, Wtx::Dbo::Session & session )
197 {
198  auto retVal = std::make_shared< Wtx::Dbo::QueryModel< Wt::Dbo::ptr<Wtx::Sys::Lookup::Item> > >();
199 
200  Wt::Dbo::Transaction t(session);
201 
202  if( tid == -1 )
203  {
204  auto query =
205  session.find<Wtx::Sys::Lookup::Item>()
206  .where("UPPER(\"cfyField\") LIKE UPPER(?) OR \"cfyField\" LIKE '%%*%%'")
207  .bind( Wt::WString("%%{1}%%").arg(group) )
208  .orderBy("\"keyField\"")
209  ;
210 
211  retVal-> setQuery( query );
212  }
213 
214  else
215  {
216  auto query =
217  session.find<Wtx::Sys::Lookup::Item>()
218  .where("id = ?")
219  .bind( tid )
220  ;
221 
222  retVal-> setQuery( query );
223  }
224 
225  retVal-> addColumn("id");
226  retVal-> addColumn("keyField");
227 
228  return retVal;
229 }
230 #endif
231 
Wt::Dbo::ptr< Wtx::Crm::Activity::Item > add(const std::string &key, const Wt::WDate &date, Wtx::Dbo::Session &session)
Add an item to the lookup table.
Definition: Activity.cpp:28
static void PostCreateTable(Wt::Dbo::Session &session)
Post Table Create.
Definition: BaseItemTpl.h:141
std::shared_ptr< Wt::WAbstractItemModel > getComboBoxModel(int tid, const std::string &group, Wtx::Dbo::Session &session, bool includeBlank=false)
Get a Combo-Box Model.
Definition: Lookup.cpp:213