-
-
Save cole007/bfd550edf6a0dd540afeb48442fc2165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
class MysteryShopper_ReportRecord extends BaseRecord | |
{ | |
public function getTableName() | |
{ | |
return 'mysteryshopper_Report'; | |
} | |
protected function defineAttributes() | |
{ | |
return array( | |
'report' => array(AttributeType::String, 'default' => '', 'column' => ColumnType::Text), | |
'stage' => array(AttributeType::Number), | |
'author' => array(AttributeType::Number), | |
'shop' => array(AttributeType::Number), | |
'instance' => array(AttributeType::Number), | |
'event' => array(AttributeType::Number), | |
'status' => array(AttributeType::String, 'default' => 'pending'), | |
); | |
} | |
/** | |
* @return array | |
*/ | |
public function defineRelations() | |
{ | |
return array( | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
class MysteryShopper_ReportService extends BaseApplicationComponent | |
{ | |
public function saveReport(MysteryShopper_ReportModel $model,$id = null) | |
{ | |
$pre = $model->report; | |
$id = (int)$id; | |
if ($id > 0) { | |
$tmp = []; | |
$record = MysteryShopper_ReportRecord::model()->findById($id); | |
$fields = json_decode($record->report); | |
// merge fields - new values take precedence | |
$merge = (object) array_merge((array) $fields, (array) json_decode($model->report)); | |
$model->report = json_encode($merge); | |
$record->setAttribute('report',json_encode($merge)); | |
} else { | |
$record = new MysteryShopper_ReportRecord; | |
} | |
foreach ($model AS $key => $value) | |
{ | |
if ($value) $record->setAttribute($key,$value); | |
} | |
if ($record->save(false)) { | |
MysteryShopperPlugin::Log('Report saved via service'); | |
} else { | |
MysteryShopperPlugin::Log('Report failed to save via service'); | |
} | |
return $record->id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment