Skip to content

Commit

Permalink
Map and form events was added
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-s committed Jul 29, 2013
1 parent 86b3914 commit 54a37cf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
6 changes: 3 additions & 3 deletions public_html/protected/components/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function filters()
// Actions
abstract public function actionList();

abstract public function actionView();
abstract public function actionView($id);

abstract public function actionCreate();

abstract public function actionUpdate();
abstract public function actionUpdate($id);

abstract public function actionDelete();
abstract public function actionDelete($id);

protected function _sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
Expand Down
47 changes: 40 additions & 7 deletions public_html/protected/controllers/PlacesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function actionList()
echo CJSON::encode($places);
}

public function actionView()
public function actionView($id)
{
// TODO: Implement actionView() method.
}
Expand All @@ -22,25 +22,58 @@ public function actionCreate()
$data = CJSON::decode(file_get_contents('php://input'));
$place = new Places();
$place->p_title = $data['p_title'];
$place->p_description = $data['p_description'];
$place->p_description = isset($data['p_description']) ? $data['p_description'] : '';
$place->p_lng = $data['p_lng'];
$place->p_lat = $data['p_lat'];
$place->p_user_id = 1;
if ($place->save()) {
$this->_sendResponse(200, CJSON::encode($place));
}
else {
$this->_sendResponse(500, CJSON::encode(array('message'=>'Could not save place')));
$this->_sendResponse(500, CJSON::encode(array(
'message'=>'Could not save place',
'errors'=>$place->getErrors(),
)));
}
}

public function actionUpdate()
public function actionUpdate($id)
{
// TODO: Implement actionUpdate() method.
$data = CJSON::decode(file_get_contents('php://input'));
$place = Places::model()->findByPk($id);
if (null === $place) {
$this->_sendResponse(404, CJSON::encode(array('message'=>'Could not find place with id = '.$id)));
}
$place->p_title = $data['p_title'];
$place->p_description = isset($data['p_description']) ? $data['p_description'] : '';
$place->p_lng = $data['p_lng'];
$place->p_lat = $data['p_lat'];
$place->p_user_id = 1;
if ($place->save()) {
$this->_sendResponse(200, CJSON::encode($place));
}
else {
$this->_sendResponse(500, CJSON::encode(array(
'message'=>'Could not save place',
'errors'=>$place->getErrors(),
)));
}
}

public function actionDelete()
public function actionDelete($id)
{
// TODO: Implement actionDelete() method.
$place = Places::model()->findByPk($id);
if (null === $place) {
$this->_sendResponse(404, CJSON::encode(array('message'=>'Could not delete place with id = '.$id)));
}
if ($place->delete()) {
$this->_sendResponse(200, CJSON::encode($place));
}
else {
$this->_sendResponse(500, CJSON::encode(array(
'message'=>'Could not delete place',
'errors'=>$place->getErrors(),
)));
}
}
}
8 changes: 5 additions & 3 deletions public_html/protected/models/Places.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public function rules()
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('p_title, p_description, p_lat, p_lng, p_user_id', 'required'),
array('p_title, p_lat, p_lng, p_user_id', 'required'),
array('p_user_id', 'numerical', 'integerOnly'=>true),
array('p_title', 'length', 'max'=>255),
array('p_lng, p_lat', 'numerical', 'max'=>180, 'min'=>-180),
array('p_lng', 'numerical', 'max'=>180, 'min'=>-180),
array('p_lat', 'numerical', 'max'=>90, 'min'=>-90),
array('p_description', 'length', 'max'=>1024),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
Expand Down Expand Up @@ -74,7 +75,8 @@ public function attributeLabels()
'id' => 'ID',
'p_title' => 'Title',
'p_description' => 'Description',
'p_coords' => 'Coords',
'p_lat' => 'Latitude',
'p_lng' => 'Longitude',
'p_user_id' => 'User',
);
}
Expand Down

0 comments on commit 54a37cf

Please sign in to comment.