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


PHP Incident_Person_Model类代码示例

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


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

示例1: submit


//.........这里部分代码省略.........
             $incident->save();
             // STEP 3: SAVE CATEGORIES
             foreach ($post->incident_category as $item) {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $item;
                 $incident_category->save();
             }
             // STEP 4: SAVE MEDIA
             // a. News
             foreach ($post->incident_news as $item) {
                 if (!empty($item)) {
                     $news = new Media_Model();
                     $news->location_id = $location->id;
                     $news->incident_id = $incident->id;
                     $news->media_type = 4;
                     // News
                     $news->media_link = $item;
                     $news->media_date = date("Y-m-d H:i:s", time());
                     $news->save();
                 }
             }
             // b. Video
             foreach ($post->incident_video as $item) {
                 if (!empty($item)) {
                     $video = new Media_Model();
                     $video->location_id = $location->id;
                     $video->incident_id = $incident->id;
                     $video->media_type = 2;
                     // Video
                     $video->media_link = $item;
                     $video->media_date = date("Y-m-d H:i:s", time());
                     $video->save();
                 }
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 // Save to DB
                 $photo = new Media_Model();
                 $photo->location_id = $location->id;
                 $photo->incident_id = $incident->id;
                 $photo->media_type = 1;
                 // Images
                 $photo->media_link = $new_filename . ".jpg";
                 $photo->media_thumb = $new_filename . "_t.jpg";
                 $photo->media_date = date("Y-m-d H:i:s", time());
                 $photo->save();
                 $i++;
             }
             // STEP 5: SAVE PERSONAL INFORMATION
             $person = new Incident_Person_Model();
             $person->location_id = $location->id;
             $person->incident_id = $incident->id;
             $person->person_first = $post->person_first;
             $person->person_last = $post->person_last;
             $person->person_email = $post->person_email;
             $person->person_date = date("Y-m-d H:i:s", time());
             $person->save();
             // Notify Admin Of New Report
             $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_report.subject'), Kohana::lang('notifications.admin_new_report.message') . "\n\n'" . strtoupper($incident->incident_title) . "'" . "\n" . $incident->incident_description);
             url::redirect('reports/thanks');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     // Retrieve Country Cities
     $default_country = Kohana::config('settings.default_country');
     $this->template->content->cities = $this->_get_cities($default_country);
     $this->template->content->multi_country = Kohana::config('settings.multi_country');
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->categories = $this->_get_categories($form['incident_category']);
     // Javascript Header
     $this->template->header->map_enabled = TRUE;
     $this->template->header->datepicker_enabled = TRUE;
     $this->template->header->js = new View('reports_submit_js');
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     if (!$form['latitude'] || !$form['latitude']) {
         $this->template->header->js->latitude = Kohana::config('settings.default_lat');
         $this->template->header->js->longitude = Kohana::config('settings.default_lon');
     } else {
         $this->template->header->js->latitude = $form['latitude'];
         $this->template->header->js->longitude = $form['longitude'];
     }
 }
开发者ID:kiirti,项目名称:Ushahidi_MHI,代码行数:101,代码来源:reports.php

示例2: _submit_report


//.........这里部分代码省略.........
                 ORM::factory('Incident_Category')->where('incident_id', $incident->id)->delete_all();
                 // Delete Previous Entries
                 foreach ($categories as $item) {
                     $incident_category = new Incident_Category_Model();
                     $incident_category->incident_id = $incident->id;
                     $incident_category->category_id = $item;
                     $incident_category->save();
                 }
             }
             // STEP 4: SAVE MEDIA
             // a. News
             if (!empty($post->incident_news) && is_array($post->incident_news)) {
                 ORM::factory('Media')->where('incident_id', $incident->id)->where('media_type <> 1')->delete_all();
                 // Delete Previous Entries
                 foreach ($post->incident_news as $item) {
                     if (!empty($item)) {
                         $news = new Media_Model();
                         $news->location_id = $location->id;
                         $news->incident_id = $incident->id;
                         $news->media_type = 4;
                         // News
                         $news->media_link = $item;
                         $news->media_date = date("Y-m-d H:i:s", time());
                         $news->save();
                     }
                 }
             }
             // b. Video
             if (!empty($post->incident_video) && is_array($post->incident_video)) {
                 foreach ($post->incident_video as $item) {
                     if (!empty($item)) {
                         $video = new Media_Model();
                         $video->location_id = $location->id;
                         $video->incident_id = $incident->id;
                         $video->media_type = 2;
                         // Video
                         $video->media_link = $item;
                         $video->media_date = date("Y-m-d H:i:s", time());
                         $video->save();
                     }
                 }
             }
             // c. Photos
             if (!empty($post->incident_photo)) {
                 $filenames = upload::save('incident_photo');
                 $i = 1;
                 foreach ($filenames as $filename) {
                     $new_filename = $incident->id . "_" . $i . "_" . time();
                     // Resize original file... make sure its max 408px wide
                     Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                     // Create thumbnail
                     Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                     // Remove the temporary file
                     unlink($filename);
                     // Save to DB
                     $photo = new Media_Model();
                     $photo->location_id = $location->id;
                     $photo->incident_id = $incident->id;
                     $photo->media_type = 1;
                     // Images
                     $photo->media_link = $new_filename . ".jpg";
                     $photo->media_thumb = $new_filename . "_t.jpg";
                     $photo->media_date = date("Y-m-d H:i:s", time());
                     $photo->save();
                     $i++;
                 }
             }
             // SAVE PERSONAL INFORMATION IF ITS FILLED UP
             if (!empty($post->person_first) or !empty($post->person_last)) {
                 ORM::factory('Incident_Person')->where('incident_id', $incident->id)->delete_all();
                 $person = new Incident_Person_Model();
                 $person->location_id = $location->id;
                 $person->incident_id = $incident->id;
                 $person->person_first = $post->person_first;
                 $person->person_last = $post->person_last;
                 $person->person_email = $post->person_email;
                 $person->person_date = date("Y-m-d H:i:s", time());
                 $person->save();
             }
             return $this->response(0);
             //success
         } else {
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             foreach ($errors as $error_item => $error_description) {
                 if (!is_array($error_description)) {
                     $this->error_messages .= $error_description;
                     if ($error_description != end($errors)) {
                         $this->error_messages .= " - ";
                     }
                 }
             }
             //FAILED!!! //validation error
             return $this->response(1, $this->error_messages);
         }
     } else {
         // Not sent by post method.
         return $this->response(3);
     }
 }
