PHPWord --> How to get header different on first page but footer same on all pages? - footer

i use PHP Word to create an invoice form.
I want to have the header on the first page different from subsequent pages but the footer same on all pages.
When i do this:
$header_page_1 = $section->addHeader();
$header_page_1->firstPage();
$header_page_1->addImage(
'myimageurl...',
array(
'alignment' => 'right',
'height' => 85,
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
)
);
$header_subseq = $section->addHeader();
$header_subseq->addPreserveText('Page {PAGE} of {NUMPAGES}', null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::RIGHT));
$footer_all_pages = $section->addFooter();
$footer_all_pages->addText('Test');
i get NO footer at first page
How to setup that the footer is also shown at the first page?
Is the only solution to define the same footer twice like this:
$footer_page_1 = $section->addFooter();
$footer_page_1->firstPage();
$footer_page_1->addText('Test');
$footer_subseq = $section->addFooter();
$footer_subseq->firstPage();
$footer_subseq->addText('Test');

Use the footer section also twice same as header.
One for first page and another for subsequent pages.
e.g
$footer = $section->addFooter();
$footer->firstPage();
$footer->addText(htmlspecialchars('Footer for page'));
$footer_sub = $section->addFooter();
$footer_sub->addText(htmlspecialchars('Footer for page'));

Related

Adding a drop down in rails and do particular action

