Saving data from JModelList (Joomla 3) - joomla-extensions

in the moment I'm trying to save the following table:
http://img5.fotos-hochladen.net/uploads/tabelle1k6xegf4tm.jpg
Only the -fields needs to be saved when I click on the blue button below the table.
My problem: I'm new at joomla and dont know to how to save this.
Am I using the right Classes?
Is it possible to solve this by an table-class?
Maybe someone can send me an component where something like this is solved?
Or can give me the right code samples?
Here you can find what I've done:
class TippspielModelTippview extends JModelList
{
protected function getListQuery()
{
//Erstelle ein neues Query-Objekt
$db= JFactory::getDbo();
$query= $db->getQuery(true);
//Hole alle Daten
$query->select('t2.id, t2.date, t2.goalsteam1, t2.goalsteam2, t1a.team AS mannschaft1, t1b.team AS mannschaft2');
$query->from('#__tournament AS t2');
$query->join('left','#__team AS t1a ON t2.team1 = t1a.id');
$query->join('left','#__team AS t1b ON t2.team2 = t1b.id');
$query->order('date');
//und liefere es zurück
return $query;
}
}
The View
class TippspielViewTippview extends JViewLegacy
{
//Variable zur Speicherung aller Teams
protected $pages;
protected $games;
function display($tpl = null)
{
//Hole Daten aus dem Modul
$this->games = $this->get('Items');
$this->pages = $this->get('Pagination');
//Layout aktivieren und ausgeben
parent::display($tpl);
}
}
The Form
<form action="<?php echo JRoute::_('index.php?option=com_tippspiel&view=tippview'); ?>" method= "post" name="adminForm" id="adminForm">
<?php echo $this->pages->getLimitBox(); ?>
<table class="table table-striped">
<thead>
<tr>
<th>Heim</th>
<th>Gast</th>
<th>Spielbeginn</th>
<th>Tipp</th>
<th>Ergebnis</th>
<th>Punkte</th>
</tr>
</thead>
<tbody>
<?php foreach($this->games as $i => $game): ?>
<tr>
<td><?php echo $game->mannschaft1; ?></td>
<td><?php echo $game->mannschaft2; ?></td>
<td><?php echo JHtml::date($game->date); ?></td>
<td>Tipp</td>
<td><?php echo $game->goalsteam1; ?> : <?php echo $game->goalsteam2; ?></td>
<td>Punkte</td>
</tr>
<?php endforeach; ?>
</tbody>

JModelList is for listing items.
To display create/edit form and save item, you need to use JModelAdmin.
However what you are trying to save is not "an item", so you could use JModelLegacy. Using JModelList here is not really a big issue, it still works but I prefer JModelLegacy.
You post your values to a controller, the controller get the values and save, after saving it redirects you to another view or the same view.

Related

Can't get footable to display

I'm new to ASP and MVC so I'm learning. I'm trying to implement footable in my ASP.NET MVC 5 test project (I ultimately want to use the pagination and sorting features, but one step at a time).
I have added the .js files and .css files to the project and included them in the BundleConfig.cs file (see below). I'm not sure if that is all I need to do in order to use them in my project.
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js",
"~/Scripts/footable.min.js",
"~/Scripts/footable.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/footable.bootstrap.min.css",
"~/Content/footable.bootstrap.css"));
I'm retrieving data from a MySQL database and passing that to my view but I'm just getting a standard html table, what am I doing wrong ?
Here is the view code :-
#model IEnumerable<MVC5Footable.Models.radacct>
#{
ViewBag.Title = "Index";
}
<table class="footable">
<thead>
<tr>
<th>#Html.DisplayNameFor(model => model.username)</th>
<th>#Html.DisplayNameFor(model => model.framedipaddress)</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>#Html.DisplayFor(modelItem => item.username)</td>
<td>#Html.DisplayFor(modelItem => item.framedipaddress)</td>
</tr>
}
</tbody>
</table>
<!-- Initialize FooTable -->
<script>
jQuery(function ($) {
$('footable').footable();
});
</script>
Hoping someone can help. Thanks.
A little late, but for the record: you forgot to include the dot.
$('.footable').footable();

