/** * @return \Zend\Http\Response */ public function pushAction() { // getting instance of service locator $sl = $this->getServiceLocator(); // checking for auth if (!$sl->get('AuthService')->hasIdentity()) { return $this->redirect()->toRoute('login'); } // getting request instance $request = $this->getRequest(); // including class file require_once 'vendor/parse-library/parse.php'; // creating parseObject object $parse = new \parseObject('Alert'); // preparing array with data $startDate = date('Y-m-d H:i:s', strtotime($request->getPost('startDate'))); $endDate = date('Y-m-d H:i:s', strtotime($request->getPost('endDate'))); $data = array('pushText' => $request->getPost('pushText'), 'fullText' => $request->getPost('fullText'), 'isSimple' => (int) $request->getPost('isSimple') ? true : false, 'startDate' => $parse->dataType('date', $startDate), 'endDate' => $parse->dataType('date', $endDate), 'rank' => (int) $request->getPost('rank'), 'points' => $request->getPost('points')); // adding params to the parseObject foreach ($data as $key => $val) { $parse->__set($key, $val); } // saving object to parse service $response = $parse->save(); // getting objectId $data['objectId'] = $response->objectId; $data['startDate'] = $startDate; $data['endDate'] = $endDate; // getting required models $notifyTable = $sl->get('Application\\Model\\NotificationsTable'); $notify = new Notification(); // preparing notification's data $notify->exchangeArray($data); // saving notification to DB $data['id'] = $notifyTable->saveNotification($notify); // redirecting to message page return $this->redirect()->toRoute('show', array('controller' => 'Application\\Controller\\Index', 'action' => 'show', 'id' => $data['id'])); }
public function addNotification(Notification $notification) { $sql = new Sql($this->dbAdapter); $insert = $sql->insert('notifications'); $newData = $notification->toArray(); $insert->values($newData); $selectString = $sql->getSqlStringForSqlObject($insert); return $this->dbAdapter->query($selectString, Adapter::QUERY_MODE_EXECUTE); }