當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Incident_Model::is_valid_incident方法代碼示例

本文整理匯總了PHP中Incident_Model::is_valid_incident方法的典型用法代碼示例。如果您正苦於以下問題:PHP Incident_Model::is_valid_incident方法的具體用法?PHP Incident_Model::is_valid_incident怎麽用?PHP Incident_Model::is_valid_incident使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Incident_Model的用法示例。


在下文中一共展示了Incident_Model::is_valid_incident方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testIsValidIncident

 /**
  * Tests Incident_Model::is_valid_incident
  * @test
  */
 public function testIsValidIncident()
 {
     // Get any incident
     $random_incident = testutils::get_random_id('incident');
     $inactive_incident = testutils::get_random_id('incident', 'WHERE incident_active = 0');
     $active_incident = testutils::get_random_id('incident', 'WHERE incident_active = 1');
     //Test to see if there are data in the incident table to test with.
     if (empty($random_incident)) {
         $this->markTestSkipped('The incident table is empty.');
     } elseif (empty($inactive_incident)) {
         $this->markTestSkipped('No inactive incidents in incident table.');
     } elseif (empty($active_incident)) {
         $this->markTestSkipped('No active incidents in incident table.');
     } else {
         $this->assertEquals(TRUE, Incident_Model::is_valid_incident($random_incident, FALSE));
         // Get inactive incident
         $inactive_incident = testutils::get_random_id('incident', 'WHERE incident_active = 0');
         // Check fails with default args and explicitly limit to active only
         $this->assertEquals(FALSE, Incident_Model::is_valid_incident($inactive_incident));
         $this->assertEquals(FALSE, Incident_Model::is_valid_incident($inactive_incident, TRUE));
         // Check success when including inactive incidents
         $this->assertEquals(TRUE, Incident_Model::is_valid_incident($inactive_incident, FALSE));
         // Get active incident
         $active_incident = testutils::get_random_id('incident', 'WHERE incident_active = 1');
         // Check success with default args and explicitly limit to active only
         $this->assertEquals(TRUE, Incident_Model::is_valid_incident($active_incident));
         $this->assertEquals(TRUE, Incident_Model::is_valid_incident($active_incident, TRUE));
         // Null incident value
         $this->assertEquals(FALSE, Incident_Model::is_valid_incident(NULL));
         // Non numeric incident value
         $this->assertEquals(FALSE, Incident_Model::is_valid_incident('0.999'));
     }
 }
開發者ID:Dirichi,項目名稱:Ushahidi_Web,代碼行數:37,代碼來源:Incident_Model_Test.php

示例2: testIsValidIncident

 /**
  * Tests Incident_Model::is_valid_incident
  * @test
  */
 public function testIsValidIncident()
 {
     // Get any incident
     $random_incident = testutils::get_random_id('incident');
     //Test to see if there are data in the incident table to test with.
     if (empty($random_incident)) {
         $this->markTestSkipped('The incident table is empty.');
     } else {
         $this->assertEquals(TRUE, Incident_Model::is_valid_incident($random_incident));
         // Get inactive incident
         $inactive_incident = testutils::get_random_id('incident', 'WHERE incident_active = 0');
         $this->assertEquals(FALSE, Incident_Model::is_valid_incident($inactive_incident, TRUE));
         // Get active incident
         $active_incident = testutils::get_random_id('incident', 'WHERE incident_active = 1');
         $this->assertEquals(TRUE, Incident_Model::is_valid_incident($active_incident, TRUE));
         // Null incident value
         $this->assertEquals(FALSE, Incident_Model::is_valid_incident(NULL));
         // Non numeric incident value
         $this->assertEquals(FALSE, Incident_Model::is_valid_incident('0.999'));
     }
 }
開發者ID:huslage,項目名稱:Ushahidi_Web,代碼行數:25,代碼來源:Incident_Model_Test.php

