/** * Deletes the data. * @param Data from a deleting row. Need for additional delete operations (and not to query these data twice). * @return integer Number of rows affected by the execution. */ protected function delete(&$deletingRow) { $affected = 0; $transaction = $this->_db->beginTransaction(); try { $this->_trigger->execute($this->_data->pk, 'before', 'delete'); $affected = $this->_db->delete(); if($affected) { //Need to delete files if they were among the fields and have been checked in the confirmation form $fieldsToDel = Yii::app()->request->getPost('filesToDelF', array()); if($fieldsToDel) { foreach($fieldsToDel as $iField) { if(isset($deletingRow->fields[$iField]) && in_array($deletingRow->fields[$iField]->type, array('image', 'file'))) { if(in_array($deletingRow->fields[$iField]->type, array('image', 'file'))) AAHelperFile::deleteFile($deletingRow->fields[$iField]->options['directoryPath'].DIRECTORY_SEPARATOR.$deletingRow->fields[$iField]->value); } } } } $this->_trigger->execute($this->_data->pk, 'after', 'delete'); $this->_db->transactionCommit($transaction); } catch(AAException $e) { $this->processQueryError($e); $this->_db->transactionRollback($transaction); } return $affected; }
public function loadFromForm($formData) { if(!empty($formData[$this->name]) && is_array($formData[$this->name]) && !empty($formData[$this->name]['del'])) { $this->value = null; } elseif(!empty($_FILES[AutoAdmin::INPUT_PREFIX]['tmp_name']["{$this->name}_new"])) { $uploadDir = $this->options['directoryPath']; if($this->options['subDirectoryPath']) $uploadDir .= '/'.$this->options['subDirectoryPath']; $this->value = ($this->options['subDirectoryPath'] ? $this->options['subDirectoryPath'].'/' : '').AAHelperFile::uploadFile("{$this->name}_new", $uploadDir); } }