public static function createDataStorageWithType($type)
 {
     if ($type == 'class') {
         $object = DataModelFactory::createDataObject('RemoteClassStorage');
     } else {
         if ($type == 'meta') {
             $object = DataModelFactory::createDataObject('RemotePropertyStorage');
         } else {
             if ($type == 'object') {
                 $object = DataModelFactory::createDataObject('RemoteObjectStorage');
             } else {
                 if ($type == 'resource') {
                     $object = DataModelFactory::createDataObject('RemoteResourceStorage');
                 } else {
                     $object = null;
                 }
             }
         }
     }
     return $object;
 }
Example #2
0
 public static function createDataObjectWithType($type)
 {
     if ($type == 'class') {
         $object = DataModelFactory::createDataObject('ClassName');
     } else {
         if ($type == 'meta') {
             $object = DataModelFactory::createDataObject('Property');
         } else {
             if ($type == 'object') {
                 $object = DataModelFactory::createDataObject('Object');
             } else {
                 if ($type == 'resource') {
                     $object = DataModelFactory::createDataObject('Resource');
                 } else {
                     $object = null;
                 }
             }
         }
     }
     return $object;
 }
Example #3
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);
     }
 }
 public function actionDelete()
 {
     if (!Parameters::hasParam('id')) {
         throw new APIException('Invalid resource IDENTIFICATOR (parameter name: \'id\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     try {
         $resource = DataModelFactory::createDataObjectWithType('resource');
         $resource->id = Parameters::get('id');
         $storage = new YiiResourceDataStorage();
         $storage->remove($resource);
     } catch (Exception $e) {
         throw new APIException('Can not save resource object', APIResponseCode::API_SHEMA_CREATE_ERROR);
     }
 }
Example #5
0
 public function actionSaveResourceObject()
 {
     $attr = $_POST;
     $type = $attr['type'];
     $object = DataModelFactory::createDataObjectWithType('resource');
     $object->setAttributes($attr);
     $storage = DataStorageFactory::createDataStorageWithType('resource');
     $storage->setType($type);
     $storage->save($object);
     $this->redirect(Yii::app()->createUrl('manager/resources', array('resource' => $type)));
 }