public function enroll() { $this->redirect_authenticated(); $this->save_details(); $this->load_helper('form'); $this->load_model('UserDetail'); $defs = array( 'id' => null, 'membership_id' => null, 'billing_id' => null, 'firstname' => null, 'address1' => null, 'suburb' => null, 'lastname' => null, 'address2' => null, 'postcode' => null, 'phone' => null ); if(isset($this->params['data'])) { $defs = array_merge($this->params['data'], $defs); } $new = $this->UserDetail->new_object($defs); $this->set('object', $new); MvcObjectRegistry::add_object('UserDetail', $new); }
static function add_object($key, &$object) { $_this =& MvcObjectRegistry::get_instance(); $key = MvcInflector::camelize($key); if (!isset($_this->__objects[$key])) { $_this->__objects[$key] =& $object; return true; } return false; }
public function index() { $userdata = wp_get_current_user(); $this->load_model('UserDetail'); $details = $this->UserDetail->find_one(array( 'conditions' => array('user_id' => $userdata->ID), )); if(empty($details)) { global $wpdb; $this->load_model('Membership'); $role = $userdata->roles[0]; $membership = $this->Membership->find_one(array( 'conditions' => array('type' => $role) )); $wpdb->insert( $wpdb->prefix . 'user_details', array( 'user_id'=>$userdata->ID, 'membership_id'=>$membership->id, 'firstname' => $userdata->user_firstname, 'lastname' => $userdata->user_lastname ), array( '%d', '%d', '%s', '%s' ) ); $details = $this->UserDetail->find_by_id($wpdb->insert_id); $this->load_model('Billing'); $details->billing = $this->Billing->new_object(array( 'id'=>null, 'card_number' => '', 'card_type' => '', )); } $this->load_helper('form'); $this->set('object', $details); MvcObjectRegistry::add_object('UserDetail', $details); }
public function create($model_name, $options = array()) { $defaults = array('action' => $this->controller->action, 'controller' => MvcInflector::tableize($model_name), 'public' => false); $options = array_merge($defaults, $options); $this->model_name = $model_name; $this->object = MvcObjectRegistry::get_object($model_name); $this->model = MvcModelRegistry::get_model($model_name); $this->schema = $this->model->schema; $object_id = !empty($this->object) && !empty($this->object->__id) ? $this->object->__id : null; $router_options = array('controller' => $options['controller'], 'action' => $options['action']); if ($object_id) { $router_options['id'] = $object_id; } $enctype = isset($options['enctype']) ? ' enctype="' . $options['enctype'] . '"' : ''; $url = $options['public'] ? MvcRouter::public_url($router_options) : MvcRouter::admin_url($router_options); $html = '<form action="' . $url . '" method="post"' . $enctype . '>'; if ($object_id) { $html .= '<input type="hidden" id="' . $this->input_id('hidden_id') . '" name="' . $this->input_name('id') . '" value="' . $object_id . '" />'; } return $html; }
public function set_object() { if (!empty($this->model->invalid_data)) { if (!empty($this->params['id']) && empty($this->model->invalid_data[$this->model->primary_key])) { $this->model->invalid_data[$this->model->primary_key] = $this->params['id']; } $object = $this->model->new_object($this->model->invalid_data); } else { if (!empty($this->params['id'])) { $object = $this->model->find_by_id($this->params['id']); } } if (!empty($object)) { $this->set('object', $object); MvcObjectRegistry::add_object($this->model->name, $this->object); return true; } MvcError::warning('Object not found.'); return false; }