120 lines
4.3 KiB
PHP
120 lines
4.3 KiB
PHP
<?php namespace App\Models;
|
|||
|
|
|
||
|
|
|
||
|
|
/*
|
||
|
|
|
||
|
|
CREATE TABLE IF NOT EXISTS `TipiWork` (
|
||
|
|
`twIDTipoWork` varchar(5) NOT NULL COMMENT 'Identificativo univoco della tipologia di lavoro',
|
||
|
|
`twDescrizione` text NOT NULL COMMENT 'Descrizione della tipologia di lavoro',
|
||
|
|
`twOrdinamento` int NOT NULL COMMENT 'Indice per l''ordinamento nella visualizzazione della tipologia',
|
||
|
|
PRIMARY KEY (`twIDTipoWork`),
|
||
|
|
UNIQUE KEY `twIDTipoWork` (`twIDTipoWork`)
|
||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Elenco delle tipologie di lavoro';
|
||
|
|
|
||
|
|
Fields:
|
||
|
|
Tab: TipiWork = ['twIDTipoWork', 'twDescrizione', 'twOrdinamento'];
|
||
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
|
||
|
|
use CodeIgniter\Model;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
class TipiWork_Model extends Model{
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//--------------------------------------------------------------------
|
||
|
|
// Property
|
||
|
|
|
||
|
|
|
||
|
|
protected $table = 'TipiWork';
|
||
|
|
protected $primaryKey = 'twIDTipoWork';
|
||
|
|
|
||
|
|
protected $returnType = 'App\Entities\TipoWork';
|
||
|
|
//protected $returnType = 'array';
|
||
|
|
|
||
|
|
protected $allowedFields = ['twDescrizione', 'twOrdinamento'];
|
||
|
|
|
||
|
|
protected $useSoftDeletes = false;
|
||
|
|
protected $useTimestamps = false;
|
||
|
|
//protected $createdField = 'spCreatedAt';
|
||
|
|
//protected $updatedField = 'spUpdatedAt';
|
||
|
|
//protected $deletedField = 'spDeletedAt';
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//--------------------------------------------------------------------
|
||
|
|
// Events
|
||
|
|
|
||
|
|
|
||
|
|
//protected $beforeInsert = ['beforeInsert'];
|
||
|
|
//protected $afterInsert = ['afterInsert'];
|
||
|
|
//protected $beforeUpdate = ['beforeUpdate'];
|
||
|
|
//protected $afterUpdate = ['afterUpdate'];
|
||
|
|
//protected $beforeDelete = ['beforeDelete'];
|
||
|
|
//protected $afterDelete = ['afterDelete'];
|
||
|
|
//protected $afterFind = ['afterFind'];
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//--------------------------------------------------------------------
|
||
|
|
// Methods
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public function get_select_on_orari(){
|
||
|
|
|
||
|
|
// Creo la string SQL:
|
||
|
|
// - join fra le tabelle
|
||
|
|
//$sql = 'SELECT TipiWork.twIDTipoWork AS val, TipiWork.twDescrizione AS txt FROM TipiWork, Orari WHERE TipiWork.twIDTipoWork=Orari.orIDTipoWork';
|
||
|
|
$sql = "SELECT TipiWork.twIDTipoWork AS val, CONCAT(TipiWork.twIDTipoWork, ' - ', TipiWork.twDescrizione) AS txt FROM TipiWork, Orari WHERE TipiWork.twIDTipoWork=Orari.orIDTipoWork";
|
||
|
|
// - Applico il filtro temporale:
|
||
|
|
$sql .= ' AND Orari.orData>=\'' . session()->get('filter_dal') . '\' AND Orari.orData<=\'' . session()->get('filter_al') . " 23:59:59" . '\'';
|
||
|
|
// - applico eventuale filtro per lavoratore
|
||
|
|
if ((null !== session()->get('filter_lavoratore')) && (session()->get('filter_lavoratore')!='-1')) {
|
||
|
|
$sql .= ' AND Orari.orIDlavoratore=\'' . session()->get('filter_lavoratore') . '\'';
|
||
|
|
}
|
||
|
|
// - Applico il filtro sulla tipologia di orario
|
||
|
|
if ((null !== session()->get('filter_tipo_ore')) && (session()->get('filter_tipo_ore')!='-1')) {
|
||
|
|
$sql .= ' AND Orari.orIDTipiWork=\'' . session()->get('filter_tipo_ore') . '\'';
|
||
|
|
}
|
||
|
|
// - Non applico il filtro sulla commessa:
|
||
|
|
if ((null !== session()->get('filter_commessa')) && (session()->get('filter_commessa')!='-1')) {
|
||
|
|
$sql .= ' AND Orari.orIDcommessa=\'' . session()->get('filter_commessa') . '\'';
|
||
|
|
}
|
||
|
|
// - Raggruppo i risultati:
|
||
|
|
$sql .= ' GROUP BY(val)';
|
||
|
|
// - Ordino in modo decrescente sul numero di presenze e in modo alfabetico.
|
||
|
|
$sql .= ' ORDER BY COUNT(val) DESC, txt';
|
||
|
|
|
||
|
|
// Creo la query:
|
||
|
|
$query = $this->query($sql);
|
||
|
|
|
||
|
|
// Eseguo la query sul DB:
|
||
|
|
return $query->getResult();
|
||
|
|
|
||
|
|
}//function select_on_orari
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//--------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public function get_select(){
|
||
|
|
//$query = $this->query("SELECT twIDTipoWork AS val, twDescrizione AS txt FROM TipiWork WHERE twIDTipoWork<>'XXX00' ORDER BY twOrdinamento");
|
||
|
|
//$query = $this->query("SELECT twIDTipoWork AS val, CONCAT(twIDTipoWork, ' - ', twDescrizione) AS txt FROM TipiWork WHERE twIDTipoWork<>'XXX00' ORDER BY twOrdinamento");
|
||
|
|
$query = $this->query("SELECT twIDTipoWork AS val, CONCAT(twIDTipoWork, ' - ', twDescrizione) AS txt FROM TipiWork WHERE twOrdinamento<9999 ORDER BY twOrdinamento");
|
||
|
|
return $query->getResult();
|
||
|
|
}//function get_select
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//--------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}//class TipiWork_Model
|
||
|
|
|