UNC Chipotle and Hamilton Whole Foods notifications deleted from database #3109

This commit is contained in:
Daniel Camargo 2014-06-05 10:15:41 -03:00
parent 1fda55f67c
commit c83ee4e379
2 changed files with 55 additions and 47 deletions

View File

@ -662,30 +662,39 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange {
* @param array $elements
*/
public function saveNotifications($elements) {
c::db()->query('DELETE FROM notification WHERE id_restaurant="'.$this->id_restaurant.'"');
if(!$elements)
return;
foreach ($elements as $data) {
foreach( $elements as $element ){
$shouldSave = false;
if( $data['type'] == 'admin' && $data['id_admin'] ){
$id_admin = $data['id_admin'];
if( $element[ 'type' ] == 'admin' && trim( $element[ 'id_admin' ] ) != '' ){
$id_admin = $element[ 'id_admin' ];
$value = '';
$shouldSave = true;
} if( $data['type'] != 'admin' && $data['value'] ){
$value = $data['value'];
}
if( $element[ 'type' ] != 'admin' && trim( $element[ 'value' ] ) != '' ){
$value = $element[ 'value' ];
$id_admin = NULL;
$shouldSave = true;
}
if (!$shouldSave) { continue; }
$element = new Crunchbutton_Notification($data['id_notification']);
$element->id_restaurant = $this->id_restaurant;
$element->active = ($data['active'] == 'true' || $data['active'] == '1') ? "1" : "0";
$element->type = $data['type'];
$element->id_admin = $id_admin;
$element->value = $value;
$element->save();
// echo '<pre>';var_dump( $shouldSave, $element );exit();
if( $shouldSave ){
if( $element[ 'id_notification' ] ){
$notification = Crunchbutton_Notification::o( $element[ 'id_notification' ] );
} else {
$notification = new Crunchbutton_Notification;
}
$notification->id_restaurant = $this->id_restaurant;
$notification->active = ( $element[ 'active' ] == 'true' || $element[ 'active' ] == '1' ) ? 1 : 0;
$notification->type = $element[ 'type' ];
$notification->id_admin = $id_admin;
$notification->value = $value;
$notification->save();
} else {
// remove
if( $element[ 'id_notification' ] ){
c::db()->query( 'DELETE FROM notification WHERE id_notification = "' . $element[ 'id_notification' ] . '"' );
}
}
}
$this->_notifications = null;
$where = [];
$where[ 'active' ] = NULL;

View File

@ -1026,7 +1026,6 @@ var WIDGET = {
restaurant.confirmation_type = data.confirmation_type;
continue;
}
if( ( !data.value || data.value==='' ) && data.type != 'admin' ) continue;
restaurant._notifications.push(data);
}
},