/** * @param array $raw * @return Batch */ protected function do_create_object(array $raw, $args = array()) { $obj = new Batch($raw['ID']); $user = $this->user_dao->find($raw['post_author']); $obj->set_guid($raw['guid']); $obj->set_title($raw['post_title']); $obj->set_creator($user); $obj->set_date($raw['post_date']); $obj->set_date_gmt($raw['post_date_gmt']); $obj->set_modified($raw['post_modified']); $obj->set_modified_gmt($raw['post_modified_gmt']); $obj->set_status($raw['post_status']); // Skip loading batch content? $skip_content = isset($args['skip_content']) ? $args['skip_content'] : false; $content = $this->get_batch_content($raw, $skip_content); $content = unserialize(base64_decode($content)); /* * Previously $content would have contained a Batch object. This check * deals with legacy batches. */ if (!is_array($content)) { $content = array(); } if (isset($content['attachments'])) { $obj->set_attachments($content['attachments']); } if (isset($content['users'])) { $obj->set_users($content['users']); } if (isset($content['posts'])) { $obj->set_posts($content['posts']); } if (isset($content['options'])) { $obj->set_options($content['options']); } if (isset($content['custom_data'])) { $obj->set_custom_data($content['custom_data']); } if (isset($content['post_rel_keys'])) { $obj->set_post_rel_keys($content['post_rel_keys']); } return $obj; }
/** * Prepare batch with relevant content. * * @param Batch $batch */ public function prepare(Batch $batch) { // Batch not yet created, nothing to prepare. if (!$batch->get_id()) { return; } $post_ids = array(); $batch->set_post_rel_keys(apply_filters('sme_post_relationship_keys', array())); // Clean batch from any old content. $batch->set_attachments(array()); $batch->set_users(array()); $batch->set_posts(array()); $batch->set_options(array()); // Get IDs of posts user has selected to include in this batch. $meta = $this->batch_dao->get_post_meta($batch->get_id(), 'sme_selected_post'); // Ensure that we got an array back when looking for posts IDs in DB. if (is_array($meta)) { $post_ids = $meta; } $this->add_table_prefix($batch); $this->add_posts($batch, $post_ids); $this->add_users($batch); $this->add_options($batch); // Add the admin URL of content stage to the batch. $batch->add_custom_data('sme_content_stage_admin_url', admin_url()); }