Displaying All Data from Custom Post Type Fields through Advanced Custom Fields

I have looked all over Google, trying to figure this out. I've made some progress but still stuck. I'm pretty new to ACF and custom post types. I have a custom post type of Attorneys that I setup through WCK. That post type has a field group with field names of attorney_photo, attorney_name and attorney_areas_of_practice. With the code below, I can get the attorney_name and attorney_areas_of_practice (repeater field) to display, but not the attorney_photo. I have the info displaying correctly on each attorneys specific page, but I need this page to be a listing of all the attorneys. Not sure what I am doing wrong with the image part.
<?php get_header(); ?>
<?php
$args = array(
'posts_per_page' => 30,
'order' => 'ASC',
'orderby' => 'title',
'post_type' => 'attorneys'
);
query_posts($args);
if ( have_posts() ) :
?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="attorney-preview">
<?php $photo = get_post_meta($post->ID,'attorney_photo', true); ?>
<img src="<?php echo $photo; ?>" />
<p><strong><?php echo get_post_meta($post->ID,'attorney_name', true); ?></strong></p>
<ul>
<?php
while ( have_rows('attorney_areas_of_practice') ) : the_row();
$attorney_area_of_practice = get_sub_field('attorney_area_of_practice');
echo "<li>" . $attorney_area_of_practice . "</li>";
endwhile;
?>
</ul>
</div><!-- .attorney-preview -->
<?php endwhile; ?>
<?php endif; ?>
<?php
wp_reset_query(); // Restore global post data stomped by the_post().
?>
<?php get_footer(); ?>
When you add image field through ACF plugin there are some options of return value. For example return value is: image object or return value is: image url, in your case return value might be selected as image object, not image url. That is why here with your code is being returned an array rather than only url. To get only image url from this array, please write as following a bit change:
<?php $photo = get_post_meta($post->ID,'attorney_photo', true); ?>
<img src="<?php echo $photo['url']; ?>" />
Try this
<?php query_posts(array('posts_per_page' => 30,'order' => 'ASC','orderby' => 'title','post_type' => 'attorneys'));
if (have_posts()) : while (have_posts()) : the_post();
$attorney_photo = get_post_meta($post->ID, 'attorney_photo', true);
$attorney_name = get_post_meta($post->ID, 'attorney_name', true); ?>
<div class="attorney-preview">
<img src="<?php echo $attorney_photo; ?>" />
<p><strong><?php echo $attorney_name; ?></strong></p>
<ul>
<?php
while ( have_rows('attorney_areas_of_practice') ) : the_row();
$attorney_area_of_practice = get_sub_field('attorney_area_of_practice');
echo "<li>" . $attorney_area_of_practice . "</li>";
endwhile;
?>
</ul>
</div><!-- .attorney-preview -->
<?php endwhile; endif; ?>
<?php
wp_reset_query(); // Restore global post data stomped by the_post().
?>

Osclass search from homepage to search for location also