开发者ID:huslage,项目名称:Ushahidi_Web,代码行数:101,代码来源:MY_Admin_Reports_Api_Object.php

示例3: edit


//.........这里部分代码省略.........
                     $video->media_type = 2;
                     // Video
                     $video->media_link = $item;
                     $video->media_date = date("Y-m-d H:i:s", time());
                     $video->save();
                 }
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 // Save to DB
                 $photo = new Media_Model();
                 $photo->location_id = $location->id;
                 $photo->incident_id = $incident->id;
                 $photo->media_type = 1;
                 // Images
                 $photo->media_link = $new_filename . ".jpg";
                 $photo->media_thumb = $new_filename . "_t.jpg";
                 $photo->media_date = date("Y-m-d H:i:s", time());
                 $photo->save();
                 $i++;
             }
             // STEP 5: SAVE PERSONAL INFORMATION
             ORM::factory('Incident_Person')->where('incident_id', $incident->id)->delete_all();
             // Delete Previous Entries
             $person = new Incident_Person_Model();
             $person->location_id = $location->id;
             $person->incident_id = $incident->id;
             $person->person_first = $post->person_first;
             $person->person_last = $post->person_last;
             $person->person_email = $post->person_email;
             $person->person_date = date("Y-m-d H:i:s", time());
             $person->save();
             // STEP 6a: SAVE LINK TO REPORTER MESSAGE
             // We're creating a report from a message with this option
             if (isset($message_id) && $message_id != "") {
                 $savemessage = ORM::factory('message', $message_id);
                 if ($savemessage->loaded == true) {
                     $savemessage->incident_id = $incident->id;
                     $savemessage->save();
                 }
             }
             // STEP 6b: SAVE LINK TO NEWS FEED
             // We're creating a report from a newsfeed with this option
             if (isset($feed_item_id) && $feed_item_id != "") {
                 $savefeed = ORM::factory('feed_item', $feed_item_id);
                 if ($savefeed->loaded == true) {
                     $savefeed->incident_id = $incident->id;
                     $savefeed->location_id = $location->id;
                     $savefeed->save();
                 }
             }
             // STEP 7: SAVE CUSTOM FORM FIELDS
             if (isset($post->custom_field)) {
                 foreach ($post->custom_field as $key => $value) {
                     $form_response = ORM::factory('form_response')->where('form_field_id', $key)->where('incident_id', $incident->id)->find();
                     if ($form_response->loaded == true) {
                         $form_response->form_field_id = $key;
开发者ID:Nyamai,项目名称:Ushahidi_Web,代码行数:67,代码来源:reports.php

示例4: submit


//.........这里部分代码省略.........
					$photo->media_thumb = $new_filename."_t".$file_type;
					$photo->media_date = date("Y-m-d H:i:s",time());
					$photo->save();
					$i++;
				}

				// STEP 7: SAVE CUSTOM FORM FIELDS
				if (isset($post->custom_field))
				{
					foreach($post->custom_field as $key => $value)
					{
						$form_response = ORM::factory('form_response')
						->where('form_field_id', $key)
						->where('incident_id', $incident->id)
						->find();
						if ($form_response->loaded == true)
						{
							$form_response->form_field_id = $key;
							$form_response->form_response = $value;
							$form_response->save();
						}
						else
						{
							$form_response = new Form_Response_Model();
							$form_response->form_field_id = $key;
							$form_response->incident_id = $incident->id;
							$form_response->form_response = $value;
							$form_response->save();
						}
					}
				}

				// STEP 5: SAVE PERSONAL INFORMATION
				$person = new Incident_Person_Model();
				$person->location_id = $location->id;
				$person->incident_id = $incident->id;
				$person->person_first = $post->person_first;
				$person->person_last = $post->person_last;
				$person->person_email = $post->person_email;
				$person->person_date = date("Y-m-d H:i:s",time());
				$person->save();

				// Action::report_add - Added a New Report
				Event::run('ushahidi_action.report_add', $incident);

				url::redirect('reports/thanks');
			}

			// No! We have validation errors, we need to show the form again, with the errors
			else
			{
				// repopulate the form fields
				$form = arr::overwrite($form, $post->as_array());

				// populate the error fields, if any
				$errors = arr::overwrite($errors, $post->errors('report'));
				$form_error = TRUE;
			}
		}

		// Retrieve Country Cities
		$default_country = Kohana::config('settings.default_country');
		$this->template->content->cities = $this->_get_cities($default_country);
		$this->template->content->multi_country = Kohana::config('settings.multi_country');

		$this->template->content->id = $id;
开发者ID:nexleaf,项目名称:Ushahidi_Web,代码行数:67,代码来源:reports.php

示例5: save_personal_info

 /**
  * Function to save personal information
  *
  * @param mixed $incident_model
  * @param mixed $post
  *
  */
 public static function save_personal_info($post, $incident)
 {
     // Delete Previous Entries
     ORM::factory('incident_person')->where('incident_id', $incident->id)->delete_all();
     $person = new Incident_Person_Model();
     $person->location_id = $incident->location_id;
     $person->incident_id = $incident->id;
     $person->person_first = $post->person_first;
     $person->person_last = $post->person_last;
     $person->person_email = $post->person_email;
     $person->person_date = date("Y-m-d H:i:s", time());
     $person->save();
 }
