/** * @param int $id * @param array|\Traversable $data * @return mixed|\Zend\Stdlib\ResponseInterface */ public function update($id, $data) { try { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $data = ($data2 = $this->getEventManager()->trigger('controller.update.data', $this, array('data' => $data, 'em' => $em))->last()) ? $data2 : $data; $model = empty($id) ? new $this->modelClass() : $em->find($this->modelClass, $id); $model->exchangeArray(ObjectUtils::objectToArray($data)); $model = ($model2 = $this->getEventManager()->trigger('controller.update.model.pre', $this, array('model' => $model, 'data' => $data, 'em' => $em))->last()) ? $model2 : $model; if (empty($model->id)) { $em->persist($model); } else { $em->merge($model); } $em->flush(); $model = ($model2 = $this->getEventManager()->trigger('controller.update.model.post', $this, array('model' => $model, 'data' => $data, 'em' => $em))->last()) ? $model2 : $model; $this->response->setStatusCode(200); $this->response->setContent(Json::encode(is_array($model) ? $model : $model->getArrayCopy())); } catch (\Exception $e) { $this->getServiceLocator()->get('Athcore\\Log\\Logger')->exception($e); $this->response->setStatusCode(500); } return $this->response; }
/** * Function used to compare two link items. * * @param \stdClass $o1 * @param \stdClass $o2 * @return boolean */ protected function compare($o1, $o2) { $o1 = ObjectUtils::objectToArray($o1); unset($o1['href']); $o2 = ObjectUtils::objectToArray($o2); unset($o2['href']); return $o1 == $o2; }
/** * Function used to compare two script items. * * @param \stdClass $o1 * @param \stdClass $o2 * @return boolean */ protected function compare($o1, $o2) { $o1 = ObjectUtils::objectToArray($o1); unset($o1['attributes']['src']); unset($o1['source']); $o2 = ObjectUtils::objectToArray($o2); unset($o2['attributes']['src']); unset($o2['source']); return $o1 == $o2; }