_a['verbose'] = __('message queue'); $this->_a['table'] = 'pluf_queue'; $this->_a['model'] = __CLASS__; $this->_a['cols'] = array( // It is mandatory to have an "id" column. 'id' => array( 'type' => 'Pluf_DB_Field_Sequence', //It is automatically added. 'blank' => true, ), 'model_class' => array( 'type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 150, 'verbose' => __('model class'), ), 'model_id' => array( 'type' => 'Pluf_DB_Field_Integer', 'blank' => false, 'verbose' => __('model id'), ), 'action' => array( 'type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 150, 'verbose' => __('action'), ), 'lock' => array( 'type' => 'Pluf_DB_Field_Integer', 'blank' => false, 'verbose' => __('lock status'), 'default' => 0, 'choices' => array( __('Free') => 0, __('In progress') => 1, __('Completed') => 2, ), ), 'creation_dtime' => array( 'type' => 'Pluf_DB_Field_Datetime', 'blank' => true, 'verbose' => __('created at'), ), 'modif_dtime' => array( 'type' => 'Pluf_DB_Field_Datetime', 'blank' => true, 'verbose' => __('modified at'), ), ); $this->_a['idx'] = array( 'lock_idx' => array( 'type' => 'normal', 'col' => 'lock', ), ); } function preSave($create=false) { if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); } $this->modif_dtime = gmdate('Y-m-d H:i:s'); } /** * Add an object to the queue. * * @param Pluf_Model Your model * @param string Action for the object */ public static function addTo($object, $action='') { $q = new Pluf_Queue(); $q->model_class = $object->_model; $q->model_id = $object->id; $q->lock = 0; $q->action = $action; $q->create(); } }