/** * @param string $gadgetId * @return string */ private function getGadgetType($gadgetId) { $gadget = new Gpf_Gadget(); $gadget->setPrimaryKeyValue($gadgetId); try { $gadget->load(); } catch (Gpf_DbEngine_NoRowException $e) { throw new Gpf_Exception("Gadget {$gadgetId} not found."); } return $gadget->getType(); }
/** * * @service gadget write * @param $fields * @return Gpf_Rpc_Form */ public function save(Gpf_Rpc_Params $params) { $form = new Gpf_Rpc_Form($params); $dbRow = $this->createDbRowObject(); $dbRow->setPrimaryKeyValue($this->getId($form)); try { $dbRow->load(); } catch (Gpf_DbEngine_NoRow $e) { $form->setErrorMessage($this->getDbRowObjectName() . $this->_(" does not exist")); return $form; } $dbRow->set(Gpf_Db_Table_Gadgets::NAME, $form->getFieldValue(self::FORM_GADGET_NAME)); if (!$this->checkBeforeSave($dbRow, $form, self::EDIT)) { return $form; } try { $dbRow->save(); $this->afterSave($dbRow, self::EDIT); } catch (Exception $e) { $form->setErrorMessage($e->getMessage()); return $form; } $form->setField(self::FORM_GADGET_NAME, $dbRow->get(Gpf_Db_Table_Gadgets::NAME)); $form->setInfoMessage($this->getDbRowObjectName() . $this->_(" saved")); $formField = new Gpf_Db_FormField(); $formField->setFormId($this->gadget->getPreferencesFormId()); foreach ($formField->loadCollection() as $field) { $code = $field->getCode(); $this->gadget->addProperty($code, $form->getFieldValue($code)); } return $form; }
public function __construct() { parent::__construct(); $this->setType('G'); }