开发者ID:rabbit09,项目名称:Taarifa_Web,代码行数:20,代码来源:reports.php

示例6: _submit


//.........这里部分代码省略.........
             } else {
                 $categories = unserialize($post->incident_category);
             }
             if (!empty($categories) && is_array($categories)) {
                 foreach ($categories as $item) {
                     $incident_category = new Incident_Category_Model();
                     $incident_category->incident_id = $incident->id;
                     $incident_category->category_id = $item;
                     $incident_category->save();
                 }
             }
             // STEP 4: SAVE MEDIA
             // a. News
             if (!empty($post->incident_news) && is_array($post->incident_news)) {
                 foreach ($post->incident_news as $item) {
                     if (!empty($item)) {
                         $news = new Media_Model();
                         $news->location_id = $location->id;
                         $news->incident_id = $incident->id;
                         $news->media_type = 4;
                         // News
                         $news->media_link = $item;
                         $news->media_date = date("Y-m-d H:i:s", time());
                         $news->save();
                     }
                 }
             }
             // b. Video
             if (!empty($post->incident_video) && is_array($post->incident_video)) {
                 foreach ($post->incident_video as $item) {
                     if (!empty($item)) {
                         $video = new Media_Model();
                         $video->location_id = $location->id;
                         $video->incident_id = $incident->id;
                         $video->media_type = 2;
                         // Video
                         $video->media_link = $item;
                         $video->media_date = date("Y-m-d H:i:s", time());
                         $video->save();
                     }
                 }
             }
             // c. Photos
             if (!empty($post->incident_photo)) {
                 $filenames = upload::save('incident_photo');
                 $i = 1;
                 foreach ($filenames as $filename) {
                     $new_filename = $incident->id . "_" . $i . "_" . time();
                     // Resize original file... make sure its max 408px wide
                     Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                     // Create thumbnail
                     Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                     // Remove the temporary file
                     unlink($filename);
                     // Save to DB
                     $photo = new Media_Model();
                     $photo->location_id = $location->id;
                     $photo->incident_id = $incident->id;
                     $photo->media_type = 1;
                     // Images
                     $photo->media_link = $new_filename . ".jpg";
                     $photo->media_thumb = $new_filename . "_t.jpg";
                     $photo->media_date = date("Y-m-d H:i:s", time());
                     $photo->save();
                     $i++;
                 }
             }
             // SAVE PERSONAL INFORMATION IF ITS FILLED UP
             if (!empty($post->person_first) || !empty($post->person_last)) {
                 $person = new Incident_Person_Model();
                 $person->location_id = $location->id;
                 $person->incident_id = $incident->id;
                 $person->person_first = $post->person_first;
                 $person->person_last = $post->person_last;
                 $person->person_email = $post->person_email;
                 $person->person_date = date("Y-m-d H:i:s", time());
                 $person->save();
             }
             return 0;
             //success
         } else {
             // populate the error fields, if any
             $this->messages = arr::overwrite($this->messages, $post->errors('report'));
             foreach ($this->messages as $error_item => $error_description) {
                 if (!is_array($error_description)) {
                     $this->error_messages .= $error_description;
                     if ($error_description != end($this->messages)) {
                         $this->error_messages .= " - ";
                     }
                 }
             }
             //FAILED!!!
             return 1;
             //validation error
         }
     } else {
         return 2;
         // Not sent by post method.
     }
 }
开发者ID:rabble,项目名称:Ushahidi_Web,代码行数:101,代码来源:api.php

示例7: _submit


//.........这里部分代码省略.........
                     $incident_category->save();
                 }
             }
             // STEP 4: SAVE MEDIA
             // a. News
             if (!empty($post->incident_news) and is_array($post->incident_news)) {
                 foreach ($post->incident_news as $item) {
                     if (!empty($item)) {
                         $news = new Media_Model();
                         $news->location_id = $location->id;
                         $news->incident_id = $incident->id;
                         $news->media_type = 4;
                         // News
                         $news->media_link = $item;
                         $news->media_date = date("Y-m-d H:i:s", time());
                         $news->save();
                     }
                 }
             }
             // b. Video
             if (!empty($post->incident_video) and is_array($post->incident_video)) {
                 foreach ($post->incident_video as $item) {
                     if (!empty($item)) {
                         $video = new Media_Model();
                         $video->location_id = $location->id;
                         $video->incident_id = $incident->id;
                         $video->media_type = 2;
                         // Video
                         $video->media_link = $item;
                         $video->media_date = date("Y-m-d H:i:s", time());
                         $video->save();
                     }
                 }
             }
             // c. Photos
             if (!empty($post->incident_photo)) {
                 $filenames = upload::save('incident_photo');
                 $i = 1;
                 foreach ($filenames as $filename) {
                     $new_filename = $incident->id . "_" . $i . "_" . time();
                     // Resize original file... make sure its max 408px wide
                     Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                     // Create thumbnail
                     Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                     // Remove the temporary file
                     unlink($filename);
                     // Save to DB
                     $photo = new Media_Model();
                     $photo->location_id = $location->id;
                     $photo->incident_id = $incident->id;
                     $photo->media_type = 1;
                     // Images
                     $photo->media_link = $new_filename . ".jpg";
                     $photo->media_thumb = $new_filename . "_t.jpg";
                     $photo->media_date = date("Y-m-d H:i:s", time());
                     $photo->save();
                     $i++;
                 }
             }
             // SAVE PERSONAL INFORMATION IF ITS FILLED UP
             if (!empty($post->person_first) || !empty($post->person_last) || !empty($post->person_email)) {
                 $person = new Incident_Person_Model();
                 $person->location_id = $location->id;
                 $person->incident_id = $incident->id;
                 if (!empty($post->person_first)) {
                     $person->person_first = $post->person_first;
                 }
                 if (!empty($post->person_last)) {
                     $person->person_last = $post->person_last;
                 }
                 if (!empty($post->person_email)) {
                     $person->person_email = $post->person_email;
                 }
                 $person->person_date = date("Y-m-d H:i:s", time());
                 $person->save();
             }
             // Action::report_edit_api - Edited a Report
             Event::run('ushahidi_action.report_edit_api', $incident);
             return 0;
             //success
         } else {
             // Populate the error fields, if any
             $this->messages = arr::overwrite($this->messages, $post->errors('report'));
             foreach ($this->messages as $error_item => $error_description) {
                 if (!is_array($error_description)) {
                     $this->error_string .= $error_description;
                     if ($error_description != end($this->messages)) {
                         $this->error_string .= " - ";
                     }
                 }
             }
             //FAILED!!!
             return 1;
             //validation error
         }
     } else {
         return 3;
         // Not sent by post method.
     }
 }
