I am creating a form and trying to upload multiple image .All thing right with single image . when I am trying to upload multiple image,Then I receive only one image in output .
Here is my View file.
<div class="from-control-div">
<?php echo $this->Form->create('Post', array('type' => 'file','id'=>'unitform','class'=>'form-horizontal','role'=>'form','url' => array('controller' => 'posts', 'action' => 'savepost')));?>
<div class="from-div-bottom">
<div class="form-group">
<label class="col-sm-4 control-label">File Upload</label>
<div class="col-sm-6" id="more-files">
<?php echo $this->Form->input('files.',array('type'=>'file','label' => false,'placeholder' => 'Upload images','id'=>"inputFile",'multiple','onchange'=>'readURL(this)'));?>
<!--<div id="fileList"></div>-->
</div>
<a class="col-sm-2 pull-right" style="font-weight:bold;" id="add-more"><i class="fa fa-plus"></i> Add More</a>
</div>
</div>
</form>
After this here is my controller.If I print print_r($data); then output is single array. No multiple array receive .Any help for me
Array ( [0] => Array ( [name] => download.jpg [type] => image/jpeg [tmp_name] => /tmp/phpX3Oy32 [error] => 0 [size] => 12988 ) )
public function savepost() {
if (count($this->request->data) > 0) {
$fileNames = '';
if (isset($this->request->data['Post']['files']) && count($this->request->data['Post']['files']) > 0) {
$data=$this->request->data['Post']['files'];
print_r($data);
$fileNames = array();
foreach ($this->request->data['Post']['files'] as $filedata) {
if(isset($filedata["name"]) && ($filedata["name"] !='')){
$upload_dir = FILE_UPLOAD_PATH;
$original = explode('.', $filedata["name"]);
$extension = array_pop($original);
$newname = time() . '.' . $extension;
if (file_exists($upload_dir . $newname)) {
unlink($upload_dir . $newname);
}
if (move_uploaded_file($filedata["tmp_name"], $upload_dir . $newname)) {
$fileNames[] = $newname;
print_r($fileNames);
}
}
}
}
}
}
public function savepost() {
if(isset($this->request->data['multifiles'])){
$file_name_all="";
for($i=0; $i<count($this->request->data['multifiles']); $i++){
if(!empty($this->request->data['multifiles'][$i]['name'])){
$file = $this->request->data['multifiles'][$i];
$file['name'] = time() . '-' . str_replace(' ', '_', $file['name']);
$uploadPath = WWW_ROOT . 'img/ ';
$fileName = $file['name'];
$uploadFile = $uploadPath.$fileName;
$file_name_all.= $file['name'].",";
if($file['name']){
move_uploaded_file($file['tmp_name'], $uploadFile);
}
}
}
}
}
in my code it is working.
Related
here I am adding attach file input in the add_incident form, but after submitting form the file name is not saved in the database and also the file is not saved in upload folder.the uploads folder path is correct. running
echo "<pre>";
print_r($_FILES);
die;
Output is:
Array
(
[filename] => Array
(
[name] => mot-testing-station 2.eps
[type] => application/postscript
[tmp_name] => /opt/lampp/temp/phpMSzQT6
[error] => 0
[size] => 405159
)
)
but it doesn't give any output and it just continue to submit the form and create new incident.
can anyone please help me what am I missing ?
view.php
<h2 class="heading">Add Incidents</h2>
<?php echo form_open_multipart('incidents_add'); ?>
<div class="row">
<div class="form-group col-md-4">
<label for="email">Incidents ID</label>
<input type="text" class="form-control" id="T_id" placeholder="Name" name="T_id"value="<?php echo $T_id;?>" readonly >
</div>
<div >
<input id = "choose_image" type="file" name="filename" size="20" />
</div>
<div class="col-md-12">
<div class="btn-section float-right">
<button class="btn btn-outline-primary" value="Create"><i class="fa fa-plus-circle" aria-hidden="true"></i> Create</button>
</div>
</div>
</div>
</form>
controller.php
function add()
{
$existing_count = $this->incidents_model->get_task_count();
$data['T_id'] = 'T'.sprintf("%'.03d\n",$existing_count+1);
$this->form_validation->set_rules('Status', 'Status ', 'required');
$this->form_validation->set_rules('Priority', 'Priority' , 'required');
$this->form_validation->set_rules('Description', 'Description' , 'required');
$data['incidents'] = $this->incidents_model->getIncidentsDetails();
$data['T_id'] = $this->incidents_model->get_task_count();
$data['company_name'] = $this->incidents_model->getAllCompanyName();
if (isset($_FILES['filename'])){
// print_r($_FILES);
// die;
$file_name = time().'_'.$_FILES['filename']['name'];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|dox|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['file_name'] = $file_name;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('filename'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/incidents/add', $error);
}
else
{
$data = array('file' =>$this->upload->data());
$this->load->view('admin/incidents/add', $data);
}
}
if ($this->form_validation->run() ==true)
{
$this->incidents_model->add();
$this->session->set_flashdata ('success','Incidents Added Sucessfully');
redirect('admin/incidents/index' ,$data);
}
else{
$this->load->view('admin/incidents/add', $data);
}
}
So here is how I solved the issue, I have added
$data['file'] = $this->incidents_model->add($image_name);
and that solved my issue.
controller:
function add()
{
$existing_count = $this->incidents_model->get_task_count();
$data['T_id'] = 'T'.sprintf("%'.03d\n",$existing_count+1);
$this->form_validation->set_rules('T_id', 'Tasks Id', 'required');
$this->form_validation->set_rules('Tname', 'Tasks Name' , 'required');
$this->form_validation->set_rules('Cname', 'Company Name ', 'required');
$this->form_validation->set_rules('Pname', 'Project Name' , 'required');
$this->form_validation->set_rules('Pversion', 'Project Version', 'required');
$this->form_validation->set_rules('Rform', 'Report Form ', 'required');
$this->form_validation->set_rules('Internal', 'Internal ', 'required');
$this->form_validation->set_rules('Assignto', 'Assign To' , 'required');
$this->form_validation->set_rules('Sdate', 'Start Date', 'required');
$this->form_validation->set_rules('Edate', 'End Date' , 'required');
$this->form_validation->set_rules('Status', 'Status ', 'required');
$this->form_validation->set_rules('Priority', 'Priority' , 'required');
$this->form_validation->set_rules('Description', 'Description' , 'required');
$data['incidents'] = $this->incidents_model->getIncidentsDetails();
$data['T_id'] = $this->incidents_model->get_task_count();
$data['company_name'] = $this->incidents_model->getAllCompanyName();
if ($this->form_validation->run() ==true)
{
if (isset($_FILES['filename']))
{
// echo "<pre>";
// print_r($_FILES);
// die;
$file_name = time().'_'.$_FILES['filename']['name'];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|dox|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['overwrite'] = TRUE;
$config['file_name'] = $file_name;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('filename'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/incidents/add', $error);
}
else
{
$image_data = $this->upload->data();
$image_name = $image_data['file_name'];
$data =array(
'file' => $image_data['file_name']
);
$data['file'] = $this->incidents_model->add($image_name);
}
}
$this->session->set_flashdata ('success','Incidents Added Sucessfully');
redirect('admin/incidents/index' ,$data);
}
else{
$this->load->view('admin/incidents/add', $data);
}
}
and modified my add function in model as below:
function add()
{
$arr['incidents_id'] = $this->input->post('T_id');
$arr['incident_name'] = $this->input->post('Tname');
$arr['company_name'] = $this->input->post('Cname');
$arr['project_name'] = $this->input->post('Pname');
$arr['project_version'] = $this->input->post('Pversion');
$arr['report_form'] = $this->input->post('Rform');
$arr['internal'] = $this->input->post('Internal');
$arr['assign_to'] = $this->input->post('Assignto');
$arr['start_date'] = $this->input->post('Sdate');
$arr['end_date'] = $this->input->post('Edate');
$arr['status'] = $this->input->post('Status');
$arr['priority'] = $this->input->post('Priority');
$arr['description'] = $this->input->post('Description');
$arr['initial_status'] = 0 ;
$arr['flag'] = 1;
$arr['file'] = time().'_'.$_FILES['filename']['name'];
$this->db->insert('incidents',$arr);
$insert_id = $this->db->insert_id();
$arr1['incident_id'] = $insert_id;
$arr1['incident_status'] = $this->input->post('Status');
$arr1['incident_description'] = $this->input->post('Description');
$this->db->insert('incident_status',$arr1);
}
Goodnight (or good morning),
I trying to upload multiple files at the same time. I am following the cookbook instructions to build the solution. I always got first file (not and array of files).
Here is my view code...
<?php
/**
* #var \App\View\AppView $this
* #var \App\Model\Entity\Upload $upload
*/
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('List Uploads'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column-responsive column-80">
<div class="uploads form content">
<?= $this->Form->create($upload, ['type' => 'file']) ?>
<fieldset>
<legend><?= __('Add Upload') ?></legend>
<?php
echo $this->Form->control('name');
echo $this->Form->control('document_type_id', ['options' => $documentTypes]);
echo $this->Form->control('period_id', ['options' => $periods]);
echo $this->Form->control('user_id', ['options' => $users]);
echo $this->Form->control('documents', ['type' => 'file', 'label' => __('Choose PDF Files'), 'accept' => 'application/pdf', 'multiple' => 'multiple']);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
And here is my controller code...
public function add()
{
$upload = $this->Uploads->newEmptyEntity();
if ($this->request->is('post')) {
$upload = $this->Uploads->patchEntity($upload, $this->request->getData());
if ($this->Uploads->save($upload)) {
if (!is_dir($this->Parameters->findByName('document_directory')->first()->toArray()['value'] )) {
mkdir($this->Parameters->findByName('document_directory')->first()->toArray()['value'], 0776, true);
}
$documents = $this->request->getData('documents');
$this->loadModel('Dockets');
$dockets = $this->Dockets->findByDocketStateId(1);
$documents_ok = 0;
$documents_nok = 0;
$dockets_without_document = 0;
foreach($documents as $documents_key => $document_to_save)
{
foreach($dockets as $dockets_key => $docket)
{
$contents = file_get_contents($document_to_save);
$pattern = str_replace('-', '', $pattern);
$pattern = str_replace('', '', $pattern);
$pattern = preg_quote($docket->cuit, '/');
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
$documentsTable = $this->getTableLocator()->get('Documents');
$document = $documentsTable->newEmptyEntity();
$document->upload_id = $upload->id;
$document->document_type_id = $upload->document_type_id;
$document->period_id = $upload->period_id;
$document->docket_id = $docket->id;
$document->user_id = $this->getRequest()->getAttribute('identity')['id'];
if ($documentsTable->save($document)) {
if (!is_dir($this->Parameters->findByName('document_directory')->first()->toArray()['value'] )) {
mkdir($this->Parameters->findByName('document_directory')->first()->toArray()['value'], 0776, true);
}
$fileobject = $this->request->getData('document');
$destination = $this->Parameters->findByName('document_directory')->first()->toArray()['value'] . 'document_' . $document->id . '.pdf';
// Existing files with the same name will be replaced.
$fileobject->moveTo($destination);
}
$this->Flash->error(__('The document could not be saved. Please, try again.'));
$documents_ok = $documents_ok + 1;
unset($dockets[$dockets_key]);
unset($documents[$documents_key]);
break;
}
}
}
if(!empty($documents)){
//print_r($documents);
$documents_nok = count($documents);
unset($documents);
}
if(!empty($dockets)){
$dockets_without_document = count($dockets);
unset($dockets);
}
$message = __('There were processed ') . $documents_ok . __(' documents succesfully. ') . $documents_nok . __(' documents did not math with a docket. And ') . $dockets_without_document . __(' active dockets ddid not not have a document.');
$this->Flash->success(__('The upload has been saved. ') . $message);
return $this->redirect(['action' => 'view', $upload->id]);
}
$this->Flash->error(__('The upload could not be saved. Please, try again.'));
}
$documentTypes = $this->Uploads->DocumentTypes->find('list', ['keyField' => 'id',
'valueField' => 'document_type',
'limit' => 200]);
$periods = $this->Uploads->Periods->find('list', ['keyField' => 'id',
'valueField' => 'period',
'limit' => 200]);
$users = $this->Uploads->Users->find('list', ['keyField' => 'id',
'valueField' => 'full_name',
'conditions' => ['id' => $this->getRequest()->getAttribute('identity')['id']],
'limit' => 200]);
$this->set(compact('upload', 'documentTypes', 'periods', 'users'));
}
Can you help me to understand what I doing wrong?
Thanks,
Gonzalo
When using PHP, multi-file form inputs must have a name with [] appended, otherwise PHP isn't able to parse out multiple entries, they will all have the same name, and PHP will simply use the last occurrence of that name.
echo $this->Form->control('documents', [
'type' => 'file',
'label' => __('Choose PDF Files'),
'accept' => 'application/pdf',
'multiple' => 'multiple',
'name' => 'documents[]',
]);
Furthermore the following line:
$fileobject = $this->request->getData('document');
should probably be more like this, as there a) is no document field and b) even if there were, you most likely wouldn't want to process the same file over and over again:
$fileobject = $documents[$documents_key];
Also make sure that you have proper validation in place for the uploaded files, even if you don't seem to use the user provided file information, you should still make sure that you've received valid data!
I have set form validation in my project. My all form validation is working but I can not display file input validation error message. The file is upload properly, it doesn't show any error when I upload an invalid file. I try a lot of ways but anythings are not working.
I give here only file uploading related code.
My controller
$config = [
'upload_path'=>'./uploads/image/',
'allowed_types'=>'jpg|png',
'max_size' => '400',
'overwrite' => FALSE
];
$this->load->library('upload', $config);
if(!($this->form_validation->run() && $this->upload->do_upload()))
{
$view = array('error' => $this->upload->display_errors());
$view['admin_view'] = "admin/add_books";
$this->load->view('layouts/admin_layout', $view);
}
MY model
public function add_books()
{
$data = $this->upload->data();
$image_path = base_url("uploads/image/".$data['raw_name'].$data['file_ext']);
$data = array(
'book_name' => $this->input->post('book_name'),
'description' => $this->input->post('description'),
'author' => $this->input->post('author'),
'publisher' => $this->input->post('publisher'),
'price' => $this->input->post('price'),
'quantity' => $this->input->post('quantity'),
'categoryId' => $this->input->post('categoryId'),
'book_image' => $image_path,
'userId' => $this->session->userdata('id'),
'status' => $this->input->post('status')
);
$insert_book = $this->db->insert('books', $data);
return $insert_book;
}
My view
<div class="form-group row">
<label for="book_image" class="col-sm-2 col-form-label">Book image</label>
<div class="col-sm-6">
<?= form_upload(['name'=>'userfile', 'class'=>'form-control'])?>
<div class="text-secondary">* Upload PNG, JPG format. Image should not be more than 400KB</div>
</div>
<div class="col-sm-4">
<div class="text-danger form-error"><?= form_error('userfile')?></div>
</div>
</div>
How it can be fixed?
I think you should separate $this->form_validation->run() and $this->upload->do_upload()
$view = array();
if($this->form_validation->run() == true){
if(!$this->upload->do_upload('userfile')){
$view['error'] = $this->upload->display_errors();
}
}else{
$view['error'] = validation_errors();
}
if(array_key_exists('error', $view)){
$view['admin_view'] = "admin/add_books";
$this->load->view('layouts/admin_layout', $view);
}else{
//Insert the record
}
In wordpress I have made a custom post type. So for custom post type my code looks like this
add_action( 'init', 'broker_post_type' );
function broker_post_type() {
register_post_type( 'new_broker',
array(
'labels' => array(
'name' => __( 'Brands' ),
'singular_name' => __( 'Brand' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
)
);
}
To show the contents of custom posts through shortcode I have done like this
function display_broker_posts() {
$args = array(
'post_type' => 'new_broker',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page'=> -1,
);
$dee_bios = new WP_Query( $args );
if( $dee_bios->have_posts() ):
$dee_output = '<div id="brokers-wrap">';
$dee_output .= '<div id="brokers-bg-wrap">';
$dee_output .= '<div class="brokers-content">';
$dee_output .= '<div class="brokers-left-content">';
while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
if( $dee_bios->current_post == 0 || ( $dee_bios->current_post % 2 ) == 0 ) {
$dee_output .= '<a class="branding first" href=""><div class="one-half first">';
}
else {
$dee_output .= '<a href="" class="branding"><div class="one-half">';
}
$dee_output .= get_the_post_thumbnail( $dee_bios->post->ID,'small', 'bios', array( 'class' => 'alignleft' ) );
$dee_output .= '<span></span>';
// $dee_output .= '<p><strong>' . get_the_title() . ',</strong> ' . get_the_content() . '</p>';
$dee_output .= '</div><!--end .one-half-->';
endwhile;
$dee_output .= '<div class="clear"></div><!--clear all floats-->';
$dee_output .= '</div><!-- end #bios-->';
endif;
wp_reset_postdata();
return $dee_output;
}
add_shortcode( 'display_brokers', 'display_broker_posts' );
Here its working fine. I can see the featured image in my page by using shortcode. But lets say I have 20 custom posts and I want that the first 6 will show in a different div and another 14 in another div. So can someone kindly tell me how to do this? Any help will be really appreciable. Thanks
How about something like this:
$dee_bios = new WP_Query( $args );
$i = 0;
if( $dee_bios->have_posts() ):
while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
if ($i ==0) {
$dee_output .= '<div id="first_broker_div">';
} elseif ($i == 6) {
$dee_output .= '</div><div id="second_broker_div">';
}
$dee_output .= //Your post content
$i++;
endwhile;
$dee_output .= '</div>';
endif;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Is there a good tutorial / instructions for the CakeDC ratings plugin anywhere? I'm 4 hours in and still no end in site - the read-me is useless.
Here is some code that I used to get the ratings plugin working. It is all Ajax, so I added one hack to the RatingHelper to avoid showing a "Rate!" button, just add submit=>false to the options.
if ($options['createForm']) {
if (!empty($options['target']) && !empty($options['createForm']['url']) && !empty($options['createForm']['ajaxOptions'])) {
$ajaxOptions = array_merge(array('url' => $options['createForm']['url']), $options['createForm']['ajaxOptions']);
$result .= $this->Js->submit(__d('ratings', 'Rate!'), $ajaxOptions) . "\n";
$flush = true;
} elseif ( !isset($options['submit']) || !empty($options['submit']) ) {
if(empty($options['submit'])) {
$result .= $this->Form->submit(__d('ratings', 'Rate!')) . "\n";
} else {
$result .= $this->Form->submit($options['submit']) . "\n";
}
}
$result .= $this->Form->end() . "\n";
if ($flush) {
$this->Js->writeBuffer();
}
}
I have an index view that is showing a bunch of car models and I show an overall rating and the current users rating:
<?php foreach ($carmodels as $carmodel): ?>
<tr>
<td><?php echo h($carmodel['Carmodel']['id']); ?> </td>
<td><?php echo h($carmodel['Carmodel']['name']); ?> </td>
<td>
<?php echo $this->Html->link($carmodel['Make']['name'], array('controller' => 'makes', 'action' => 'view', $carmodel['Make']['id'])); ?>
</td>
<td>
<?php $overall_div = 'overall-rating' . $carmodel['Carmodel']['id']; ?>
<div id="<?php echo $overall_div; ?>">
<?php
echo $this->element('rating', array('rating' => $carmodel['Carmodel']['rating']));
?>
</div>
</td>
<td>
<?php
$msg_div = 'rating-msg' . $carmodel['Carmodel']['id'];
$rating = 0;
if (!empty($carmodel['Rating'])) {
$rating = $carmodel['Rating'][0]['value'];
}
echo $this->Rating->display(array(
'item' => $carmodel['Carmodel']['id'],
'type' => 'radio',
'stars' => 5,
'value' => $rating,
'submit' => false,
'createForm' => array(
'id' => 'CarmodelsRatingsDemoForm' . $carmodel['Carmodel']['id'],
'url' => array('action' => 'ratings_update', $carmodel['Carmodel']['id']),
'class' => 'rating',
'update-overall' => '#' . $overall_div,
'update-msg' => '#' . $msg_div,
)));
?>
<div id="<?php echo $msg_div; ?>" class="label label-info hidden">
<button class="close" data-dismiss="alert" type="button">×</button>
<div class="msg-default"><?php echo __('One moment...'); ?></div>
<div class="msg-result"></div>
</div>
</td>
Then I have some Jquery goodness to create the stars and then react on the click
$(document).ready(function(){
$('form.rating').stars({
cancelShow:true,
callback: function(ui, type, new_value) {
var values = ui.$form.serializeArray();
values.push({
'name': 'rating',
'value': new_value
});
values = jQuery.param(values);
var msg = ui.$form.attr('update-msg');
$(msg).removeClass('hidden');
$(msg).show();
$(msg).find('div.msg-default').show();
$(msg).find('div.msg-result').hide();
$.ajax({
'type': 'POST',
'dataType': 'json',
'url': ui.$form.attr('action'),
'data': values
}).done(function(data) {
var overall_rating = ui.$form.attr('update-overall');
if(overall_rating && data['overall_rating']){
$(overall_rating).html(data['overall_rating']);
}
if(msg){
$(msg).find('div.msg-default').hide();
if(data['msg']) {
$(msg).find('div.msg-result').show();
$(msg).find('div.msg-result').html(data['msg']);
window.setTimeout(function() {
$(msg).addClass('hidden');
}, 2000);
} else {
$(msg).addClass('hidden');
}
}
if(data['user_rating'] && data['user_rating']>0) {
ui.select(parseInt(data['user_rating']));
}
});
}
});
})
Plus I need a little snippet of css to hide the radio button labels that Cake adds.
form.rating > div.input {
display: none;
}
Then in the controller, I check if the user has rated the item before and save if not. I return a json array that contains a rendered element of the overall rating, the users rating (new or existing) and a string message to show in a div that disappears after 2 seconds.
public function ratings_update($id = null) {
$this->Carmodel->id = $id;
if (!$this->Carmodel->exists()) {
throw new NotFoundException(__('Invalid carmodel'));
}
$ratings = $this->Carmodel->isRatedBy($id, 1);
if (!$ratings) {
$this->Carmodel->rate($id, 1, $this->request->data['rating'], array('values' => array_combine(range(1, 5), range(1, 5))));
$json['msg'] = __('Thank you');
} else {
if ($this->request->data['rating'] == 0) {
$this->Carmodel->removeRating($id, 1);
$json['msg'] = __('Rating removed');
} else {
$json['msg'] = __('Already rated');
}
}
$this->set('rating', $this->Carmodel->field('rating'));
$ratings = $this->Carmodel->isRatedBy($id, 1);
$my_rating = 0;
if (!empty($ratings)) {
$my_rating = $ratings['Rating']['value'];
}
$this->autoRender = false;
App::uses('View', 'View');
$View = new View($this);
$response = $View->render('/Elements/rating', 'ajax');
$json['overall_rating'] = $response;
$json['user_rating'] = $my_rating;
return json_encode($json);
}
Here is the code for the element that shows stars for the overall rating, it probably should be part of the helper.
if (empty($rating)) {
echo __('Be the first to rate!');
} else {
echo str_repeat('<div class="ui-stars-star ui-stars-star-on"><a title=""></a></div>', $rating);
}
So while that isn't a super-detailed instruction, you should be able to figure out what the code is doing and replicate it. It took me the better part of a day to get it working.