public static function deleteById($id) { self::deleteCache(); // make sure the language record exists $inst = ActiveRecord::getInstanceById('Language', $id, true); // make sure it's not the default currency if (true != $inst->isDefault->get()) { ActiveRecord::deleteByID('Language', $id); return true; } else { return false; } }
public function save() { ActiveRecord::beginTransaction(); $image = null; try { $image = ActiveRecord::getInstanceById($this->getModelClass(), $this->request->get('imageId'), true); $multilingualFields = array("title"); $image->setValueArrayByLang($multilingualFields, $this->application->getDefaultLanguageCode(), $this->application->getLanguageArray(true), $this->request); $image->save(); if ($_FILES['image']['tmp_name']) { $resizer = new ImageManipulator($_FILES['image']['tmp_name']); if (!$resizer->isValidImage()) { throw new InvalidImageException(); } if (!$image->resizeImage($resizer)) { throw new ImageResizeException(); } } } catch (InvalidImageException $exc) { $error = $this->translate('_err_not_image'); } catch (ImageResizeException $exc) { $error = $this->translate('_err_resize'); } catch (Exception $exc) { $error = $this->translate('_err_not_found ' . get_class($exc)); } $response = new ActionResponse(); if (isset($error)) { ActiveRecord::rollback(); $result = array('error' => $error); } else { ActiveRecord::commit(); $result = $image->toArray(); } $this->setLayout('iframeJs'); $response->set('ownerId', $this->request->get('ownerId')); $response->set('imageId', $this->request->get('imageId')); $response->set('result', @json_encode($result)); return $response; }
/** * Sets if currency is enabled * @role status * @return ActionResponse */ public function setEnabled() { $id = $this->request->get('id'); $curr = ActiveRecord::getInstanceById('Currency', $id, true); $curr->isEnabled->set((int) (bool) $this->request->get("status")); $curr->save(); return new JSONResponse(array('currency' => $curr->toArray()), 'success'); }
public function restoreInstance() { $instance = ActiveRecord::getInstanceById($this->instanceClassName, $this->instanceId); return $instance; }