mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-08 00:52:01 +01:00
New: Enhancement in project module
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,12 +17,12 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file task.class.php
|
||||
\ingroup project
|
||||
\brief This file is a CRUD class file for Taks (Create/Read/Update/Delete)
|
||||
\version $Id$
|
||||
\remarks Initialy built by build_class_from_table on 2008-09-10 12:41
|
||||
*/
|
||||
* \file task.class.php
|
||||
* \ingroup project
|
||||
* \brief This file is a CRUD class file for Taks (Create/Read/Update/Delete)
|
||||
* \version $Id$
|
||||
* \remarks Initialy built by build_class_from_table on 2008-09-10 12:41
|
||||
*/
|
||||
|
||||
// Put here all includes required by your class file
|
||||
//require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
|
||||
@@ -31,20 +31,20 @@
|
||||
|
||||
|
||||
/**
|
||||
\class Projet_task
|
||||
\brief Put here description of your class
|
||||
\remarks Initialy built by build_class_from_table on 2008-09-10 12:41
|
||||
*/
|
||||
class Task // extends CommonObject
|
||||
* \class Projet_task
|
||||
* \brief Put here description of your class
|
||||
* \remarks Initialy built by build_class_from_table on 2008-09-10 12:41
|
||||
*/
|
||||
class Task extends CommonObject
|
||||
{
|
||||
var $db; //!< To store db handler
|
||||
var $error; //!< To return error code (or message)
|
||||
var $errors=array(); //!< To return several error codes (or messages)
|
||||
//var $element='projet_task'; //!< Id that identify managed objects
|
||||
//var $table_element='projet_task'; //!< Name of table without prefix where object is stored
|
||||
|
||||
var $element='projet_task'; //!< Id that identify managed objects
|
||||
var $table_element='projet_task'; //!< Name of table without prefix where object is stored
|
||||
|
||||
var $id;
|
||||
|
||||
|
||||
var $fk_projet;
|
||||
var $fk_task_parent;
|
||||
var $title;
|
||||
@@ -53,20 +53,20 @@ class Task // extends CommonObject
|
||||
var $statut;
|
||||
var $note;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructor
|
||||
* \param DB Database handler
|
||||
*/
|
||||
function Task($DB)
|
||||
function Task($DB)
|
||||
{
|
||||
$this->db = $DB;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Create in database
|
||||
* \param user User that create
|
||||
@@ -77,9 +77,9 @@ class Task // extends CommonObject
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
|
||||
// Clean parameters
|
||||
|
||||
|
||||
if (isset($this->fk_projet)) $this->fk_projet=trim($this->fk_projet);
|
||||
if (isset($this->fk_task_parent)) $this->fk_task_parent=trim($this->fk_task_parent);
|
||||
if (isset($this->title)) $this->title=trim($this->title);
|
||||
@@ -88,14 +88,14 @@ class Task // extends CommonObject
|
||||
if (isset($this->statut)) $this->statut=trim($this->statut);
|
||||
if (isset($this->note)) $this->note=trim($this->note);
|
||||
|
||||
|
||||
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task(";
|
||||
|
||||
|
||||
$sql.= "fk_projet,";
|
||||
$sql.= "fk_task_parent,";
|
||||
$sql.= "title,";
|
||||
@@ -104,9 +104,9 @@ class Task // extends CommonObject
|
||||
$sql.= "statut,";
|
||||
$sql.= "note";
|
||||
|
||||
|
||||
|
||||
$sql.= ") VALUES (";
|
||||
|
||||
|
||||
$sql.= " ".(! isset($this->fk_projet)?'NULL':"'".$this->fk_projet."'").",";
|
||||
$sql.= " ".(! isset($this->fk_task_parent)?'NULL':"'".$this->fk_task_parent."'").",";
|
||||
$sql.= " ".(! isset($this->title)?'NULL':"'".$this->title."'").",";
|
||||
@@ -115,24 +115,24 @@ class Task // extends CommonObject
|
||||
$sql.= " ".(! isset($this->statut)?'NULL':"'".$this->statut."'").",";
|
||||
$sql.= " ".(! isset($this->note)?'NULL':"'".$this->note."'")."";
|
||||
|
||||
|
||||
|
||||
$sql.= ")";
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
|
||||
|
||||
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Uncomment this and change MYOBJECT to your own tag if you
|
||||
// want this action call a trigger.
|
||||
|
||||
|
||||
//// Call triggers
|
||||
//include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||
//$interface=new Interfaces($this->db);
|
||||
@@ -149,7 +149,7 @@ class Task // extends CommonObject
|
||||
{
|
||||
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
|
||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||
}
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1*$error;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class Task // extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Load object in memory from database
|
||||
* \param id id object
|
||||
@@ -171,7 +171,7 @@ class Task // extends CommonObject
|
||||
global $langs;
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.rowid,";
|
||||
|
||||
|
||||
$sql.= " t.fk_projet,";
|
||||
$sql.= " t.fk_task_parent,";
|
||||
$sql.= " t.title,";
|
||||
@@ -180,10 +180,10 @@ class Task // extends CommonObject
|
||||
$sql.= " t.statut,";
|
||||
$sql.= " t.note";
|
||||
|
||||
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task as t";
|
||||
$sql.= " WHERE t.rowid = ".$id;
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
@@ -191,9 +191,10 @@ class Task // extends CommonObject
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
|
||||
$this->ref = $obj->rowid;
|
||||
|
||||
$this->fk_projet = $obj->fk_projet;
|
||||
$this->fk_task_parent = $obj->fk_task_parent;
|
||||
$this->title = $obj->title;
|
||||
@@ -202,10 +203,10 @@ class Task // extends CommonObject
|
||||
$this->statut = $obj->statut;
|
||||
$this->note = $obj->note;
|
||||
|
||||
|
||||
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -215,7 +216,7 @@ class Task // extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Update database
|
||||
@@ -227,9 +228,9 @@ class Task // extends CommonObject
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
|
||||
// Clean parameters
|
||||
|
||||
|
||||
if (isset($this->fk_projet)) $this->fk_projet=trim($this->fk_projet);
|
||||
if (isset($this->fk_task_parent)) $this->fk_task_parent=trim($this->fk_task_parent);
|
||||
if (isset($this->title)) $this->title=trim($this->title);
|
||||
@@ -238,14 +239,14 @@ class Task // extends CommonObject
|
||||
if (isset($this->statut)) $this->statut=trim($this->statut);
|
||||
if (isset($this->note)) $this->note=trim($this->note);
|
||||
|
||||
|
||||
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
|
||||
// Update request
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
|
||||
|
||||
|
||||
$sql.= " fk_projet=".(isset($this->fk_projet)?$this->fk_projet:"null").",";
|
||||
$sql.= " fk_task_parent=".(isset($this->fk_task_parent)?$this->fk_task_parent:"null").",";
|
||||
$sql.= " title=".(isset($this->title)?"'".addslashes($this->title)."'":"null").",";
|
||||
@@ -254,22 +255,22 @@ class Task // extends CommonObject
|
||||
$sql.= " statut=".(isset($this->statut)?$this->statut:"null").",";
|
||||
$sql.= " note=".(isset($this->note)?"'".addslashes($this->note)."'":"null")."";
|
||||
|
||||
|
||||
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Uncomment this and change MYOBJECT to your own tag if you
|
||||
// want this action call a trigger.
|
||||
|
||||
|
||||
//// Call triggers
|
||||
//include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||
//$interface=new Interfaces($this->db);
|
||||
@@ -278,7 +279,7 @@ class Task // extends CommonObject
|
||||
//// End call triggers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Commit or rollback
|
||||
if ($error)
|
||||
{
|
||||
@@ -286,7 +287,7 @@ class Task // extends CommonObject
|
||||
{
|
||||
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
|
||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||
}
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1*$error;
|
||||
}
|
||||
@@ -294,10 +295,10 @@ class Task // extends CommonObject
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Delete object in database
|
||||
* \param user User that delete
|
||||
@@ -308,9 +309,9 @@ class Task // extends CommonObject
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
if ($this->hasChildren() > 0)
|
||||
{
|
||||
dol_syslog(get_class($this)."::delete Can't delete record as it has some child", LOG_WARNING);
|
||||
@@ -318,30 +319,30 @@ class Task // extends CommonObject
|
||||
$this->db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Uncomment this and change MYOBJECT to your own tag if you
|
||||
// want this action call a trigger.
|
||||
|
||||
|
||||
//// Call triggers
|
||||
//include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||
//$interface=new Interfaces($this->db);
|
||||
//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
|
||||
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
//// End call triggers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Commit or rollback
|
||||
if ($error)
|
||||
{
|
||||
@@ -349,7 +350,7 @@ class Task // extends CommonObject
|
||||
{
|
||||
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
|
||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||
}
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1*$error;
|
||||
}
|
||||
@@ -367,10 +368,10 @@ class Task // extends CommonObject
|
||||
function hasChildren()
|
||||
{
|
||||
$ret=0;
|
||||
|
||||
|
||||
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."projet_task";
|
||||
$sql.= " WHERE fk_task_parent=".$this->id;
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::hasChildren sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
@@ -379,17 +380,43 @@ class Task // extends CommonObject
|
||||
$obj=$this->db->fetch_object($resql);
|
||||
if ($obj) $ret=$obj->nb;
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
return $ret;
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoie nom clicable (avec eventuellement le picto)
|
||||
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
|
||||
* \param option Sur quoi pointe le lien
|
||||
* \return string Chaine avec URL
|
||||
*/
|
||||
function getNomUrl($withpicto=0,$option='')
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$result='';
|
||||
|
||||
$lien = '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$this->id.'">';
|
||||
$lienfin='</a>';
|
||||
|
||||
$picto='projecttask';
|
||||
|
||||
$label=$langs->trans("ShowTask").': '.$this->ref;
|
||||
|
||||
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialise object with example values
|
||||
* \remarks id must be 0 if object instance is a specimen.
|
||||
@@ -397,7 +424,7 @@ class Task // extends CommonObject
|
||||
function initAsSpecimen()
|
||||
{
|
||||
$this->id=0;
|
||||
|
||||
|
||||
$this->fk_projet='';
|
||||
$this->fk_task_parent='';
|
||||
$this->title='';
|
||||
|
||||
Reference in New Issue
Block a user