示例3: get_custom_form_fields

 /**
  * Retrieve Custom Form Fields
  * @param bool|int $incident_id The unique incident_id of the original report
  * @param int $form_id The unique form_id. Uses default form (1), if none selected
  * @param bool $field_names_only Whether or not to include just fields names, or field names + data
  * @param bool $data_only Whether or not to include just data
  * @param string $action If this is being used to grab fields for submit or view of data
  */
 public static function get_custom_form_fields($incident_id = FALSE, $form_id = 1, $data_only = FALSE, $action = "submit")
 {
     $fields_array = array();
     if (!$form_id) {
         $form_id = 1;
     }
     // Validation
     if (!Form_Model::is_valid_form($form_id)) {
         return $fields_array;
     }
     // Database table prefix
     $table_prefix = Kohana::config('database.default.table_prefix');
     //NOTE will probably need to add a user_level variable for non-web based requests
     $user_level = self::get_user_max_auth();
     // Get the predicates for the public state
     $public_state = $action == "view" ? '<=' . $user_level : ' <= ' . $user_level;
     // Query to fetch the form fields and their responses
     $sql = "SELECT ff.*, '' AS form_response FROM " . $table_prefix . "form_field ff WHERE 1=1 ";
     // Check if the provided incident exists
     if (Incident_Model::is_valid_incident($incident_id)) {
         // Overwrite the previous query
         $sql = "SELECT ff.*, fr.form_response " . "FROM " . $table_prefix . "form_field ff " . "RIGHT JOIN " . $table_prefix . "form_response fr ON (fr.form_field_id = ff.id) " . "WHERE fr.incident_id = " . $incident_id . " ";
     }
     $sql .= "AND ff.form_id = " . $form_id . " " . "AND ff.field_ispublic_visible " . $public_state . " " . "ORDER BY ff.field_position ASC";
     // Execute the SQL to fetch the custom form fields
     $form_fields = Database::instance()->query($sql);
     foreach ($form_fields as $custom_formfield) {
         if ($data_only) {
             // Return Data Only
             $fields_array[$custom_formfield->id] = $custom_formfield->form_response;
         } else {
             // Return Field Structure
             $fields_array[$custom_formfield->id] = array('field_id' => $custom_formfield->id, 'field_name' => $custom_formfield->field_name, 'field_type' => $custom_formfield->field_type, 'field_default' => $custom_formfield->field_default, 'field_required' => $custom_formfield->field_required, 'field_maxlength' => $custom_formfield->field_maxlength, 'field_height' => $custom_formfield->field_height, 'field_width' => $custom_formfield->field_width, 'field_isdate' => $custom_formfield->field_isdate, 'field_ispublic_visible' => $custom_formfield->field_ispublic_visible, 'field_ispublic_submit' => $custom_formfield->field_ispublic_submit, 'field_response' => $custom_formfield->form_response);
         }
     }
     // Garbage collection
     unset($form_fields);
     // Return
     return $fields_array;
 }
開發者ID:kjgarza,項目名稱:ushahidi,代碼行數:48,代碼來源:customforms.php

