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


PHP Arr::intersect方法代码示例

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


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

示例1: action_foursquare

 /**
  * Action: foursquare proxy
  */
 public function action_foursquare()
 {
     $foursquare = Arr::get_once($_REQUEST, 'method');
     $url = 'https://api.foursquare.com/v2';
     $method = 'GET';
     $required = $optional = array();
     switch ($foursquare) {
         // Venue info
         case 'venue':
             $url .= '/venue.json';
             $required = array('vid');
             break;
             // Venue search
         // Venue search
         case 'venues':
             $url .= '/venues/search';
             $required = array('ll', 'query');
             $optional = array('limit', 'intent');
             break;
         default:
             return;
     }
     $params = array_filter(Arr::intersect($_REQUEST, $required));
     if (!empty($params)) {
         $params += array_filter(Arr::intersect($_REQUEST, $optional));
         try {
             if ($method == 'GET') {
                 // Send GET request
                 if (!empty($params)) {
                     $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params, '', '&');
                 }
                 $options = array();
             } else {
                 // Send POST request
                 $options = array(CURLOPT_POST => true, CURLOPT_FOLLOWLOCATION => true);
                 if (!empty($params)) {
                     $options[CURLOPT_POSTFIELDS] = http_build_query($params);
                 }
             }
             /** @var  Request  $request */
             $request = Request::factory($url);
             $request->get_client()->options($options);
             $response = $request->execute();
             var_dump($response);
             if ($response->status() == 200) {
                 $this->data[$foursquare] = json_decode($response->body());
             }
         } catch (Kohana_Exception $e) {
         }
     }
 }
开发者ID:anqh,项目名称:venues,代码行数:54,代码来源:api.php

