protected function save($id, $values) { if ($id) { if ($entity = $this->getItem($id)) { Doctrine::setValues($entity, $this->entityClass, $values); } else { throw new \Exception('Entity: ' . $this->entityClass . ' with id=' . $id . ' not found'); } } else { $entity = new $this->entityClass(); Doctrine::setValues($entity, $this->entityClass, $values); } $em = $this->getEntityManager(); $em->persist($entity); $em->flush(); return $entity; }
public function pay($params = array()) { //ID платежа в системе Onpay.ru $onpay_id = $params->get('onpay_id'); //Номер заказа $pay_for = $params->get('pay_for'); //Сумма платежа $order_amount = $params->get('order_amount'); //Валюта, аналогичная атрибуту “ticker” платёжной ссылки $order_currency = $params->get('order_currency'); //Сумма, которая будет *фактически* внесена на баланс Продавца $balance_amount = $params->get('balance_amount'); //Валюта, в которой сумма платежа будет зачислена на баланс Продавца $balance_currency = $params->get('balance_currency'); //“check” запрос - это запрос на проверку возможности оплаты указанного счёта, “pay” запрос - это уведомление о платеже, поступившем на счет Продавца $type = $params->get('type'); //Дата и время, в которое платёж был получен системой Onpay.ru от Клиента $paymentDateTime = $params->get('paymentDateTime'); //MD5 это хэш подпись платежа. Строка в верхнем регистре $md5 = $params->get('md5'); $order_id = $pay_for; //type;pay_for;onpay_id;order_amount;order_ticker;secret_key_for_api_in $arr = array($type, $pay_for, $onpay_id, $order_amount, $order_currency, $this->secret_key_for_api_in); $my_md5 = $this->md5($arr); $ok = false; if (!$this->test && $md5 == $my_md5) { if ($order = Doctrine::getRepository('Front\\Entity\\Order')->findOneBy(array('number' => $pay_for))) { $order->setPaymentSum($order_amount); $order->setPaymentDate(\DateTime::createFromFormat(\DateTime::ATOM, $paymentDateTime)); $order->setPay(1); Doctrine::getEntityManager()->persist($order); Doctrine::getEntityManager()->flush(); $ok = true; } } //--- RESULT --- $result = new \stdClass(); $result->onpay_id = $onpay_id; $result->pay_for = $pay_for; $result->order_id = $order_id; if ($ok) { $result->code = 0; $result->comment = 'OK'; } else { $result->code = 2; $result->comment = 'Error'; } //type;pay_for;onpay_id;order_id;order_amount;order_ticker;code;secret_key_api_in if (!$this->test) { $arr = array($type, $pay_for, $onpay_id, $order_id, $order_amount, $order_ticker, $code, $this->secret_key_for_api_in); $result->md5 = $this->md5($arr); } //--- RESPONSE --- return $this->responseXml($this->xml($result)); }
/** * * @param string $entityClass * @return \Doctrine\ORM\EntityRepository The repository class. */ public function getRepository($entityClass) { return Doctrine::getRepository($entityClass); }
public function get() { $html = '<table style="width:100%;">'; $metadata = $this->getMetadata(); //echo '<pre>';var_dump($metadata); $columns = $this->getColumns(); $values = $this->getValues(); $this->getRequired(); foreach ($columns as $column => $label) { if (isset($metadata->associationMappings[$column])) { $row = $metadata->associationMappings[$column]; if (Doctrine::isManyToOne($metadata, $column)) { $class = $row['targetEntity']; $name = $row['fieldName']; $method = 'get_' . $name; $method = Camel::to_camel_case($method); $obj = $this->entity->{$method}(); $value = !empty($obj) ? $obj->getId() : 0; $class_meta = Doctrine::getEntityManager()->getClassMetadata($class); if (isset($class_meta->fieldMappings['path_alias'])) { $items = Doctrine::getEntityManager()->getRepository($class)->findBy(array(), array('path_alias' => 'ASC')); } else { $items = Doctrine::getEntityManager()->getRepository($class)->findAll(); } $attributes = array('required' => $this->has($name, $this->required), 'style' => 'width: 100%;'); $html .= '<tr><td>' . $label . '</td><td>' . self::getSelect($name, $value, $items, $attributes) . '</td></tr>'; } elseif (Doctrine::isManyToMany($metadata, $column)) { $class = $row['targetEntity']; $name = $row['fieldName']; $method = 'get_' . $name; $method = Camel::to_camel_case($method); $arr = $this->entity->{$method}(); $class_meta = Doctrine::getEntityManager()->getClassMetadata($class); if (isset($class_meta->fieldMappings['path_alias'])) { $items = Doctrine::getEntityManager()->getRepository($class)->findBy(array(), array('path_alias' => 'ASC')); } else { $items = Doctrine::getEntityManager()->getRepository($class)->findAll(); } $attributes = array('required' => $this->has($name, $this->required), 'style' => 'width: 100%;'); $html .= '<tr><td>' . $label . '</td><td>' . self::getMulti($name . '[]', $arr, $items, $attributes) . '</td></tr>'; } } else { $row = $metadata->fieldMappings[$column]; $name = $row['fieldName']; $primary = isset($row['id']) && $row['id'] == TRUE; $type = $row['type']; $length = isset($row['length']) ? $row['length'] : null; $value = $values->{$name}; $attributes = array('required' => $this->has($name, $this->required)); $html .= '<tr><td>' . $label . '</td><td>' . self::getInput($type, $name, $value, $length, $primary, $attributes) . '</td></tr>'; } } $html .= '</table>'; $html .= HTML::submit('submit', 'Сохранить'); $form_atr = array('action' => BASE_URL . Sokol::getCom()->name . '/' . Sokol::getController()->name . '/save', 'method' => 'POST', 'style' => 'width: 100%;'); return HTML::form($html, $form_atr); }