开发者ID:neumicro,项目名称:Ushahidi_Web_Dev,代码行数:101,代码来源:MY_Report_Api_Object.php

示例8: edit


//.........这里部分代码省略.........
                     $video->media_type = 2;
                     // Video
                     $video->media_link = $item;
                     $video->media_date = date("Y-m-d H:i:s", time());
                     $video->save();
                 }
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 // Save to DB
                 $photo = new Media_Model();
                 $photo->location_id = $location->id;
                 $photo->incident_id = $incident->id;
                 $photo->media_type = 1;
                 // Images
                 $photo->media_link = $new_filename . ".jpg";
                 $photo->media_thumb = $new_filename . "_t.jpg";
                 $photo->media_date = date("Y-m-d H:i:s", time());
                 $photo->save();
                 $i++;
             }
             // STEP 5: SAVE PERSONAL INFORMATION
             ORM::factory('Incident_Person')->where('incident_id', $incident->id)->delete_all();
             // Delete Previous Entries
             $person = new Incident_Person_Model();
             $person->location_id = $location->id;
             $person->incident_id = $incident->id;
             $person->person_first = $post->person_first;
             $person->person_last = $post->person_last;
             $person->person_email = $post->person_email;
             $person->person_date = date("Y-m-d H:i:s", time());
             $person->save();
             if ($is_new) {
                 groups::forward_incident_to_own_instance($incident->id, $this->group->id);
             }
             // STEP 6a: SAVE LINK TO REPORTER MESSAGE
             // We're creating a report from a message with this option
             if (isset($message_id) && $message_id != "") {
                 $savemessage = ORM::factory('message', $message_id);
                 if ($savemessage->loaded == true) {
                     $savemessage->incident_id = $incident->id;
                     $savemessage->save();
                 }
             }
             // STEP 6b: SAVE LINK TO NEWS FEED
             // We're creating a report from a newsfeed with this option
             if (isset($feed_item_id) && $feed_item_id != "") {
                 $savefeed = ORM::factory('feed_item', $feed_item_id);
                 if ($savefeed->loaded == true) {
                     $savefeed->incident_id = $incident->id;
                     $savefeed->location_id = $location->id;
                     $savefeed->save();
                 }
             }
             // STEP 7: SAVE CUSTOM FORM FIELDS
             if (isset($post->custom_field)) {
                 foreach ($post->custom_field as $key => $value) {
开发者ID:rabbit09,项目名称:Taarifa_Web,代码行数:67,代码来源:reports.php

示例9: _submit


//.........这里部分代码省略.........
             // STEP 4: SAVE MEDIA
             // a. News
             if (!empty($post->incident_news) && is_array($post->incident_news)) {
                 foreach ($post->incident_news as $item) {
                     if (!empty($item)) {
                         $news = new Media_Model();
                         $news->location_id = $location->id;
                         $news->incident_id = $incident->id;
                         $news->media_type = 4;
                         // News
                         $news->media_link = $item;
                         $news->media_date = date("Y-m-d H:i:s", time());
                         $news->save();
                     }
                 }
             }
             // b. Video
             if (!empty($post->incident_video) && is_array($post->incident_video)) {
                 foreach ($post->incident_video as $item) {
                     if (!empty($item)) {
                         $video = new Media_Model();
                         $video->location_id = $location->id;
                         $video->incident_id = $incident->id;
                         $video->media_type = 2;
                         // Video
                         $video->media_link = $item;
                         $video->media_date = date("Y-m-d H:i:s", time());
                         $video->save();
                     }
                 }
             }
             // c. Photos
             if (!empty($post->incident_photo)) {
                 $filenames = upload::save('incident_photo');
                 $i = 1;
                 foreach ($filenames as $filename) {
                     $new_filename = $incident->id . "_" . $i . "_" . time();
                     // Resize original file... make sure its max 408px wide
                     Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                     // Create thumbnail
                     Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                     // Remove the temporary file
                     unlink($filename);
                     // Save to DB
                     $photo = new Media_Model();
                     $photo->location_id = $location->id;
                     $photo->incident_id = $incident->id;
                     $photo->media_type = 1;
                     // Images
                     $photo->media_link = $new_filename . ".jpg";
                     $photo->media_thumb = $new_filename . "_t.jpg";
                     $photo->media_date = date("Y-m-d H:i:s", time());
                     $photo->save();
                     $i++;
                 }
             }
             // SAVE PERSONAL INFORMATION IF ITS FILLED UP
             if (!empty($post->person_first) || !empty($post->person_last)) {
                 $person = new Incident_Person_Model();
                 $person->location_id = $location->id;
                 $person->incident_id = $incident->id;
                 $person->person_first = $post->person_first;
                 $person->person_last = $post->person_last;
                 $person->person_email = $post->person_email;
                 $person->person_date = date("Y-m-d H:i:s", time());
                 $person->save();
             }
             // The $_POST['date'] is a value posted by form in dd/mm/yyyy format
             $incident_date2 = explode("/", $post->incident_date);
             $incident_date2 = $incident_date2[1] . "-" . $incident_date2[0] . "-" . $incident_date2[2];
             //Send e-mail notification to the moderator
             //Hardcoded mail-adress here. This is simple addition, no gui for it.
             $to = 'theun@fo.am';
             $subject = 'New report: ' . $post->incident_title;
             $message = 'The following report was submitted and requires moderation:' . "\r\n" . 'Title: ' . $post->incident_title . "\r\n" . 'Description: ' . $post->incident_description . "\r\n" . 'Date: ' . $incident_date2 . "\r\n";
             $headers = 'From: boskoi.mail@gmail.com' . "\r\n" . 'Reply-To: boskoi.mail@gmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
             mail($to, $subject, $message, $headers);
             return 0;
             //success
         } else {
             // No! We have validation errors, we need to show the form again, with the errors
             // populate the error fields, if any
             $this->messages = arr::overwrite($this->messages, $post->errors('report'));
             foreach ($this->messages as $error_item => $error_description) {
                 if (!is_array($error_description)) {
                     $this->error_messages .= $error_description;
                     if ($error_description != end($this->messages)) {
                         $this->error_messages .= " - ";
                     }
                 }
             }
             //FAILED!!!
             return 1;
             //validation error
         }
     } else {
         return 2;
         // Not sent by post method.
     }
 }