示例2: action_edit

 /**
  * Action: edit
  */
 public function action_edit()
 {
     $this->history = false;
     $this->tabs = null;
     $group_id = (int) $this->request->param('id', null);
     // Load group
     if ($group_id) {
         $group = Model_Forum_Group::factory((int) $group_id);
         if (!$group->loaded()) {
             throw new Model_Exception($group, (int) $group_id);
         }
     } else {
         $group = Model_Forum_Group::factory();
         $group->created = time();
         $group->author_id = self::$user->id;
     }
     Permission::required($group, $group->loaded() ? Model_Forum_Group::PERMISSION_UPDATE : Model_Forum_Group::PERMISSION_CREATE, self::$user);
     // Handle post
     $errors = array();
     if ($_POST) {
         $group->set_fields(Arr::intersect($_POST, array('name', 'description', 'sort')));
         try {
             $group->save();
             $this->request->redirect(Route::model($group));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Build page
     $this->view = new View_Page(__('Forum group') . ($group->name ? ': ' . HTML::chars($group->name) : ''));
     $this->view->tab = 'areas';
     // Set actions
     if ($group->loaded() && Permission::has($group, Model_Forum_Group::PERMISSION_DELETE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($group, 'delete'), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete group'), 'class' => 'btn btn-danger group-delete');
     }
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_edit($group, $errors));
 }
开发者ID:anqh,项目名称:forum,代码行数:40,代码来源:group.php

示例3: action_foursquare

 /**
  * Action: foursquare proxy
  */
 public function action_foursquare()
 {
     $foursquare = Arr::get_once($_REQUEST, 'method');
     $url = 'https://api.foursquare.com/v2';
     $required = $optional = array();
     switch ($foursquare) {
         // Venue info
         case 'venue':
             $url .= '/venue.json';
             $required = array('vid');
             break;
             // Venue search
         // Venue search
         case 'venues':
             $url .= '/venues/search';
             $required = array('ll', 'query');
             $optional = array('limit', 'intent');
             break;
         default:
             return;
     }
     $params = array_filter(Arr::intersect($_REQUEST, $required));
     if (!empty($params)) {
         $params += array_filter(Arr::intersect($_REQUEST, $optional));
         // Client keys
         $client_id = Kohana::$config->load('site.foursquare_client_id');
         $client_secret = Kohana::$config->load('site.foursquare_client_secret');
         if (!$client_id || !$client_secret) {
             throw new Anqh_Controller_API_Exception('Client id or secret missing');
         }
         $params['client_id'] = $client_id;
         $params['client_secret'] = $client_secret;
         $params['v'] = '20130815';
         try {
             if (!empty($params)) {
                 $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params, '', '&');
             }
             /** @var  Request  $request */
             $request = Request::factory($url);
             Kohana::$log->add(Log::DEBUG, 'Foursquare API call: :url ', array(':url' => $url));
             $response = $request->execute();
             switch ($response->status()) {
                 // Success
                 case 200:
                     $result = json_decode($response->body(), true);
                     $this->data[$foursquare] = self::_prepare_foursquare($foursquare, $result['response']);
                     Kohana::$log->add(Log::DEBUG, 'Foursquare API response: :response ', array(':response' => $response->body()));
                     break;
                     // Error in request
                 // Error in request
                 case 400:
                     $this->data['error'] = json_decode($response->body(), true);
                     throw new Controller_API_Exception('Error in request: :response', array(':response' => $response->body()));
                     break;
                 default:
                     $this->data['error'] = json_decode($response->body(), true);
                     throw new Controller_API_Exception('Unknown response: :response', array(':response' => $response->body()));
             }
         } catch (Controller_API_Exception $e) {
             Kohana::$log->add(Log::DEBUG, 'Foursquare API error: :error ', array(':error' => $e->getMessage()));
         } catch (Kohana_Exception $e) {
         }
     }
 }
开发者ID:anqh,项目名称:anqh,代码行数:67,代码来源:api.php

示例4: _edit_gallery

 /**
  * Edit gallery
  *
  * @param  integer  $gallery_id
  * @param  integer  $event_id
  */
 protected function _edit_gallery($gallery_id = null, $event_id = null)
 {
     $this->history = false;
     if ($gallery_id) {
         // Editing old
         $gallery = Model_Gallery::factory($gallery_id);
         if (!$gallery->loaded()) {
             throw new Model_Exception($gallery, $gallery_id);
         }
         Permission::required($gallery, Model_Gallery::PERMISSION_UPDATE, self::$user);
         $cancel = Route::model($gallery);
         $save = null;
         $upload = false;
     } else {
         // Creating new
         $gallery = Model_Gallery::factory();
         Permission::required($gallery, Model_Gallery::PERMISSION_CREATE, self::$user);
         $cancel = Request::back(Route::url('galleries'), true);
         $save = __('Continue');
         $upload = true;
         if ($event_id) {
             /** @var  Model_Event  $event */
             $event = Model_Event::factory($event_id);
         }
     }
     // Handle post
     $errors = array();
     if ($_POST || isset($_GET['from'])) {
         $event_id = $_POST ? (int) Arr::get($_POST, 'event') : (int) Arr::get($_GET, 'from');
         $event = Model_Event::factory($event_id);
         if (!$gallery->loaded() && $event->loaded()) {
             // Redirect to existing gallery if trying to create duplicate
             $old = Model_Gallery::factory()->find_by_event($event_id);
             if ($old->loaded()) {
                 $this->request->redirect(Route::model($old, 'upload'));
             }
             // Fill gallery info from event when creating new
             $gallery->name = $event->name;
             $gallery->date = $event->stamp_begin;
             $gallery->event_id = $event->id;
         } else {
             if ($gallery->loaded()) {
                 // Editing old
                 $gallery->set_fields(Arr::intersect($_POST, Model_Gallery::$editable_fields));
             }
         }
         try {
             $gallery->save();
             $this->request->redirect(Route::model($gallery, $upload ? 'upload' : null));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Build page
     $this->view = View_Page::factory(__('Upload images'));
     // Gallery edit form
     $section = $this->section_gallery_edit(isset($event) ? $event : null);
     $section->errors = $errors;
     $this->view->add(View_Page::COLUMN_MAIN, $section);
     // Gallery event info
     if (isset($event) && $event->loaded()) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_event_info($event));
     }
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_upload_help());
 }
开发者ID:anqh,项目名称:galleries,代码行数:71,代码来源:galleries.php

示例5: _edit_topic


