/** * Update watch status * * @access public * @param string $foreign_table target related table * @param int $foreign_id target related table id * @return Response (json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_update_watch_status($foreign_table = null, $foreign_id = null) { $this->controller_common_api(function () use($foreign_table, $foreign_id) { if (!is_enabled('notice')) { throw new \HttpNotFoundException(); } if (\Input::post('foreign_table')) { $foreign_table = \Input::post('foreign_table'); } $foreign_id = intval(\Input::post('foreign_id') ?: $foreign_id); if (!$foreign_table || !$foreign_id) { throw new \HttpNotFoundException(); } if (!in_array($foreign_table, Site_Util::get_accept_foreign_tables())) { throw new \HttpNotFoundException(); } $this->response_body['errors']['message_default'] = term('form.watch') . '状態の変更に失敗しました。'; $model = \Site_Model::get_model_name($foreign_table); $foreign_obj = $model::check_authority($foreign_id); $member_id = $foreign_table == 'album_image' ? $foreign_obj->album->member_id : $foreign_obj->member_id; $this->check_browse_authority($foreign_obj->public_flag, $member_id); if ($member_id == $this->u->id) { throw new \HttpBadRequestException(); } \DB::start_transaction(); $is_registerd = (bool) Model_MemberWatchContent::change_registered_status4unique_key(array('foreign_table' => $foreign_table, 'foreign_id' => $foreign_id, 'member_id' => $this->u->id)); \DB::commit_transaction(); $data = array('result' => $is_registerd, 'message' => $is_registerd ? term('form.watch') . '対象に追加しました。' : term('form.watch') . 'を解除しました。', 'html' => icon_label($is_registerd ? 'form.do_unwatch' : 'form.do_watch', 'both', false)); $this->set_response_body_api($data); }); }
public static function _init() { static::$_properties['foreign_table']['validation']['in_array'][] = Site_Util::get_accept_foreign_tables(); static::$_properties['foreign_id'] = \Util_Orm::get_relational_numeric_key_prop(); static::$_properties['type']['validation']['in_array'][] = \Config::get('notice.types'); static::$_properties['parent_table']['validation']['in_array'][] = Site_Util::get_accept_parent_tables(); static::$_properties['parent_id'] = \Util_Orm::get_relational_numeric_key_prop(false); // unread cache を削除 if (\Config::get('notice.cache.unreadCount.isEnabled')) { static::$_observers['MyOrm\\Observer_DeleteUnreadNoticeCountCache'] = array('events' => array('before_delete')); } }
public static function _init() { static::$_properties['member_id'] = \Util_Orm::get_relational_numeric_key_prop(); static::$_properties['foreign_id'] = \Util_Orm::get_relational_numeric_key_prop(); static::$_properties['foreign_table']['validation']['in_array'][] = Site_Util::get_accept_foreign_tables(); }