示例4: get_custom_form_fields

 /**
  * Retrieve Custom Form Fields
  * @param bool|int $incident_id The unique incident_id of the original report
  * @param int $form_id The unique form_id. If none selected, retrieve custom form fields from ALL custom forms
  * @param bool $data_only Whether or not to include just data
  * @param string $action If this is being used to grab fields for submit or view of data
  */
 public static function get_custom_form_fields($incident_id = FALSE, $form_id = NULL, $data_only = FALSE, $action = "submit")
 {
     $fields_array = array();
     // If we have a form id but its invalid, return empty
     if (!empty($form_id) and !Form_Model::is_valid_form($form_id)) {
         return $fields_array;
     }
     // Database table prefix
     $table_prefix = Kohana::config('database.default.table_prefix');
     // Get field we'll check permissions against
     $ispublic_field = $action == "view" ? 'field_ispublic_visible' : 'field_ispublic_submit';
     // NOTE will probably need to add a user_level variable for non-web based requests
     $user_level = self::get_user_max_auth();
     // Check if incident is valid
     // Have to do this early since we can't build 2 ORM queries at once.
     $valid_incident = Incident_Model::is_valid_incident($incident_id, FALSE);
     // Check if the provided incident exists, then fill in the data
     if ($valid_incident) {
         $sql = "SELECT ff.*, fr.form_response\n\t\t\tFROM `{$table_prefix}form_field` ff\n\t\t\tLEFT JOIN `{$table_prefix}roles` r ON (r.id = {$ispublic_field})\n\t\t\tLEFT JOIN\n\t\t\t\t`{$table_prefix}form_response` fr ON (\n\t\t\t\t\tfr.form_field_id = ff.id AND\n\t\t\t\t\tfr.incident_id = :incident_id\n\t\t\t\t)\n\t\t\tWHERE (access_level <= :user_level OR access_level IS NULL) " . (!empty($form_id) ? "AND form_id = :form_id " : '') . "ORDER BY field_position ASC";
     } else {
         $sql = "SELECT ff.*\n\t\t\tFROM `{$table_prefix}form_field` ff\n\t\t\tLEFT JOIN `{$table_prefix}roles` r ON (r.id = {$ispublic_field})\n\t\t\tWHERE (access_level <= :user_level OR access_level IS NULL) " . (!empty($form_id) ? "AND form_id = :form_id " : '') . "ORDER BY field_position ASC";
     }
     $form_fields = Database::instance()->query($sql, array(':form_id' => $form_id, ':user_level' => $user_level, ':incident_id' => $incident_id));
     foreach ($form_fields as $custom_formfield) {
         if ($data_only) {
             // Return Data Only
             $fields_array[$custom_formfield->id] = isset($custom_formfield->form_response) ? $custom_formfield->form_response : '';
         } else {
             // Return Field Structure
             // JP: added field description
             $fields_array[$custom_formfield->id] = array('field_id' => $custom_formfield->id, 'form_id' => $custom_formfield->form_id, 'field_name' => $custom_formfield->field_name, 'field_description' => $custom_formfield->field_description, 'field_type' => $custom_formfield->field_type, 'field_default' => $custom_formfield->field_default, 'field_required' => $custom_formfield->field_required, 'field_maxlength' => $custom_formfield->field_maxlength, 'field_height' => $custom_formfield->field_height, 'field_width' => $custom_formfield->field_width, 'field_isdate' => $custom_formfield->field_isdate, 'field_ispublic_visible' => $custom_formfield->field_ispublic_visible, 'field_ispublic_submit' => $custom_formfield->field_ispublic_submit, 'field_response' => isset($custom_formfield->form_response) ? $custom_formfield->form_response : '');
         }
     }
     // Garbage collection
     unset($form_fields);
     // Return
     return $fields_array;
 }
開發者ID:niiyatii,項目名稱:crowdmap,代碼行數:45,代碼來源:customforms.php

示例5: view

 /**
  * Displays a report.
  * @param boolean $id If id is supplied, a report with that id will be
  * retrieved.
  */
 public function view($id = FALSE)
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports_view');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     if (!Incident_Model::is_valid_incident($id, TRUE)) {
         url::redirect('main');
     } else {
         $incident = ORM::factory('incident')->where('id', $id)->where('incident_active', 1)->find();
         if ($incident->id == 0) {
             url::redirect('reports/view/');
         }
         // Comment Post?
         // Setup and initialize form field names
         $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST and Kohana::config('settings.allow_comments')) {
             // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
             $post = Validation::factory($_POST);
             // Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks, carried out in order
             if (!$this->user) {
                 $post->add_rules('comment_author', 'required', 'length[3,100]');
                 $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
             }
             $post->add_rules('comment_description', 'required');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid
                 if ($api_akismet != "") {
                     // Run Akismet Spam Checker
                     $akismet = new Akismet();
                     // Comment data
                     $comment = array('website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                     if ($this->user) {
                         $comment['author'] = $this->user->name;
                         $comment['email'] = $this->user->email;
                     } else {
                         $comment['author'] = $post->comment_author;
                         $comment['email'] = $post->comment_email;
                     }
                     $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                     $akismet->init($config);
                     if ($akismet->errors_exist()) {
                         if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                             // throw new Kohana_Exception('akismet.api_key');
                         } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                             // throw new Kohana_Exception('akismet.server_failed');
                         } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                             // throw new Kohana_Exception('akismet.server_not_found');
                         }
                         // If the server is down, we have to post
                         // the comment :(
                         // $this->_post_comment($comment);
                         $comment_spam = 0;
                     } else {
                         $comment_spam = $akismet->is_spam() ? 1 : 0;
                     }
                 } else {
                     // No API Key!!
                     $comment_spam = 0;
                 }
                 $comment = new Comment_Model();
                 $comment->incident_id = $id;
                 if ($this->user) {
                     $comment->user_id = $this->user->id;
                     $comment->comment_author = $this->user->name;
                     $comment->comment_email = $this->user->email;
                 } else {
                     $comment->comment_author = strip_tags($post->comment_author);
                     $comment->comment_email = strip_tags($post->comment_email);
                 }
                 $comment->comment_description = strip_tags($post->comment_description);
                 $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
                 $comment->comment_date = date("Y-m-d H:i:s", time());
                 // Activate comment for now
                 if ($comment_spam == 1) {
                     $comment->comment_spam = 1;
                     $comment->comment_active = 0;
                 } else {
                     $comment->comment_spam = 0;
                     $comment->comment_active = Kohana::config('settings.allow_comments') == 1 ? 1 : 0;
                 }
                 $comment->save();
                 // Event::comment_add - Added a New Comment
                 Event::run('ushahidi_action.comment_add', $comment);
                 // Notify Admin Of New Comment
                 $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/view/' . $id);
                 // Redirect
