Example #1
0
 public static function save_timeline($member_id, $public_flag = null, $type_key = null, $foreign_id = null, $save_datetime = null, $body = null, Model_Timeline $timeline = null, $child_foreign_ids = array())
 {
     if (!Site_Util::check_type_enabled($type_key)) {
         return;
     }
     list($type, $foreign_table, $child_foreign_table) = Site_Util::get_timeline_save_values($type_key);
     if (!$timeline) {
         $timeline = Site_Util::get_timeline_object($type_key, $foreign_id);
     }
     $is_new = empty($timeline->id);
     if (!is_null($body)) {
         $timeline->body = $body;
     }
     if ($is_new) {
         $timeline->member_id = $member_id;
         $timeline->type = $type;
         $timeline->public_flag = is_null($public_flag) ? conf('public_flag.default') : $public_flag;
         $timeline->foreign_table = $foreign_table;
         $timeline->foreign_id = $foreign_id;
         $timeline->created_at = $save_datetime ?: \Date::time()->format('mysql');
     } else {
         if (\Site_Util::check_is_expanded_public_flag_range($timeline->public_flag, $public_flag)) {
             $timeline->public_flag = $public_flag;
         }
         if ($child_foreign_ids) {
             $timeline->sort_datetime = $save_datetime ?: \Date::time()->format('mysql');
         }
         if ($timeline->is_changed() && $save_datetime) {
             $timeline->updated_at = $save_datetime;
         }
     }
     $timeline->save();
     if ($child_foreign_ids) {
         Model_TimelineChildData::save_multiple($timeline->id, $child_foreign_table, $child_foreign_ids);
     }
     return $timeline;
 }