本文整理汇总了PHP中Arr::map方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::map方法的具体用法?PHP Arr::map怎么用?PHP Arr::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insBook
/**
* @param bool $id
* @return bool
* @throws Kohana_Exception
*
* insert or update book
*/
public function insBook($id = false)
{
$_POST = Arr::map('trim', $_POST);
$post = Validation::factory($_POST);
$post->rule('name', 'not_empty')->rule('name', 'alpha_numeric', array(':value', false))->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 20))->rule('email', 'email')->rule('body', 'not_empty')->rule('body', 'max_length', array(':value', 1024));
if ($post->check()) {
if ($id) {
$book = ORM::factory('Guestbook', $id);
} else {
$book = ORM::factory('Guestbook');
}
$book->name = Security::encode_php_tags(HTML::chars($_POST['name']));
$book->email = Security::encode_php_tags(HTML::chars($_POST['email']));
$book->body = Security::encode_php_tags(HTML::chars($_POST['body']));
try {
if ($id) {
$book->update();
} else {
$book->create();
}
return true;
} catch (ORM_Validation_Exception $e) {
return false;
}
} else {
//$errors = $post -> errors('validation');
return false;
}
}
示例2: action_index
public function action_index()
{
$config = Kohana::$config->load('huia/email');
$values = Arr::map('strip_tags', $this->request->post());
$view = View::factory('huia/email/' . $values['view']);
$view->set($values);
$result = Email::factory($values['subject'], $view->render(), 'text/html')->to($values['to_email'])->from($config->from_email, $config->from_name)->send();
$this->response->body(@json_encode(array('success' => $result)));
}
示例3: action_edit
public function action_edit()
{
$view = View::factory('exercise/form')->bind('form', $form)->bind('questions', $questions)->bind('selected_questions', $selected_questions)->bind('exercise_questions', $exercise_questions)->bind('error_notif', $error_notif);
$submitted = false;
$course = ORM::factory('course', Session::instance()->get('course_id'));
$error_notif = array();
$exercise_id = (int) $this->request->param('id');
$exercise = ORM::factory('exercise', $exercise_id);
if ($this->request->method() === 'POST' && $this->request->post()) {
$submitted = true;
$safepost = Arr::map('Security::xss_clean', $this->request->post());
$validator = $exercise->validator($safepost);
if ($validator->check() && $this->validate_form($safepost)) {
$exercise->values(array_merge($safepost, array('course_id' => $course->id, 'slug' => Text::limit_chars(Inflector::underscore($safepost['title'])), 'modified_at' => date('Y-m-d H:i:s', time()))));
$exercise->save();
$zip_ques = Arr::zip($safepost['selected'], $safepost['marks']);
$exercise->delete_questions()->add_questions($zip_ques);
if ($safepost['pub_status'] == '1') {
$exist = ORM::factory('feed');
$exist->where('type', ' = ', 'exercise');
$exist->where('action', ' = ', 'add');
$exist->where('respective_id', ' = ', $exercise->id);
$exist->where('course_id', ' = ', Session::instance()->get('course_id'));
$exists = $exist->find_all();
if (count($exists) == 0) {
$feed = new Feed_Exercise();
$feed->set_action('add');
$feed->set_course_id(Session::instance()->get('course_id'));
$feed->set_respective_id($exercise->id);
$feed->set_actor_id(Auth::instance()->get_user()->id);
$feed->streams(array('course_id' => (int) Session::instance()->get('course_id')));
$feed->save();
}
}
Session::instance()->set('success', 'Exercise edited successfully.');
Request::current()->redirect('exercise');
exit;
} else {
$this->_errors = array_merge($this->_errors, $validator->errors('exercise'));
$error_notif = Arr::get($this->_errors, 'questions', '');
}
}
$exercise_questions = $exercise->questions()->as_array('question_id', 'marks');
$selected_questions = array_keys($exercise_questions);
$saved_data = $exercise->as_array();
$form = $this->form('exercise/edit/id/' . $exercise->id, $submitted, $saved_data);
Breadcrumbs::add(array('Edit', ''));
// set content
$questions = Model_Question::get_questions(array('course_id' => $course->id));
$this->content = $view;
}
示例4: __construct
public function __construct($preset = 'default')
{
Arr::map('Security::xss_clean', $_POST);
$settings = Kohana::$config->load('fbuilder.' . $preset);
$this->view = View::factory($settings['view']);
$this->defaults = $settings['params_default'];
$this->theme = $settings['theme'];
if ($post = $_POST) {
$dta = $this->flatten_array($post);
}
if (isset($dta) and !empty($dta)) {
$this->post = Arr::merge($this->post, $dta);
}
}
示例5: index
/**
* Form with mentions keywords list
*/
public function index()
{
$keywords = User_search_keyword::inst()->get_user_keywords($this->c_user->id, $this->profile->id);
$new_keywords = array();
$errors = array();
$saved_ids = array(0);
// '0' to prevent datamapper error caused by empty array
$delete = true;
if ($post = $this->input->post()) {
unset($post['submit']);
$grouped = Arr::collect($post);
foreach ($grouped as $id => $data) {
if (strpos($id, 'new_') === 0) {
$keyword = User_search_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id);
$new_keywords[$id] = $keyword;
} else {
$keyword = User_search_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id, $id);
if ($keyword->id !== $id) {
$new_keywords[$id] = $keyword;
}
}
if ($keyword->save()) {
$saved_ids[] = $keyword->id;
} else {
$errors[$id] = $keyword->error->string;
}
}
if (empty($errors)) {
if ($delete) {
User_search_keyword::inst()->set_deleted($this->c_user->id, $this->profile->id, $saved_ids);
}
$this->addFlash(lang('keywords_saved_success'), 'success');
redirect('settings/user_search_keywords');
} else {
$this->addFlash(implode('<br>', Arr::map('strip_tags', $errors)));
}
}
CssJs::getInst()->c_js('settings/user_search_keywords', 'index');
$configs = Available_config::getByKeysAsArray(array('auto_follow_users_by_search', 'max_daily_auto_follow_users_by_search'), $this->c_user, $this->profile->id);
$outp_keywords = array();
foreach ($keywords as $keyword) {
$outp_keywords[$keyword->id] = $keyword;
}
$outp_keywords = array_merge($outp_keywords, $new_keywords);
$this->template->set('keywords', $outp_keywords);
$this->template->set('errors', $errors);
$this->template->set('configs', $configs);
$this->template->render();
}
示例6: _search
/**
* Прослойка поиска
* @param array $data
* @return array
*/
private function _search(array $data)
{
$result = NULL;
$validation = Validation::factory($data)->rule('str', 'not_empty')->rule('str', 'min_length', array(':value', 4));
if ($validation->check()) {
// Обработка строки
$search_str = trim(preg_replace('/ +/ ', ' ', preg_replace('/[^A-ZА-ЯЁ0-9]+/ui', ' ', mb_strtolower($validation['str']))));
// Выпиливание стоп-слов, слов короче 3 букв, не больше 7 слов
$original_words = array_slice(array_diff(Arr::map('Controller_Search::clear_short_words', explode(' ', $search_str)), Kohana::$config->load('settings.search_stop_words')), 0, 7);
// Поиск леммы
$words = Arr::map('Controller_Search::stemm', $original_words);
if (!empty($words)) {
// ORM object
$company = ORM::factory('service')->search($words, $original_words);
$news = ORM::factory('news')->search($words, $original_words);
$stocks = ORM::factory('stock')->search($words, $original_words);
$vacancies = ORM::factory('vacancy')->search($words, $original_words);
$types = array();
if (count($company->services) > 0) {
$types['services'] = __('site_search_services');
}
if (count($company->shops) > 0) {
$types['shops'] = __('site_search_shops');
}
if (count($news->companies) > 0) {
$types['companies-news'] = __('services_news');
}
if (count($news->world) > 0) {
$types['news-world'] = __('world_news');
}
if (count($news->portal) > 0) {
$types['news-association'] = __('association_news');
}
if (count($stocks) > 0) {
$types['stocks'] = __('cb_stocks');
}
if (count($vacancies) > 0) {
$types['vacancies'] = __('cb_vacancies');
}
$result = View::factory('frontend/search/result')->set('types', $types)->set('company', $company->company)->set('services', $company->services)->set('shops', $company->shops)->set('stocks', $stocks)->set('news', $news)->set('vacancies', $vacancies);
} else {
$this->errors[] = 'Ошибка поиска, возможно введены недопустимые слова';
}
} else {
$this->errors = $validation->errors('search_on_site');
}
$this->values = $data;
return $result;
}
示例7: action_index
public function action_index()
{
$installation_status = Kohana::$config->load('install.status');
switch ($installation_status) {
case NOT_INSTALLED:
if (!$this->check_installation_parameters()) {
//$data['title']=__('Installation: something wrong');
// $this->data=Arr::merge($this->data, Helper::get_db_settings());
$this->data = Arr::merge($this->data, get_object_vars($this->install_config));
$res = View::factory('install_form', $this->data)->render();
//Model::factory('model_name')->model_method( $data );
} else {
$_post = Arr::map('trim', $_POST);
$post = new Validation($_post);
$post->rule('db_path', 'not_empty')->rule('db_name', 'not_empty')->rule('db_login', 'not_empty')->rule('installer_login', 'not_empty')->rule('installer_password', 'not_empty');
if ($post->check()) {
Helper::save_install_settings($post);
if (!Model::factory('install')->install($err_list)) {
Helper::set_installation_status(NOT_INSTALLED);
foreach ($err_list as $e) {
$this->data['errors'][] = $e['error'];
}
$res = View::factory('installing', $this->data)->render();
} else {
$res = View::factory('installing_ok', $this->data)->render();
}
} else {
// Кажется что-то случилось
//$data['title']=__('Installation: something wrong');
$this->data['errors'] = $post->errors('validation');
$res = View::factory('install_form', $this->data)->render();
}
}
break;
case INSTALLING:
$res = View::factory('installing')->render();
break;
case INSTALLED:
// $res = View::factory('/')->render();
$this->redirect('/');
break;
default:
// $res = View::factory('/')->render();
$this->redirect('/');
break;
}
// Save result / Сохраняем результат
$this->_result = $res;
}
示例8: init
/**
* Initializing method: Removes slashes from GPC.
*
* @return Recipe_Request_Adapter
*/
protected function init()
{
if ($this->hasMagicQuotes()) {
if (is_array($_GET) && count($_GET) > 0) {
$_GET = Arr::map("stripslashes", $_GET);
}
if (is_array($_POST) && count($_POST) > 0) {
$_POST = Arr::map("stripslashes", $_POST);
}
if (is_array($_COOKIE) && count($_COOKIE) > 0) {
$_COOKIE = Arr::map("stripslashes", $_COOKIE);
}
}
return $this;
}
示例9: action_third
function action_third()
{
$reg_status = $this->session->get('reg_status', NULL);
if (empty($reg_status) and $reg_status['step'] != 3 and !isset($reg_status['service_id'])) {
$this->request->redirect('/');
}
$service = ORM::factory('service', $reg_status['service_id']);
if ($service->user->id != $this->user->id or !$service->loaded()) {
$this->request->redirect('/');
}
$work_category = ORM::factory('workcategory');
$cars = ORM::factory('car_brand')->get_cars_as_array();
$discounts = ORM::factory('discount')->get_all_as_array();
if ($_POST) {
$post = Arr::map('trim', $_POST);
if (isset($post['skip'])) {
Message::set(Message::SUCCESS, 'Вы успешно зарегистрировались, но не указали дополнительную информацию для фирмы. Вы можете сделать это в ' . HTML::anchor('cabinet', 'личном кабинете') . '.');
$this->session->delete('reg_status');
$this->request->redirect('cabinet');
}
try {
$service->values($post, array('about', 'work_times', 'discount_id', 'coupon_text'));
$cars_input = Arr::get($_POST, 'model', array());
foreach ($cars_input as $c) {
$service->add('cars', $c);
}
if ($service->type == 1) {
$works_input = Arr::get($_POST, 'work', array());
foreach ($works_input as $w) {
$service->add('works', $w);
}
}
$service->update();
Message::set(Message::SUCCESS, 'Вы успешно зарегистрировались.');
$this->session->delete('reg_status');
$this->request->redirect('cabinet');
//throw ORM_Validation_Exception::text('')
} catch (ORM_Validation_Exception $e) {
$this->values = $post;
$this->errors = $e->errors('models');
}
}
$reg_step_view = View::factory('frontend/auth/register/steps')->set('step', 3);
$this->view = View::factory('frontend/auth/register/third')->set('type', $service->type)->set('discounts', $discounts)->set('work_category', $work_category)->set('auto_models', $cars)->set('values', $this->values)->set('errors', $this->errors)->set('reg_steps', $reg_step_view);
$this->template->title = $this->site_name . __('s_reg_3_step');
$this->template->bc['#'] = 'Регистрация';
$this->template->content .= $this->view;
}
示例10: action_edit
public function action_edit()
{
$submitted = false;
$id = $this->request->param('id');
if (!$id) {
Request::current()->redirect('batch');
}
$batch = ORM::factory('batch', $id);
if ($this->request->method() === 'POST' && $this->request->post()) {
if (Arr::get($this->request->post(), 'save') !== null) {
$submitted = true;
$safepost = Arr::map('Security::xss_clean', $this->request->post());
$validator = $batch->validator($safepost);
if ($validator->check()) {
$batch->name = Arr::get($safepost, 'name');
$batch->description = Arr::get($safepost, 'description');
$batch->save();
Session::instance()->set('success', 'Batch edited successfully.');
Request::current()->redirect('batch');
exit;
} else {
$this->_errors = $validator->errors('batch');
}
}
}
Breadcrumbs::add(array('Batches', Url::site('batch')));
Breadcrumbs::add(array('Edit', Url::site('batch/edit/id/' . $id)));
$this->form('batch/edit/id/' . $id, $submitted, array('name' => $batch->name, 'description' => $batch->description));
}
示例11: action_login
function action_login()
{
$this->view = View::factory('frontend/auth/login')->bind('values', $this->values)->bind('errors', $this->errors);
if ($_POST) {
$post = Arr::map('trim', $_POST);
if ($this->auth->login($post['username'], $post['password'])) {
$user = $this->auth->get_user();
// проверяем настройки доступа человека - не просрочен ли его аккаунт
if ($user->user_type == 'unconfirmed') {
$this->auth->logout();
Message::set(Message::NOTICE, 'Вы должны активировать ваш аккаунт');
$this->request->redirect('/auth/confirm_email');
}
Message::set(Message::SUCCESS, 'Добро пожаловать!');
Logger::write(Logger::ACTION, 'Пользователь авторизовался', $user);
$this->request->redirect('cabinet');
} else {
Message::set(Message::ERROR, 'Неправильное имя пользователя или пароль');
}
}
$this->template->content = $this->view;
}
示例12: action_edit
public function action_edit()
{
$submitted = false;
$id = $this->request->param('id');
if (!$id) {
Request::current()->redirect('flashcard');
}
$flashcard = ORM::factory('flashcard', $id);
if ($this->request->method() === 'POST' && $this->request->post()) {
if (Arr::get($this->request->post(), 'save') !== null) {
$submitted = true;
$safepost = Arr::map('Security::xss_clean', $this->request->post());
$validator = $flashcard->validator($safepost);
if ($validator->check()) {
$flashcard->title = Arr::get($safepost, 'title');
$flashcard->description = Arr::get($safepost, 'description');
$flashcard->course_id = Session::instance()->get('course_id');
$flashcard->save();
if (Arr::get($safepost, 'question_selected')) {
Model_Flashcard::insert_flashcard_question($flashcard->id, Arr::get($safepost, 'question_selected'));
}
Session::instance()->set('success', 'Flashcard edited successfully.');
Request::current()->redirect('flashcard');
exit;
} else {
$this->_errors = $validator->errors('flashcard');
}
}
}
Breadcrumbs::add(array('Edit', Url::site('flashcard/edit/id/' . $id)));
$this->form('flashcard/edit/id/' . $id, $submitted, array('title' => $flashcard->title, 'description' => $flashcard->description));
}
示例13: escape
/**
* @param mixed $value
* @return mixed
*/
public function escape($value)
{
if (is_array($value)) {
return Arr::map(array($this, "escape"), $value);
}
return substr($this->pdo->quote($value), 1, -1);
}
示例14: action_edit
public function action_edit()
{
$submitted = false;
$id = $this->request->param('id');
if (!$id) {
Request::current()->redirect('examgroup');
}
$examgroup = ORM::factory('examgroup', $id);
if ($this->request->method() === 'POST' && $this->request->post()) {
if (Arr::get($this->request->post(), 'save') !== null) {
$submitted = true;
$safepost = Arr::map('Security::xss_clean', $this->request->post());
$validator = $examgroup->validator($safepost);
if ($validator->check()) {
$examgroup->name = Arr::get($safepost, 'name');
$examgroup->save();
Session::instance()->set('success', 'Grading Period edited successfully.');
Request::current()->redirect('examgroup');
exit;
} else {
$this->_errors = $validator->errors('examgroup');
}
}
}
$form = $this->form('examgroup/edit/id/' . $id, $submitted, array('name' => $examgroup->name));
$links = array('cancel' => Html::anchor('/examgroup/', 'or cancel'));
$view = View::factory('examgroup/form')->bind('links', $links)->bind('form', $form);
$this->content = $view;
Breadcrumbs::add(array('Exams', Url::site('exam')));
Breadcrumbs::add(array('Grading Period', Url::site('examgroup')));
Breadcrumbs::add(array('Edit', Url::site('examgroup/edit/id/' . $id)));
}
示例15: map
/**
* Recursive version of [array_map](http://php.net/array_map), applies the
* same callback to all elements in an array, including sub-arrays.
*
* // Apply "strip_tags" to every element in the array
* $array = Arr::map('strip_tags', $array);
*
* [!!] Unlike `array_map`, this method requires a callback and will only map
* a single array.
*
* @param mixed callback applied to every element in the array
* @param array array to map
* @return array
*/
public static function map($callback, $array)
{
foreach ($array as $key => $val) {
if (is_array($val)) {
$array[$key] = Arr::map($callback, $val);
} else {
$array[$key] = call_user_func($callback, $val);
}
}
return $array;
}