public function getEntitlementsForPrincipalToService(Principal $p, Service $s) { $user = sfContext::getInstance()->getUser(); $eids = array(); $rps = Doctrine::getTable('RolePrincipal')->findByPrincipalId($p->getId()); foreach ($rps as $rp) { $res = Doctrine::getTable('RoleEntitlement')->findByRoleId($rp->getRoleId()); foreach ($res as $re) { $eids[] = $re->getEntitlementId(); } } $ueids = array_unique($eids); foreach ($ueids as $ueid) { $e = Doctrine::getTable('Entitlement')->find($ueid); // $tmp .= $e->getName()." ".$e->getService()." ".$s->getName()."<br>"; if ($s->isValidated()) { if ($e->getServiceId() == $s->getId()) { $es[] = $e; } } } if (isset($es)) { return $es; } else { //var_dump(array($tmp));exit; return NULL; } }
/** * Тест /robokassa/init * */ public function testInit() { $user = $this->helper->makeUser(); //$user->setUserName('Admin'); $this->authenticateUser($user); $user->save(); $service = new Service(); $service->price = 100; $service->save(); // Верный запрос // Ожидаем редирект $this->browser->post($this->generateUrl('robokassa', array('action' => 'init')), array('service' => $service->getId(), 'term' => 6))->with('request')->begin()->isParameter('service', $service->getId())->isParameter('term', 6)->end()->with('response')->begin()->isStatusCode(200)->matches('/(robokassa)/i')->end(); // Неверный запрос с несуществующим id сервиса // Ожидаем переброс на 404 $this->browser->post('robokassa/init/', array('service' => time(), 'term' => 6))->with('response')->begin()->isStatusCode(404)->end(); }
/** * Тест каскадных удалений * */ public function testCascade() { $bt = new BillingTransaction(); // Создаем пользователя, услугу и транзакцию $user = $this->helper->makeUser(); $user->save(); $service = new Service(); $service->save(); $bt->setUserId($user->getId()); $bt->setServiceId($service->getId()); $bt->save(); // При удалении службы транзакция остается $service->delete(); $findBt = Doctrine::getTable('BillingTransaction')->find($bt->getId()); $this->assertType('BillingTransaction', $findBt); $this->assertEquals($findBt->getId(), $bt->getId()); // При удалении пользователя удаляется запись о транзакции $user->delete(); $findBt = Doctrine::getTable('BillingTransaction')->find($bt->getId()); $this->assertEquals($findBt, null); }
public function moveService(\Service $Service, \Site $Site, \User $user = null) { //Throws exception if user is not an administrator $this->checkUserIsAdmin($user); $this->em->getConnection()->beginTransaction(); //suspend auto-commit try { //If the site or service have no ID - throw logic exception $site_id = $Site->getId(); if (empty($site_id)) { throw new LogicException('Site has no ID'); } $Service_id = $Service->getId(); if (empty($Service_id)) { throw new LogicException('Service has no ID'); } //find old site $old_Site = $Service->getParentSite(); //If the Site has changed, then we move the site. if ($old_Site != $Site) { //Remove the service from the old site if it has an old site if (!empty($old_Site)) { $old_Site->getServices()->removeElement($Service); } //Add Service to new Site $Site->addServiceDoJoin($Service); //persist $this->em->merge($Site); $this->em->merge($old_Site); } //close if $this->em->flush(); $this->em->getConnection()->commit(); } catch (Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } }
public function addService(Service $service) { $this->services[$service->getId()] = $service; }