예제 #1
0
 /**
  * 
  */
 public static function do_files_upload($entity_data, $file_upload_param)
 {
     $count = 0;
     $entity_data['files_uploaded'] = array();
     $current_user = wp_get_current_user();
     /*$validation_errors = ContentFileUploadValidatorAPI::validate_file_upload($file_upload_param);
             if(!empty($validation_errors)) {
                 $entity_data['has_errors'] = true;
                 foreach ($validation_errors['file_upload_error_msg'] as $key => $value) {
                   $entity_data['message'] = $value;
                   LogUtils::shadow_log($entity_data['message']);
                 }
                 return $entity_data;
             }
     */
     if (!empty($_FILES)) {
         foreach ($_FILES[$file_upload_param]['name'] as $filename) {
             if ($_FILES[$file_upload_param]['tmp_name'][$count] != '') {
                 // Use the WordPress API to upload the file
                 $upload = wp_upload_bits($_FILES[$file_upload_param]['name'][$count], null, file_get_contents($_FILES[$file_upload_param]['tmp_name'][$count]));
                 if (isset($upload['error']) && $upload['error'] != 0) {
                     wp_die('There was an error uploading your file. The error is: ' . $upload['error']);
                 } else {
                     $file_size = $_FILES[$file_upload_param]["size"][$count];
                     $file_size = $file_size / 1024;
                     $file_size = number_format((double) $file_size, 2, '.', '');
                     $date_obj = new DateTime();
                     $file_obj = array('file_name' => $_FILES[$file_upload_param]['name'][$count], 'file_code' => $entity_data['entity_code'], 'file_url' => $upload['url'], 'file_size' => $file_size, 'file_owner' => $entity_data['id'], 'file_created_date' => $date_obj->format('M j, Y, H:i'), 'file_type' => 'FILE', 'file_mime_type' => '', 'file_description' => '');
                     // Post information
                     $post_information = array('post_title' => $file_obj['file_name'], 'post_content' => $file_obj['file_description'], 'post_type' => 'content_file', 'post_status' => 'publish');
                     // Insert the order into the database
                     $post_id = wp_insert_post($post_information);
                     if ($entity_data['entity_artifact_name'] == 'party') {
                         $image_entity_data = EntityAPIUtils::init_entity_data('partyimage');
                         $image_entity_data['file_party'] = $entity_data['id'];
                         self::save_image($entity_data, $image_entity_data, $file_obj);
                     }
                     if ($entity_data['entity_artifact_name'] == 'contentorder') {
                         $image_entity_data = EntityAPIUtils::init_entity_data('contentorderfile');
                         $image_entity_data['file_content_order'] = $entity_data['id'];
                         self::save_image($entity_data, $image_entity_data, $file_obj);
                     }
                     array_push($entity_data['files_uploaded'], $file_obj);
                 }
                 // end
             }
             $count++;
         }
     }
     return $entity_data;
 }
 /**
  * 
  */
 public static function create_individual($content_user_data)
 {
     $entity_data = EntityAPIUtils::init_entity_data('person');
     $entity_data['edit_mode'] = true;
     $entity_data['role'] = $content_user_data['role'];
     $entity_data['email'] = $content_user_data['user_login'];
     $entity_data['last_name'] = $content_user_data['last_name'];
     $entity_data['first_name'] = $content_user_data['first_name'];
     if (isset($content_user_data['description'])) {
         $entity_data['description'] = $content_user_data['description'];
     }
     if (isset($content_user_data['display_name'])) {
         $entity_data['display_name'] = $content_user_data['display_name'];
     }
     $entity_data = PartyAPI::do_create_individual($entity_data);
     return $entity_data;
 }
 /**
  *
  */
 public static function do_create_party($entity_data, $party_type)
 {
     $party_data = EntityAPIUtils::init_entity_data('party');
     $party_data['edit_mode'] = true;
     $party_data['role'] = $entity_data['role'];
     $party_data['name'] = $entity_data['name'];
     $party_data['party_type'] = $party_type['id'];
     $party_data['user_name'] = $entity_data['email'];
     // Process the display
     if (isset($entity_data['display_name'])) {
         $party_data['display_name'] = $entity_data['display_name'];
     } else {
         $party_data['display_name'] = $entity_data['name'];
     }
     // If the description is not available the we form
     // one from the name
     if (!isset($entity_data['description'])) {
         $party_data['description'] = $entity_data['name'];
     } else {
         $party_data['description'] = $entity_data['description'];
     }
     return self::do_create_entity($party_data);
 }
 /**
  *
  */
 public static function find_child_entities_ajax()
 {
     if (!isset($_POST['artifact']) || !isset($_POST['parent_id']) || !isset($_POST['parent_field_name'])) {
         return array();
     }
     $parent_id = EntityRequestUtils::get_query_string_field('parent_id');
     $artifact_name = EntityRequestUtils::get_query_string_field('artifact');
     $parent_field_name = EntityRequestUtils::get_query_string_field('parent_field_name');
     $search_results = EntityAPI::find_by_criteria($artifact_name, array($parent_field_name => $parent_id));
     ArtficatAjaxRequestProcessorUtils::do_after_ajax_find(EntityAPIUtils::init_entity_data($artifact_name), $search_results);
 }
 /**
  *
  */
 public static function do_before_ajax_delete()
 {
     // Ensure we have a valid form
     if (!isset($_POST['submitted']) && !isset($_POST['post_nonce_field']) && !wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
         // Nounce field did not validate
         wp_send_json_error(array('message' => "Invalid form operation!"));
     }
     // Ensure we have a valid ID
     if (!isset($_POST['id'])) {
         wp_send_json_error(array('message' => "Entity identifier missing"));
     }
     $artifact_name = EntityRequestUtils::get_artifact_name();
     $entity_data = EntityAPIUtils::init_entity_data($artifact_name);
     return $entity_data;
 }