Add delete button on docs

This commit is contained in:
2019-09-08 12:51:52 +02:00
parent a1e60adde9
commit 9ca119111e
12 changed files with 92 additions and 37 deletions

View File

@@ -14,7 +14,7 @@ class Doc extends PhpObject {
private $iUserId;
private $iCourseId;
public function __construct(Db &$oDb, $iUserId, $iCourseId)
public function __construct(Db &$oDb, $iUserId=0, $iCourseId=0)
{
parent::__construct(__CLASS__, Settings::DEBUG);
$this->oDb = &$oDb;
@@ -53,13 +53,24 @@ class Doc extends PhpObject {
return $bResult?'':'error_db';
}
public function delete($sFileName) {
public function delete() {
if($this->iDocId > 0) {
$asDoc = $this->getDoc();
$bResult = $this->oDb->deleteRow(self::DOC_TABLE, $this->iDocId);
if($bResult) $bResult = unlink($asDoc['filepath']);
}
return $bResult;
}
public function getList() {
$this->oDb->setTrace(true);
$asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$this->getDocKeys()));
public function getDoc() {
$asDocList = $this->getList(array(Db::getId(self::DOC_TABLE) => $this->iDocId));
return array_shift($asDocList);
}
public function getList($asConstraint=array()) {
$asKeys = empty($asConstraint)?$this->getDocKeys():$asConstraint;
$asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$asKeys));
foreach($asDocs as &$asDoc) $asDoc['filepath'] = self::getFilePath($asDoc['filename']);
return $asDocs;