예제 #1
0
파일: notice.php 프로젝트: uzura8/flockbird
 public static function check_and_create($foreign_table, $foreign_id, $type)
 {
     $since_datetime = \Date::forge(strtotime('-' . \Config::get('notice.periode_to_update.default')))->format('mysql');
     if (!($obj = self::get_last4foreign_data($foreign_table, $foreign_id, $type, $since_datetime))) {
         $obj = self::forge(array('foreign_table' => $foreign_table, 'foreign_id' => $foreign_id, 'type' => $type, 'body' => Site_Util::get_notice_body($foreign_table, $type)));
         if (!in_array($foreign_table, Site_Util::get_accept_parent_tables()) && ($parent_table = \Site_Model::get_parent_table($foreign_table))) {
             $obj->parent_table = $parent_table;
             $foreign_obj_name = \Site_Model::get_model_name($foreign_table);
             $foreign_obj = $foreign_obj_name::find($foreign_id);
             $parent_id_prop = $parent_table . '_id';
             $obj->parent_id = $foreign_obj->{$parent_id_prop};
         }
         $obj->save();
     }
     return $obj;
 }