本文整理汇总了PHP中Location_Model类的典型用法代码示例。如果您正苦于以下问题:PHP Location_Model类的具体用法?PHP Location_Model怎么用?PHP Location_Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Location_Model类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: add_reports
/**
* Adds reports in JSON format to the database
* @param string $data - CF JSON results
*/
private function add_reports($data)
{
$reports = json_decode($data, false);
foreach ($reports as $report) {
//Save the Report location
$location = new Location_Model();
$location->longitude = $report->{'longitude'};
$location->latitude = $report->{'latitude'};
$location->location_name = $report->{'location_city'};
$location->save();
// Save CF result as Report
$incident = new Incident_Model();
$incident->location_id = $location->id;
// $incident->id = $report->{'id'};
$incident->incident_title = date("Y-m-d H:i:s", time());
$incident->incident_description = $report->{'sms_text'};
$incident->incident_date = date("Y-m-d H:i:s", time());
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
$incident->incident_active = 1;
$incident->incident_verified = 1;
$incident->save();
// Save Incident Category
$categories = explode(",", $report->{'categories'});
foreach ($categories as $category) {
$report_category_id = ORM::factory("category")->where("category_title", $category)->find();
if ($report_category_id->loaded) {
$incident_category = new Incident_Category_Model();
$incident_category->incident_id = $incident->id;
$incident_category->category_id = $report_category_id->id;
$incident_category->save();
}
}
}
}
开发者ID:rrbaker,项目名称:ushahidicrowdflower,代码行数:38,代码来源:s_crowdflower.php
示例2: __construct
function __construct()
{
$this->conf = array('model' => 'Shift_model', 'path' => 'admin/shifts', 'entity' => 'shift', 'after_save' => 'shift');
parent::__construct(User_model::LEVEL_MANAGER);
/* check how many locations do we have */
$lm = new Location_Model();
$location_count = $lm->count();
$this->data['location_count'] = $location_count;
}
开发者ID:RVRKC,项目名称:Hackathon_2015,代码行数:9,代码来源:shifts.php
示例3: view_text
public function view_text($skip = array())
{
$return = parent::view_text($skip);
unset($return['start']);
unset($return['end']);
unset($return['status']);
$return['date'][1] = $this->date_view($skip);
/* optimize it sometime later */
$lm = new Location_Model();
$location_count = $lm->count();
if ($location_count < 2) {
unset($return['location']);
}
return $return;
}
开发者ID:RVRKC,项目名称:Hackathon_2015,代码行数:15,代码来源:shift_model.php
示例4: _get_locations
/**
* Get a list of locations
*
* @param array $where Key->value array of the set of filters to apply
* @return string JSON/XML string with the location data
*/
private function _get_locations($where = array())
{
// Fetch the location items
$items = Location_Model::get_locations($where, $this->list_limit);
//No record found.
if ($items->count() == 0) {
return $this->response(4);
}
// Counter
$i = 0;
// To hold the json data
$json_locations = array();
foreach ($items as $item) {
// Needs different treatment depending on the output
if ($this->response_type == 'json') {
$json_locations[] = array("location" => $item);
} else {
$json_locations['location' . $i] = array("location" => $item);
$this->replar[] = 'location' . $i;
}
$i++;
}
// Array to be converted to either JSON or xml
$data = array("payload" => array("domain" => $this->domain, "locations" => $json_locations), "error" => $this->api_service->get_error_msg(0));
return $this->response_type == 'json' ? $this->array_as_json($data) : $this->array_as_xml($data, $this->replar);
}
开发者ID:huslage,项目名称:Ushahidi_Web,代码行数:32,代码来源:MY_Locations_Api_Object.php
示例5: Location_Model
/**
* 单例模式
* @return Location_Model
*/
public static function &instance()
{
if (!isset(self::$instance)) {
// Create a new instance
self::$instance = new Location_Model();
}
return self::$instance;
}
开发者ID:momoim,项目名称:momo-api,代码行数:12,代码来源:location.php
示例6: shifts
function shifts()
{
if ($this->staff_id) {
$um = new User_Model();
$um->get_by_id($this->staff_id);
$sm = $um->shift;
} elseif ($this->location_id) {
$lm = new Location_Model();
$lm->get_by_id($this->location_id);
$sm = $lm->shift;
} else {
$sm = new Shift_Model();
}
if ($this->start) {
$sm->where('date >=', $this->start);
}
if ($this->end) {
$sm->where('date <=', $this->end);
}
$sm->order_by('date', 'ASC')->order_by('start', 'ASC')->include_related('user', 'id');
return $sm->get();
}
开发者ID:RVRKC,项目名称:Hackathon_2015,代码行数:22,代码来源:schedule_model.php
示例7: submit
/**
* Submits a new report.
*/
public function submit()
{
$this->template->header->this_page = 'reports_submit';
$this->template->content = new View('reports_submit');
// setup and initialize form field names
$form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
//copy the form as errors, so the errors will be stored with keys corresponding to the form field names
$errors = $form;
$form_error = FALSE;
// Initialize Default Values
$form['incident_date'] = date("m/d/Y", time());
$form['incident_hour'] = "12";
$form['incident_minute'] = "00";
$form['incident_ampm'] = "pm";
// check, has the form been submitted, if so, setup validation
if ($_POST) {
// Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
$post = Validation::factory(array_merge($_POST, $_FILES));
// Add some filters
$post->pre_filter('trim', TRUE);
// Add some rules, the input field, followed by a list of checks, carried out in order
$post->add_rules('incident_title', 'required', 'length[3,200]');
$post->add_rules('incident_description', 'required');
$post->add_rules('incident_date', 'required', 'date_mmddyyyy');
$post->add_rules('incident_hour', 'required', 'between[1,12]');
$post->add_rules('incident_minute', 'required', 'between[0,59]');
if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") {
$post->add_error('incident_ampm', 'values');
}
// Validate for maximum and minimum latitude values
$post->add_rules('latitude', 'required', 'between[-90,90]');
$post->add_rules('longitude', 'required', 'between[-180,180]');
$post->add_rules('location_name', 'required', 'length[3,200]');
//XXX: Hack to validate for no checkboxes checked
if (!isset($_POST['incident_category'])) {
$post->incident_category = "";
$post->add_error('incident_category', 'required');
} else {
$post->add_rules('incident_category.*', 'required', 'numeric');
}
// Validate only the fields that are filled in
if (!empty($_POST['incident_news'])) {
foreach ($_POST['incident_news'] as $key => $url) {
if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
$post->add_error('incident_news', 'url');
}
}
}
// Validate only the fields that are filled in
if (!empty($_POST['incident_video'])) {
foreach ($_POST['incident_video'] as $key => $url) {
if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
$post->add_error('incident_video', 'url');
}
}
}
// Validate photo uploads
$post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]');
// Validate Personal Information
if (!empty($_POST['person_first'])) {
$post->add_rules('person_first', 'length[3,100]');
}
if (!empty($_POST['person_last'])) {
$post->add_rules('person_last', 'length[3,100]');
}
if (!empty($_POST['person_email'])) {
$post->add_rules('person_email', 'email', 'length[3,100]');
}
// Test to see if things passed the rule checks
if ($post->validate()) {
// STEP 1: SAVE LOCATION
$location = new Location_Model();
$location->location_name = $post->location_name;
$location->latitude = $post->latitude;
$location->longitude = $post->longitude;
$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 = $post->incident_title;
$incident->incident_description = $post->incident_description;
$incident_date = explode("/", $post->incident_date);
// The $_POST['date'] is a value posted by form in mm/dd/yyyy format
$incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1];
$incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm;
$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();
}
//.........这里部分代码省略.........
开发者ID:kiirti,项目名称:Ushahidi_MHI,代码行数:101,代码来源:reports.php
示例8: array_to_Group_contact
/**
* 过滤输入、创建群联系人对象
* @param array $data 联系人信息
* @return Group_Contact $contact
*/
public function array_to_Group_contact($data)
{
$contact = new Group_Contact();
$location_model = Location_Model::instance();
$bjx_arr = Kohana::config_load('bjx');
foreach ($data as $type => $value) {
switch ($type) {
case 'tels':
if (!empty($value)) {
$values = $tmp = array();
foreach ($value as $val) {
if (!in_array(trim($val['value']), $tmp)) {
$tmp[] = trim($val['value']);
$values[] = array('value' => trim($val['value']), 'type' => $val['type'], 'city' => $location_model->get_tel_location(trim($val['value'])), 'pref' => !empty($val['pref']) ? (int) $val['pref'] : 0);
}
}
call_user_func(array($contact, 'set_' . $type), $values);
}
break;
case 'ims':
if (!empty($value)) {
$values = $tmp = $protocols = array();
foreach ($value as $val) {
$val['protocol'] = strtolower($val['protocol']);
$keys = array_keys($tmp, trim($val['value']));
$key = isset($keys[0]) ? $keys[0] : -1;
if ($key < 0 or $protocols[$key] != $val['protocol']) {
$tmp[] = trim($val['value']);
$protocols[] = $val['protocol'];
$values[] = array('value' => trim($val['value']), 'protocol' => $val['protocol'], 'type' => $val['type']);
}
}
call_user_func(array($contact, 'set_' . $type), $values);
}
break;
case 'addresses':
if (!empty($value)) {
$values = $tmp = array();
$t = '';
foreach ($value as $val) {
$t = trim($val['country']) . '|' . trim($val['region']) . '|' . trim($val['city']) . '|' . trim($val['street']) . '|' . trim($val['postal']);
if (!in_array($t, $tmp)) {
$values[] = array('country' => trim($val['country']), 'region' => trim($val['region']), 'city' => trim($val['city']), 'street' => trim($val['street']), 'postal' => trim($val['postal']), 'type' => $val['type']);
$tmp[] = $t;
}
}
call_user_func(array($contact, 'set_' . $type), $values);
}
break;
case 'emails':
case 'urls':
case 'events':
case 'relations':
if (!empty($value)) {
$values = $tmp = array();
foreach ($value as $val) {
if (!in_array(trim($val['value']), $tmp)) {
$tmp[] = trim($val['value']);
$values[] = array('value' => trim($val['value']), 'type' => $val['type']);
}
}
call_user_func(array($contact, 'set_' . $type), $values);
}
break;
case 'birthday':
$contactModel = Contact_Model::instance();
call_user_func(array($contact, 'set_' . $type), !empty($value) ? $contactModel->_filter_birthday($value) : '');
break;
case 'id':
break;
default:
call_user_func(array($contact, 'set_' . $type), !empty($value) ? $value : '');
break;
}
}
$formatted_name = $this->name_to_formatted_name($data['family_name'], $data['given_name']);
//拼接后的全名为空,并且输入的全名不是空的,把全名拆分设置
if (empty($formatted_name) and !empty($data['formatted_name'])) {
$name = $this->formatted_name_to_name($data['formatted_name']);
$contact->set_given_name($name['given_name']);
$contact->set_family_name($name['family_name']);
} else {
$fn = $formatted_name;
}
if (!empty($fn)) {
require_once Kohana::find_file('vendor', 'pinyin/c2p');
$phonetic = getPinYin($fn, false, ' ');
$tmp = explode(' ', $phonetic);
$sort = '';
if (is_array($tmp)) {
foreach ($tmp as $t) {
$sort .= isset($t[0]) ? $t[0] : '';
}
}
$t = ord($sort[0]);
//.........这里部分代码省略.........
开发者ID:momoim,项目名称:momo-api,代码行数:101,代码来源:group_contact.php
示例9: _parse_feed
/**
* parse feed and send feed items to database
*/
private function _parse_feed()
{
// Max number of feeds to keep
$max_feeds = 100;
// Today's Date
$today = strtotime('now');
// Get All Feeds From DB
$feeds = ORM::factory('feed')->find_all();
foreach ($feeds as $feed) {
$last_update = $feed->feed_update;
// Has it been more than 24 hours since the last update?
// Since its a manual refresh, we don't need to set a time
if ((int) $today - (int) $last_update > 0) {
// Parse Feed URL using Feed Helper
$feed_data = feed::simplepie($feed->feed_url);
foreach ($feed_data->get_items(0, 50) as $feed_data_item) {
$title = $feed_data_item->get_title();
$link = $feed_data_item->get_link();
$description = $feed_data_item->get_description();
$date = $feed_data_item->get_date();
$latitude = $feed_data_item->get_latitude();
$longitude = $feed_data_item->get_longitude();
// Make Sure Title is Set (Atleast)
if (isset($title) && !empty($title)) {
// We need to check for duplicates!!!
// Maybe combination of Title + Date? (Kinda Heavy on the Server :-( )
$dupe_count = ORM::factory('feed_item')->where('item_title', $title)->where('item_date', date("Y-m-d H:i:s", strtotime($date)))->count_all();
if ($dupe_count == 0) {
// Does this feed have a location??
$location_id = 0;
// STEP 1: SAVE LOCATION
if ($latitude && $longitude) {
$location = new Location_Model();
$location->location_name = Kohana::lang('ui_admin.unknown');
$location->latitude = $latitude;
$location->longitude = $longitude;
$location->location_date = date("Y-m-d H:i:s", time());
$location->save();
$location_id = $location->id;
}
$newitem = new Feed_Item_Model();
$newitem->feed_id = $feed->id;
$newitem->location_id = $location_id;
$newitem->item_title = $title;
if (isset($description) && !empty($description)) {
$newitem->item_description = $description;
}
if (isset($link) && !empty($link)) {
$newitem->item_link = $link;
}
if (isset($date) && !empty($date)) {
$newitem->item_date = date("Y-m-d H:i:s", strtotime($date));
} else {
$newitem->item_date = date("Y-m-d H:i:s", time());
}
if (isset($feed_type) && !empty($feed_type)) {
$newitem->feed_type = $feed_type;
}
$newitem->save();
}
}
}
// Get Feed Item Count
$feed_count = ORM::factory('feed_item')->where('feed_id', $feed->id)->count_all();
if ($feed_count > $max_feeds) {
// Excess Feeds
$feed_excess = $feed_count - $max_feeds;
// Delete Excess Feeds
foreach (ORM::factory('feed_item')->where('feed_id', $feed->id)->orderby('id', 'ASC')->limit($feed_excess)->find_all() as $del_feed) {
$del_feed->delete($del_feed->id);
}
}
// Set feed update date
$feed->feed_update = strtotime('now');
$feed->save();
}
}
}
开发者ID:kvin33,项目名称:Ushahidi_Web,代码行数:81,代码来源:manage.php
示例10: edit
//.........这里部分代码省略.........
// Validate only the fields that are filled in
if (!empty($_POST['incident_video'])) {
foreach ($_POST['incident_video'] as $key => $url) {
if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
$post->add_error('incident_video', 'url');
}
}
}
// Validate photo uploads
$post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]');
// Validate Personal Information
if (!empty($_POST['person_first'])) {
$post->add_rules('person_first', 'length[3,100]');
}
if (!empty($_POST['person_last'])) {
$post->add_rules('person_last', 'length[3,100]');
}
if (!empty($_POST['person_email'])) {
$post->add_rules('person_email', 'email', 'length[3,100]');
}
// Validate Custom Fields
if (isset($post->custom_field) && !$this->_validate_custom_form_fields($post->custom_field)) {
$post->add_error('custom_field', 'values');
}
$post->add_rules('incident_active', 'required', 'between[0,1]');
$post->add_rules('incident_verified', 'required', 'length[0,1]');
$post->add_rules('incident_source', 'numeric', 'length[1,1]');
$post->add_rules('incident_information', 'numeric', 'length[1,1]');
// Test to see if things passed the rule checks
if ($post->validate()) {
// Yes! everything is valid
$location_id = $post->location_id;
// STEP 1: SAVE LOCATION
$location = new Location_Model($location_id);
$location->location_name = $post->location_name;
$location->latitude = $post->latitude;
$location->longitude = $post->longitude;
$location->location_date = date("Y-m-d H:i:s", time());
$location->save();
// STEP 2: SAVE INCIDENT
$incident = new Incident_Model($id);
$incident->location_id = $location->id;
//$incident->locale = $post->locale;
$incident->form_id = $post->form_id;
$incident->user_id = $_SESSION['auth_user']->id;
$incident->incident_title = $post->incident_title;
$incident->incident_description = $post->incident_description;
$incident_date = explode("/", $post->incident_date);
// where the $_POST['date'] is a value posted by form in mm/dd/yyyy format
$incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1];
$incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm;
$incident->incident_date = date("Y-m-d H:i:s", strtotime($incident_date . " " . $incident_time));
// Is this new or edit?
if ($id) {
$incident->incident_datemodify = date("Y-m-d H:i:s", time());
} else {
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
}
// Is this an Email, SMS, Twitter submitted report?
//XXX: We may get rid of incident_mode altogether... ???
//$_POST
if (!empty($service_id)) {
if ($service_id == 1) {
// SMS
$incident->incident_mode = 2;
} elseif ($service_id == 2) {
开发者ID:Nyamai,项目名称:Ushahidi_Web,代码行数:67,代码来源:reports.php
示例11: _submit
/**
* the actual reporting - ***must find a cleaner way to do this than duplicating code verbatim - modify report***
*/
function _submit()
{
// setup and initialize form field names
$form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
// copy the form as errors, so the errors will be stored with keys corresponding to the form field names
$this->messages = $form;
// check, has the form been submitted, if so, setup validation
if ($_POST) {
// Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
$post = Validation::factory(array_merge($_POST, $_FILES));
// Add some filters
$post->pre_filter('trim', TRUE);
// Add some rules, the input field, followed by a list of checks, carried out in order
$post->add_rules('incident_title', 'required', 'length[3,200]');
$post->add_rules('incident_description', 'required');
$post->add_rules('incident_date', 'required', 'date_mmddyyyy');
$post->add_rules('incident_hour', 'required', 'between[1,12]');
//$post->add_rules('incident_minute','required','between[0,59]');
if ($this->_verifyArrayIndex($_POST, 'incident_ampm')) {
if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") {
$post->add_error('incident_ampm', 'values');
}
}
$post->add_rules('latitude', 'required', 'between[-90,90]');
// Validate for maximum and minimum latitude values
$post->add_rules('longitude', 'required', 'between[-180,180]');
// Validate for maximum and minimum longitude values
$post->add_rules('location_name', 'required', 'length[3,200]');
$post->add_rules('incident_category', 'required', 'length[3,100]');
// Validate Personal Information
if (!empty($post->person_first)) {
$post->add_rules('person_first', 'length[3,100]');
}
if (!empty($post->person_last)) {
$post->add_rules('person_last', 'length[3,100]');
}
if (!empty($post->person_email)) {
$post->add_rules('person_email', 'email', 'length[3,100]');
}
// Test to see if things passed the rule checks
if ($post->validate()) {
// SAVE LOCATION (***IF IT DOES NOT EXIST***)
$location = new Location_Model();
$location->location_name = $post->location_name;
$location->latitude = $post->latitude;
$location->longitude = $post->longitude;
$location->location_date = date("Y-m-d H:i:s", time());
$location->save();
// SAVE INCIDENT
$incident = new Incident_Model();
$incident->location_id = $location->id;
$incident->user_id = 0;
$incident->incident_title = $post->incident_title;
$incident->incident_description = $post->incident_description;
$incident_date = split("/", $post->incident_date);
// where the $_POST['date'] is a value posted by form in mm/dd/yyyy format
$incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1];
$incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm;
$incident->incident_date = $incident_date . " " . $incident_time;
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
$incident->save();
// SAVE CATEGORIES
//check if data is array or a serialized data.
if (is_array($post->incident_category)) {
$categories = $post->incident_category;
} 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();
//.........这里部分代码省略.........
开发者ID:rabble,项目名称:Ushahidi_Web,代码行数:101,代码来源:api.php
示例12: index
function index()
{
if (isset($_GET['key'])) {
$frontlinesms_key = $_GET['key'];
}
if (isset($_GET['s'])) {
$message_from = $_GET['s'];
// Remove non-numeric characters from string
$message_from = ereg_replace("[^0-9]", "", $message_from);
}
if (isset($_GET['m'])) {
$message_description = $_GET['m'];
}
if (!empty($frontlinesms_key) && !empty($message_from) && !empty($message_description)) {
// Is this a valid FrontlineSMS Key?
$keycheck = ORM::factory('settings', 1)->where('frontlinesms_key', $frontlinesms_key)->find();
if ($keycheck->loaded == true) {
$services = new Service_Model();
$service = $services->where('service_name', 'SMS')->find();
if (!$service) {
return;
}
$reporter_check = ORM::factory('reporter')->where('service_id', $service->id)->where('service_account', $message_from)->find();
if ($reporter_check->loaded == true) {
$reporter_id = $reporter_check->id;
} else {
// get default reporter level (Untrusted)
$levels = new Level_Model();
$default_level = $levels->where('level_weight', 0)->find();
$reporter = new Reporter_Model();
$reporter->service_id = $service->id;
$reporter->service_userid = null;
$reporter->service_account = $message_from;
$reporter->reporter_level = $default_level;
$reporter->reporter_first = null;
$reporter->reporter_last = null;
$reporter->reporter_email = null;
$reporter->reporter_phone = null;
$reporter->reporter_ip = null;
$reporter->reporter_date = date('Y-m-d');
$reporter->save();
$reporter_id = $reporter->id;
}
$rest = $this->getsms($message_description);
if ($rest['incidencia'] != '') {
if ($coord = $this->gettextaddress($rest['localidad'] . ', mexico')) {
// STEP 1: SAVE LOCATION
$location = new Location_Model('');
$location->location_name = $coord['textaddress'];
$location->country_id = 157;
//Mexico
$location->latitude = $coord['latitude'];
$location->longitude = $coord['longitude'];
$location->location_date = date("Y-m-d H:i:s", time());
$location->save();
$locationid = $location->id;
} else {
$locationid = 0;
}
// STEP 2: SAVE INCIDENT
$incident = new Incident_Model('');
$incident->location_id = $locationid;
//$incident->locale = $post->locale;
$incident->form_id = 1;
$incident->user_id = 0;
$incident->incident_title = $rest['mensaje'];
$incident->incident_description = $rest['mensaje'];
$incident->incident_date = date("Y-m-d H:i:s", time());
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
$incident->incident_mode = 2;
// Incident Evaluation Info
$incident->incident_active = 0;
$incident->incident_verified = 0;
$incident->incident_source = null;
$incident->incident_information = null;
//Save
$incident->save();
$incidentid = $incident->id;
// STEP 3: SAVE CATEGORIES
$incident_category = new Incident_Category_Model();
$incident_category->incident_id = $incident->id;
$incident_category->category_id = $rest['incidencia'];
$incident_category->save();
} else {
$incidentid = 0;
}
// Save Message
$message = new Message_Model();
$message->parent_id = 0;
$message->incident_id = $incidentid;
$message->user_id = 0;
$message->reporter_id = $reporter_id;
$message->message_from = $message_from;
$message->message_to = null;
$message->message = $message_description;
$message->message_type = 1;
// Inbox
$message->message_date = date("Y-m-d H:i:s", time());
$message->service_messageid = null;
$message->save();
//.........这里部分代码省略.........
开发者ID:shukster,项目名称:Cuidemos-el-Voto,代码行数:101,代码来源:frontlinesms.php
示例13: importreport
/**
* Function to import a report form a row in the CSV file
* @param array $row
* @return bool
*/
function importreport($row)
{
// If the date is not in proper date format
if (!strtotime($row['INCIDENT DATE'])) {
$this->errors[] = 'Could not parse incident date "' . htmlspecialchars($row['INCIDENT DATE']) . '" on line ' . ($this->rownumber + 1);
}
// If a value of Yes or No is NOT set for approval status for the imported row
if (isset($row["APPROVED"]) and !in_array($row["APPROVED"], array('NO', 'YES'))) {
$this->errors[] = 'APPROVED must be either YES or NO on line ' . ($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($row["VERIFIED"], array('NO', 'YES'))) {
$this->errors[] = 'VERIFIED must be either YES or NO on line ' . ($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'] : '';
$location->latitude = isset($row['LATITUDE']) ? $row['LATITUDE'] : '';
$location->longitude = isset($row['LONGITUDE']) ? $row['LONGITUDE'] : '';
$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->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 $row['APPROVED'] == 'YES') ? 1 : 0;
$incident->incident_verified = (isset($row['VERIFIED']) and $row['VERIFIED'] == 'YES') ? 1 : 0;
$incident->save();
$this->incidents_added[] = $incident->id;
// STEP 3: SAVE CATEGORIES
// If CATEGORIES column exists
if (isset($row['CATEGORY'])) {
$categorynames = explode(',', trim($row['CATEGORY']));
// Add categories to incident
foreach ($categorynames as $categoryname) {
// There seems to be an uppercase convention for categories... Don't know why
$categoryname = strtoupper(trim($categoryname));
// Empty categoryname not allowed
if ($categoryname != '') {
if (!isset($this->category_ids[$categoryname])) {
$this->notices[] = 'There exists no category "' . htmlspecialchars($categoryname) . '" in database yet.' . ' Added to database.';
$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_type = 5;
$category->category_visible = 1;
$category->category_description = $categoryname;
$category->save();
$this->categories_added[] = $category->id;
// Now category_id is known: This time, and for the rest of the import.
$this->category_ids[$categoryname] = $category->id;
}
$incident_category = new Incident_Category_Model();
$incident_category->incident_id = $incident->id;
$incident_category->category_id = $this->category_ids[$categoryname];
$incident_category->save();
$this->incident_categories_added[] = $incident_category->id;
}
}
}
return true;
}
开发者ID:kjgarza,项目名称:ushahidi,代码行数:79,代码来源:ReportsImporter.php
示例14: _submit
/**
* the actual reporting - ***must find a cleaner way to do this than duplicating code verbatim - modify report***
*/
function _submit()
{
// setup and initialize form field names
$form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => '', 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
//copy the form as errors, so the errors will be stored with keys corresponding to the form field names
$this->messages = $form;
// check, has the form been submitted, if so, setup validation
if ($_POST) {
// Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
$post = Validation::factory(array_merge($_POST, $_FILES));
// Add some filters
$post->pre_filter('trim', TRUE);
// Add some rules, the input field, followed by a list of checks, carried out in order
$post->add_rules('incident_title', 'required', 'length[3,200]');
$post->add_rules('incident_description', 'required');
$post->add_rules('incident_date', 'required', 'date_mmddyyyy');
$post->add_rules('incident_hour', 'required', 'between[0,23]');
//$post->add_rules('incident_minute','required','between[0,59]');
if ($this->_verifyArrayIndex($_POST, 'incident_ampm')) {
if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") {
$post->add_error('incident_ampm', 'values');
}
}
$post->add_rules('latitude', 'required', 'between[-90,90]');
// Validate for maximum and minimum latitude values
$post->add_rules('longitude', 'required', 'between[-180,180]');
// Validate for maximum and minimum longitude values
$post->add_rules('location_name', 'required', 'length[3,200]');
$post->add_rules('incident_category', 'required', 'length[1,100]');
// Validate Personal Information
if (!empty($post->person_first)) {
$post->add_rules('person_first', 'length[3,100]');
}
if (!empty($post->person_last)) {
$post->add_rules('person_last', 'length[3,100]');
}
if (!empty($post->person_email)) {
$post->add_rules('person_email', 'email', 'length[3,100]');
}
// Test to see if things passed the rule checks
if ($post->validate()) {
// SAVE LOCATION (***IF IT DOES NOT EXIST***)
$location = new Location_Model();
$location->location_name = $post->location_name;
$location->latitude = $post->latitude;
$location->longitude = $post->longitude;
$location->location_date = date("Y-m-d H:i:s", time());
$location->save();
// SAVE INCIDENT
$incident = new Incident_Model();
$incident->location_id = $location->id;
$incident->user_id = 0;
$incident->incident_title = $post->incident_title;
$incident->incident_description = $post->incident_description;
$incident_date = explode("/", $post->incident_date);
/**
* where the $_POST['date'] is a value posted by form in
* mm/dd/yyyy format
*/
$incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1];
$incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm;
$incident->incident_date = $incident_date . " " . $incident_time;
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
$incident->save();
// SAVE CATEGORIES
//check if data is csv or a single value.
$pos = strpos($post->incident_category, ",");
if ($pos === false) {
//for backward compactibility. will drop support for it in the future.
if (@unserialize($post->incident_category)) {
$categories = unserialize($post->incident_category);
} else {
$categories = array($post->incident_category);
}
} else {
$categories = explode(",", $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($po
|
请发表评论