Skip to content

Instantly share code, notes, and snippets.

@demental
Created March 15, 2012 16:39
Show Gist options
  • Save demental/2045187 to your computer and use it in GitHub Desktop.
Save demental/2045187 to your computer and use it in GitHub Desktop.
hooks on linksFormTables
<?php
// office/lib/hooks/Client.php
class Client_hook
{
public static function alterLinkFromTables($links,$do)
{
require_once 'lib/CustomUtils.php';
CustomUtils::addTicketsClosedToLinks(&$links,$do);
}
}
<?php
// office/lib/CustomUtils.php
class CustomUtils {
public function addTicketsClosedToLinks(&$links,$do)
{
$canViewTickets = M_Office_Util::getGLobalOption('view','showtable','ticket_closed');
if(!$canViewTickets) return;
$res = array();
foreach($links as $k =>$v) {
if($v['table']=='ticket') {
$t = M_Office_Util::doForModule('ticket');
$t->client_id = $do->id;
$count = $t->count();
$open = array(
'table'=>'ticket',
'linkField'=>'client_id',
'field'=>'id',
'link'=>M_Office::URL(array('module'=>'ticket','filterField'=>'client_id','filterValue'=>$do->id),array('record')),
'nb'=>$count,
'tablename'=>'Tickets ouverts',
'add'=>false
);
$res[]=$open;
$t = M_Office_Util::doForModule('ticket_closed');
$t->client_id = $do->id;
$count = $t->count();
$closed = array(
'table'=>'ticket',
'linkField'=>'client_id',
'field'=>'id',
'link'=>M_Office::URL(array('module'=>'ticket_closed','filterField'=>'client_id','filterValue'=>$do->id),array('record')),
'nb'=>$count,
'tablename'=>'Tickets clôturés',
'add'=>false
);
$res[]=$closed;
} else {
$res[]=$v;
}
}
$links = $res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment