/**
  * Remove old main image and add new one
  *
  * @param array $files
  * @param RM_Unit_Row $unit
  */
 private function _changeOrderMain($files, $unit)
 {
     $fileName = $files[count($files) - 1];
     $fileModel = new RM_UnitMediaFiles();
     $file = $fileModel->getByUnit($unit, $fileName);
     if ($file == null) {
         return;
     }
     $data = array();
     $data['file_id'] = $file->id;
     $data['type_id'] = RM_UnitMediaTypes::MAIN;
     $data['order'] = 1;
     $this->insert($data);
 }
 /**
  * Delete unit images
  */
 function deleteJsonAction()
 {
     $filename = $this->_getParam('filename');
     if ($filename === null) {
         return array('data' => array('success' => false, 'error' => $this->_translate->_('Admin.Unit.Media', 'FilenameMustBeNonEmpty')));
     }
     $filename = trim($filename);
     $unitID = $this->_getParam('unit_id');
     if ($unitID === null) {
         return array('data' => array('success' => false, 'error' => $this->_translate->_('Admin.Unit.Media', 'UnitIDMustBeNonEmpty')));
     }
     $unitModel = new RM_Units();
     $unit = $unitModel->find($unitID)->current();
     if ($unit === null) {
         return array('data' => array('success' => false, 'error' => $this->_translate->_('Admin.Unit.Media', 'WrongUnitID')));
     }
     $model = new RM_UnitMediaFiles();
     $file = $model->getByUnit($unit, $filename);
     if ($file !== null) {
         $model->deleteFile($unit, $file);
     } else {
         return array('data' => array('success' => false, 'error' => $this->_translate->_('Admin.Unit.Media', 'WrongFilename')));
     }
     return array('data' => array('success' => true));
 }
Exemple #3
0
 private function _assignImage($filename)
 {
     //we need to check is the same image record is already exists
     $model = new RM_UnitMediaFiles();
     $row = $model->getByUnit($this->_unit, $filename);
     if ($row !== null) {
         //Image was already overwriting and we just need to delete database row
         $row->delete();
     }
     $data = array();
     $data['unit_id'] = $this->_unit->id;
     $data['filename'] = $filename;
     $data['caption'] = '';
     $data['details'] = '';
     $data['notes'] = '';
     return $model->insert($data);
 }