//.........这里部分代码省略.........
             if (Permission::has($topic, Model_Forum_Topic::PERMISSION_DELETE, self::$user)) {
                 $this->view->actions[] = array('link' => Route::model($topic, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete topic'), 'class' => 'btn btn-danger topic-delete');
             }
         } else {
             throw new InvalidArgumentException('Topic and area missing');
         }
     }
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         // Get recipients
         if ($this->private) {
             $post_recipients = array();
             foreach (explode(',', Arr::get_once($_POST, 'recipients')) as $recipient) {
                 if ($user = Model_User::find_user_light(trim($recipient))) {
                     $post_recipients[$user['id']] = $user['username'];
                 }
             }
             // Make sure author is included
             $post_recipients[self::$user->id] = self::$user->username;
         }
         if (isset($post)) {
             // New topic
             $post->post = $_POST['post'];
             $post->forum_area_id = $area->id;
             $post->author_id = self::$user->id;
             $post->author_name = self::$user->username;
             $post->author_ip = Request::$client_ip;
             $post->author_host = Request::host_name();
             $post->created = time();
             try {
                 $post->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             $topic->author_id = self::$user->id;
             $topic->author_name = self::$user->username;
             $topic->name = $_POST['name'];
             $topic->forum_area_id = $area->id;
             $topic->created = time();
             try {
                 $topic->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             // If no errors found, save models
             if (empty($errors)) {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 // Post
                 $post->forum_topic_id = $topic->id;
                 $post->save();
                 // Topic
                 $topic->first_post_id = $topic->last_post_id = $post->id;
                 $topic->last_poster = self::$user->username;
                 $topic->last_posted = time();
                 $topic->post_count = 1;
                 $topic->save();
                 // Area, only public forums
                 if (!$this->private) {
                     $area->last_topic_id = $topic->id;
                     $area->post_count++;
                     $area->topic_count++;
                     $area->save();
                 }
                 // User
                 self::$user->post_count++;
                 self::$user->save();
                 // News feed
                 if (!$this->private) {
                     NewsfeedItem_Forum::topic(self::$user, $topic);
                 }
                 $this->request->redirect(Route::model($topic));
             }
             isset($post_recipients) and $recipients = $post_recipients;
         } else {
             // Old topic
             $topic->set_fields(Arr::intersect($_POST, array('name', 'status', 'sticky')));
             try {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 $this->request->redirect(Route::model($topic));
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validate');
             }
         }
     }
     $form['errors'] = $errors;
     $section = $this->section_post_edit($mode, isset($post) ? $post : null);
     $section->forum_topic = $topic;
     $section->errors = $errors;
     $section->cancel = $cancel;
     $section->recipients = isset($recipients) ? implode(', ', $recipients) : null;
     $this->view->add(View_Page::COLUMN_MAIN, $section);
 }
开发者ID:anqh,项目名称:forum,代码行数:101,代码来源:topic.php

示例6: action_settings

 /**
  * Action: settings
  */
 public function action_settings()
 {
     $this->history = false;
     $user = $this->_get_user();
     Permission::required($user, Model_User::PERMISSION_UPDATE, self::$user);
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         $user->set_fields(Arr::intersect($_POST, Model_User::$editable_fields));
         $user->modified = time();
         try {
             $user->save();
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Build page
     $this->_set_page($user);
     $this->view->tab = 'settings';
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_settings($user, $errors));
 }
开发者ID:anqh,项目名称:core,代码行数:25,代码来源:user.php

示例7: url

 /**
  * Generates the full URL for a certain page.
  *
  * @param   string|boolean  $filter
  * @return  string
  */
 public function url($filter)
 {
     if ($this->type === self::TYPE_URL) {
         return URL::site($this->base_url . '/' . $filter);
     }
     $query = $_GET;
     if ($filter === false) {
         // Remove filters
         unset($query[$this->parameter]);
     } elseif ($this->multiple_query) {
         // Add filter
         $filters = explode(',', Arr::get($query, $this->parameter));
         $filters[] = $filter;
         $query[$this->parameter] = implode(',', $filters);
     } else {
         // Replace filter
         $query[$this->parameter] = $filter;
     }
     // Clear other parameters?
     if ($this->clear_query) {
         $query = Arr::intersect($query, array($this->parameter));
     }
     list($uri) = $this->base_url ? array($this->base_url) : explode('?', Request::current()->current_uri());
     return URL::site($uri) . URL::query($query);
 }
开发者ID:anqh,项目名称:anqh,代码行数:31,代码来源:filters.php