开发者ID:nebogeo,项目名称:borrowed-scenery,代码行数:101,代码来源:api.php

示例10: submit


//.........这里部分代码省略.........
             $incident->incident_date = $incident_date . " " . $incident_time;
             $incident->incident_dateadd = date("Y-m-d H:i:s", time());
             $incident->save();
             // STEP 3: SAVE CATEGORIES
             foreach ($post->incident_category as $item) {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $item;
                 $incident_category->save();
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 // Save to DB
                 $photo = new Media_Model();
                 $photo->location_id = $location->id;
                 $photo->incident_id = $incident->id;
                 $photo->media_type = 1;
                 // Images
                 $photo->media_link = $new_filename . ".jpg";
                 $photo->media_thumb = $new_filename . "_t.jpg";
                 $photo->media_date = date("Y-m-d H:i:s", time());
                 $photo->save();
                 $i++;
             }
             // STEP 7: SAVE CUSTOM FORM FIELDS
             if (isset($post->custom_field)) {
                 foreach ($post->custom_field as $key => $value) {
                     $form_response = ORM::factory('form_response')->where('form_field_id', $key)->where('incident_id', $incident->id)->find();
                     if ($form_response->loaded == true) {
                         $form_response->form_field_id = $key;
                         $form_response->form_response = $value;
                         $form_response->save();
                     } else {
                         $form_response = new Form_Response_Model();
                         $form_response->form_field_id = $key;
                         $form_response->incident_id = $incident->id;
                         $form_response->form_response = $value;
                         $form_response->save();
                     }
                 }
             }
             // STEP 5: SAVE PERSONAL INFORMATION
             $person = new Incident_Person_Model();
             $person->location_id = $location->id;
             $person->incident_id = $incident->id;
             $person->person_first = $post->person_first;
             $person->person_last = $post->person_last;
             $person->person_email = $post->person_email;
             $person->person_date = date("Y-m-d H:i:s", time());
             $person->save();
             url::redirect('reports/thanks');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     // Retrieve Country Cities
     $default_country = Kohana::config('settings.default_country');
     $this->template->content->cities = $this->_get_cities($default_country);
     $this->template->content->multi_country = Kohana::config('settings.multi_country');
     $this->template->content->id = $id;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->categories = $this->_get_categories($form['incident_category']);
     // Retrieve Custom Form Fields Structure
     $disp_custom_fields = $this->_get_custom_form_fields($id, $form['form_id'], false);
     $this->template->content->disp_custom_fields = $disp_custom_fields;
     // Javascript Header
     $this->template->header->map_enabled = TRUE;
     $this->template->header->datepicker_enabled = TRUE;
     $this->template->header->js = new View('reports_submit_js');
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     if (!$form['latitude'] || !$form['latitude']) {
         $this->template->header->js->latitude = Kohana::config('settings.default_lat');
         $this->template->header->js->longitude = Kohana::config('settings.default_lon');
     } else {
         $this->template->header->js->latitude = $form['latitude'];
         $this->template->header->js->longitude = $form['longitude'];
     }
     //include footer form js file
     $footerjs = new View('footer_form_js');
     // Pack the javascript using the javascriptpacker helper
     $myPacker = new javascriptpacker($footerjs, 'Normal', false, false);
     $footerjs = $myPacker->pack();
     $this->template->header->js .= $footerjs;
 }
开发者ID:eyedol,项目名称:agbena,代码行数:101,代码来源:reports.php

示例11: edit


