/** * @param ModuleMresource_EntityMresource $oMresource * * @return bool */ public function AddTargetRel($oMresource) { $aParams = array(':id' => $oMresource->GetMresourceId(), ':target_type' => $oMresource->GetTargetType(), ':target_id' => $oMresource->GetTargetId(), ':date_add' => F::Now(), ':description' => $oMresource->GetDescription(), ':target_tmp' => $oMresource->GetTargetTmp(), ':incount' => $oMresource->GetIncount() ? $oMresource->GetIncount() : 1); $sql = "\n SELECT mresource_id\n FROM ?_mresource_target\n WHERE\n target_type = ?:target_type\n AND target_id = ?d:target_id\n AND mresource_id = ?d:id\n LIMIT 1\n "; if ($iId = $this->oDb->sqlSelectCell($sql, $aParams)) { $sql = "\n UPDATE ?_mresource_target\n SET incount=incount+?d:incount\n WHERE mresource_id = ?d:id\n "; if ($this->oDb->sqlQuery($sql, $aParams)) { return $iId; } } else { $sql = "\n INSERT INTO ?_mresource_target\n (\n mresource_id,\n target_type,\n target_id,\n date_add,\n description,\n target_tmp,\n incount\n )\n VALUES (\n ?d:id,\n ?:target_type,\n ?d:target_id,\n ?:date_add,\n ?:description,\n ?:target_tmp,\n ?d:incount\n )\n "; if ($iId = $this->oDb->sqlQuery($sql, $aParams)) { return $iId ? $iId : false; } } return false; }