示例8: action_settings

 /**
  * Action: settings
  */
 public function action_settings()
 {
     $this->history = false;
     $user = $this->_get_user();
     Permission::required($user, Model_User::PERMISSION_UPDATE);
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         // Login information
         if ($user->username !== Arr::get($_POST, 'username') || $user->email !== UTF8::strtolower(Arr::get($_POST, 'email')) || Arr::get($_POST, 'password')) {
             $visitor = Visitor::instance();
             $old_password = Arr::get($_POST, 'current_password');
             $new_password = Arr::get($_POST, 'password');
             $validation = Validation::factory(array('current_password' => $old_password));
             $validation->rule('current_password', 'not_empty');
             if (!$visitor->check_password($old_password) && Visitor::generate_password($user->password_kohana) !== $old_password) {
                 $validation->rule('current_password', 'equals', array(':validation', __('current password')));
             } else {
                 if ($new_password) {
                     // Change password only if correct old one given
                     $user->password_kohana = $new_password;
                 }
             }
             $user->username = Arr::get($_POST, 'username');
             $user->email = Arr::get($_POST, 'email');
         }
         $user->set_fields(Arr::intersect($_POST, Model_User::$editable_fields));
         // Settings
         $name_visiblity = Arr::get($_POST, 'name_visibility');
         if (in_array($name_visiblity, array(Model_User::NAME_HIDDEN, Model_User::NAME_VISIBLE))) {
             $user->setting('user.name', $name_visiblity);
         }
         $dob_visiblity = Arr::get($_POST, 'dob_visibility');
         if (in_array($dob_visiblity, array(Model_User::DOB_DATEONLY, Model_User::DOB_HIDDEN, Model_User::DOB_VISIBLE))) {
             $user->setting('user.dob', $dob_visiblity);
         }
         // Clear default image id if Facebook image is set
         if (Arr::get($_POST, 'picture')) {
             $user->default_image_id = null;
         }
         $user->modified = time();
         try {
             $user->save(isset($validation) ? $validation : null);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Build page
     $this->view = self::_set_page($user);
     $this->view->add(View_Page::COLUMN_TOP, $this->section_settings($user, $errors));
 }
开发者ID:anqh,项目名称:anqh,代码行数:55,代码来源:user.php

示例9: _edit_event

 /**
  * Edit event
  *
  * @param  integer  $event_id
  */
 protected function _edit_event($event_id = null)
 {
     $this->history = false;
     if ($event_id) {
         // Editing old
         $event = Model_Event::factory($event_id);
         if (!$event->loaded()) {
             throw new Model_Exception($event, $event_id);
         }
         Permission::required($event, Model_Event::PERMISSION_UPDATE, self::$user);
         $cancel = Request::back(Route::model($event), true);
         $this->view = View_Page::factory(HTML::chars($event->name));
         // Set actions
         if (Permission::has($event, Model_Event::PERMISSION_DELETE, self::$user)) {
             $this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete');
         }
         $edit = true;
     } else {
         // Creating new
         $event = new Model_Event();
         Permission::required($event, Model_Event::PERMISSION_CREATE, self::$user);
         $cancel = Request::back(Route::get('events')->uri(), true);
         $this->view = View_Page::factory(__('New event'));
         $event->author_id = self::$user->id;
         $event->created = time();
         $edit = false;
     }
     // Handle post
     if ($_POST && Security::csrf_valid()) {
         // Handle venue
         if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) {
             // Hidden events require only city
         } else {
             if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) {
                 // Old venue
                 $venue = Model_Venue::factory($venue_id);
             } else {
                 if ($venue_name = Arr::get($_POST, 'venue_name')) {
                     // Check for duplicate venue
                     $venues = Model_Venue::factory()->find_by_name($venue_name);
                     if ($venues->count()) {
                         $city_name = strtolower(Arr::get($_POST, 'city_name'));
                         foreach ($venues as $venue_old) {
                             if (strtolower($venue_old->city_name) == $city_name) {
                                 $venue = $venue_old;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         $post = Arr::intersect($_POST, Model_Event::$editable_fields);
         if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time'])) {
             $post['stamp_end']['date'] = $post['stamp_begin']['date'];
         }
         $event->set_fields($post);
         if (Arr::get($_POST, 'free')) {
             $event->price = 0;
         }
         // Venue/location
         $event->venue_hidden = (bool) $venue_hidden;
         if ($venue_hidden) {
             // Hidden events don't have a venue
             $event->venue_id = null;
             $event->venue_name = null;
         } else {
             if (isset($venue)) {
                 // Venue loaded
                 $event->venue_id = $venue->id;
                 $event->city_name = $venue->city_name;
             } else {
                 if (!empty($venue_name)) {
                     // Create new venue
                     $venue = Model_Venue::factory();
                     $venue->name = Arr::get($_POST, 'venue_name');
                     $venue->address = Arr::get($_POST, 'address');
                     $venue->latitude = Arr::get($_POST, 'latitude');
                     $venue->longitude = Arr::get($_POST, 'longitude');
                     $venue->event_host = true;
                     $venue->author_id = self::$user->id;
                     $venue->city_name = $event->city_name;
                     try {
                         $venue->save();
                         $event->venue_id = $venue->id;
                     } catch (Validation_Exception $venue_validation) {
                     }
                 }
             }
         }
         // Validate event
         try {
             $event->is_valid();
         } catch (Validation_Exception $event_validation) {
         }
//.........这里部分代码省略.........
开发者ID:anqh,项目名称:events,代码行数:101,代码来源:events.php

示例10: _edit_track

 /**
  * Edit track.
  *
  * @param   integer  $track_id
  *
  * @throws  Model_Exception
  */
 protected function _edit_track($track_id = null)
 {
     $this->history = false;
     if ($track_id) {
         // Editing old
         $track = new Model_Music_Track($track_id);
         if (!$track->loaded()) {
             throw new Model_Exception($track, $track_id);
         }
         Permission::required($track, Model_Music_Track::PERMISSION_UPDATE);
         $cancel = Route::model($track);
         $this->view = new View_Page(HTML::chars($track->name));
         // Set actions
         if (Permission::has($track, Model_Music_Track::PERMISSION_DELETE)) {
             $this->view->actions[] = array('link' => Route::model($track, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete'), 'class' => 'btn-danger music-delete');
         }
     } else {
         // Creating new
         $track = new Model_Music_Track();
         Permission::required($track, Model_Music_Track::PERMISSION_CREATE);
         $cancel = Request::back(Route::url('charts'), true);
         $newsfeed = true;
         $this->view = new View_Page($this->request->param('music') === 'mixtape' ? __('New mixtape') : __('New track'));
         $track->author_id = Visitor::$user->id;
         $track->type = $this->request->param('music') === 'mixtape' ? Model_Music_Track::TYPE_MIX : Model_Music_Track::TYPE_TRACK;
         $track->created = time();
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         try {
             $track->set_fields(Arr::intersect($_POST, Model_Music_Track::$editable_fields));
             $track->save();
             // Set tags
             $track->set_tags(Arr::get($_POST, 'tag'));
             // Newsfeed
             if (isset($newsfeed) && $newsfeed) {
                 NewsfeedItem_Music::track(Visitor::$user, $track);
                 // Create forum topic
                 if ($track->add_forum_topic()) {
                     Visitor::$user->post_count++;
                     Visitor::$user->save();
                 }
             }
             $this->request->redirect(Route::model($track));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Form
     $section = $this->section_track_edit($track);
     $section->cancel = $cancel;
     $section->errors = $errors;
     $this->view->add(View_Page::COLUMN_TOP, $section);
 }
开发者ID:anqh,项目名称:anqh,代码行数:62,代码来源:music.php

示例11: _edit_venue

 /**
  * Edit venue
  *
  * @param  integer  $venue_id
  */
 protected function _edit_venue($venue_id = null)
 {
     $this->history = false;
     $edit = true;
     if ($venue_id) {
         // Editing old
         $venue = Model_Venue::factory($venue_id);
         if (!$venue->loaded()) {
             throw new Model_Exception($venue, $venue_id);
         }
         Permission::required($venue, Model_Venue::PERMISSION_UPDATE);
         $cancel = Route::model($venue);
         $this->view = View_Page::factory($venue->name);
         // Modified timestamp
         $venue->modified = time();
         // Set actions
         if (Permission::has($venue, Model_Venue::PERMISSION_DELETE)) {
             $this->view->actions[] = array('link' => Route::model($venue, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete venue'), 'class' => 'btn btn-danger venue-delete');
         }
     } else {
         // Creating new
         $edit = false;
         $venue = Model_Venue::factory();
         $venue->author_id = Visitor::$user->id;
         $cancel = Route::url('venues');
         $this->view = View_Page::factory(__('New venue'));
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         $venue->set_fields(Arr::intersect($_POST, Model_Venue::$editable_fields));
         try {
             $venue->save();
             $edit ? NewsfeedItem_Venues::venue_edit(Visitor::$user, $venue) : NewsfeedItem_Venues::venue(Visitor::$user, $venue);
             $this->request->redirect(Route::model($venue));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     $section = $this->section_venue_edit($venue);
     $section->errors = $errors;
     $section->cancel = $cancel;
     $this->view->add(View_Page::COLUMN_TOP, $section);
 }
开发者ID:anqh,项目名称:anqh,代码行数:49,代码来源:venues.php

示例12: _edit_event

 /**
  * Edit event
  *
  * @param  integer  $event_id
  */
 protected function _edit_event($event_id = null)
 {
     $this->history = false;
     if ($event_id) {
         // Editing old
         $event = Model_Event::factory($event_id);
         if (!$event->loaded()) {
             throw new Model_Exception($event, $event_id);
         }
         Permission::required($event, Model_Event::PERMISSION_UPDATE);
         $cancel = Request::back(Route::model($event), true);
         $this->view = View_Page::factory(HTML::chars($event->name));
         // Set actions
         if (Permission::has($event, Model_Event::PERMISSION_DELETE)) {
             $this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete');
         }
         $edit = true;
         $event->update_count++;
         $event->modified = time();
     } else {
         // Creating new
         $event = new Model_Event();
         Permission::required($event, Model_Event::PERMISSION_CREATE);
         $cancel = Request::back(Route::get('events')->uri(), true);
         $this->view = View_Page::factory(__('New event'));
         $event->author_id = Visitor::$user->id;
         $event->created = time();
         $edit = false;
     }
     // Handle post
     if ($_POST && Security::csrf_valid()) {
         $preview = isset($_POST['preview']);
         // Handle venue
         if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) {
             // Hidden events require only city
         } else {
             if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) {
                 // Old venue
                 $venue = Model_Venue::factory($venue_id);
             } else {
                 if ($venue_name = Arr::get($_POST, 'venue_name')) {
                     // Check for duplicate venue
                     $venues = Model_Venue::factory()->find_by_name($venue_name);
                     if ($venues->count()) {
                         $city_name = strtolower(Arr::get($_POST, 'city_name'));
                         foreach ($venues as $venue_old) {
                             if (strtolower($venue_old->city_name) == $city_name) {
                                 $venue = $venue_old;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         $post = Arr::intersect($_POST, Model_Event::$editable_fields);
         if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time']) && !isset($post['stamp_end']['date'])) {
             $post['stamp_end']['date'] = $post['stamp_begin']['date'];
         }
         $event->set_fields($post);
         if (Arr::get($_POST, 'free')) {
             $event->price = 0;
         }
         // Venue/location
         $event->venue_hidden = (bool) $venue_hidden;
         if ($venue_hidden) {
             // Hidden events don't have a venue
             $event->venue_id = null;
             $event->venue_name = null;
         } else {
             if (isset($venue)) {
                 // Venue loaded
                 $event->venue_id = $venue->id;
                 $event->city_name = $venue->city_name;
             } else {
                 if (!empty($venue_name)) {
                     // Create new venue
                     $venue = Model_Venue::factory();
                     $venue->name = Arr::get($_POST, 'venue_name');
                     $venue->address = Arr::get($_POST, 'address');
                     $venue->latitude = Arr::get($_POST, 'latitude');
                     $venue->longitude = Arr::get($_POST, 'longitude');
                     $venue->foursquare_id = Arr::get($_POST, 'foursquare_id');
                     $venue->event_host = true;
                     $venue->author_id = Visitor::$user->id;
                     $venue->city_name = $event->city_name;
                     if (!$preview) {
                         try {
                             $venue->save();
                             $event->venue_id = $venue->id;
                         } catch (Validation_Exception $venue_validation) {
                         }
                     }
                 }
             }
//.........这里部分代码省略.........
开发者ID:anqh,项目名称:anqh,代码行数:101,代码来源:events.php


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