mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-21 17:02:19 +00:00
Merge branch 'master' into feature-10450/DVUH_requestMatrikelnummer
This commit is contained in:
@@ -12,6 +12,7 @@ class AnrechnungLib
|
||||
|
||||
const ANRECHNUNG_NOTIZTITEL_NOTIZ_BY_LEKTOR = 'AnrechnungNotizLektor';
|
||||
const ANRECHNUNG_NOTIZTITEL_NOTIZ_BY_STGL = 'AnrechnungNotizSTGL';
|
||||
const ANRECHNUNG_NOTIZTITEL_EMPFEHLUNGSNOTIZ_BY_STGL = 'AnrechnungEmpfehlungsnotizSTGL';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -23,6 +24,10 @@ class AnrechnungLib
|
||||
$this->ci->load->model('organisation/Studiengang_model', 'StudiengangModel');
|
||||
$this->ci->load->model('crm/Student_model', 'StudentModel');
|
||||
$this->ci->load->model('content/DmsVersion_model', 'DmsVersionModel');
|
||||
$this->ci->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
$this->ci->load->model('person/Notiz_model', 'NotizModel');
|
||||
|
||||
$this->ci->load->library('DmsLib');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,16 +37,19 @@ class AnrechnungLib
|
||||
* @param $lv_id
|
||||
* @return StdClass
|
||||
*/
|
||||
public function getAntragData($uid, $studiensemester_kurzbz, $lv_id)
|
||||
public function getAntragData($prestudent_id, $studiensemester_kurzbz, $lv_id)
|
||||
{
|
||||
$antrag_data = new StdClass();
|
||||
|
||||
|
||||
// Get students UID.
|
||||
$uid = $this->ci->StudentModel->getUID($prestudent_id);
|
||||
|
||||
// Get lehrveranstaltung data. Break, if course is not assigned to student.
|
||||
if(!$lv = getData($this->ci->LehrveranstaltungModel->getLvByStudent($uid, $studiensemester_kurzbz, $lv_id))[0])
|
||||
{
|
||||
show_error('You are not assigned to this course yet.');
|
||||
}
|
||||
|
||||
|
||||
// Get the students personal data
|
||||
if (!$person = getData($this->ci->PersonModel->getByUid($uid))[0])
|
||||
{
|
||||
@@ -61,12 +69,18 @@ class AnrechnungLib
|
||||
}
|
||||
|
||||
// Get lectors of lehrveranstaltung
|
||||
$antrag_data->lektoren = array();
|
||||
if (!$lv_lektoren = getData($this->ci->LehrveranstaltungModel->getLecturersByLv($studiensemester_kurzbz, $lv_id)))
|
||||
$result = $this->ci->LehrveranstaltungModel->getLecturersByLv($studiensemester_kurzbz, $lv_id);
|
||||
if (isError($result))
|
||||
{
|
||||
show_error('Failed loading course lectors.');
|
||||
}
|
||||
|
||||
|
||||
$lv_lektoren_arr = hasData($result) ? getData($result) : array();
|
||||
|
||||
// Get latest ZGV
|
||||
$result = $this->ci->PrestudentModel->getLatestZGVBezeichnung($prestudent_id);
|
||||
$latest_zgv_bezeichnung = hasData($result) ? getData($result)[0]->bezeichnung : '';
|
||||
|
||||
// Set the given studiensemester
|
||||
$antrag_data->lv_id = $lv_id;
|
||||
$antrag_data->lv_bezeichnung = $lv->bezeichnung;
|
||||
@@ -76,7 +90,8 @@ class AnrechnungLib
|
||||
$antrag_data->nachname = $person->nachname;
|
||||
$antrag_data->matrikelnr = $student->matrikelnr;
|
||||
$antrag_data->stg_bezeichnung = $studiengang->bezeichnung;
|
||||
$antrag_data->lektoren = $lv_lektoren;
|
||||
$antrag_data->lektoren = $lv_lektoren_arr;
|
||||
$antrag_data->zgv = $latest_zgv_bezeichnung;
|
||||
|
||||
return $antrag_data;
|
||||
}
|
||||
@@ -107,8 +122,12 @@ class AnrechnungLib
|
||||
{
|
||||
$anrechnung_data = $this->_setAnrechnungDataObject($anrechnung);
|
||||
}
|
||||
else
|
||||
{
|
||||
show_error('No Anrechnung with this anrechnung_id.');
|
||||
}
|
||||
|
||||
return success($anrechnung_data);
|
||||
return $anrechnung_data;
|
||||
|
||||
}
|
||||
|
||||
@@ -153,7 +172,7 @@ class AnrechnungLib
|
||||
$anrechnung_data = $this->_setAnrechnungDataObject($anrechnung);
|
||||
}
|
||||
|
||||
return success($anrechnung_data);
|
||||
return $anrechnung_data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,8 +190,8 @@ class AnrechnungLib
|
||||
$this->ci->AnrechnungModel->addSelect('tbl_benutzer.uid, tbl_prestudent.prestudent_id, tbl_person.person_id, tbl_anrechnung.studiensemester_kurzbz, vorname, nachname, geschlecht, tbl_lehrveranstaltung.bezeichnung AS "lv_bezeichnung"');
|
||||
$this->ci->AnrechnungModel->addJoin('public.tbl_prestudent', 'prestudent_id');
|
||||
$this->ci->AnrechnungModel->addJoin('public.tbl_student', 'prestudent_id');
|
||||
$this->ci->AnrechnungModel->addJoin('public.tbl_benutzer', 'uid=student_uid');
|
||||
$this->ci->AnrechnungModel->addJoin('public.tbl_person', 'tbl_benutzer.person_id=tbl_person.person_id');
|
||||
$this->ci->AnrechnungModel->addJoin('public.tbl_benutzer', 'uid = student_uid');
|
||||
$this->ci->AnrechnungModel->addJoin('public.tbl_person', 'tbl_benutzer.person_id = tbl_person.person_id');
|
||||
$this->ci->AnrechnungModel->addJoin('lehre.tbl_lehrveranstaltung', 'lehrveranstaltung_id');
|
||||
|
||||
$result = $this->ci->AnrechnungModel->load($anrechnung_id);
|
||||
@@ -207,28 +226,53 @@ class AnrechnungLib
|
||||
$empfehlung_data->empfehlung = null;
|
||||
$empfehlung_data->empfehlung_von = '-';
|
||||
$empfehlung_data->empfehlung_am = '-';
|
||||
$empfehlung_data->empfehlung_angefordert_am = '-';
|
||||
$empfehlung_data->notiz = ''; // Begruendung, if not recommended
|
||||
|
||||
$empfehlung_data->empfehlungsanfrageAm = '-';
|
||||
$empfehlung_data->empfehlungsanfrageAn = '-';
|
||||
$empfehlung_data->begruendung = '-'; // Begruendung, if not recommended
|
||||
$empfehlung_data->notiz_id = ''; // Empfehlungsnotiz from STGL
|
||||
$empfehlung_data->notiz = ''; // Empfehlungsnotiz from STGL
|
||||
|
||||
|
||||
if(!$anrechnung = getData($this->ci->AnrechnungModel->load($anrechnung_id))[0])
|
||||
{
|
||||
show_error('Failed loading Anrechnung');
|
||||
}
|
||||
|
||||
// Get Empfehlungsnotiz
|
||||
$result = $this->ci->NotizModel->getNotizByAnrechnung(
|
||||
$anrechnung_id,
|
||||
self::ANRECHNUNG_NOTIZTITEL_EMPFEHLUNGSNOTIZ_BY_STGL
|
||||
);
|
||||
|
||||
if ($notiz = getData($result)[0])
|
||||
{
|
||||
$empfehlung_data->notiz_id = $notiz->notiz_id;
|
||||
$empfehlung_data->notiz = $notiz->text;
|
||||
}
|
||||
|
||||
// Get date, where recommendation was last requested
|
||||
$result = $this->ci->AnrechnungModel->getLastAnrechnungstatus(
|
||||
$anrechnung_id,
|
||||
self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR // when STLG asks for recommendation, status is set to in progress lektor
|
||||
);
|
||||
if ($result = getData($result)[0])
|
||||
|
||||
// If request for recommendation exists
|
||||
if (hasData($result))
|
||||
{
|
||||
$empfehlung_data->empfehlung_angefordert_am = (new DateTime($result->insertamum))->format('d.m.Y');
|
||||
$empfehlung_data->empfehlungsanfrageAm = (new DateTime($result->retval[0]->insertamum))->format('d.m.Y');
|
||||
|
||||
// Get lectors who received request for recommendation
|
||||
$lector_arr = self::getLectors($anrechnung_id);
|
||||
|
||||
if (!isEmptyArray($lector_arr))
|
||||
{
|
||||
$empfehlung_data->empfehlungsanfrageAn = implode(', ', array_column($lector_arr, 'fullname'));
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($anrechnung->empfehlung_anrechnung))
|
||||
{
|
||||
return success($empfehlung_data);
|
||||
return $empfehlung_data;
|
||||
}
|
||||
|
||||
// If Empfehlung is true or false
|
||||
@@ -260,15 +304,14 @@ class AnrechnungLib
|
||||
if (!$anrechnung->empfehlung_anrechnung)
|
||||
{
|
||||
// Get Ablehnungsbegruendung (only set, if Anrechnung was not recommended yet)
|
||||
$this->ci->load->model('person/Notiz_model', 'NotizModel');
|
||||
$result = $this->ci->NotizModel->getNotizByAnrechnung($anrechnung_id, self::ANRECHNUNG_NOTIZTITEL_NOTIZ_BY_LEKTOR);
|
||||
if ($notiz = getData($result)[0])
|
||||
{
|
||||
$empfehlung_data->notiz = $notiz->text;
|
||||
$empfehlung_data->begruendung = $notiz->text;
|
||||
}
|
||||
}
|
||||
|
||||
return success($empfehlung_data);
|
||||
return $empfehlung_data;
|
||||
|
||||
}
|
||||
|
||||
@@ -300,9 +343,10 @@ class AnrechnungLib
|
||||
// Get date of approvement or rejection
|
||||
$result = $this->ci->AnrechnungModel->getApprovedOrRejected($anrechnung_id);
|
||||
|
||||
// If no approved or rejected Anrechnung exist, return basic genehmigung data object
|
||||
if (!$result = getData($result)[0])
|
||||
{
|
||||
return success($genehmigung_data);
|
||||
return $genehmigung_data;
|
||||
}
|
||||
|
||||
|
||||
@@ -331,9 +375,30 @@ class AnrechnungLib
|
||||
}
|
||||
}
|
||||
|
||||
return success($genehmigung_data);
|
||||
return $genehmigung_data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Anrechnungstatusbezeichnung of given status_kurzbz in users language.
|
||||
*
|
||||
* @param $status_kurzbz
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStatusbezeichnung ($status_kurzbz)
|
||||
{
|
||||
$this->ci->AnrechnungstatusModel->addSelect('bezeichnung_mehrsprachig');
|
||||
$result = $this->ci->AnrechnungstatusModel->load($status_kurzbz);
|
||||
|
||||
if (!hasData($result))
|
||||
{
|
||||
show_error('Failed retrieving Anrechnungstatusbezeichung');
|
||||
}
|
||||
|
||||
return getUserLanguage() == 'German'
|
||||
? $result->retval[0]->bezeichnung_mehrsprachig[0]
|
||||
: $result->retval[0]->bezeichnung_mehrsprachig[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last Anrechnungstatusbezeichnung in users language.
|
||||
@@ -370,7 +435,7 @@ class AnrechnungLib
|
||||
// Exit if already approved or rejected
|
||||
if ($status_kurzbz == self::ANRECHNUNGSTATUS_APPROVED || $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED)
|
||||
{
|
||||
return success(false); // dont approve
|
||||
return false; // dont approve
|
||||
}
|
||||
|
||||
// Start DB transaction
|
||||
@@ -395,10 +460,10 @@ class AnrechnungLib
|
||||
if ($this->ci->db->trans_status() === false)
|
||||
{
|
||||
$this->ci->db->trans_rollback();
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
return success(true); // approved
|
||||
return true; // approved
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,16 +484,14 @@ class AnrechnungLib
|
||||
// Exit if already approved or rejected
|
||||
if ($status_kurzbz == self::ANRECHNUNGSTATUS_APPROVED || $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED)
|
||||
{
|
||||
return success(false); // dont reject
|
||||
return false; // dont reject
|
||||
}
|
||||
|
||||
// Start DB transaction
|
||||
$this->ci->db->trans_start(false);
|
||||
|
||||
// Insert new status rejected
|
||||
$result = $this->ci->AnrechnungModel->saveAnrechnungstatus($anrechnung_id, self::ANRECHNUNGSTATUS_REJECTED);
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
show_error(getError($result));
|
||||
}
|
||||
$this->ci->AnrechnungModel->saveAnrechnungstatus($anrechnung_id, self::ANRECHNUNGSTATUS_REJECTED);
|
||||
|
||||
// Add begruendung as notiz
|
||||
$this->ci->load->model('person/Notiz_model', 'NotizModel');
|
||||
@@ -438,8 +501,17 @@ class AnrechnungLib
|
||||
$begruendung,
|
||||
getAuthUID()
|
||||
);
|
||||
|
||||
// Transaction complete
|
||||
$this->ci->db->trans_complete();
|
||||
|
||||
if ($this->ci->db->trans_status() === false)
|
||||
{
|
||||
$this->ci->db->trans_rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
return success(true); // rejected
|
||||
return true; // rejected
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,7 +534,7 @@ class AnrechnungLib
|
||||
|| $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED
|
||||
|| $status_kurzbz == self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR)
|
||||
{
|
||||
return success(false); // dont ask for recommendation
|
||||
return false; // dont ask for recommendation
|
||||
}
|
||||
|
||||
// Start DB transaction
|
||||
@@ -492,7 +564,7 @@ class AnrechnungLib
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
|
||||
return success(true); // recommended
|
||||
return true; // recommended
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -537,10 +609,10 @@ class AnrechnungLib
|
||||
if ($this->ci->db->trans_status() === false)
|
||||
{
|
||||
$this->ci->db->trans_rollback();
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
return success(true); // recommended
|
||||
return true; // recommended
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,7 +634,7 @@ class AnrechnungLib
|
||||
// Exit if already approved or rejected
|
||||
if ($status_kurzbz == self::ANRECHNUNGSTATUS_APPROVED || $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED)
|
||||
{
|
||||
return success(false); // dont approve
|
||||
return false; // dont approve
|
||||
}
|
||||
|
||||
// Start DB transaction
|
||||
@@ -596,10 +668,125 @@ class AnrechnungLib
|
||||
if ($this->ci->db->trans_status() === false)
|
||||
{
|
||||
$this->ci->db->trans_rollback();
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
return success(true); // recommended
|
||||
return true; // recommended
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Filename that should be used on download
|
||||
* @param $dms_id
|
||||
* @return string|null
|
||||
*/
|
||||
public function setFilenameOnDownload($dms_id)
|
||||
{
|
||||
// Load Anrechnung
|
||||
$result = $this->ci->AnrechnungModel->loadWhere(array('dms_id' => $dms_id));
|
||||
|
||||
// Return null if no data found
|
||||
if (!hasData($result))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$prestudent_id = $result->retval[0]->prestudent_id;
|
||||
$lehrveranstaltung_id = $result->retval[0]->lehrveranstaltung_id;
|
||||
|
||||
// Get LV OrgForm
|
||||
$this->ci->LehrveranstaltungModel->addSelect('stg.orgform_kurzbz');
|
||||
$this->ci->LehrveranstaltungModel->addJoin('public.tbl_studiengang AS stg', 'studiengang_kz');
|
||||
$result = $this->ci->LehrveranstaltungModel->load($lehrveranstaltung_id);
|
||||
$orgform_kurzbz = hasData($result) ? '_'. $result->retval[0]->orgform_kurzbz : '';
|
||||
|
||||
// Get full name of student
|
||||
$this->ci->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
$this->ci->PrestudentModel->addSelect('vorname, nachname');
|
||||
$this->ci->PrestudentModel->addJoin('public.tbl_person', 'person_id');
|
||||
$result = $this->ci->PrestudentModel->load($prestudent_id);
|
||||
$fullname = hasData($result) ? $result->retval[0]->vorname. $result->retval[0]->nachname : '';
|
||||
|
||||
// Return filename
|
||||
return 'Anrechnungsantrag'. $orgform_kurzbz .'_LV-'. $lehrveranstaltung_id. '_'. $fullname;
|
||||
}
|
||||
|
||||
public function LVhasLector($anrechnung_id)
|
||||
{
|
||||
$result = $this->ci->AnrechnungModel->load($anrechnung_id);
|
||||
if (!hasData($result))
|
||||
{
|
||||
showError('Anrechnung existiert nicht');
|
||||
}
|
||||
|
||||
// Get lectors of lehrveranstaltung
|
||||
$result = $this->ci->LehrveranstaltungModel->getLecturersByLv(
|
||||
$result->retval[0]->studiensemester_kurzbz,
|
||||
$result->retval[0]->lehrveranstaltung_id
|
||||
);
|
||||
|
||||
// Continue, if LV has no lector (there is no one to ask for recommendation)
|
||||
return hasData($result) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get LV Leitung. If not present, get all LV lectors.
|
||||
*
|
||||
* @param $anrechnung_id
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getLectors($anrechnung_id)
|
||||
{
|
||||
$this->ci->AnrechnungModel->addSelect('lehrveranstaltung_id, studiensemester_kurzbz');
|
||||
$result = $this->ci->AnrechnungModel->load($anrechnung_id);
|
||||
|
||||
if (!hasData($result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$lehrveranstaltung_id = getData($result)[0]->lehrveranstaltung_id;
|
||||
$studiensemester_kurzbz = getData($result)[0]->studiensemester_kurzbz;
|
||||
|
||||
// Get lectors
|
||||
$lector_arr = array();
|
||||
|
||||
$this->ci->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel');
|
||||
$result = $this->ci->LehrveranstaltungModel->getLecturersByLv($studiensemester_kurzbz, $lehrveranstaltung_id);
|
||||
|
||||
if (!$result = getData($result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if lv has LV-Leitung
|
||||
$key = array_search(true, array_column($result, 'lvleiter'));
|
||||
|
||||
// If lv has LV-Leitung, keep only the one
|
||||
if ($key !== false)
|
||||
{
|
||||
$lector_arr[]= $result[$key];
|
||||
}
|
||||
// ...otherwise keep all lectors
|
||||
else
|
||||
{
|
||||
$lector_arr = array_merge($lector_arr, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: This step is only done to make the array unique by uid, vorname and nachname in the following step
|
||||
* (e.g. if same lector is ones LV-Leitung and another time not, then array_unique would leave both.
|
||||
* But we wish to send only one email by to that one person)
|
||||
* **/
|
||||
foreach ($lector_arr as $lector)
|
||||
{
|
||||
unset($lector->lvleiter);
|
||||
$lector->fullname = $lector->vorname. ' '. $lector->nachname;
|
||||
}
|
||||
|
||||
// Now make the lector array aka mail receivers unique
|
||||
$lector_arr = array_unique($lector_arr, SORT_REGULAR);
|
||||
|
||||
return $lector_arr;
|
||||
}
|
||||
|
||||
// Return an object with Anrechnungdata
|
||||
@@ -631,12 +818,7 @@ class AnrechnungLib
|
||||
$this->ci->DmsVersionModel->addSelect('name');
|
||||
$result = $this->ci->DmsVersionModel->loadWhere(array('dms_id' => $anrechnung->dms_id));
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
show_error(getError($result));
|
||||
}
|
||||
|
||||
$anrechnung_data->dokumentname = $result->retval[0]->name;
|
||||
$anrechnung_data->dokumentname = hasData($result) ? getData($result)[0]->name : '';
|
||||
|
||||
return $anrechnung_data;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class DmsLib
|
||||
class DmsLib extends FHC_Controller
|
||||
{
|
||||
const FILE_CONTENT_PROPERTY = 'file_content';
|
||||
|
||||
const FILE_INPUT_NAME = 'uploadfile'; // name of the HTML input tag containing the uploaded file
|
||||
|
||||
private $UPLOAD_PATH = DMS_PATH; // temporary directory to store the upload file
|
||||
|
||||
/**
|
||||
@@ -21,6 +20,34 @@ class DmsLib
|
||||
$this->ci->load->model('content/DmsVersion_model', 'DmsVersionModel');
|
||||
$this->ci->load->model('content/DmsFS_model', 'DmsFSModel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a DMS Document.
|
||||
* If no version is particularly given, the latest version is loaded.
|
||||
*
|
||||
* @param $dms_id
|
||||
* @param integer $version
|
||||
* @return array
|
||||
*/
|
||||
public function load($dms_id, $version = null)
|
||||
{
|
||||
if (is_numeric($dms_id))
|
||||
{
|
||||
$this->ci->DmsModel->addJoin('campus.tbl_dms_version', 'dms_id');
|
||||
$this->ci->DmsModel->addOrder('version', 'DESC');
|
||||
$this->ci->DmsModel->addLimit(1);
|
||||
|
||||
if (!is_numeric($version))
|
||||
{
|
||||
return $this->ci->DmsModel->load($dms_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->ci->DmsModel->loadWhere(array('dms_id' => $dms_id, 'version' => $version));
|
||||
}
|
||||
}
|
||||
return error('The parameter DMS ID must be a number');
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a DMS Document from the Filesystem
|
||||
@@ -95,19 +122,20 @@ class DmsLib
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uploads a document and saves it to DMS
|
||||
* @param $dms DMS assoc array
|
||||
* @param array $allowed_types Default: all. Param example: array(jpg, pdf)
|
||||
* @param $field_name Name of the HTML uploadfile input name attribute
|
||||
* @param array $allowed_types Default: all. Param example: array(jpg, pdf)
|
||||
* @return array
|
||||
*/
|
||||
public function upload($dms, $allowed_types = array('*'))
|
||||
public function upload($dms, $field_name, $allowed_types = array('*'))
|
||||
{
|
||||
// Init upload configs
|
||||
$this->_loadUploadLibrary($allowed_types);
|
||||
|
||||
if (!$this->ci->upload->do_upload(DmsLib::FILE_INPUT_NAME))
|
||||
if (!$this->ci->upload->do_upload($field_name))
|
||||
{
|
||||
return error($this->ci->upload->display_errors());
|
||||
}
|
||||
@@ -132,46 +160,80 @@ class DmsLib
|
||||
// return result of uploaded data
|
||||
return success($upload_data); // data about the uploaded file
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Download a document
|
||||
* Download a document.
|
||||
*
|
||||
* @param $dms_id
|
||||
* @param string $filename $filename If String is given, it will be used as filename on download
|
||||
* @param string $disposition [inline | attachment]
|
||||
* Inline opens doc in new tab. Attachment displays download dialog box.
|
||||
*/
|
||||
public function download($dms_id)
|
||||
public function download($dms_id, $filename = null, $disposition = 'inline')
|
||||
{
|
||||
if (!is_numeric($dms_id))
|
||||
{
|
||||
show_error('Wrong parameter');
|
||||
}
|
||||
|
||||
$this->ci->DmsVersionModel->addSelect('filename');
|
||||
$result = $this->ci->DmsVersionModel->loadWhere(array('dms_id' => $dms_id));
|
||||
|
||||
$result = $this->getFileInfo($dms_id);
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
show_error(getError($result));
|
||||
return error(getError($result));
|
||||
}
|
||||
|
||||
$filename = $result->retval[0]->filename;
|
||||
$file = DMS_PATH. $filename;
|
||||
|
||||
if (file_exists($file))
|
||||
$fileObj = getData($result);
|
||||
|
||||
// Change filename, if filename is provided
|
||||
if (is_string($filename))
|
||||
{
|
||||
$finfo = new finfo(FILEINFO_MIME);
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: '.$finfo->file($file));
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($file));
|
||||
readfile($file);
|
||||
exit;
|
||||
$fileObj->name = $filename;
|
||||
}
|
||||
|
||||
// Add file disposition
|
||||
if ($disposition == 'attachment')
|
||||
{
|
||||
$fileObj->disposition = 'attachment';
|
||||
}
|
||||
else
|
||||
{
|
||||
show_error('File does not exist');
|
||||
$fileObj->disposition = 'inline';
|
||||
}
|
||||
|
||||
// Output file
|
||||
if(!$this->outputFile($fileObj))
|
||||
{
|
||||
return error('Error on file output');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file information.
|
||||
*
|
||||
* @param $dms_id
|
||||
* @param integer $version
|
||||
* @return array with File Object.
|
||||
*/
|
||||
public function getFileInfo($dms_id, $version = null)
|
||||
{
|
||||
if (!is_numeric($dms_id))
|
||||
{
|
||||
return error('Wrong parameter');
|
||||
}
|
||||
|
||||
// Load file
|
||||
$result = $this->load($dms_id, $version);
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
return error(getError($result));
|
||||
}
|
||||
|
||||
// Store file information in fileObj
|
||||
$fileObj = new StdClass();
|
||||
$fileObj->filename = getData($result)[0]->filename;
|
||||
$fileObj->file = DMS_PATH. getData($result)[0]->filename;
|
||||
$fileObj->name = DMS_PATH. getData($result)[0]->name; // original users filename
|
||||
$fileObj->mimetype = DMS_PATH. getData($result)[0]->mimetype;
|
||||
|
||||
return success($fileObj);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user