//.........这里部分代码省略.........
                     $video->media_type = 2;
                     // Video
                     $video->media_link = $item;
                     $video->media_date = date("Y-m-d H:i:s", time());
                     $video->save();
                 }
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 // Save to DB
                 $photo = new Media_Model();
                 $photo->location_id = $location->id;
                 $photo->incident_id = $incident->id;
                 $photo->media_type = 1;
                 // Images
                 $photo->media_link = $new_filename . ".jpg";
                 $photo->media_thumb = $new_filename . "_t.jpg";
                 $photo->media_date = date("Y-m-d H:i:s", time());
                 $photo->save();
                 $i++;
             }
             // STEP 5: SAVE PERSONAL INFORMATION
             ORM::factory('Incident_Person')->where('incident_id', $incident->id)->delete_all();
             // Delete Previous Entries
             $person = new Incident_Person_Model();
             $person->location_id = $location->id;
             $person->incident_id = $incident->id;
             $person->person_first = $post->person_first;
             $person->person_last = $post->person_last;
             $person->person_email = $post->person_email;
             $person->person_date = date("Y-m-d H:i:s", time());
             $person->save();
             // STEP 6: SAVE LINK TO SMS MESSAGE
             if (isset($mobile_id) && $mobile_id != "") {
                 $savemessage = ORM::factory($dbtable, $mobile_id);
                 if ($savemessage->loaded == true) {
                     $savemessage->incident_id = $incident->id;
                     $savemessage->save();
                 }
             }
             // STEP 7: SAVE AND CLOSE?
             if ($post->save == 1) {
                 url::redirect('admin/reports/edit/' . $incident->id . '/saved');
             } else {
                 url::redirect('admin/reports/');
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     } else {
         if ($id) {
             // Retrieve Current Incident
             $incident = ORM::factory('incident', $id);
开发者ID:emoksha,项目名称:freefairelections,代码行数:67,代码来源:reports.php

示例12: import_reports


//.........这里部分代码省略.........
                                     $match_field_defaults = $match_fields->field_default;
                                     // Grab form responses
                                     $field_response = trim($field->nodeValue);
                                     if ($field_response != '') {
                                         // Initialize form response model
                                         $new_form_response = new Form_Response_Model();
                                         $new_form_response->incident_id = $new_report->id;
                                         $new_form_response->form_field_id = $match_field_id;
                                         // For radio buttons, checkbox fields and drop downs, make sure form responses are
                                         // within bounds of allowable options for that field
                                         // Split field defaults into individual values
                                         $field_defaults = explode(',', $match_field_defaults);
                                         /* Radio buttons and Drop down fields which take single responses */
                                         if ($match_field_type == 5 or $match_field_type == 7) {
                                             foreach ($field_defaults as $match_field_default) {
                                                 // Carry out a case insensitive string comparison
                                                 $new_form_response->form_response = strcasecmp($match_field_default, $field_response) == 0 ? $match_field_default : NULL;
                                             }
                                         }
                                         // Checkboxes which
                                         if ($match_field_type == 6) {
                                             // Split user responses into individual value
                                             $responses = explode(',', $field_response);
                                             $values = array();
                                             foreach ($match_field_defaults as $match_field_default) {
                                                 foreach ($responses as $response) {
                                                     $values[] = strcasecmp($match_field_default, $response) == 0 ? $match_field_default : NULL;
                                                 }
                                             }
                                             // Concatenate checkbox values into a string, separated by a comma
                                             $new_form_response->form_response = implode(",", $values);
                                         } else {
                                             $new_form_response->form_response = $field_response;
                                         }
                                         // Only save if form response is not empty
                                         if ($new_form_response->form_response != NULL) {
                                             $new_form_response->save();
                                         }
                                         // Add this to array of form responses added
                                         $this->incident_responses_added[] = $new_form_response->id;
                                     }
                                 } else {
                                     $this->notices[] = Kohana::lang('import.xml.form_field_no_match') . $this->totalreports . ': "' . $field_name . '" on form "' . $new_report->form->form_title . '"';
                                 }
                             }
                         }
                     }
                 }
                 /* Step 5: Save incident persons for this report */
                 // Report Personal Information
                 $personal_info = $report->getElementsByTagName('personal_info');
                 // If personal info exists
                 if ($personal_info->length > 0) {
                     $report_info = $personal_info->item(0);
                     // First Name
                     $firstname = xml::get_node_text($report_info, 'first_name');
                     // Last Name
                     $lastname = xml::get_node_text($report_info, 'last_name');
                     // Email
                     $r_email = xml::get_node_text($report_info, 'email');
                     $email = ($r_email and valid::email($r_email)) ? $r_email : NULL;
                     $new_incident_person = new Incident_Person_Model();
                     $new_incident_person->incident_id = $new_report->id;
                     $new_incident_person->person_date = $new_report->incident_dateadd;
                     // Make sure that at least one of the personal info field entries is provided
                     if ($firstname or $lastname or $email != NULL) {
                         $new_incident_person->person_first = $firstname ? $firstname : NULL;
                         $new_incident_person->person_last = $lastname ? $firstname : NULL;
                         $new_incident_person->person_email = $email;
                         $new_incident_person->save();
                         // Add this to array of incident persons added during import
                         $this->incident_persons_added[] = $new_incident_person->id;
                     }
                 }
                 /* Step 6: Save media links for this report */
                 // Report Media
                 $media = $report->getElementsByTagName('media');
                 if ($media->length > 0) {
                     $media = $media->item(0);
                     foreach ($media->getElementsByTagName('item') as $media_element) {
                         $media_link = trim($media_element->nodeValue);
                         $media_date = $media_element->getAttribute('date');
                         if (!empty($media_link)) {
                             $media_item = new Media_Model();
                             $media_item->location_id = isset($new_location) ? $new_location->id : 0;
                             $media_item->incident_id = $new_report->id;
                             $media_item->media_type = $media_element->getAttribute('type');
                             $media_item->media_link = $media_link;
                             $media_item->media_date = !empty($media_date) ? $media_date : $new_report->incident_date;
                             $media_item->save();
                         }
                     }
                 }
             }
         }
     }
     // end individual report import
     // If we have errors, return FALSE, else TRUE
     return count($this->errors) === 0;
 }
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:101,代码来源:XMLImporter.php

示例13: submit