I am new to rails and this might me be a basic question. I checked on the internet but not able to find a simple example(might be my search is bad).
I need to create a form in my view and based the value selected and button clicking action i need to execute a particular action in my controller. I am able to create a drop down in my view using following lines.
= form_tag("/rtes", method: "get") do
= label_tag(:q, "Get Trip Type:")
= select_tag(:q, options_for_select({ "a" => "r4d_001", "b" => "r4d_002" })
<br>
= button_to( "Get Trip", :action => "rtes", :controller =>:q)
where rtes is my controller and i have mapped the value of the drop down values to the corresponding action names that needs to be executed when the button is clicked. This is my controller.
class RtesController < ApplicationController
##client=OptimusRtesServiceModel.new
def index
end
def r4d_001
result = ##client.r4t_001()
#driver_username = result.trip.loads[0].driver_details[0].driver_user_name
#driver_password = result.trip.loads[0].driver_details[0].driver_password
#trip_id = result.trip.trip_id
#carrier_username = result.carrier_details.carrier_user_name
#carrier_password = result.carrier_details.carrier_password
end
def r4d_002
result = ##client.r4t_002()
#driver_username = result.trip.loads[0].driver_details[0].driver_user_name
#driver_password = result.trip.loads[0].driver_details[0].driver_password
#trip_id = result.trip.trip_id
#carrier_username = result.carrier_details.carrier_user_name
#carrier_password = result.carrier_details.carrier_password
end
end
Now, if the first option in the drop down is selected and the button is clicked the "r4d_001" action in the controller needs to be executed. Your help is highly appreciated.
Rails is not like angular that you are trying to use :q variable to pass the value of selection to the button. You can create a drop-down menu instead of using select field to send them to different action for different option. Still if you want to use select field, then you need javascript to handle the front-end task here.
I have slightly modified my code to made it work. The idea is to get use the rails params and execute the corresponding action in my controller using case/when.
My view code:
= form_tag({:controller=>"r4d", :action=>"result"}, method: :get) do
= label_tag(:q, "Trip Type: ")
= select_tag(:q, options_for_select({"a" => "1", "b" => "2"})
= submit_tag("GetDetails")
My Contoller code:
class R4dController < ApplicationController
##client=ServiceModel.new
def r4d_result
result = case params[:q]
when "1"
##client.1
when "2"
##client.2
end
#value = result.value
end
end
By this way, i am able to pass the selected value of the drop down and execute the corresponding thing.

sfWidgetFormDoctrineChoice: bug, error or what?

I'm using sfWidgetFormDoctrineChoice to build select elements in a form. This is how I'm using:
// Fill maquinaemisorid
$this->widgetSchema['maquinaemisorid'] = new sfWidgetFormDoctrineChoice(array('model' => 'SdrivingMaquina', 'add_empty' => 'Seleccione una Máquina', 'table_method' => 'fillChoice'));
// Fill idoperador
$this->widgetSchema['idoperador'] = new sfWidgetFormDoctrineChoice(array('model' => 'SdrivingOperador', 'add_empty' => 'Seleccione un Operador', 'table_method' => 'fillChoice'));
// Fill idturno
$this->widgetSchema['idturno'] = new sfWidgetFormDoctrineChoice(array('model' => 'SdrivingTurno', 'add_empty' => 'Seleccione un Turno', 'table_method' => 'fillChoice'));
For the first widget all is fine and values are taken from DB as should be but for the second one and the third is not working. As you may notice I'm calling a method fillChoice in all widgets table_method. This is the code for the three:
SdrivingMaquinaTable.class.php
public function fillChoice() {
$id_empresa = sfContext::getInstance()->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
return Doctrine_Core::getTable('SdrivingMaquina')->createQuery('a')->where('a.idempresa = ?', $id_empresa)->execute();
}
SdrivingOperadorTable.class.php
public function fillChoice() {
$id_empresa = sfContext::getInstance()->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
return Doctrine_Core::getTable('SdrivingOperador')->createQuery('a')->where('a.idempresa = ?', $id_empresa)->execute();
}
SdrivingTurno.class.php
public function fillChoice() {
$id_empresa = sfContext::getInstance()->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
return Doctrine_Core::getTable('SdrivingTurno')->createQuery('a')->where('a.idempresa = ?', $id_empresa)->execute();
}
The method is the same always just changes the table used for each class. I check the generated queries and all are fine and if I run each on phpMyAdmin for example more than one value is fetched altough in idoperador and idturno just the latest is rendered. This is a very rare behavior and I can't find the error or mistake so I need some help or advice here.
As an adition I tried this in SdrivingRegistrosEmisoresForm.class.php (this is where the widgets are being generated):
$id_empresa = $this->current_user->getSfGuardUserProfile()->getIdempresa();
$choices_operador = Doctrine_Core::getTable('SdrivingOperador')->createQuery('a')->where('a.idempresa = ?', $id_empresa)->execute();
$this->widgetSchema['idoperador'] = new sfWidgetFormSelect(array('choices' => $choices_operador));
And this way works fine but the id for each item fetched isn't right meaning:
id item real_id
0 Item1 2
1 Item2 16
2 Item4 3
I talked about this in this topic but didn't get any answer, any help?
As stated in sfWidgetFormDoctrineChoice, if option *table_method* returns a collection like your methods, it renders choices with options *key_method* and method. By default , they are respectively getPrimaryKey() and *__toString()*.
Can we check you schema.yml and the __toString() ?
As for your last example the option choices of sfWidgetFormSelect should be an array an not a *Doctrine_Collection*

How do I add an addPolylines feature to gmaps4rails?

I'm working with the gmaps4rails gem (version 1.5.6), and I want to add the ability to add more Polylines to a map rather than replacing the Polylines that are already there. On github, this code is viewable here.
This feature already exists for Markers:
Gmaps.map.replaceMarkers(your_markers_json_array); Gmaps.map.addMarkers(your_markers_json_array);.
The Markers feature seems to be laid out in two places:
1) In gmaps4rails.base.js as:
Gmaps4Rails.prototype.addMarkers = function(new_markers) {
this.markers = this.markers.concat(new_markers);
this.create_markers();
return this.adjustMapToBounds();
};
2) In gmaps4rails.base.js.coffee as:
#add new markers to on an existing map
addMarkers : (new_markers, adjustBounds = true) ->
#update the list of markers to take into account
#markers = #markers.concat(new_markers)
#put markers on the map
#create_markers()
#adjustMapToBounds() if adjustBounds
I figured I could work with the replacePolylines code in to make my own addPolylines call:
1) In gmaps4rails.base.js near the replacePolylines code as:
Gmaps4Rails.prototype.addPolylines = function(new_polylines) {
this.polylines = this.polylines.concat(new_polylines);
this.create_polylines();
return this.adjustMapToBounds();
};
2) In gmaps4rails.base.js.coffee near the replacePolylines code as:
#add new polylines to on an existing map
addPolylines : (new_polylines) ->
#update the list of polylines to take into account
#polylines = #polylines.concat(new_polylines)
#put polylines on the map
#create_polylines()
#.... and adjust map boundaries
#adjustMapToBounds()
I've made these changes to the gem that's already added to my Rails project, and I've restarted my Rails server. I call it the same way I call replacePolylines, with Gmaps.map.addPolylines(your_polylines_json_array);. It produces an error in the console: Uncaught TypeError: Object #<Gmaps4RailsGoogle> has no method 'addPolylines'.
There doesn't seem to be anywhere else in the gmaps4rails project where I have to do anything for my addPolylines call, but I'm obviously not doing something right. Can anyone explain what I need to do to get this to work, based on this information?
As a workaround, until I can figure out how to build the functionality into gmaps4rails itself, I've taken these measures to asynchronously load Polylines onto a map...
In my UsersController, I've set up the show action to build a blank #polylines_json set:
def show
#user = User.find(params[:id])
#polylines_json = {}
end
The idea here is to have nothing for gmaps4rails to display on its initial map load, so that the initial page display is as quick as possible. In the view, I'm loading the map with this line:
<%= gmaps( :polylines => { :data => #polylines_json }, :map_options => { :type => 'HYBRID', :zoom => 12, :auto_adjust => false, :center_latitude => "-77", :center_longitude => "21" } ) %>
Back in the UsersController, I've got a custom action maps that is set up to handle json requests that contain from and to parameters (so that I can find items within specific ranges). It's in this action that I'm building the actual Polyline json data based on the from/to parameters:
def items
items = items.find(:all, :conditions => ['id >= ? AND id <= ?', params[:from], params[:to]])
polyline = []
i=0
items.each do |item|
polyline[i] = []
polyline[i] += [{:lng=>item.longitude.to_f,:lat=>item.latitude.to_f}]
i += 1
end
#polylines_json = polyline.to_json
respond_to do |format|
format.json { render json: #polylines_json }
end
end
Finally, back in the view to bring it all together, I'm asynchronously building up the Polyline collection ten at a time until I retrieve them all from the database:
<% content_for :scripts do %>
<script type="text/javascript" charset="utf-8">
numberOfItems = <%= #user.items.count %>;
var polylines= [];
function LoadMap(from, to) {
if (to < numberOfItems){
nextFrom = to + 1;
nextTo = to + 10;
}
if(nextTo <= numberOfItems){
$.ajax({
dataType: 'json',
url: "http://<%= request.host %>/users/<%= #user.id %>/maps.json?from="+from+"&to="+to,
success: function(response) {
polylines = polylines.concat(response);
Gmaps.map.replacePolylines(polylines);
LoadMap(nextFrom, nextTo);
}
});
}
}
LoadMap(1,10);
</script>
<% end %>

Strange infinite loop on mediawiki-gateway gem

Code is trapped in an infinite loop right on the REXML line. I've debugged and strangely, that line of code is run again and again, forever. Doesn't make any sense.
This method is from the mediawiki-gateway gem https://github.com/jpatokal/mediawiki-gateway
# Get a list of pages with matching content in given namespaces
#
# [key] Search key
# [namespaces] Array of namespace names to search (defaults to main only)
# [limit] Maximum number of hits to ask for (defaults to 500; note that Wikimedia Foundation wikis allow only 50 for normal users)
#
# Returns array of page titles (empty if no matches)
def search(key, namespaces=nil, limit=#options[:limit])
titles = []
offset = nil
in_progress = true
form_data = { 'action' => 'query',
'list' => 'search',
'srwhat' => 'text',
'srsearch' => key,
'srlimit' => limit
}
if namespaces
namespaces = [ namespaces ] unless namespaces.kind_of? Array
form_data['srnamespace'] = namespaces.map! do |ns| namespaces_by_prefix[ns] end.join('|')
end
begin
form_data['sroffset'] = offset if offset
res, offset = make_api_request(form_data, '//query-continue/search/#sroffset')
titles += REXML::XPath.match(res, "//p").map { |x| x.attributes["title"] }
end while offset
titles
end
The steps to reproduce are as follow
Open an irb and code
require 'media_wiki'
options = {
:limit => 50
}
#mw = MediaWiki::Gateway.new('http://en.wikipedia.org/w/api.php', options)
#mw.search('Strange Loop')
Unfortunately, it will never end.

Grails controller/view list pagination not showing next/prev option

I am having problems with the next/prev options not displaying on lists with a Groovy on Grails site. I have modified the automatically generated controller code to limit the items in the list to be items that were created by the user. This works fine, however, if the user has more than 10 items, the next/prev buttons don't show up as expected. Below are the relevant code snippits...
Controller:
def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
def login = authenticationService.getSessionUser().getLogin()
def authUser = AuthenticationUser.findByLogin(login)
def userAcct = User.findByLoginID(authUser)
def userServices = Service.createCriteria()
def results
if (userAcct.role == 'admin') {
results = userServices.list(params) {}
} else {
results = userServices.list(params) {
eq("userID", userAcct)
}
}
[serviceInstanceList: results, serviceInstanceTotal: results.count()]
}
GSP:
<div class="paginateButtons">
<g:paginate total="${serviceInstanceTotal}" />
</div>
When I log in with an account with the "admin' role, the next/prev links appear fine. Non-admin accounts do not display the next/prev links when there are more than 10 items to be listed. Can anyone see what I'm doing wrong?
Your criteria should give you a pagedResultList which has a totalCount. So try
to change the last line of your controller to:
[serviceInstanceList: results, serviceInstanceTotal: results.totalCount]

Resources