I've a module made using "tabs", each tab call a component in this way:
include_component('logotipo', 'index');
Now this is the code for the component:
class logotipoComponents extends sfComponents {
public function executeIndex(sfWebRequest $request) {
$id_empresa = $this->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
$this->sdriving_logotipo = Doctrine_Core::getTable('SdrivingLogotipo')->createQuery('a')->leftJoin('a.SdrivingEmpresa e')->where('e.idempresa = ?', $id_empresa)->execute();
}
}
And this is the template _index.php
:
<?php if ($sdriving_logotipo->count() > 0): ?>
<div class="span3">
<span class="gris">Vista previa</span>
<?php echo image_tag('/uploads/' . $sdriving_logotipo[0]->getArchivo()); ?>
</div>
<?php else: ?>
<div class="alert alert-block">
<h4><?php echo __('Información!') ?></h4>
<?php echo __('No se ha subido ningún logotipo aún. Haga clic en el botón "Subir nuevo" para crear uno.') ?>
</div>
<?php endif; ?>
This code works fine, but I need a bit more. What I need to do here is update logotipo uploading a new one and delete the existent from file system and also from database or just editing the existent record and updating values. Now takes a look at this schema.yml
:
SdrivingEmpresa:
columns:
idempresa:
type: integer(4)
unsigned: true
primary: true
autoincrement: true
idlogotipo:
type: integer(4)
unsigned: true
primary: true
nombre_empresa:
type: string(250)
notnull: true
ruta_emp:
type: string(45)
notnull: true
autoincrement: false
relations:
SdrivingLogotipo:
local: idlogotipo
foreign: idlogotipo
type: one
SdrivingEmisor:
local: idempresa
foreign: idempresa
type: many
SdrivingMaquina:
local: idempresa
foreign: idempresa
type: many
SdrivingOperador:
local: idempresa
foreign: idempresa
type: many
SdrivingTurno:
local: idempresa
foreign: idempresa
type: many
SfGuardUserProfile:
local: idempresa
foreign: idempresa
type: many
SdrivingLogotipo:
columns:
idlogotipo:
type: integer(4)
unsigned: true
primary: true
autoincrement: true
archivo:
type: string(250)
relations:
SdrivingEmpresa:
local: idlogotipo
foreign: idlogotipo
type: many
Taking this if I pick the first option then I need to build a query for get the filename from DB and then delete the file from file system, upload the new file and update SdrivingEmpresa
table with the new ID for uploaded file. In this case I don't know how to get the ID and where to write the logic for those actions: in protected function processForm(sfWebRequest $request, sfForm $form) { }
? in 'doSave($con = null){ }' at SdrivingLogotipoForm.class.php
? Where?
Any help?