observer-pattern

How to get the current_user in a model observer?

左心房为你撑大大i 提交于 2019-12-01 05:26:02
Given the following models: Room (id, title) RoomMembers (id, room_id) RoomFeed, also an observer When a Room title is updated, I want to create a RoomFeed item, showing who the user is who made the update. @room.update_attributes(:title => "This is my new title") Problem is in my observer for RoomFeed: def after_update(record) # record is the Room object end The is no way for me to get the user.id of the person who just made the update. How do I go about doing that? is there a better way to do the update so I get the current_user? I think what you are looking for is, room.updated_by inside

php observer pattern to log user out when session times out

混江龙づ霸主 提交于 2019-11-30 21:14:18
I'm trying to log users out when the user's session timeout happens. Logging users out - in my case - requires modifying the user's "online" status in a database. I was thinking that I might be able to use the observer pattern to make something that would monitor the state of the user session and trigger a callback when the session expires - which would preserve the user's name so we can update the db. I'm not exactly sure where to begin on the session side. Can I tie a callback to the session's timeout? are these things built into any available pear or zend session packages? I will use

Stopping product saving process in observer

有些话、适合烂在心里 提交于 2019-11-30 17:18:04
问题 I am currently developing a module working with the product edit in the backend. Its purpose is to retrieve categories the product belongs to and populate an attribute (the Brand attribute) with the list of selected categories. It is mandatory for the admin to select at least one category. My module works as expected except that I don't know how to stop the saving process if the admin hasn't selected any category while editing a product. Here is the workflow Administrator selects categories

Events not firing/or observer not working in magento

↘锁芯ラ 提交于 2019-11-30 15:59:16
问题 I have a module which listens to a few events. It works fine in at least a dozen installations I have tested it on. On on specific installation, a client which I installed it, on Magento version 1.4.1.1, It does not work. When I tested his system, and I fire the events manually, eg Mage::dispatchEvent('..') the observer does listen to them. What should I look into ? I do not have a clue what could be the reason for this. 回答1: There's a few reasons this could be happening The event you're

Events not firing/or observer not working in magento

穿精又带淫゛_ 提交于 2019-11-30 15:36:47
I have a module which listens to a few events. It works fine in at least a dozen installations I have tested it on. On on specific installation, a client which I installed it, on Magento version 1.4.1.1, It does not work. When I tested his system, and I fire the events manually, eg Mage::dispatchEvent('..') the observer does listen to them. What should I look into ? I do not have a clue what could be the reason for this. There's a few reasons this could be happening The event you're trying to listen for doesn't exist in your version of Magento Someone's hacked the core file and accidentally

Observer for removed items in the cart

两盒软妹~` 提交于 2019-11-30 13:45:46
Is there an observer which can be used to observe events when a product is removed from the cart? I haven't found any. What I have found is checkout_cart_update_items_after which can be used if a product is removed by altering the product count, but not when the user uses the remove button. The only alternative I see in the moment is checkout_cart_save_after which is used whenever the cart changes. Of course this needs custom logic which check which product was removed. Not perfect. So is there a better way to watch out for remove events? You can use the sales_quote_remove_item event,

Simple, clean way to sync observables from different view models

百般思念 提交于 2019-11-30 09:55:37
Say I have two view models that each have an observable property that represents different, but similar data. function site1Model(username) { this.username = ko.observable(username); .... } function site2Model(username) = { this.username = ko.observable(username); .... } These view models are independent and not necessarily linked to each other, but in some cases, a third view model creates a link between them. function site3Model(username) = { this.site1 = new site1Model(username); this.site2 = new site2Model(username); // we now need to ensure that the usernames are kept the same between

How to trigger an event on payment received in magento?

烈酒焚心 提交于 2019-11-30 06:39:42
问题 Greetings, in Magento I want to trigger an event, once an order has been set to processing (by gateway confirmation or manually) that, example: If a general customer (id 1) spends over 100$ and the payment has been confirmed, set his group id to 4 (silver VIP, which by promotion rule gets 2% discount globally) I would give a bounty to this, but I'd like the answer before 2 days O_o EDIT : the answer I received so far is only a partial answer, also I find the links very confusing, I'm not

When should I remove observers? Error about deallocating objects before removing observers

时光毁灭记忆、已成空白 提交于 2019-11-30 06:19:16
问题 I am trying to use key-value observing in one of my classes. I register the observers in the init method and remove/deregister them in the dealloc, but I get the following error which seems to occur before my dealloc method gets called, according to my debug prints. An instance 0x583870 of class TekkPoint is being deallocated while key value observers are still registered with it. Observation info is being leaked, and may even become mistakenly attached to some other object. Set a breakpoint

MVC Java: How does a Controller set listeners to the children classes of a View

╄→гoц情女王★ 提交于 2019-11-30 05:30:34
I have a Controller, and a View with many children views with children with children. Example: JPanels within JPanels that have buttons and fields for a controller to pass to the model. The current way I'm doing it is instantiating 'Controllers' in the view that have action listeners and access my models which are singletons. This works- But it's definitely not MVC. So the question is- how do I do it? Is the only way to daisy chain from the controller: mainview.getSubView().getSubView().getSubView().setActionListener(new AL()); and: mainview.getSubView().getSubView().getSubView()