//.........這裏部分代碼省略.........
開發者ID:huslage,項目名稱:Ushahidi_Web,代碼行數:101,代碼來源:reports.php

示例6: edit

 /**
  * Edit a report
  * @param bool|int $id The id no. of the report
  * @param bool|string $saved
  */
 public function edit($id = FALSE, $saved = FALSE)
 {
     $db = new Database();
     // If user doesn't have access, redirect to dashboard
     if (!$this->auth->has_permission("reports_edit")) {
         url::redirect('admin/dashboard');
     }
     $this->template->content = new View('admin/reports/edit');
     $this->template->content->title = Kohana::lang('ui_admin.create_report');
     // Setup and initialize form field names
     $form = array('location_id' => '', 'form_id' => '', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'geometry' => array(), 'location_name' => '', 'country_id' => '', 'country_name' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'custom_field' => array(), 'incident_active' => '', 'incident_verified' => '', 'incident_zoom' => '');
     // Copy the form as errors, so the errors will be stored with keys
     // corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = $saved == 'saved';
     // Initialize Default Values
     $form['locale'] = Kohana::config('locale.language');
     //$form['latitude'] = Kohana::config('settings.default_lat');
     //$form['longitude'] = Kohana::config('settings.default_lon');
     $form['incident_date'] = date("m/d/Y", time());
     $form['incident_hour'] = date('h');
     $form['incident_minute'] = date('i');
     $form['incident_ampm'] = date('a');
     $form['country_id'] = Kohana::config('settings.default_country');
     // get the form ID if relevant, kind of a hack
     // to just hit the database like this for one
     // tiny bit of info then throw away the DB model object,
     // but seems to be what everyone else does, so
     // why should I care. Just know that when your Ush system crashes
     // because you have 1000 concurrent users you'll need to do this
     // correctly. Etherton.
     $form['form_id'] = 1;
     $form_id = $form['form_id'];
     if ($id and Incident_Model::is_valid_incident($id, FALSE)) {
         $form_id = ORM::factory('incident', $id)->form_id;
     }
     // Initialize custom field array
     $form['custom_field'] = customforms::get_custom_form_fields($id, $form_id, TRUE);
     // Locale (Language) Array
     $this->template->content->locale_array = Kohana::config('locale.all_languages');
     // Create Categories
     $this->template->content->new_categories_form = $this->_new_categories_form_arr();
     // Time formatting
     $this->template->content->hour_array = $this->_hour_array();
     $this->template->content->minute_array = $this->_minute_array();
     $this->template->content->ampm_array = $this->_ampm_array();
     $this->template->content->stroke_width_array = $this->_stroke_width_array();
     // Get Countries
     $countries = array();
     foreach (ORM::factory('country')->orderby('country')->find_all() as $country) {
         // Create a list of all countries
         $this_country = $country->country;
         if (strlen($this_country) > 35) {
             $this_country = substr($this_country, 0, 35) . "...";
         }
         $countries[$country->id] = $this_country;
     }
     // Initialize Default Value for Hidden Field Country Name,
     // just incase Reverse Geo coding yields no result
     $form['country_name'] = $countries[$form['country_id']];
     $this->template->content->countries = $countries;
     // GET custom forms
     $forms = array();
     foreach (customforms::get_custom_forms(FALSE) as $custom_forms) {
         $forms[$custom_forms->id] = $custom_forms->form_title;
     }
     $this->template->content->forms = $forms;
     // Get the incident media
     $incident_media = Incident_Model::is_valid_incident($id, FALSE) ? ORM::factory('incident', $id)->media : FALSE;
     $this->template->content->incident_media = $incident_media;
     // Are we creating this report from SMS/Email/Twitter?
     // If so retrieve message
     if (isset($_GET['mid']) and intval($_GET['mid']) > 0) {
         $message_id = intval($_GET['mid']);
         $service_id = "";
         $message = ORM::factory('message', $message_id);
         if ($message->loaded and $message->message_type == 1) {
             $service_id = $message->reporter->service_id;
             // Has a report already been created for this Message?
             if ($message->incident_id != 0) {
                 // Redirect to report
                 url::redirect('admin/reports/edit/' . $message->incident_id);
             }
             $this->template->content->show_messages = TRUE;
             $incident_description = $message->message;
             if (!empty($message->message_detail)) {
                 $form['incident_title'] = $message->message;
                 $incident_description = $message->message_detail;
             }
             $form['incident_description'] = $incident_description;
             $form['incident_date'] = date('m/d/Y', strtotime($message->message_date));
             $form['incident_hour'] = date('h', strtotime($message->message_date));
             $form['incident_minute'] = date('i', strtotime($message->message_date));
             $form['incident_ampm'] = date('a', strtotime($message->message_date));
//.........這裏部分代碼省略.........
開發者ID:Dirichi,項目名稱:Ushahidi_Web,代碼行數:101,代碼來源:reports.php

示例7: single

 /**
  * Retrieve Single Marker (and its neighbours)
  * 
  * @param int $incident_id
  */
 public function single($incident_id = 0)
 {
     $json_features = array();
     $incident_id = intval($incident_id);
     // Check if incident valid/approved
     if (!Incident_Model::is_valid_incident($incident_id, TRUE)) {
         throw new Kohana_404_Exception();
     }
     // Load the incident
     // @todo avoid the double load here
     $marker = ORM::factory('incident')->where('incident.incident_active', 1)->with('location')->find($incident_id);
     if (!$marker->loaded) {
         throw new Kohana_404_Exception();
     }
     // Get geojson features for main incident (including geometry)
     $json_features = $this->markers_geojson(array($marker), 0, null, null, TRUE);
     // Get the neigbouring incidents & their json (without geometries)
     $neighbours = Incident_Model::get_neighbouring_incidents($incident_id, FALSE, 20, 100);
     if ($neighbours) {
         $json_features = array_merge($json_features, $this->markers_geojson($neighbours, 0, null, null, FALSE));
     }
     Event::run('ushahidi_filter.json_single_features', $json_features);
     $this->render_geojson($json_features);
 }
開發者ID:niiyatii,項目名稱:crowdmap,代碼行數:29,代碼來源:json.php

示例8: get_custom_form_fields

 /**
  * Retrieve Custom Form Fields
  * @param bool|int $incident_id The unique incident_id of the original report
  * @param int $form_id The unique form_id. If none selected, retrieve custom form fields from ALL custom forms
  * @param bool $data_only Whether or not to include just data
  * @param string $action If this is being used to grab fields for submit or view of data
  */
 public static function get_custom_form_fields($incident_id = FALSE, $form_id = NULL, $data_only = FALSE, $action = "submit")
 {
     $fields_array = array();
     if ($form_id != null and $form_id != '') {
         // Validation
         if (!Form_Model::is_valid_form($form_id)) {
             return $fields_array;
         }
     }
     // Database table prefix
     $table_prefix = Kohana::config('database.default.table_prefix');
     // Get field we'll check permissions against
     $ispublic_field = $action == "view" ? 'field_ispublic_visible' : 'field_ispublic_submit';
     // Query to fetch the form fields associated with the given form id
     $sql = "SELECT ff.*, '' AS form_response FROM " . $table_prefix . "form_field ff LEFT JOIN roles r ON (r.id = {$ispublic_field}) WHERE 1=1 ";
     if ($form_id != null and $form_id != '') {
         $sql .= "AND ff.form_id = " . $form_id . " ";
     }
     // NOTE will probably need to add a user_level variable for non-web based requests
     $user_level = self::get_user_max_auth();
     // Check access_level
     $sql .= 'AND (r.access_level <= ' . $user_level . ' OR r.access_level IS NULL)';
     $sql .= " ORDER BY ff.field_position ASC";
     // Execute the SQL to fetch the custom form fields
     $form_fields = Database::instance()->query($sql);
     foreach ($form_fields as $custom_formfield) {
         if ($data_only) {
             // Return Data Only
             $fields_array[$custom_formfield->id] = $custom_formfield->form_response;
         } else {
             // Return Field Structure
             $fields_array[$custom_formfield->id] = array('field_id' => $custom_formfield->id, 'field_name' => $custom_formfield->field_name, 'field_type' => $custom_formfield->field_type, 'field_default' => $custom_formfield->field_default, 'field_required' => $custom_formfield->field_required, 'field_maxlength' => $custom_formfield->field_maxlength, 'field_height' => $custom_formfield->field_height, 'field_width' => $custom_formfield->field_width, 'field_isdate' => $custom_formfield->field_isdate, 'field_ispublic_visible' => $custom_formfield->field_ispublic_visible, 'field_ispublic_submit' => $custom_formfield->field_ispublic_submit, 'field_response' => $custom_formfield->form_response);
         }
     }
     // Garbage collection
     unset($form_fields);
     // Check if the provided incident exists, then fill in the data
     if (Incident_Model::is_valid_incident($incident_id)) {
         // Overwrite the previous query
         $sql = "SELECT ff.*, fr.form_response " . "FROM " . $table_prefix . "form_field ff " . "RIGHT JOIN " . $table_prefix . "form_response fr ON (fr.form_field_id = ff.id) " . "LEFT JOIN roles r ON (r.id = {$ispublic_field})" . "WHERE fr.incident_id = " . $incident_id . " ";
         if ($form_id != null and $form_id != '') {
             $sql .= "AND ff.form_id = " . $form_id . " ";
         }
         $sql .= 'AND (r.access_level <= ' . $user_level . ' OR r.access_level IS NULL)';
         $sql .= " ORDER BY ff.field_position ASC";
         // Execute the SQL to fetch the custom form fields
         $form_fields = Database::instance()->query($sql);
         foreach ($form_fields as $custom_formfield) {
             if ($data_only) {
                 // Return Data Only
                 $fields_array[$custom_formfield->id] = $custom_formfield->form_response;
             } else {
                 // Return Field Structure
                 $fields_array[$custom_formfield->id] = array('field_id' => $custom_formfield->id, 'field_name' => $custom_formfield->field_name, 'field_type' => $custom_formfield->field_type, 'field_default' => $custom_formfield->field_default, 'field_required' => $custom_formfield->field_required, 'field_maxlength' => $custom_formfield->field_maxlength, 'field_height' => $custom_formfield->field_height, 'field_width' => $custom_formfield->field_width, 'field_isdate' => $custom_formfield->field_isdate, 'field_ispublic_visible' => $custom_formfield->field_ispublic_visible, 'field_ispublic_submit' => $custom_formfield->field_ispublic_submit, 'field_response' => $custom_formfield->form_response);
             }
         }
     }
     // Garbage collection
     unset($form_fields);
     // Return
     return $fields_array;
 }
開發者ID:nemmy,項目名稱:Ushahidi_Web,代碼行數:69,代碼來源:customforms.php

示例9: single

 /**
  * Retrieve Single Marker
  */
 public function single($incident_id = 0)
 {
     $json = "";
     $json_item = "";
     $json_features = array();
     $incident_id = intval($incident_id);
     // Check if incident valid/approved
     if (!Incident_Model::is_valid_incident($incident_id, TRUE)) {
         throw new Kohana_404_Exception();
     }
     // Get the neigbouring incidents
     $neighbours = Incident_Model::get_neighbouring_incidents($incident_id, FALSE, 20, 100);
     if ($neighbours) {
         // Load the incident
         // @todo Get this fixed
         $marker = ORM::factory('incident')->where('incident.incident_active', 1)->find($incident_id);
         if (!$marker->loaded) {
             throw new Kohana_404_Exception();
         }
         // Get the incident/report date
         $incident_date = date('Y-m', strtotime($marker->incident_date));
         foreach ($neighbours as $row) {
             $link = url::base() . "reports/view/" . $row->id;
             $item_name = $this->get_title($row->incident_title, $link);
             $json_item = array();
             $json_item['type'] = 'Feature';
             $json_item['properties'] = array('id' => $row->id, 'name' => $item_name, 'link' => $link, 'category' => array(0), 'timestamp' => strtotime($row->incident_date));
             $json_item['geometry'] = array('type' => 'Point', 'coordinates' => array($row->longitude, $row->latitude));
             array_push($json_features, $json_item);
         }
         // Get Incident Geometries
         $geometry = $this->_get_geometry($marker->id, $marker->incident_title, $marker->incident_date);
         // If there are no geometries, use Single Incident Marker
         if (!count($geometry)) {
             // Single Main Incident
             $link = url::base() . "reports/view/" . $marker->id;
             $item_name = $this->get_title($marker->incident_title, $link);
             $json_item = array();
             $json_item['type'] = 'Feature';
             $json_item['properties'] = array('id' => $marker->id, 'name' => $item_name, 'link' => $link, 'category' => array(0), 'timestamp' => strtotime($marker->incident_date));
             $json_item['geometry'] = array('type' => 'Point', 'coordinates' => array($marker->location->longitude, $marker->location->latitude));
             array_push($json_features, $json_item);
         } else {
             foreach ($geometry as $g) {
                 array_push($json_features, $g);
             }
         }
     }
     Event::run('ushahidi_filter.json_single_features', $json_features);
     $json = json_encode(array("type" => "FeatureCollection", "features" => $json_features));
     header('Content-type: application/json; charset=utf-8');
     echo $json;
 }
開發者ID:nanangsyaifudin,項目名稱:HAC-2012,代碼行數:56,代碼來源:json.php

示例10: edit

 /**
  * Edit a report
  * @param bool|int $id The id no. of the report
  * @param bool|string $saved
  */
 public function edit($id = FALSE, $saved = FALSE)
 {
     $db = new Database();
     $this->template->content = new View('members/reports_edit');
     $this->template->content->title = Kohana::lang('ui_admin.create_report');
     // Setup and initialize form field names
     // JP: added additional form data for advanced settings
     $form = array('location_id' => '', 'form_id' => '', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'geometry' => array(), 'location_name' => '', 'country_id' => '', 'country_name' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'custom_field' => array(), 'incident_zoom' => '', 'incident_source' => '', 'incident_information' => '', 'form_data' => array());
     // Copy the form as errors, so the errors will be stored with keys
     // corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = $saved == 'saved';
     // Initialize Default Values
     $form['locale'] = Kohana::config('locale.language');
     //$form['latitude'] = Kohana::config('settings.default_lat');
     //$form['longitude'] = Kohana::config('settings.default_lon');
     $form['country_id'] = Kohana::config('settings.default_country');
     $form['incident_date'] = date("m/d/Y", time());
     $form['incident_hour'] = date('h');
     $form['incident_minute'] = date('i');
     $form['incident_ampm'] = date('a');
     // JP: If we are editing an existing report, given by $id,
     // we need to make sure we are using the correct form id.
     // Otherwise, we use the id of the default report (1).
     if ($id and Incident_Model::is_valid_incident($id, FALSE)) {
         $form['form_id'] = ORM::factory('incident', $id)->form_id;
     } else {
         $form['form_id'] = 1;
     }
     // Initialize custom field array
     $form_id = $form['form_id'];
     $form['custom_field'] = customforms::get_custom_form_fields($id, $form_id, TRUE);
     // JP: Grab additional form information for advanced settings.
     $form['form_data'] = customforms::get_custom_form($form_id);
     // Locale (Language) Array
     $this->template->content->locale_array = Kohana::config('locale.all_languages');
     // Time formatting
     $this->template->content->hour_array = $this->_hour_array();
     $this->template->content->minute_array = $this->_minute_array();
     $this->template->content->ampm_array = $this->_ampm_array();
     $this->template->content->stroke_width_array = $this->_stroke_width_array();
     // Get Countries
     $countries = array();
     foreach (ORM::factory('country')->orderby('country')->find_all() as $country) {
         // Create a list of all categories
         $this_country = $country->country;
         if (strlen($this_country) > 35) {
             $this_country = substr($this_country, 0, 35) . "...";
         }
         $countries[$country->id] = $this_country;
     }
     $this->template->content->countries = $countries;
     // Initialize Default Value for Hidden Field Country Name, just incase Reverse Geo coding yields no result
     $form['country_name'] = $countries[$form['country_id']];
     //GET custom forms
     $forms = array();
     foreach (ORM::factory('form')->where('form_active', 1)->find_all() as $custom_forms) {
         $forms[$custom_forms->id] = $custom_forms->form_title;
     }
     $this->template->content->forms = $forms;
     // Retrieve thumbnail photos (if edit);
     //XXX: fix _get_thumbnails
     $this->template->content->incident = $this->_get_thumbnails($id);
     // 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 = array_merge($_POST, $_FILES);
         // JP: Make sure we are using the correct form ID so that the page does not revert to the default form if it is reloaded.
         $form_id = $post['form_id'];
         // JP: Ensure that the advanced settings are correct.
         $form['form_data'] = customforms::get_custom_form($form_id);
         // JP: Add the description_active boolean to our post data so the appropriate validation rules can be added
         $post['description_active'] = $form['form_data']->description_active;
         if (reports::validate($post)) {
             // STEP 1: SAVE LOCATION
             $location = new Location_Model();
             reports::save_location($post, $location);
             // STEP 2: SAVE INCIDENT
             $incident = new Incident_Model($id);
             reports::save_report($post, $incident, $location->id);
             // STEP 2b: SAVE INCIDENT GEOMETRIES
             reports::save_report_geometry($post, $incident);
             // STEP 3: SAVE CATEGORIES
             reports::save_category($post, $incident);
             // STEP 4: SAVE MEDIA
             reports::save_media($post, $incident);
             // STEP 5: SAVE CUSTOM FORM FIELDS
             reports::save_custom_fields($post, $incident);
             // STEP 6: SAVE PERSONAL INFORMATION
             reports::save_personal_info($post, $incident);
             // Action::report_add / report_submit_members - Added a New Report
             Event::run('ushahidi_action.report_submit_members', $post);
             Event::run('ushahidi_action.report_edit', $incident);
             // SAVE AND CLOSE?
//.........這裏部分代碼省略.........
開發者ID:niiyatii,項目名稱:crowdmap,代碼行數:101,代碼來源:reports.php

示例11: _tag_media

 /**
  * Tag a news item to an incident.
  * 
  * @param int incidentid - The incident id.
  * @param string mediatype - The media type,video, picture,etc
  *
  * @return Array
  */
 private function _tag_media($incidentid, $mediatype)
 {
     if ($_POST) {
         // Check if incident ID exist
         $incidentid_exist = Incident_Model::is_valid_incident($incidentid);
         if (!$incidentid_exist) {
             return $this->set_error_message(array("error" => $this->api_service->get_error_msg(012)));
         }
         // Get the locationid for the incidentid
         $locationid = 0;
         $items = ORM::factory('incident')->select(array('location_id'))->where(array('incident.id' => $incidentid))->find();
         if ($items->count_all() > 0) {
             $locationid = $items->location_id;
         }
         $media = new Media_Model();
         //create media model object
         $url = '';
         $post = Validation::factory(array_merge($_POST, $_FILES));
         if ($mediatype == 2 or $mediatype == 4) {
             //require a url
             if (!$this->api_service->verify_array_index($this->request, 'url')) {
                 return $this->set_error_message(array("error" => $this->api_service->get_error_msg(01, 'url')));
             } else {
                 $url = $this->request['url'];
                 $media->media_link = $url;
             }
         } else {
             if (!$this->api_service->verify_array_index($this->request, 'photo')) {
                 $this->set_error_message(array("error" => $this->api_service->get_error_msg(01), 'photo'));
             }
             $post->add_rules('photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]');
             if ($post->validate(FALSE)) {
                 //assuming this is a photo
                 $filename = upload::save('photo');
                 $new_filename = $incidentid . "_" . $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);
                 $media->media_link = $new_filename . ".jpg";
                 $media->media_thumb = $new_filename . "_t.jpg";
             }
         }
         // Optional title & description
         $title = '';
         if ($this->api_service->verify_array_index($_POST, 'title')) {
             $title = $_POST['title'];
         }
         $description = '';
         if ($this->api_service->verify_array_index($_POST, 'description')) {
             $description = $_POST['description'];
         }
         $media->location_id = $locationid;
         $media->incident_id = $incidentid;
         $media->media_type = $mediatype;
         $media->media_title = $title;
         $media->media_description = $description;
         $media->media_date = date("Y-m-d H:i:s", time());
         $media->save();
         //save the thing
         // SUCESS!!!
         $ret = array("payload" => array("domain" => $this->domain, "success" => "true"), "error" => $this->api_service->get_error_msg(0));
         return $this->set_error_message($ret);
     } else {
         return $this->set_error_message(array("error" => $this->api_service->get_error_msg(03)));
     }
 }
開發者ID:Dirichi,項目名稱:Ushahidi_Web,代碼行數:77,代碼來源:MY_Tag_Media_Api_Object.php


注:本文中的Incident_Model::is_valid_incident方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。