//.........这里部分代码省略.........
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 // Save to DB
                 $photo = new Media_Model();
                 $photo->location_id = $location->id;
                 $photo->incident_id = $incident->id;
                 $photo->media_type = 1;
                 // Images
                 $photo->media_link = $new_filename . ".jpg";
                 $photo->media_thumb = $new_filename . "_t.jpg";
                 $photo->media_date = date("Y-m-d H:i:s", time());
                 $photo->save();
                 $i++;
             }
             // STEP 7: SAVE CUSTOM FORM FIELDS
             if (isset($post->custom_field)) {
                 foreach ($post->custom_field as $key => $value) {
                     $form_response = ORM::factory('form_response')->where('form_field_id', $key)->where('incident_id', $incident->id)->find();
                     if ($form_response->loaded == true) {
                         $form_response->form_field_id = $key;
                         $form_response->form_response = $value;
                         $form_response->save();
                     } else {
                         $form_response = new Form_Response_Model();
                         $form_response->form_field_id = $key;
                         $form_response->incident_id = $incident->id;
                         $form_response->form_response = $value;
                         $form_response->save();
                     }
                 }
             }
             // STEP 5: SAVE PERSONAL INFORMATION
             $person = new Incident_Person_Model();
             $person->location_id = $location->id;
             $person->incident_id = $incident->id;
             $person->person_first = $post->person_first;
             $person->person_last = $post->person_last;
             $person->person_email = $post->person_email;
             $person->person_date = date("Y-m-d H:i:s", time());
             $person->save();
             // Action::report_add - Added a New Report
             Event::run('ushahidi_action.report_add', $incident);
             // The $_POST['date'] is a value posted by form in dd/mm/yyyy format
             $incident_date2 = explode("/", $post->incident_date);
             $incident_date2 = $incident_date2[1] . "-" . $incident_date2[0] . "-" . $incident_date2[2];
             //Send e-mail notification to the moderator
             //Hardcoded mail-adress here. This is simple addition, no gui for it.
             $to = 'theun@fo.am';
             $subject = 'New report: ' . $incident->incident_title;
             $message = 'The following report was submitted and requires moderation:' . "\r\n" . 'Title: ' . $incident->incident_title . "\r\n" . 'Description: ' . $post->incident_description . "\r\n" . 'Date: ' . $incident_date2 . "\r\n";
             $headers = 'From: boskoi.mail@gmail.com' . "\r\n" . 'Reply-To: boskoi.mail@gmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
             mail($to, $subject, $message, $headers);
             url::redirect('reports/thanks');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     // Retrieve Country Cities
     $default_country = Kohana::config('settings.default_country');
     $this->template->content->cities = $this->_get_cities($default_country);
     $this->template->content->multi_country = Kohana::config('settings.multi_country');
     $this->template->content->id = $id;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->categories = $this->_get_categories($form['incident_category']);
     // Retrieve Custom Form Fields Structure
     $disp_custom_fields = $this->_get_custom_form_fields($id, $form['form_id'], false);
     $this->template->content->disp_custom_fields = $disp_custom_fields;
     // Javascript Header
     $this->themes->map_enabled = TRUE;
     $this->themes->datepicker_enabled = TRUE;
     $this->themes->treeview_enabled = TRUE;
     $this->themes->js = new View('reports_submit_js');
     $this->themes->js->default_map = Kohana::config('settings.default_map');
     $this->themes->js->default_zoom = Kohana::config('settings.default_zoom');
     if (!$form['latitude'] or !$form['latitude']) {
         $this->themes->js->latitude = Kohana::config('settings.default_lat');
         $this->themes->js->longitude = Kohana::config('settings.default_lon');
     } else {
         $this->themes->js->latitude = $form['latitude'];
         $this->themes->js->longitude = $form['longitude'];
     }
     // Rebuild Header Block
     $this->template->header->header_block = $this->themes->header_block();
 }
开发者ID:nebogeo,项目名称:borrowed-scenery,代码行数:101,代码来源:reports.php

示例14: index

 function index()
 {
     $source = 'http://legacy.ushahidi.com/export_data.asp';
     ORM::factory('Location')->delete_all();
     ORM::factory('Incident')->delete_all();
     ORM::factory('Media')->delete_all();
     ORM::factory('Incident_Person')->delete_all();
     ORM::factory('Incident_Category')->delete_all();
     ORM::factory('Comment')->delete_all();
     ORM::factory('Rating')->delete_all();
     // load as string
     $xmlstr = file_get_contents($source);
     $incidents = new SimpleXMLElement($xmlstr);
     foreach ($incidents as $post) {
         // STEP 1: SAVE LOCATION
         $location = new Location_Model();
         $location->location_name = (string) $post->location_name;
         $location->latitude = (string) $post->latitude;
         $location->longitude = (string) $post->longitude;
         $location->country_id = 115;
         $location->location_date = date("Y-m-d H:i:s", time());
         $location->save();
         // STEP 2: SAVE INCIDENT
         $incident = new Incident_Model();
         $incident->location_id = $location->id;
         $incident->user_id = 0;
         $incident->incident_title = (string) $post->incident_title;
         $incident->incident_description = (string) $post->incident_description;
         $incident->incident_date = (string) $post->incident_date;
         $incident->incident_active = (string) $post->active;
         $incident->incident_verified = (string) $post->verified;
         $incident->incident_dateadd = date("Y-m-d H:i:s", time());
         $incident->save();
         // STEP 3: SAVE CATEGORIES
         $incident_category = split(",", (string) $post->incident_category);
         foreach ($incident_category as $item) {
             if ($item != "") {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $item;
                 $incident_category->save();
             }
         }
         // STEP 4: SAVE MEDIA
         // a. News
         $news = new Media_Model();
         $news->location_id = $location->id;
         $news->incident_id = $incident->id;
         $news->media_type = 4;
         // News
         $news->media_link = (string) $post->news;
         $news->media_date = date("Y-m-d H:i:s", time());
         $news->save();
         // b. Video
         $video = new Media_Model();
         $video->location_id = $location->id;
         $video->incident_id = $incident->id;
         $video->media_type = 2;
         // Video
         $video->media_link = (string) $post->video;
         $video->media_date = date("Y-m-d H:i:s", time());
         $video->save();
         // STEP 5: SAVE PERSONAL INFORMATION
         $person = new Incident_Person_Model();
         $person->location_id = $location->id;
         $person->incident_id = $incident->id;
         $person->person_first = (string) $post->person_first;
         $person->person_phone = (string) $post->person_phone;
         $person->person_email = (string) $post->person_email;
         $person->person_ip = (string) $post->person_ip;
         $person->person_date = date("Y-m-d H:i:s", time());
         $person->save();
     }
     echo "******************************************<BR>";
     echo "******************************************<BR>";
     echo "**** IMPORT COMPLETE!!!<BR>";
     echo "******************************************<BR>";
     echo "******************************************<BR>";
 }
