NEW : we need to be able to put more filters on deleteByParentField() function
This commit is contained in:
parent
a6c3c6b7ec
commit
412746ec8f
@ -9056,10 +9056,13 @@ abstract class CommonObject
|
||||
$className = str_replace('@', '', $deleteFromObject[0]);
|
||||
$filePath = $deleteFromObject[1];
|
||||
$columnName = $deleteFromObject[2];
|
||||
$TMoreSQL = array();
|
||||
$more_sql = $deleteFromObject[3];
|
||||
if(!empty($more_sql)) $TMoreSQL['customsql'] = $more_sql;
|
||||
if (dol_include_once($filePath)) {
|
||||
$childObject = new $className($this->db);
|
||||
if (method_exists($childObject, 'deleteByParentField')) {
|
||||
$result = $childObject->deleteByParentField($this->id, $columnName);
|
||||
$result = $childObject->deleteByParentField($this->id, $columnName, $TMoreSQL);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->errors[] = $childObject->error;
|
||||
@ -9144,7 +9147,7 @@ abstract class CommonObject
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteByParentField($parentId = 0, $parentField = '')
|
||||
public function deleteByParentField($parentId = 0, $parentField = '', $filter=array(), $filtermode="AND")
|
||||
{
|
||||
global $user;
|
||||
|
||||
@ -9157,6 +9160,23 @@ abstract class CommonObject
|
||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element;
|
||||
$sql .= " WHERE ".$parentField." = ".(int) $parentId;
|
||||
|
||||
// Manage filter
|
||||
$sqlwhere = array();
|
||||
if (count($filter) > 0) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if ($key == 'customsql') {
|
||||
$sqlwhere[] = $value;
|
||||
} elseif (strpos($value, '%') === false) {
|
||||
$sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
|
||||
} else {
|
||||
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($sqlwhere) > 0) {
|
||||
$sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
|
||||
}
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
$this->errors[] = $this->db->lasterror();
|
||||
|
||||
@ -154,7 +154,7 @@ class Job extends CommonObject
|
||||
// * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
|
||||
// * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
|
||||
// */
|
||||
// protected $childtablesoncascade = array('hrm_jobdet');
|
||||
protected $childtablesoncascade = array("@SkillRank:hrm/class/skillrank.class.php:fk_object:objecttype='job'");
|
||||
|
||||
// /**
|
||||
// * @var JobLine[] Array of subtable lines
|
||||
|
||||
Loading…
Reference in New Issue
Block a user