Class: Activity
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Activity
- Extended by:
- ConditionExtensions
- Defined in:
- app/models/activity.rb
Constant Summary
- EARLIEST_TRACKED_ACTIVITY_DATE =
'2005-11-01 00:00:00'- PRIVATE =
PRIVACY SETTINGS
100- PROTECTED =
101- PUBLIC =
102- LOGIN =
activity types
1- INFORMATION =
2- PEOPLE =
4- COMMUNITY =
5- SIGNUP =
activity codes
101- INVITATION =
102- VOUCHED_BY =
103- VOUCHED_FOR =
104- UPDATE_PROFILE =
105- LOGIN_PASSWORD =
106- LOGIN_OPENID =
107- LOGIN_OPENID_EXTERNAL =
108- INVITATION_ACCEPTED =
109- CREATED_COMMUNITY =
110- EDIT =
111- COMMUNITY_ACTIVITY =
COMMUNITY
200- COMMUNITY_ACTIVITY_START =
201- COMMUNITY_ACTIVITY_END =
599- COMMUNITY_JOIN =
201- COMMUNITY_WANTSTOJOIN =
202- COMMUNITY_LEFT =
203- COMMUNITY_INVITATION =
204- COMMUNITY_ACCEPT_INVITATION =
205- COMMUNITY_DECLINE_INVITATION =
206- COMMUNITY_NOWANTSTOJOIN =
207- COMMUNITY_INTEREST =
208- COMMUNITY_NOINTEREST =
209- COMMUNITY_INVITEDASLEADER =
210- COMMUNITY_INVITEDASMEMBER =
211- COMMUNITY_ADDEDASLEADER =
212- COMMUNITY_ADDEDASMEMBER =
213- COMMUNITY_REMOVEDASLEADER =
214- COMMUNITY_REMOVEDASMEMBER =
215- COMMUNITY_INVITATIONRESCINDED =
216- COMMUNITY_INVITELEADER =
301- COMMUNITY_INVITEMEMBER =
302- COMMUNITY_ADDLEADER =
303- COMMUNITY_ADDMEMBER =
304- COMMUNITY_REMOVELEADER =
305- COMMUNITY_REMOVEMEMBER =
306- COMMUNITY_RESCINDINVITATION =
307- COMMUNITY_INVITEREMINDER =
308- COMMUNITY_UPDATE_INFORMATION =
401- COMMUNITY_CREATED_LIST =
402- COMMUNITY_TAGGED =
403- LIST_POST =
501- INFORMATION_EDIT =
INFORMATION
701- INFORMATION_COMMENT =
702- INFORMATION_PUBLISH =
703- INFORMATION_CHANGESET =
704- ACTIVITY_LOCALE_STRINGS =
{ COMMUNITY_ACCEPT_INVITATION => 'community_accept_invitation', COMMUNITY_ADDEDASLEADER => 'community_addedasleader', COMMUNITY_ADDEDASMEMBER => 'community_addedasmember', COMMUNITY_ADDLEADER => 'unknown', COMMUNITY_ADDMEMBER => 'unknown', COMMUNITY_CREATED_LIST => 'community_created_list', COMMUNITY_DECLINE_INVITATION => 'community_decline_invitation', COMMUNITY_INTEREST => 'community_interest', COMMUNITY_INVITATION => 'unknown', COMMUNITY_INVITATIONRESCINDED => 'community_invitation_rescinded', COMMUNITY_INVITEDASLEADER => 'community_invited_leader', COMMUNITY_INVITEDASMEMBER => 'community_invited_member', COMMUNITY_INVITELEADER => 'unknown', COMMUNITY_INVITEMEMBER => 'unknown', COMMUNITY_INVITEREMINDER => 'community_invite_reminder', COMMUNITY_JOIN => 'community_join', COMMUNITY_LEFT => 'community_left', COMMUNITY_NOINTEREST => 'community_nointerest', COMMUNITY_NOWANTSTOJOIN => 'community_nowantstojoin', COMMUNITY_REMOVEDASLEADER => 'community_removedasleader', COMMUNITY_REMOVEDASMEMBER => 'community_removedasmember', COMMUNITY_REMOVELEADER => 'unknown', COMMUNITY_REMOVEMEMBER => 'unknown', COMMUNITY_RESCINDINVITATION => 'unknown', COMMUNITY_TAGGED => 'community_tagged', COMMUNITY_UPDATE_INFORMATION => 'community_update_information', COMMUNITY_WANTSTOJOIN => 'community_wantstojoin', CREATED_COMMUNITY=> 'community_create', EDIT=> 'edit', INFORMATION_CHANGESET => 'information_changeset', INFORMATION_COMMENT => 'information_comment', INFORMATION_EDIT => 'information_edit', INFORMATION_PUBLISH => 'information_publish', INVITATION => 'invitation', INVITATION_ACCEPTED => 'acceptedinvitation', LIST_POST => 'listpost', LOGIN_OPENID => 'login', LOGIN_PASSWORD => 'login', SIGNUP => 'signup', UPDATE_PROFILE => 'updateprofile', VOUCHED_BY => 'vouched_by', VOUCHED_FOR => 'vouched_for' }
Class Method Summary (collapse)
- + (Object) activity_to_codes(activity)
- + (Object) activitygroup_to_types(activitygroup)
- + (Object) build_activity_conditions(options = {})
- + (Object) build_community_conditions(options)
- + (Object) build_community_joins(options)
- + (Object) build_communitytype_conditions(options)
- + (Object) build_communitytype_joins(options)
- + (Object) build_userlimit_condition(options = {})
- + (Object) code_to_activity(activitycode)
- + (Object) count_active_users(options = {}, forcecacheupdate = false)
- + (Object) count_signups(options = {}, forcecacheupdate = false)
- + (Object) count_unique_communities_with_new_members(options = {}, forcecacheupdate = false)
- + (Object) count_unique_logins(options = {}, forcecacheupdate = false)
- + (Object) count_unique_users(options = {}, forcecacheupdate = false)
- + (Object) count_unique_users_as_new_community_members(options = {}, forcecacheupdate = false)
- + (Object) count_with_userfilter(options = {}, forcecacheupdate = false)
- + (Object) datecount_with_userfilter(options = {}, forcecacheupdate = false)
- + (Object) filteredparameters
- + (Object) hourlycount_with_userfilter(options = {}, forcecacheupdate = false)
- + (Object) log_activity(opts = {})
- + (Object) monthcount_with_userfilter(options = {}, forcecacheupdate = false)
- + (Object) per_page
- + (Object) useractivity_filter(options = {})
- + (Object) weekdaycount_with_userfilter(options = {}, forcecacheupdate = false)
- + (Object) weekofyearcount_with_userfilter(options = {}, forcecacheupdate = false)
- + (Object) yearmonthcount_with_userfilter(options = {}, forcecacheupdate = false)
- + (Object) yearweekcount_with_userfilter(options = {}, forcecacheupdate = false)
Methods included from ConditionExtensions
build_association_condition, build_date_condition, count_cache_expiry, get_cache_key
Class Method Details
+ (Object) activity_to_codes(activity)
551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'app/models/activity.rb', line 551 def activity_to_codes(activity) case activity when 'signup' return [Activity::SIGNUP] when 'login' return [Activity::LOGIN_PASSWORD,Activity::LOGIN_OPENID] when 'joinedcommunity' return [Activity::COMMUNITY_JOIN,Activity::COMMUNITY_ACCEPT_INVITATION,Activity::COMMUNITY_ADDEDASMEMBER,Activity::COMMUNITY_ADDEDASLEADER] else return nil end end |
+ (Object) activitygroup_to_types(activitygroup)
564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'app/models/activity.rb', line 564 def activitygroup_to_types(activitygroup) case activitygroup when 'people' return [Activity::PEOPLE] when 'login' return [Activity::LOGIN] when 'active' return [Activity::LOGIN,Activity::COMMUNITY] when 'community' return [Activity::COMMUNITY] else return nil end end |
+ (Object) build_activity_conditions(options = {})
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'app/models/activity.rb', line 267 def build_activity_conditions(={}) conditionsarray = [] #ipaddress if([:activityaddress]) conditionsarray << "#{table_name}.ipaddr LIKE '#{[:activityaddress]}%'" end # activity code(s) or activity label (most common case) if([:activitycode]) conditionsarray << "#{table_name}.activitycode = #{[:activitycode]}" elsif([:activitycodes]) conditionsarray << "#{table_name}.activitycode IN (#{[:activitycodes].join(',')})" elsif([:activity]) if(activitycodes = self.activity_to_codes([:activity])) conditionsarray << "#{table_name}.activitycode IN (#{activitycodes.join(',')})" end end # activity types(s) or activitygroup label (most common case) if([:activitytype]) conditionsarray << "#{table_name}.activitytype = #{[:activitytype]}" elsif([:activitytypes]) conditionsarray << "#{table_name}.activitytype IN (#{[:activitytypes].join(',')})" elsif([:activitygroup]) if(activitytypes = self.activitygroup_to_types([:activitygroup])) conditionsarray << "#{table_name}.activitytype IN (#{activitytypes.join(',')})" end end # narrow to certain activity_applications if([:activityapplication]) conditionsarray << "#{table_name}.activity_application_id = #{[:activityapplication].id}" elsif([:activityapplications]) conditionsarray << "#{table_name}.activity_application_id IN (#{[:activityapplications].map(&:id).join(',')})" elsif([:appname]) if(aa = ActivityApplication.find_by_shortname([:appname])) conditionsarray << "#{table_name}.activity_application_id = #{aa.id}" end end # TODO? 'appnames?' if(!conditionsarray.blank?) return conditionsarray.join(' AND ') else return nil end end |
+ (Object) build_community_conditions(options)
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'app/models/activity.rb', line 214 def build_community_conditions() connectiontype = [:connectiontype] || 'joined' communityactivity = [:communityactivity] || 'member' if(communityactivity == 'community') return "#{table_name}.community_id = #{[:community].id}" elsif(communityactivity == 'all') # hack! userlist = User.filtered({:community => [:community], :connectiontype => connectiontype, :dateinterval => 'all'}) if(userlist.size > 0) return "#{table_name}.user_id IN (#{userlist.map(&:id).join(',')}) OR #{table_name}.community_id = #{[:community].id}" else return "#{table_name}.community_id = #{[:community].id}" end else # member return "#{Community.table_name}.id = #{[:community].id} AND #{Communityconnection.connection_condition([:connectiontype])}" end end |
+ (Object) build_community_joins(options)
205 206 207 208 209 210 211 212 |
# File 'app/models/activity.rb', line 205 def build_community_joins() communityactivity = [:communityactivity] || 'member' if(communityactivity == 'member') return {:user => :communities} else return nil end end |
+ (Object) build_communitytype_conditions(options)
243 244 245 246 247 248 249 250 251 252 |
# File 'app/models/activity.rb', line 243 def build_communitytype_conditions() connectiontype = [:connectiontype] || 'joined' communityactivity = [:communityactivity] || 'member' if(communityactivity == 'community') return "#{Community.communitytype_condition([:communitytype])}" else return "(#{Community.communitytype_condition([:communitytype])} AND #{Communityconnection.connection_condition([:connectiontype])})" end end |
+ (Object) build_communitytype_joins(options)
234 235 236 237 238 239 240 241 |
# File 'app/models/activity.rb', line 234 def build_communitytype_joins() communityactivity = [:communityactivity] || 'member' if(communityactivity == 'member') return {:user => :communities} else return :community end end |
+ (Object) build_userlimit_condition(options = {})
255 256 257 258 259 260 261 262 263 264 265 |
# File 'app/models/activity.rb', line 255 def build_userlimit_condition(={}) if([:user]) return "activities.user_id = #{[:user].id}" elsif([:person]) return "activities.user_id = #{[:person].id}" elsif([:userlist]) return"activities.user_id IN (#{[:userlist].map(&:id).join(',')})" else return nil end end |
+ (Object) code_to_activity(activitycode)
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'app/models/activity.rb', line 580 def code_to_activity(activitycode) case activitycode when Activity::SIGNUP return 'signup' when Activity::LOGIN_OPENID when Activity::LOGIN_PASSWORD return 'login' when Activity::COMMUNITY_ACTIVITY return 'community' when Activity::COMMUNITY_JOIN when Activity::COMMUNITY_ACCEPT_INVITATION when Activity::COMMUNITY_ADDEDASMEMBER when Activity::COMMUNITY_ADDEDASLEADER return 'joinedcommunity' else return nil end end |
+ (Object) count_active_users(options = {}, forcecacheupdate = false)
523 524 525 526 527 528 |
# File 'app/models/activity.rb', line 523 def count_active_users(={},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do Activity.filtered(.merge({:activity => 'active'})).count(:all,:group => "accounts.id").size end end |
+ (Object) count_signups(options = {}, forcecacheupdate = false)
509 510 511 512 513 514 |
# File 'app/models/activity.rb', line 509 def count_signups(={},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do Activity.filtered(.merge({:activity => 'signup'})).count(:all,:group => "accounts.id").size end end |
+ (Object) count_unique_communities_with_new_members(options = {}, forcecacheupdate = false)
537 538 539 540 541 542 |
# File 'app/models/activity.rb', line 537 def count_unique_communities_with_new_members(={},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do Activity.filtered(.merge({:activity => 'joincommunity'})).count(:all,:group => "communities.id").size end end |
+ (Object) count_unique_logins(options = {}, forcecacheupdate = false)
516 517 518 519 520 521 |
# File 'app/models/activity.rb', line 516 def count_unique_logins(={},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do Activity.filtered(.merge({:activity => 'login'})).count(:all,:group => "accounts.id").size end end |
+ (Object) count_unique_users(options = {}, forcecacheupdate = false)
530 531 532 533 534 535 |
# File 'app/models/activity.rb', line 530 def count_unique_users(={},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do Activity.filtered().count(:all,:group => "accounts.id").size end end |
+ (Object) count_unique_users_as_new_community_members(options = {}, forcecacheupdate = false)
544 545 546 547 548 549 |
# File 'app/models/activity.rb', line 544 def count_unique_users_as_new_community_members(={},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do Activity.filtered(.merge({:activity => 'joincommunity'})).count(:all,:group => "accounts.id").size end end |
+ (Object) count_with_userfilter(options = {}, forcecacheupdate = false)
502 503 504 505 506 507 |
# File 'app/models/activity.rb', line 502 def count_with_userfilter(={},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do Activity.filtered().count(:all) end end |
+ (Object) datecount_with_userfilter(options = {}, forcecacheupdate = false)
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'app/models/activity.rb', line 480 def datecount_with_userfilter( = {},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do datefield = [:datefield] || AppConfig.configtable['default_datefield'] tz = [:tz] || AppConfig.configtable['default_timezone'] if(tz and tz != 'UTC' and TZInfo::Timezone.all_identifiers.include?(tz)) activitydate = "DATE(CONVERT_TZ(#{table_name}.#{datefield},'UTC','#{tz}'))" else activitydate = "DATE(#{table_name}.#{datefield})" end counts = self.filtered().count(:all, :group => activitydate) activity = {} returncounts = [] counts.map{|values| activity[Date.parse(values[0])] = values[1].to_i} firstday = activity.keys.sort.first lastday = activity.keys.sort.last return activity end end |
+ (Object) filteredparameters
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/models/activity.rb', line 181 def filteredparameters filteredparams_list = [] # list everything that Activity#useractivity_filter handles - which needs to be refactored # build_date_condition filteredparams_list += [:dateinterval,:datefield] # build_activity_conditions filteredparams_list += [:appname,:activityapplication,:activityaddress,:activity,:activitygroup] # build_activityentrytype_condition filteredparams_list += [:activityentrytype] # build_community_joins, build_communitytype_joins, build_community_conditions, build_communitytype_conditions filteredparams_list += [:communityactivity,:connectiontype] # build_userlimit_condition filteredparams_list += [:person] # build_association_conditions filteredparams_list += [:institution,:location,:position, :county] # useractivity_filter itself filteredparams_list += [{:allactivity => :boolean},:community,:communitytype, {:allusers => :boolean}] filteredparams_list end |
+ (Object) hourlycount_with_userfilter(options = {}, forcecacheupdate = false)
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'app/models/activity.rb', line 360 def hourlycount_with_userfilter( = {},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do datefield = [:datefield] || AppConfig.configtable['default_datefield'] tz = [:tz] || AppConfig.configtable['default_timezone'] if(tz and tz != 'UTC' and TZInfo::Timezone.all_identifiers.include?(tz)) activityhour = "HOUR(CONVERT_TZ(#{table_name}.#{datefield},'UTC','#{tz}'))" else activityhour = "HOUR(#{table_name}.#{datefield})" end counts = self.filtered().count(:all, :group => activityhour) activity = {} counts.map{|values| activity[values[0].to_i] = values[1].to_i} return activity end end |
+ (Object) log_activity(opts = {})
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'app/models/activity.rb', line 600 def log_activity(opts = {}) # TODO: public activity if(opts[:activitycode] == COMMUNITY_INVITATIONRESCINDED or opts[:activitycode] == COMMUNITY_NOINTEREST) opts[:privacy] = Activity::PRIVATE else opts[:privacy] = Activity::PROTECTED end # creator check if(opts[:creator].nil?) opts[:creator] = User.systemuser end if(opts[:ipaddr].nil?) opts[:ipaddr] = AppConfig.configtable['request_ip_address'] end # ActivityApplication lookups aa = opts.delete(:activity_application) if(aa.nil?) # check for appname/trustroot - except for api auth, we should basically always hit this branch if(opts[:activitycode] == Activity::LOGIN_OPENID) trustroot = opts.delete(:trustroot) # must have a trustroot for now opts[:activity_uri] = trustroot aa = ActivityApplication.finduri(trustroot) if(aa.nil?) opts[:privacy] = Activity::PRIVATE end elsif(!opts[:appname].nil?) appname = opts.delete(:appname) if(appname == 'local') aa = ActivityApplication.local else aa = ActivityApplication.find_by_shortname(appname) end else #assume local aa = ActivityApplication.local end end if(aa.nil?) opts[:activity_application] = nil else opts[:activity_application] = aa end begin Activity.create(opts) rescue ActiveRecord::StatementInvalid => e raise unless e.to_s =~ /duplicate/i end end |
+ (Object) monthcount_with_userfilter(options = {}, forcecacheupdate = false)
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'app/models/activity.rb', line 460 def monthcount_with_userfilter( = {},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do datefield = [:datefield] || AppConfig.configtable['default_datefield'] tz = [:tz] || AppConfig.configtable['default_timezone'] if(tz and tz != 'UTC' and TZInfo::Timezone.all_identifiers.include?(tz)) activitymonth = "MONTH(CONVERT_TZ(#{table_name}.#{datefield},'UTC','#{tz}'))" else activitymonth = "MONTH(#{table_name}.#{datefield})" end counts = self.filtered().count(:all, :group => activitymonth) activity = {} returncounts = [] counts.map{|values| activity[values[0].to_i] = values[1].to_i} return activity end end |
+ (Object) per_page
201 202 203 |
# File 'app/models/activity.rb', line 201 def per_page 25 end |
+ (Object) useractivity_filter(options = {})
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'app/models/activity.rb', line 316 def useractivity_filter(={}) joins = [:user] conditions = [] conditions << build_date_condition() # activity conditions? conditions << build_activity_conditions() if([:allactivity].nil? or ![:allactivity]) conditions << "#{table_name}.privacy != #{Activity::PRIVATE}" end # activity object type? if([:community]) conditions << "#{table_name}.privacy != #{Activity::PRIVATE}" end # TODO: how much of this check is relevant if looking at a user or userlist? if([:community]) joins << build_community_joins() conditions << build_community_conditions() elsif([:communitytype]) joins << build_communitytype_joins() conditions << build_communitytype_conditions() end if(userlimitconditions = build_userlimit_condition()) conditions << userlimitconditions else # location, position, institution? conditions << User.build_association_conditions() if([:allusers].nil? or ![:allusers]) #conditions << "#{User.table_name}.retired = 0 and #{User.table_name}.vouched = 1 and #{User.table_name}.id != 1" conditions << "#{User.table_name}.retired = 0 and #{User.table_name}.vouched = 1" end end return {:joins => joins.compact, :conditions => conditions.compact.join(' AND ')} end |
+ (Object) weekdaycount_with_userfilter(options = {}, forcecacheupdate = false)
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'app/models/activity.rb', line 379 def weekdaycount_with_userfilter( = {},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do datefield = [:datefield] || AppConfig.configtable['default_datefield'] tz = [:tz] || AppConfig.configtable['default_timezone'] if(tz and tz != 'UTC' and TZInfo::Timezone.all_identifiers.include?(tz)) activityweekday = "WEEKDAY(CONVERT_TZ(#{table_name}.#{datefield},'UTC','#{tz}'))" else activityweekday = "WEEKDAY(#{table_name}.#{datefield})" end counts = self.filtered().count(:all, :group => activityweekday) activity = {} returncounts = [] counts.map{|values| activity[values[0].to_i] = values[1].to_i} return activity end end |
+ (Object) weekofyearcount_with_userfilter(options = {}, forcecacheupdate = false)
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'app/models/activity.rb', line 399 def weekofyearcount_with_userfilter( = {},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do datefield = [:datefield] || AppConfig.configtable['default_datefield'] tz = [:tz] || AppConfig.configtable['default_timezone'] if(tz and tz != 'UTC' and TZInfo::Timezone.all_identifiers.include?(tz)) activityweekofyear = "WEEK(CONVERT_TZ(#{table_name}.#{datefield},'UTC','#{tz}'),1)" else activityweekofyear = "WEEK(#{table_name}.#{datefield},1)" end counts = self.filtered().count(:all, :group => activityweekofyear) activity = {} returncounts = [] counts.map{|values| activity[values[0].to_i] = values[1].to_i} return activity end end |
+ (Object) yearmonthcount_with_userfilter(options = {}, forcecacheupdate = false)
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'app/models/activity.rb', line 439 def yearmonthcount_with_userfilter( = {},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do datefield = [:datefield] || AppConfig.configtable['default_datefield'] tz = [:tz] || AppConfig.configtable['default_timezone'] if(tz and tz != 'UTC' and TZInfo::Timezone.all_identifiers.include?(tz)) activitymonth = "DATE_FORMAT(CONVERT_TZ(#{table_name}.#{datefield},'UTC','#{tz}'),'%Y-%m')" else activitymonth = "DATE_FORMAT(#{table_name}.#{datefield}, '%Y-%m')" end counts = self.filtered().count(:all, :group => activitymonth) activity = {} returncounts = [] counts.map{|values| activity[values[0]] = values[1].to_i} return activity end end |
+ (Object) yearweekcount_with_userfilter(options = {}, forcecacheupdate = false)
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'app/models/activity.rb', line 419 def yearweekcount_with_userfilter( = {},forcecacheupdate=false) cache_key = self.get_cache_key(this_method,) Rails.cache.fetch(cache_key, :force => forcecacheupdate, :expires_in => self.count_cache_expiry) do datefield = [:datefield] || AppConfig.configtable['default_datefield'] tz = [:tz] || AppConfig.configtable['default_timezone'] if(tz and tz != 'UTC' and TZInfo::Timezone.all_identifiers.include?(tz)) activityweek = "DATE_FORMAT(CONVERT_TZ(#{table_name}.#{datefield},'UTC','#{tz}'),'%Y-%u')" else activityweek = "DATE_FORMAT(#{table_name}.#{datefield}, '%Y-%u')" end counts = self.filtered().count(:all, :group => activityweek) activity = {} returncounts = [] counts.map{|values| activity[values[0]] = values[1].to_i} return activity end end |