当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation::add_callbacks方法代码示例

本文整理汇总了PHP中Validation::add_callbacks方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::add_callbacks方法的具体用法?PHP Validation::add_callbacks怎么用?PHP Validation::add_callbacks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validation的用法示例。


在下文中一共展示了Validation::add_callbacks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _get_valid_accinfo

 private function _get_valid_accinfo($old_pass)
 {
     $form = array('txt_old_pass' => '', 'txt_new_pass' => '', 'txt_cf_new_pass' => '', 'txt_email' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         if (!empty($old_pass)) {
             $post->add_rules('txt_new_pass', 'required', 'length[6,50]');
             $post->add_rules('txt_cf_new_pass', 'matches[txt_new_pass]');
             $post->add_callbacks('txt_old_pass', array($this, '_check_old_pass'));
         }
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_callbacks('txt_email', array($this, '_check_email'));
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $this->session->set_flash('input_data', $form);
             $errors = arr::overwrite($errors, $post->errors('account_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect($this->uri->segment(1));
             die;
         }
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:33,代码来源:admin_myaccount.php

示例2: test_data_create

 public function test_data_create()
 {
     access::verify_csrf();
     list($form, $errors) = $this->_get_test_data_form();
     $post = new Validation($_POST);
     $post->add_rules("albums", "numeric");
     $post->add_rules("photos", "numeric");
     $post->add_rules("comments", "numeric");
     $post->add_rules("tags", "numeric");
     $post->add_callbacks("albums", array($this, "_set_default"));
     $post->add_callbacks("photos", array($this, "_set_default"));
     $post->add_callbacks("comments", array($this, "_set_default"));
     $post->add_callbacks("tags", array($this, "_set_default"));
     if ($post->validate()) {
         $task_def = Task_Definition::factory()->callback("developer_task::create_content")->description(t("Create test content"))->name(t("Create Test Data"));
         $total = $post->albums + $post->photos + $post->comments + $post->tags;
         $success_msg = t("Successfully generated test data");
         $error_msg = t("Problems with test data generation was encountered");
         $task = task::create($task_def, array("total" => $total, "batch" => (int) ceil($total / 10), "success_msg" => $success_msg, "current" => 0, "error_msg" => $error_msg, "albums" => $post->albums, "photos" => $post->photos, "comments" => $post->comments, "tags" => $post->tags));
         batch::start();
         print json_encode(array("result" => "started", "max_iterations" => $total + 5, "url" => url::site("admin/developer/run_task/{$task->id}?csrf=" . access::csrf_token()), "task" => $task->as_array()));
     } else {
         $v = $this->_get_test_data_view(arr::overwrite($form, $post->as_array()), arr::overwrite($errors, $post->errors()));
         print json_encode(array("result" => "error", "form" => $v->__toString()));
     }
 }
开发者ID:ChrisRut,项目名称:gallery3-contrib,代码行数:26,代码来源:admin_developer.php

示例3: upload

 public function upload()
 {
     access::verify_csrf();
     $validation = new Validation(array_merge($_POST, $_FILES));
     $validation->add_rules("zip_file", "upload::valid", "upload::required", "upload::type[zip]");
     $validation->add_rules("is_admin", "chars[0,1]");
     $validation->add_callbacks("zip_file", array($this, "_unload_zip"));
     if ($validation->validate()) {
         $session = Session::instance();
         $themeroller_name = $session->get("themeroller_name");
         $is_admin = $validation["is_admin"];
         $counter = 0;
         $theme_name_generated = $theme_name = ($is_admin ? "admin_" : "") . $themeroller_name;
         while (file_exists(THEMEPATH . "{$theme_name_generated}/theme.info")) {
             $counter++;
             $theme_name_generated = "{$theme_name}_{$counter}";
         }
         $theme_name = strtolower(strtr($theme_name_generated, " ", "_"));
         $session->set("theme_name", $theme_name);
         $session->set("themeroller_is_admin", $is_admin);
         print "FILEID: {$validation["zip_file"]["tmp_name"]}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid zip archive");
     }
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:26,代码来源:admin_themeroller.php

示例4: validate

 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('title', 'required');
     $array->add_callbacks('deleted', array($this, '_dependents'));
     // Explicitly add those fields for which we don't do validation
     $this->unvalidatedFields = array('description', 'website_id', 'parent_id', 'deleted');
     return parent::validate($array, $save);
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:9,代码来源:termlist.php

示例5: create

 function create()
 {
     $this->template->title = Kohana::lang('user.sign_up');
     $this->template->view->errors = array();
     $this->template->view->username = '';
     $this->template->view->email = '';
     if ($post = $this->input->post()) {
         $this->template->view->email = $post['email'];
         $this->template->view->username = $post['username'];
         $form = new Validation($post);
         $form->add_rules('email', 'required', 'valid::email');
         $form->add_rules('username', 'required');
         $form->add_rules('password', 'required');
         $form->add_callbacks('email', array($this, '_unique_email'));
         $form->add_callbacks('username', array($this, '_unique_username'));
         if ($form->validate()) {
             $user = ORM::factory('user');
             $user->email = $post['email'];
             $user->username = $post['username'];
             $user->password = $post['password'];
             if ($user->save()) {
                 // Save confirm code
                 $prop = ORM::factory('user_property');
                 $prop->user_id = $user->id;
                 $prop->key = 'confirm';
                 $prop->value = sha1($user->id . time() . Kohana::config('qaargh.confirm_salt'));
                 $prop->save();
                 // Send confirm email
                 $to = $post['email'];
                 $from = Kohana::config('qaargh.mailer');
                 $subject = Kohana::lang('user.email_account_created');
                 $email_view = new View('user/confirm_email');
                 $email_view->code = $prop->value;
                 $message = $email_view->render();
                 email::send($to, $from, $subject, $message, TRUE);
                 // And bounce.
                 $this->session->set_flash('notice', Kohana::lang('user.user_created'));
                 url::redirect("/user/confirm");
             }
         } else {
             $this->template->view->errors = $form->errors('form_errors');
         }
     }
 }
开发者ID:jmhobbs,项目名称:q-aargh,代码行数:44,代码来源:user.php

示例6: saveprefs

 public function saveprefs()
 {
     // Prevent Cross Site Request Forgery
     access::verify_csrf();
     $post = new Validation($_POST);
     $post->add_callbacks("IccPath", array($this, "_validate_icc_path"));
     $icc_path = Input::instance()->post("IccPath");
     if ($post->validate()) {
         module::set_var("rawphoto", "icc_path", $icc_path);
         message::success(t("Your preferences have been saved."));
     } else {
         message::error(t("Your preferences are not valid."));
     }
     print $this->_get_view($post->errors(), $icc_path);
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:15,代码来源:admin_rawphoto.php

示例7: setting

 /**
  * Settings
  * @return void
  */
 public function setting($state = NULL)
 {
     if (user::is_logged()) {
         // Messages about success
         $success = array();
         if ($state == "changed") {
             $success[] = Kohana::lang('user.successfully_changed');
         }
         $this->add_breadcrumb(Kohana::lang('user.settings'), url::current());
         $this->set_title(Kohana::lang('user.settings'));
         // default values
         $form = array('password' => '', 'password2' => '', 'password3' => '');
         $form['fullname'] = $this->user->get_name($this->LogSession->who_is_logged());
         //$errors = $form;
         $errors = array();
         // change data
         if ($_POST) {
             $post = new Validation($_POST);
             $post->add_rules('password3', 'required');
             // old password is always required
             $post->add_rules('fullname', 'required');
             $post->add_rules('password', 'depends_on[password2]');
             $post->add_rules('password2', 'depends_on[password]');
             $post->add_rules('password', 'length[6,128]');
             $post->add_rules('password', 'matches[password2]', 'depends_on[password]', 'depends_on[password2]');
             $post['email'] = $this->LogSession->who_is_logged();
             $post->add_callbacks('password3', array($this->user, '_password_match'));
             // Some filters
             $post->pre_filter('trim', TRUE);
             if ($post->validate()) {
                 $this->user->change_data($post, $this->LogSession->who_is_logged());
                 if (!empty($post['password'])) {
                     $this->user->change_password($this->LogSession->who_is_logged(), $post['password']);
                 }
                 url::redirect('/user/setting/changed');
             } else {
                 // Repopulate form with error and original values
                 $form = arr::overwrite($form, $post->as_array());
                 $errors = $post->errors('users_settings_errors');
                 $success = array();
             }
         }
         $this->template->content = new View('setting');
         $this->template->content->form = $form;
         $this->template->content->errors = $errors;
         $this->template->content->success = $success;
     } else {
         // User is not suppose to be here, redirect
         url::redirect('/user/login');
     }
 }
开发者ID:repli2dev,项目名称:re-eshop,代码行数:55,代码来源:user.php

示例8: index

 public function index()
 {
     // Create new session
     $this->session->create();
     $this->template->header->this_page = 'alerts';
     $this->template->content = new View('alerts');
     // Display news feeds?
     $this->template->content->allow_feed = Kohana::config('settings.allow_feed');
     // Retrieve default country, latitude, longitude
     $default_country = Kohana::config('settings.default_country');
     // Retrieve Country Cities
     $this->template->content->cities = $this->_get_cities($default_country);
     // setup and initialize form field names
     $form = array('alert_mobile' => '', 'alert_mobile_yes' => '', 'alert_email' => '', 'alert_email_yes' => '', 'alert_lat' => '', 'alert_lon' => '');
     // copy the form as errors, so the errors will be stored with keys
     // corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = new Validation($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         if (!empty($_POST['alert_mobile']) || isset($_POST['alert_mobile_yes'])) {
             $post->add_rules('alert_mobile', 'required', 'numeric', 'length[6,20]');
         }
         if (!empty($_POST['alert_email']) || isset($_POST['alert_email_yes'])) {
             $post->add_rules('alert_email', 'required', 'email', 'length[3,64]');
         }
         if (empty($_POST['alert_email']) && empty($_POST['alert_mobile'])) {
             $post->add_error('alert_mobile', 'one_required');
             $post->add_error('alert_email', 'one_required');
         }
         $post->add_rules('alert_lat', 'required', 'between[-90,90]');
         // Validate for maximum and minimum latitude values
         $post->add_rules('alert_lon', 'required', 'between[-180,180]');
         // Validate for maximum and minimum longitude values
         // Add a callback, to validate the mobile phone/email (See the methods below)
         $post->add_callbacks('alert_mobile', array($this, 'mobile_check'));
         $post->add_callbacks('alert_email', array($this, 'email_check'));
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             // Save alert and send out confirmation code
             $email_confirmation_saved = FALSE;
             $sms_confirmation_saved = FALSE;
             if (!empty($post->alert_mobile)) {
                 $alert_code = $this->_mk_code();
                 $settings = ORM::factory('settings', 1);
                 if ($settings->loaded == true) {
                     // Get SMS Numbers
                     if (!empty($settings->sms_no3)) {
                         $sms_from = $settings->sms_no3;
                     } elseif (!empty($settings->sms_no2)) {
                         $sms_from = $settings->sms_no2;
                     } elseif (!empty($settings->sms_no1)) {
                         $sms_from = $settings->sms_no1;
                     } else {
                         $sms_from = "000";
                         // User needs to set up an SMS number
                     }
                     $sms = new Clickatell();
                     $sms->api_id = $settings->clickatell_api;
                     $sms->user = $settings->clickatell_username;
                     $sms->password = $settings->clickatell_password;
                     $sms->use_ssl = false;
                     $sms->sms();
                     $message = "Your alerts confirmation code\n\t\t\t\t\t\t\t\tis: " . $alert_code . " This code is NOT case sensitive";
                     if ($sms->send($post->alert_mobile, $sms_from, $message) == "OK") {
                         $alert = ORM::factory('alert');
                         $alert->alert_type = self::MOBILE_ALERT;
                         $alert->alert_recipient = $post->alert_mobile;
                         $alert->alert_code = $alert_code;
                         $alert->alert_lon = $post->alert_lon;
                         $alert->alert_lat = $post->alert_lat;
                         $alert->save();
                         if ($alert->saved == TRUE) {
                             $sms_confirmation_saved = TRUE;
                         }
                     }
                 }
             }
             if (!empty($post->alert_email)) {
                 $alert_code = $this->_mk_code();
                 //Send verification email
                 $config = kohana::config('alerts');
                 $settings = kohana::config('settings');
                 $to = $post->alert_email;
                 $from = $config['alerts_email'];
                 $subject = $settings['site_name'] . ' alerts - verification';
                 $message = 'Please follow ' . url::base() . 'alerts/verify/' . $alert_code . ' to confirm your alert request';
                 if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                     $alert = ORM::factory('alert');
                     $alert->alert_type = self::EMAIL_ALERT;
                     $alert->alert_recipient = $post->alert_email;
                     $alert->alert_code = $alert_code;
                     $alert->alert_lon = $post->alert_lon;
//.........这里部分代码省略.........
开发者ID:rabble,项目名称:Ushahidi_Web,代码行数:101,代码来源:alerts.php

示例9: _get_frm_valid

 private function _get_frm_valid()
 {
     $form = $this->promotion_model->get_frm();
     $hd_id = $this->input->post('hd_id');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->add_rules('txt_company', 'required');
         $post->add_rules('txt_email', 'required');
         $post->add_rules('txt_code', 'required');
         if (empty($hd_id)) {
             // create account
             $post->add_callbacks('txt_code', array($this, '_check_code'));
         } else {
             $post->add_callbacks('txt_code', array($this, '_check_code_exist'));
         }
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors('promotion_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             if ($hd_id) {
                 url::redirect('admin_promotion/edit/' . $hd_id);
             } else {
                 url::redirect('admin_promotion/create');
             }
             die;
         }
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:38,代码来源:admin_promotion.php

示例10: checkout

 /**
  * Checkout
  */
 public function checkout()
 {
     $output = '';
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $output = $this->_checkout_step_1();
     } else {
         //valid helper
         include 'classes/valid.class.php';
         $valid = new Valid();
         //validation class
         include 'classes/validation.class.php';
         $step = $_POST['step'];
         if ($step == '1') {
             //step 1 validation
             $post = new Validation($_POST['order']);
             $post->add_rules('first_name', 'required');
             $post->add_rules('last_name', 'required');
             $post->add_rules('company', 'required');
             $post->add_rules('address', 'required');
             $post->add_rules('city', 'required');
             $post->add_rules('state', 'required');
             $post->add_rules('country', 'required');
             $post->add_rules('zip', 'required');
             $post->add_rules('phone', 'required', array($valid, 'phone'));
             $post->add_rules('email', 'required', array($valid, 'email'));
             if (!isset($_POST['billing_is_shipping'])) {
                 $post->add_rules('ship_first_name', 'required');
                 $post->add_rules('ship_last_name', 'required');
                 $post->add_rules('ship_company', 'required');
                 $post->add_rules('ship_address', 'required');
                 $post->add_rules('ship_city', 'required');
                 $post->add_rules('ship_state', 'required');
                 $post->add_rules('ship_country', 'required');
                 $post->add_rules('ship_zip', 'required');
                 $post->add_rules('ship_phone', 'required', array($valid, 'phone'));
             }
             $post->pre_filter('trim');
             //success, go to step 2
             if ($post->validate()) {
                 //save order data
                 $_SESSION['order'] = $_POST['order'];
                 $output = $this->_checkout_step_2();
             } else {
                 $errors = $post->errors();
                 $output = $this->_checkout_step_1($_POST, $errors);
             }
         } elseif ($step == '2') {
             //step 2 validation
             $post = new Validation($_POST['order']);
             $post->add_rules('cc_name', 'required');
             $post->add_rules('cc_type', 'required');
             $post->add_rules('cc_number', 'required', array($valid, 'credit_card'));
             $post->add_rules('cc_cvv', 'required', 'length[3,4]', array($valid, 'digit'));
             $post->add_rules('cc_exp_month', 'required');
             $post->add_rules('cc_exp_year', 'required');
             if (isset($_POST['order']['cc_exp_month']) && isset($_POST['order']['cc_exp_year'])) {
                 $post->add_callbacks('cc_exp_year', array($this, '_validate_cc_exp_date'));
             }
             $post->pre_filter('trim');
             if ($post->validate()) {
                 $cart = new Cart('shopping_cart');
                 //order data array
                 $order_arr = array_merge($_SESSION['order'], $_POST['order']);
                 $full_cc_number = $order_arr['cc_number'];
                 $order_arr['cc_number'] = substr($order_arr['cc_number'], -4);
                 $order_arr['promo_discount'] = $cart->getDiscount($order_arr['promo_code']);
                 $order_arr['subtotal'] = $cart->getTotal();
                 $order_arr['tax'] = $cart->getTax();
                 //process payment
                 include 'merchants/firstdata.class.php';
                 $merchant = new FirstData();
                 //billing info
                 $merchant->name = $order_arr['first_name'] . ' ' . $order_arr['last_name'];
                 $merchant->company = $order_arr['company'];
                 $merchant->address = $order_arr['address'];
                 $merchant->address2 = $order_arr['address2'];
                 $merchant->city = $order_arr['city'];
                 $merchant->state = $order_arr['state'];
                 $merchant->country = $order_arr['country'];
                 $merchant->phone = $order_arr['phone'];
                 $merchant->fax = $order_arr['fax'];
                 $merchant->email = $order_arr['email'];
                 $merchant->zip = $order_arr['zip'];
                 //shipping info
                 $merchant->ship_name = $order_arr['ship_first_name'] . ' ' . $order_arr['ship_last_name'];
                 $merchant->ship_address = $order_arr['ship_address'];
                 $merchant->ship_saddress2 = $order_arr['ship_address2'];
                 $merchant->ship_city = $order_arr['ship_city'];
                 $merchant->ship_state = $order_arr['ship_state'];
                 $merchant->ship_country = $order_arr['ship_country'];
                 $merchant->ship_zip = $order_arr['ship_zip'];
                 //payment info
                 $merchant->cc_number = $full_cc_number;
                 $merchant->cc_exp_month = $order_arr['cc_exp_month'];
                 $merchant->cc_exp_year = substr($order_arr['cc_exp_year'], -2);
                 $merchant->cc_cvv = $order_arr['cc_cvv'];
                 $merchant->subtotal = $order_arr['subtotal'];
//.........这里部分代码省略.........
开发者ID:shuhrat,项目名称:frog_ecommerce,代码行数:101,代码来源:EcommerceController.php

示例11: create

 /**
  * 创建活动
  */
 public function create()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400505:活动信息非法');
     }
     $post = new Validation($data);
     $post->add_rules('title', 'required', 'length[1, 30]');
     $post->add_rules('start_at', 'required', 'numeric');
     $post->add_rules('end_at', 'required', 'numeric');
     $post->add_rules('spot', 'required', 'length[1, 30]');
     $post->add_rules('type', 'required', 'numeric', array($this, '_check_type_validation'));
     $post->add_rules('is_allow_invite', 'required', 'numeric', array($this, '_check_allow_invite_validation'));
     $post->add_rules('content', 'length[0, 300]');
     $post->add_rules('group_ids', array($this, '_check_group_ids_validation'));
     $post->add_callbacks(TRUE, array($this, '_check_time_validation'));
     if ($post->validate()) {
         $activity = array();
         $form = $post->as_array();
         $activity['creator_id'] = $this->user_id;
         $activity['title'] = $form['title'];
         $activity['start_time'] = $form['start_at'];
         $activity['end_time'] = $form['end_at'];
         $nowTime = time();
         $activity['create_time'] = $nowTime;
         $activity['spot'] = $form['spot'];
         $activity['type'] = $form['type'];
         $activity['is_allow_invite'] = $form['is_allow_invite'];
         if (isset($form['content'])) {
             $activity['content'] = $form['content'];
         }
         $groupIds = array();
         if (isset($form['group_ids'])) {
             $groupIds = $form['group_ids'];
         }
         $groupModel = new Group_Model();
         $gidArray = array();
         foreach ($groupIds as $id) {
             $id = floatval($id);
             if ($id != -1) {
                 $groupInfo = $groupModel->getGroupInfo($id);
                 if (!$groupInfo) {
                     $this->send_response(400, NULL, '400506:活动发布到的群不存在');
                 }
                 $grade = $groupModel->getMemberGrade($id, $this->user_id);
                 if ($grade < 1) {
                     $this->send_response(400, NULL, '400507:您不是活动指定发布到群的成员');
                 }
             }
             $gidArray[] = $id;
         }
         if (!$gidArray) {
             $activity['is_publish'] = 0;
         } else {
             $activity['is_publish'] = 1;
         }
         $activity_id = $this->model->add($activity);
         $activityMember = array('aid' => $activity_id, 'uid' => $this->user_id, 'apply_type' => Kohana::config('activity.apply_type.join'), 'apply_time' => $nowTime, 'grade' => Kohana::config('activity.grade.creator'));
         $result = $this->model->applyActivity($activityMember);
         $this->model->addActivityUser($activity_id, $this->user_id);
         $friendModel = new Friend_Model();
         $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
         //活动动态发送到指定momo成员
         foreach ($gidArray as $gid) {
             $this->model->addActivityGroup($activity_id, $gid);
             if ($gid == -1) {
                 $friendModel = new Friend_Model();
                 $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
                 foreach ($fidList as $fid) {
                     $this->model->addActivityUser($activity_id, $fid);
                 }
             } else {
                 $this->model->addActivityGroup($activity_id, $gid);
                 $members = $groupModel->getGroupAllMember($gid);
                 foreach ($members as $value) {
                     $this->model->addActivityUser($activity_id, $value['uid']);
                 }
             }
         }
         $feedModel = new Feed_Model();
         $title = array('uid' => $this->user_id, 'name' => sns::getrealname($this->user_id), 'id' => $activity_id, 'title' => $activity['title']);
         $messageModel = new Message_Model();
         if ($activity['is_publish']) {
             $feedModel->addFeed($this->user_id, 'action_add', Kohana::config('uap.app.action'), $title, array(), $activity_id);
         }
         $this->send_response(200, array('id' => floatval($activity_id)));
     }
     $errors = $post->errors();
     $this->send_response(400, NULL, '400505:活动信息非法');
 }
开发者ID:momoim,项目名称:momo-api,代码行数:96,代码来源:activity.php

示例12: invite

 /**
  * 
  * 活动邀请
  */
 public function invite($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     if (empty($id)) {
         $this->send_response(400, NULL, '400501:活动ID为空');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400412:活动信息非法');
     }
     $event_info = $this->model->get($id);
     if (!$event_info) {
         $this->send_response(400, NULL, '400506:活动不存在');
     }
     if (empty($data['user'])) {
         $this->send_response(400, NULL, '400508:活动报名信息为空');
     }
     $return = array();
     $update_apply_type = false;
     $post = new Validation($data);
     $post->add_rules('user', 'required');
     $post->add_callbacks(TRUE, array($this, '_check_user_validation'));
     if ($post->validate()) {
         $form = $post->as_array();
         if (count($form['user'] > 0)) {
             $user_array = $this->_get_event_uid($form['user']);
             $i = 0;
             $cover = Event_Image_Model::instance()->getCover($id);
             $cover = $cover ? $cover : '';
             $opt = array('event' => array('id' => $id, 'name' => $event_info['title'], 'cover' => $cover), 'no_sign' => 1);
             foreach ($user_array as $mobile => $user) {
                 $i++;
                 if ($this->user_id == $user['user_id'] || empty($user['user_id'])) {
                     continue;
                 }
                 $apply_type = $this->model->getApplyType(array('eid' => $id, 'uid' => $user['user_id']));
                 if (!$apply_type || $apply_type == Kohana::config('event.apply_type.refused')) {
                     if ($apply_type == Kohana::config('event.apply_type.refused')) {
                         $update_apply_type = true;
                     }
                     $eventUser = array('eid' => $id, 'pid' => 0, 'uid' => $user['user_id'], 'name' => $user['name'], 'mobile' => $mobile, 'apply_type' => Kohana::config('event.apply_type.unconfirmed'), 'apply_time' => time(), 'invite_by' => $this->user_id, 'grade' => Kohana::config('event.grade.normal'));
                     $this->model->applyEvent($eventUser, $update_apply_type);
                 }
                 if (!in_array($apply_type, array(Kohana::config('event.apply_type.joined'), Kohana::config('event.apply_type.interested')))) {
                     $return[] = array('uid' => $user['user_id'], 'name' => $user['name'], 'mobile' => $mobile, 'avatar' => sns::getAvatar($user['user_id']));
                     $device_id = md5($mobile . '_' . '0');
                     $token = User_Model::instance()->request_access_token(0, $user['user_id'], $device_id, Kohana::config('event.appid'));
                     $event_url = MO_EVENT . 'event/show/' . $id . '?token=' . $token['oauth_token'];
                     $event_short_url = url::getShortUrl($event_url);
                     $content = '邀请你参加活动:' . $event_short_url;
                     $this->send_event_mq($this->user_id, $user['user_id'], $content, $opt);
                 } else {
                     $this->send_response(400, NULL, '400511:该用户已报名');
                 }
             }
             $this->send_response(200, array('num' => $i, 'user' => $return));
         }
     }
     $errors = $post->errors();
     foreach ($errors as $key => $value) {
         switch ($key) {
             case 'user_name_empty':
                 $this->send_response(400, NULL, '400502:名字为空');
                 break;
             case 'user_mobile_empty':
                 $this->send_response(400, NULL, '400503:手机号为空');
                 break;
             case 'user_mobile_format':
                 $this->send_response(400, NULL, '400504:手机号格式不正确');
                 break;
         }
     }
 }
开发者ID:momoim,项目名称:momo-api,代码行数:79,代码来源:event.php

示例13: add

 /**
  *  Add page
  * @return void
  */
 public function add()
 {
     // Check for user permission
     if (user::is_got()) {
         // Settings
         $this->set_title(Kohana::lang('page.add_page'));
         $this->add_breadcrumb(Kohana::lang('page.add_page'), url::current());
         // Load tinymce
         $this->add_javascript('/libs/tinymce/tiny_mce.js');
         $this->add_javascript('/libs/tinymce/richEditor.js');
         // Default values
         $form = array('heading' => '', 'url' => '', 'page_text' => '', 'display_menu' => 0);
         $errors = array();
         // Validation
         if ($_POST) {
             $post = new Validation($_POST);
             // Some filters
             $post->pre_filter('trim', TRUE);
             // Rules
             $post->add_rules('heading', 'required');
             $post->add_rules('url', 'required', 'alpha_dash');
             $post->add_rules('page_text', 'required');
             $post->add_callbacks('url', array($this->page, '_url_is_free'));
             if ($post->validate()) {
                 // Everything seems to be ok, insert into db
                 $this->page->add_data($post);
                 url::redirect('/page/' . $post['url']);
             } else {
                 // Repopulate form with error and original values
                 $form = arr::overwrite($form, $post->as_array());
                 $errors = $post->errors('page_errors');
             }
         }
         // View
         $this->template->content = new View('admin/page_add');
         $this->template->content->form = $form;
         $this->template->content->errors = $errors;
     } else {
         url::redirect('/denied');
     }
 }
开发者ID:repli2dev,项目名称:re-eshop,代码行数:45,代码来源:page.php

示例14: checkout

 /**
  * Checkout 
  * @return void
  */
 public function checkout()
 {
     // Check user permission
     if (user::is_logged()) {
         if ($this->cart->count_cart() != 0) {
             $customer = new Customer_Model();
             if ($customer->has_info()) {
                 // check if customer profile is set (at least personal informations)
                 // Settings
                 $this->set_title(Kohana::lang('eshop.checkout'));
                 $this->add_breadcrumb(Kohana::lang('eshop.checkout'), '/cart/checkout');
                 // Other needed models, and data
                 $shipping = new Shipping_Model();
                 $payment = new Payment_Model();
                 $order = new Order_Model();
                 // Fetching values
                 $cart = $this->cart->get_cart();
                 $total = $this->cart->get_total();
                 $shipping_methods = $shipping->get_all();
                 $payment_methods = $payment->get_all();
                 $profile = $customer->get_profile(user::user_id());
                 // Default values
                 $form = array('delivery_name' => $profile['name'], 'delivery_street' => $profile['customer_street'], 'delivery_city' => $profile['customer_city'], 'delivery_postal_code' => $profile['customer_postal_code'], 'shipping' => $shipping->get_default(), 'payment' => $payment->get_default());
                 $errors = array();
                 // Validation
                 if ($_POST) {
                     $post = new Validation($_POST);
                     // Some filters
                     $post->pre_filter('trim', TRUE);
                     // Rules
                     $post->add_rules('delivery_name', 'required', 'length[0,255]');
                     $post->add_rules('delivery_street', 'required');
                     $post->add_rules('delivery_city', 'required');
                     $post->add_rules('delivery_postal_code', 'required', 'length[0,255]');
                     $post->add_rules('shipping', 'required');
                     $post->add_callbacks('shipping', array($shipping, '_exists'));
                     $post->add_rules('payment', 'required');
                     $post->add_callbacks('payment', array($payment, '_exists'));
                     if ($post->validate()) {
                         // Everything seems to be ok, insert to db
                         $id = $order->add_data($post, $profile, $cart);
                         $this->cart->empty_cart();
                         // Now payment
                         url::redirect('/cart/payment/' . $id);
                     } else {
                         // Repopulate form with error and original values
                         $form = arr::overwrite($form, $post->as_array());
                         $errors = $post->errors('cart_checkout_errors');
                     }
                 }
                 // View
                 $this->template->content = new View('cart_checkout');
                 $this->template->content->cart = $cart;
                 $this->template->content->total = $total;
                 $this->template->content->profile = $profile;
                 $this->template->content->shipping_methods = $shipping_methods;
                 $this->template->content->payment_methods = $payment_methods;
                 $this->template->content->form = $form;
                 $this->template->content->errors = $errors;
             } else {
                 url::redirect('/customer/profile/needed');
             }
         } else {
             url::redirect('/cart/show');
         }
     } else {
         url::redirect('/user/login/login');
     }
 }
开发者ID:repli2dev,项目名称:re-eshop,代码行数:73,代码来源:cart.php

示例15: removeSetting

 public function removeSetting()
 {
     $user = $this->authenticate();
     $emptyrequest = !isset($_GET) && !isset($_POST) || sizeof($_GET) == 0 && sizeof($_POST) == 0;
     $input;
     if (!$emptyrequest) {
         $input = new Validation(array_merge($_GET, $_POST));
         $input->add_rules('setting_id', 'required', 'numeric');
         $validator = new SettingValidation_Model();
         $validator->expectedUser_id = $user->user_id;
         $input->add_callbacks('setting_id', array($validator, "validateExists"));
         $input->add_callbacks('setting_id', array($validator, "validateUserOwnsSetting"));
     } else {
         $input = new Validation(array());
         $input->add_error('setting_id', 'required');
     }
     if ($input->validate()) {
         $setting = new Setting_Model();
         $setting->setting_id = $input->setting_id;
         $setting->retrieveInfoFromDB();
         $setting->removeFromDB();
         Kohana::render($this->encode($setting));
     } else {
         //@TODO : make better error messages......
         Kohana::render($this->encode(NULL, $input->errors()));
     }
 }
开发者ID:scottasoutherland,项目名称:todo-list,代码行数:27,代码来源:api.php


注:本文中的Validation::add_callbacks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。