I am trying to configure osclass for a real estate website. when searching from the home page, i need the search keywords to be searched in city and region too... ie, if the search key is "apartment newyork", all apartments where city or region is newyork should be displayed.
for the city filter try this one
<?php $aCities = City::newInstance()->listAll(); ?>
<?php if(count($aCities) > 0 ) { ?>
<select name="sCity" id="sCity">
<option value=""><?php _e('Select a city...')?></option>
<?php foreach($aCities as $city) { ?>
<option value="<?php echo $city['s_name'] ; ?>">
<?php echo $city['s_name'] ; ?></option>
<?php } ?>

Best way to open dialog in MVC 4 application

I'm just starting to learn MVC so try to bear with me.
I have a table that has a few options to the side that you can edit, delete and show the details of.
If I click the Details button now It will take me to another page (Details.cshtml)
which is located in the same Controller as the Index.cshtml which displays the table above.
This is the code for the table (Index.cshtml)
#model Collusus.Models.IndexModel
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<h2>Hello #Html.ActionLink(Model.userLoggedIN, "getProfile")</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Change ID</th>
<th>Owner</th>
<th>Priority</th>
<th>Disposition Date</th>
<th>Completion Date</th>
<th>Do what?</th>
</tr>
</thead>
<tbody>
#for(int i=0; i<Model.changes.Count(); i++)
{
<tr>
<td>#Model.changes[i].ID</td>
<td>#Model.changes[i].Owner</td>
<td>#Model.changes[i].Priority</td>
<td>#Model.changes[i].DispositionDate.ToShortDateString()</td>
<td>#Model.changes[i].ActualCompletionDate.ToShortDateString()</td>
<td>#if (Model.changes[i].Owner == Model.userLoggedIN)
{
#Html.ActionLink("Delete", "Delete", new { id=Model.changes[i].ID })
#Html.ActionLink("Edit", "Edit", new { id=Model.changes[i].ID })
}
#Html.ActionLink("Details", "Details", new { id=Model.changes[i].ID })
</td>
</tr>
}
</tbody>
</table>
As you can see because of the code below, it will just take me to another page.
#Html.ActionLink("Details", "Details", new { id=Model.changes[i].ID })
What I want to do:
Open Delete,Edit or Details view in a dialog instead of another page.
Be able to still have the same functionality as if they were just opening another page.
I don't know if that makes too much sense. I've tried to explain it the best I could and been frustrated searching Google / trying code from other solutions but can't get it to work.
If you suggest another way besides the JQUERY dialog I'm willing to go that option too. All help is appreciated since I've been so frustrated.
I'm assuming you want to open them into a modal dialog. To accomplish this you can return partial views from your controller.
You can add a class to your action links like this:
#Html.ActionLink("Details", "Details", new { id=Model.changes[i].ID }, new { #class = "details-modal" })
Your Details action method:
public ActionResult Details(int id)
{
// Your code here
return PartialView("_Details", myModel); // return the partial view with the model
}
jQuery (off the top of my head so it may not be 100% correct):
$('#my-dialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
modal: true
});
$('.details-modal').click(function() {
var theURL = $(this).attr('href');
$('#my-dialog').load(theURL, function() {
$(this).dialog('open');
});
return false; // ensures the browser is not redirected to the link's URL
});

PHPExcel reading xls file, get cell styling (font-weight, color, etc)

I am trying to read an excel file and render it as a html table. I would like to get the style that has been applied in excel to a cell and render it in html as well. For example, some cells may have text in BOLD, how do I get that information and use it in the most efficient way?
This is the code I have so far (I am trying out PHPExcel the first time so I am eager to hear any comments or improvements I can make to this):
if ($_GET["xls"]) {
require_once("classes/PHPExcel.php");
$objPHPExcel = PHPExcel_IOFactory::load( dirname(__FILE__) . "/demo.xls" );
$sheetData = $objPHPExcel->getSheetByName('Sheet1')->toArray(null,true,true,true);
?>
<?php if ( count($sheetData) < 0) : ?>
<table class="table striped">
<?php foreach( $sheetData as $y => $row ) : ?>
<tr>
<?php foreach ( $row as $x => $cell) : ?>
<?php if ( $x === "A" ) : ?>
<th><?php echo $cell; ?></th>
<?php else : ?>
<td><?php echo $cell; ?></td>
<?php endif; ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<?php
}
Why not take a look at PHPExcel's existing HTML Writer: that already handles merged cells, cell formatting (including borders), font styles, etc.
It seems that the following code works:
$objPHPExcel->getSheetByName('Sheet1')->getStyle("B13")->getFont()->getBold()

Resources