Ejemplo n.º 1
0
 public function actionCreate()
 {
     if (!Parameters::hasParam('type')) {
         throw new APIException('Invalid resource TYPE (parameter name: \'type\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     $type = Parameters::get('type');
     $storage = DataStorageFactory::createStorage($type);
     if (is_null($storage)) {
         throw new APIException('Could not create data storage', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     try {
         $obj = DataModelFactory::createDataObjectWithType($type);
         $data = Parameters::getRaw('data', 'post');
         $attr = $storage->decodeResponse($data);
         $obj->setAttributes($attr);
         $storage->save($obj);
     } catch (Exception $e) {
         throw new APIException('Can not save resource object', APIResponseCode::API_SHEMA_CREATE_ERROR);
     }
 }
Ejemplo n.º 2
0
 public function delete($coreModelName, $id)
 {
     $storage = DataStorageFactory::factory()->createObject($coreModelName);
     return true;
     //return $storage->removeById($id);
 }
Ejemplo n.º 3
0
 public function actionRemoveResourceObject($type = null, $id = null)
 {
     $finder = FinderFactory::createFinderWithType('resource');
     $finder->setType($type);
     $object = $finder->findById($id);
     if ($object !== null) {
         $storage = DataStorageFactory::createDataStorageWithType('resource');
         $storage->setType($type);
         $storage->remove($object);
     }
     $this->redirect(Yii::app()->createUrl('manager/resources', array('resource' => $type)));
 }