Ejemplo n.º 1
0
 function prepare_items()
 {
     // number of items per page
     $per_page = 1000;
     // define column headers
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // retrieve data
     // TODO select data for current page only
     $data = \Podlove\Model\FileType::all();
     // get current page
     $current_page = $this->get_pagenum();
     // get total items
     $total_items = count($data);
     // extrage page for current page only
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     // add items to table
     $this->items = $data;
     // register pagination options & calculations
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
    private function form_template($episode_asset, $action, $button_text = NULL)
    {
        $raw_formats = \Podlove\Model\FileType::all();
        $formats = array();
        foreach ($raw_formats as $format) {
            $formats[$format->id] = array('title' => $format->title(), 'name' => $format->name, 'extension' => $format->extension, 'type' => $format->type);
        }
        $format_optionlist = array_map(function ($f) {
            return array('value' => $f['title'], 'attributes' => 'data-type="' . $f['type'] . '" data-extension="' . $f['extension'] . '" data-name="' . $f['name'] . '"');
        }, $formats);
        $form_args = array('context' => 'podlove_episode_asset', 'hidden' => array('episode_asset' => $episode_asset->id, 'action' => $action), 'attributes' => array('id' => 'podlove_episode_assets'), 'submit_button' => false, 'form_end' => function () {
            echo "<p>";
            submit_button(__('Save Changes'), 'primary', 'submit', false);
            echo " ";
            submit_button(__('Save Changes and Continue Editing', 'podlove'), 'secondary', 'submit_and_stay', false);
            echo "</p>";
        });
        \Podlove\Form\build_for($episode_asset, $form_args, function ($form) use($format_optionlist) {
            $f = new \Podlove\Form\Input\TableWrapper($form);
            if ($form->object->file_type_id) {
                $current_file_type = Model\FileType::find_by_id($form->object->file_type_id)->type;
            } else {
                $current_file_type = '';
            }
            ?>
			<tr class="row_podlove_episode_asset_type">
				<th scope="row" valign="top">
					<label for="podlove_episode_asset_type"><?php 
            echo __('Asset Type', 'podlove');
            ?>
</label>
				</th>
				<td>
					<select name="podlove_episode_asset_type" id="podlove_episode_asset_type">
						<option><?php 
            echo __('Please choose ...', 'podlove');
            ?>
</option>
						<?php 
            foreach (Model\FileType::get_types() as $type) {
                ?>
							<option value="<?php 
                echo $type;
                ?>
" <?php 
                selected($type, $current_file_type);
                ?>
><?php 
                echo $type;
                ?>
</option>	
						<?php 
            }
            ?>
					</select>
					<div id="option_storage" style="display:none"></div>
				</td>
			</tr>
			<?php 
            $f->select('file_type_id', array('label' => __('File Format', 'podlove'), 'description' => __('', 'podlove'), 'options' => $format_optionlist));
            $f->string('title', array('label' => __('Title', 'podlove'), 'description' => __('Description to identify the media file type to the user in download buttons.', 'podlove'), 'html' => array('class' => 'regular-text required podlove-check-input')));
            $f->checkbox('downloadable', array('label' => __('Downloadable', 'podlove'), 'description' => sprintf('Allow downloads for users.', 'podlove'), 'default' => true));
            ?>
			<tr>
				<th colspan="2">
					<h3><?php 
            echo __('Asset File Name', 'podlove');
            ?>
</h3>
				</th>
			</tr>
			<?php 
            $f->string('suffix', array('label' => __('File Name Suffix', 'podlove'), 'description' => __('Optional. Is appended to file name after episode slug.', 'podlove'), 'html' => array('class' => 'regular-text required podlove-check-input')));
            ?>
			<tr class="row_podlove_asset_url_preview">
				<th>
					<?php 
            echo __('URL Preview', 'podlove');
            ?>
				</th>
				<td>
					<div id="url_preview" style="font-size: 1.5em"></div>
					<div id="url_template" style="display: none;"><?php 
            echo Model\Podcast::get()->get_url_template();
            ?>
</div>
				</td>
			</tr>
			<?php 
        });
        // hidden fields for JavaScript
        ?>
		<input type="hidden" id="podlove_show_media_file_base_uri" value="<?php 
        echo Model\Podcast::get()->media_file_base_uri;
        ?>
">
		<?php 
    }
Ejemplo n.º 3
0
    private function form_template($episode_asset, $action, $button_text = NULL)
    {
        $raw_formats = \Podlove\Model\FileType::all();
        $formats = array();
        foreach ($raw_formats as $format) {
            $formats[$format->id] = array('title' => $format->title(), 'extension' => $format->extension);
        }
        $format_optionlist = array_map(function ($f) {
            return $f['title'];
        }, $formats);
        $form_args = array('context' => 'podlove_episode_asset', 'hidden' => array('episode_asset' => $episode_asset->id, 'action' => $action), 'attributes' => array('id' => 'podlove_episode_assets'));
        \Podlove\Form\build_for($episode_asset, $form_args, function ($form) use($format_optionlist) {
            $f = new \Podlove\Form\Input\TableWrapper($form);
            $f->select('file_type_id', array('label' => __('File Format', 'podlove'), 'description' => __('', 'podlove'), 'options' => $format_optionlist));
            $f->string('title', array('label' => __('Title', 'podlove'), 'description' => __('Description to identify the media file type to the user in download buttons.', 'podlove'), 'html' => array('class' => 'regular-text required')));
            $f->string('url_template', array('label' => __('URL Template', 'podlove'), 'description' => sprintf(__('Preview: %s'), '<span class="url_template_preview"></span><br/>', 'podlove'), 'html' => array('class' => 'large-text required'), 'default' => '%media_file_base_url%%episode_slug%.%format_extension%'));
            $f->checkbox('downloadable', array('label' => __('Downloadable', 'podlove'), 'description' => sprintf('Allow downloads for users.', 'podlove'), 'default' => true));
        });
        // hidden fields for JavaScript
        ?>
		<input type="hidden" id="podlove_show_media_file_base_uri" value="<?php 
        echo Model\Podcast::get_instance()->media_file_base_uri;
        ?>
">
		<?php 
    }