开发者ID:emoksha,项目名称:freefairelections,代码行数:79,代码来源:import.php

示例15: import_report

 /**
  * Function to import a report form a row in the CSV file
  * @param array $row
  * @return bool
  */
 function import_report($row)
 {
     // If the date is not in proper date format
     if (!strtotime($row['INCIDENT DATE'])) {
         $this->errors[] = Kohana::lang('import.incident_date') . ($this->rownumber + 1) . ': ' . $row['INCIDENT DATE'];
     }
     // If a value of Yes or No is NOT set for approval status for the imported row
     if (isset($row["APPROVED"]) and !in_array(utf8::strtoupper($row["APPROVED"]), array('NO', 'YES'))) {
         $this->errors[] = Kohana::lang('import.csv.approved') . ($this->rownumber + 1);
     }
     // If a value of Yes or No is NOT set for verified status for the imported row
     if (isset($row["VERIFIED"]) and !in_array(utf8::strtoupper($row["VERIFIED"]), array('NO', 'YES'))) {
         $this->errors[] = Kohana::lang('import.csv.verified') . ($this->rownumber + 1);
     }
     if (count($this->errors)) {
         return false;
     }
     // STEP 1: SAVE LOCATION
     if (isset($row['LOCATION'])) {
         $location = new Location_Model();
         $location->location_name = isset($row['LOCATION']) ? $row['LOCATION'] : '';
         // For Geocoding purposes
         $location_geocoded = map::geocode($location->location_name);
         // If we have LATITUDE and LONGITUDE use those
         if (isset($row['LATITUDE']) and isset($row['LONGITUDE'])) {
             $location->latitude = isset($row['LATITUDE']) ? $row['LATITUDE'] : 0;
             $location->longitude = isset($row['LONGITUDE']) ? $row['LONGITUDE'] : 0;
         } else {
             $location->latitude = $location_geocoded ? $location_geocoded['latitude'] : 0;
             $location->longitude = $location_geocoded ? $location_geocoded['longitude'] : 0;
         }
         $location->country_id = $location_geocoded ? $location_geocoded['country_id'] : 0;
         $location->location_date = $this->time;
         $location->save();
         $this->locations_added[] = $location->id;
     }
     // STEP 2: SAVE INCIDENT
     $incident = new Incident_Model();
     $incident->location_id = isset($row['LOCATION']) ? $location->id : 0;
     $incident->user_id = 0;
     $incident->form_id = (isset($row['FORM #']) and Form_Model::is_valid_form($row['FORM #'])) ? $row['FORM #'] : 1;
     $incident->incident_title = $row['INCIDENT TITLE'];
     $incident->incident_description = isset($row['DESCRIPTION']) ? $row['DESCRIPTION'] : '';
     $incident->incident_date = date("Y-m-d H:i:s", strtotime($row['INCIDENT DATE']));
     $incident->incident_dateadd = $this->time;
     $incident->incident_active = (isset($row['APPROVED']) and utf8::strtoupper($row['APPROVED']) == 'YES') ? 1 : 0;
     $incident->incident_verified = (isset($row['VERIFIED']) and utf8::strtoupper($row['VERIFIED']) == 'YES') ? 1 : 0;
     $incident->save();
     $this->incidents_added[] = $incident->id;
     // STEP 3: Save Personal Information
     if (isset($row['FIRST NAME']) or isset($row['LAST NAME']) or isset($row['EMAIL'])) {
         $person = new Incident_Person_Model();
         $person->incident_id = $incident->id;
         $person->person_first = isset($row['FIRST NAME']) ? $row['FIRST NAME'] : '';
         $person->person_last = isset($row['LAST NAME']) ? $row['LAST NAME'] : '';
         $person->person_email = (isset($row['EMAIL']) and valid::email($row['EMAIL'])) ? $row['EMAIL'] : '';
         $person->person_date = date("Y-m-d H:i:s", time());
         // Make sure that you're not importing an empty record i.e at least one field has been recorded
         // If all fields are empty i.e you have an empty record, don't save
         if (!empty($person->person_first) or !empty($person->person_last) or !empty($person->person_email)) {
             $person->save();
             // Add to array of incident persons added
             $this->incident_persons_added[] = $person->id;
         }
     }
     // STEP 4: SAVE CATEGORIES
     // If CATEGORY column exists
     if (isset($row['CATEGORY'])) {
         $categorynames = explode(',', trim($row['CATEGORY']));
         // Trim whitespace from array values
         $categorynames = array_map('trim', $categorynames);
         // Get rid of duplicate category entries in a row
         $categories = array_unique(array_map('strtolower', $categorynames));
         // Add categories to incident
         foreach ($categories as $categoryname) {
             // Convert the first string character of the category name to Uppercase
             $categoryname = utf8::ucfirst($categoryname);
             // For purposes of adding an entry into the incident_category table
             $incident_category = new Incident_Category_Model();
             $incident_category->incident_id = $incident->id;
             // If category name exists, add entry in incident_category table
             if ($categoryname != '') {
                 // Check if the category exists (made sure to convert to uppercase for comparison)
                 if (!isset($this->existing_categories[utf8::strtoupper($categoryname)])) {
                     $this->notices[] = Kohana::lang('import.new_category') . $categoryname;
                     $category = new Category_Model();
                     $category->category_title = $categoryname;
                     // We'll just use black for now. Maybe something random?
                     $category->category_color = '000000';
                     // because all current categories are of type '5'
                     $category->category_visible = 1;
                     $category->category_description = $categoryname;
                     $category->category_position = count($this->existing_categories);
                     $category->save();
                     $this->categories_added[] = $category->id;
//.........这里部分代码省略.........
开发者ID:rjmackay,项目名称:Ushahidi_Web,代码行数:101,代码来源:CSVImporter.php


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