array( ), ); }/**/ /** * Implementation of hook_rules_event_info(). * @ingroup rules * @return Array * Returns an array of events that can be triggered from this module. */ function uc_product_registration_rules_event_info() { $module = 'Ubercart Product Registration'; // basic arguments related to product registration $common_args = array( 'customer' => array( 'label' => t('Customer'), 'type' => 'user', ), 'product' => array( 'label' => t('Product'), 'type' => 'node', ), /* 'model' => array( 'label' => t('Model Number'), 'type' => 'String' ), 'serial' => array( 'label' => t('Serial Number'), 'type' => 'String' ), 'registered' => array( 'label' => t('Date Registered'), 'type' => 'Date' ), 'purchdate' => array( 'label' => t('Date of Purchase'), 'type' => 'Date' ), /**/ 'registered_product' => array( 'label' => t('Registered Product'), 'type' => 'registered_product', ), ); return array( // Displays a message when a product is registered. 'uc_product_registration_rules_product_registered_event' => array( 'label' => t('A product is registered.'), 'help' => t('Displays a message when a user finishes registering a product from your catalog.'), 'module' => $module, 'arguments' => $common_args, ), 'uc_product_registration_rules_product_updated_event' => array( 'label' => t('A registered product is updated.'), 'help' => t('A user updates information regarding their registered product.'), 'module' => $module, 'arguments' => $common_args, ), 'uc_product_registration_rules_product_deleted_event' => array( 'label' => t('A registered product is deleted.'), 'help' => t('A user deletes their registered product.'), 'module' => $module, 'arguments' => $common_args, ), ); } /** * Defines conditions available to product registration rules. * @return Array */ function uc_product_registration_rules_condition_info() { $module = 'Ubercart Product Registration'; // basic arguments related to product registration $common_args = array( 'customer' => array( 'label' => t('Customer'), 'type' => 'user', ), 'product' => array( 'label' => t('Product'), 'type' => 'node', ), /* 'model' => array( 'label' => t('Model Number'), 'type' => 'String' ), 'serial' => array( 'label' => t('Serial Number'), 'type' => 'String' ), 'registered' => array( 'label' => t('Date Registered'), 'type' => 'Date' ), 'purchdate' => array( 'label' => t('Date of Purchase'), 'type' => 'Date' ),*/ 'registered_product' => array( 'label' => t('Registered Product'), 'type' => 'registered_product', ), // miscellaneous arguments 'text2' => array( 'label' => t('Text 2'), 'type' => 'string', ), 'date2' => array( 'label' => t('Date 2'), 'type' => 'Date', ), ); return array( // Displays a message when a product is registered. 'uc_product_registration_rules_modelnumber_compare' => array( 'label' => t('Compare a Model Number.'), 'help' => t('TRUE if the model number is correct.'), 'module' => $module, 'arguments' => array($common_args['model'], $common_args['text2']), ), 'uc_product_registration_rules_serialnumber_compare' => array( 'label' => t('Compare a Serial Number.'), 'help' => t('TRUE if the serial number is correct.'), 'module' => $module, 'arguments' => array($common_args['serial'], $common_args['text2']), ), 'uc_product_registration_rules_regdate_compare' => array( 'label' => t('Compare the registration date.'), 'help' => t('TRUE if the registration date meets your criteria.'), 'module' => $module, 'arguments' => array($common_args['registered'], $common_args['date2']), ), 'uc_product_registration_rules_purchdate_compare' => array( 'label' => t('Compare the purchase date.'), 'help' => t('TRUE if the purchase date meets your criteria.'), 'module' => $module, 'arguments' => array($common_args['purchdate'], $common_args['date2']), ), ); } /** * Action Implementation: * @ingroup rules * @return Array * Returns an array that defines actions and additional variables. */ function uc_product_registration_rules_action_info() { $common_args = array( 'customer' => array( 'label' => t('Customer'), 'type' => 'user', ), 'product' => array( 'label' => t('Product'), 'type' => 'node', ), 'registered_product' => array( 'label' => t('Registered Product'), 'type' => 'registered_product', ), ); return array( 'uc_product_registration_delete_registration' => array( 'label' => t('Delete Registration'), 'arguments' => $common_args ), ); } /** * Compares input with a serial number. * @param String $text1 * A string to compare $text2 to. * @param String $text2 * A string to compare $text1 to. * @param Array $settings * An array of miscellaneous settings passed to this function. * @return bool * Returns TRUE if the serial number matches */ function uc_product_registration_rules_serialnumber_compare($text1, $text2, $settings=array()) { return $settings['regex'] ? preg_match( sprintf("#%s#ixu", $text1), $text2 ) : ($text1==$text2); } /** * Adds form fields for comparison of model numbers. * @param Array $settings * @param Array $form */ function uc_product_registration_rules_serialnumber_compare_form($settings=array(), &$form) { $form['settings']['text1']['#title'] = t('Compare this'); $form['settings']['text2']['#title'] = t('To this'); $form['settings']['regex'] = array( '#type' => 'checkbox', '#title' => t('Evaluate the second text as a regular expression'), '#default_value' => isset($settings['regex']) ? $settings['regex'] : 0, ); } /** * Compares input with a model number. * @param String $text1 * A string to compare $text2 to. * @param String $text2 * A string to compare $text1 to. * @param Array $settings * An array of miscellaneous settings passed to this function. * @return bool * Returns TRUE if the model number matches */ function uc_product_registration_rules_modelnumber_compare($text1, $text2, $settings=array()) { return $settings['regex'] ? preg_match( sprintf("#%s#ixu", $text1), $text2 ) : ($text1==$text2); } /** * Adds form fields for comparison of model numbers. * @param Array $settings * @param Array $form */ function uc_product_registration_rules_modelnumber_compare_form($settings=array(), &$form) { $form['settings']['text1']['#title'] = t('Compare this'); $form['settings']['text2']['#title'] = t('To this'); $form['settings']['regex'] = array( '#type' => 'checkbox', '#title' => t('Evaluate the second text as a regular expression'), '#default_value' => isset($settings['regex']) ? $settings['regex'] : 0, ); } /** * Event Implementation: do something when a product is registered * @ingroup rules * @param Array $settings */ function uc_product_registration_rules_product_registered_event() { } /** * Lets the rules module know that a data type is defined here. */ function uc_product_registration_rules_data_type_info() { return array( 'registered_product' => array( 'label' => t('Registered Product'), 'class' => 'uc_product_registration_data_type_registered_product', 'saveable' => FALSE, 'identifiable' => FALSE, 'uses_input_form' => TRUE, 'module' => 'uc_product_registration', ), ); } /** * This class must remain in-tact to work properly. * Don't modify it unless you KNOW it is compatible with * the uc_product_registration tables. **/ class uc_product_registration_data_type_registered_product extends rules_data_type { function save() { $node = &$this->get(); node_save($node); return TRUE; } function load($uid, $nid, $vid=NULL, $model=NULL, $serial=NULL) { return node_load( array( 'uid' => $uid, 'nid' => $nid, 'vid' => $vid, 'model' => $model, 'serial' => $serial, ) ); } function get_related_product($nid, $vid=NULL) { return node_load($nid, $vid, TRUE); } function get_default_input_form($info, $value) { $info[] = array( 'long' => FALSE, 'required' => TRUE, 'description' => "", ); return array( '#type' => $info['long'] ? 'textarea' : 'textfield', '#title' => $info['label'], '#description' => $info['description'], '#required' => $info['required'], '#default_value' => $value, ); } }