Esempio n. 1
0
 /**
  *
  * @return Doctrine_Collection 
  */
 protected function getSampleDoctrineCollection()
 {
     $employee1 = new Employee();
     $employee2 = new Employee();
     $employee3 = new Employee();
     $employee1->fromArray(array('firstName' => 'John', 'lastName' => 'Smith'));
     $employee2->fromArray(array('firstName' => 'John', 'lastName' => 'Carter'));
     $employee3->fromArray(array('firstName' => 'John', 'lastName' => 'Jayapala'));
     $collection = new Doctrine_Collection('Employee');
     $collection->add($employee1);
     $collection->add($employee2);
     $collection->add($employee3);
     return $collection;
 }
Esempio n. 2
0
 public function executeImportSentences(dmWebRequest $request)
 {
     $catalogue = $this->getObjectOrForward404($request);
     $form = new DmCatalogueImportForm();
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
     if ($request->isMethod('post') && $form->bindAndValid($request)) {
         $file = $form->getValue('file');
         $override = $form->getValue('override');
         $dataFile = $file->getTempName();
         $table = dmDb::table('DmTransUnit');
         $existQuery = $table->createQuery('t')->select('t.id, t.source, t.target, t.created_at, t.updated_at')->where('t.dm_catalogue_id = ? AND t.source = ?');
         $catalogueId = $catalogue->get('id');
         $nbAdded = 0;
         $nbUpdated = 0;
         try {
             if (!is_array($data = sfYaml::load(file_get_contents($dataFile)))) {
                 $this->getUser()->logError($this->getI18n()->__('Could not load file: %file%', array('%file%' => $file->getOriginalName())));
                 return $this->renderPartial('dmInterface/flash');
             }
         } catch (Exception $e) {
             $this->getUser()->logError($this->getI18n()->__('Unable to parse file: %file%', array('%file%' => $file->getOriginalName())));
             return $this->renderPartial('dmInterface/flash');
         }
         $addedTranslations = new Doctrine_Collection($table);
         $line = 0;
         foreach ($data as $source => $target) {
             ++$line;
             if (!is_string($source) || !is_string($target)) {
                 $this->getUser()->logError($this->getI18n()->__('Error line %line%: %file%', array('%line%' => $line, '%file%' => $file->getOriginalName())));
                 return $this->renderPartial('dmInterface/flash');
             } else {
                 $existing = $existQuery->fetchOneArray(array($catalogueId, $source));
                 if (!empty($existing) && $existing['source'] === $source) {
                     if ($existing['target'] !== $target) {
                         if ($override || $existing['created_at'] === $existing['updated_at']) {
                             $table->createQuery()->update('DmTransUnit')->set('target', '?', array($target))->where('id = ?', $existing['id'])->execute();
                             ++$nbUpdated;
                         }
                     }
                 } elseif (empty($existing)) {
                     $addedTranslations->add(dmDb::create('DmTransUnit', array('dm_catalogue_id' => $catalogue->get('id'), 'source' => $source, 'target' => $target)));
                     ++$nbAdded;
                 }
             }
         }
         $addedTranslations->save();
         if ($nbAdded) {
             $this->getUser()->logInfo($this->getI18n()->__('%catalogue%: added %count% translation(s)', array('%catalogue%' => $catalogue->get('name'), '%count%' => $nbAdded)));
         }
         if ($nbUpdated) {
             $this->getUser()->logInfo($this->getI18n()->__('%catalogue%: updated %count% translation(s)', array('%catalogue%' => $catalogue->get('name'), '%count%' => $nbUpdated)));
         }
         if (!$nbAdded && !$nbUpdated) {
             $this->getUser()->logInfo($this->getI18n()->__('%catalogue%: nothing to add and update', array('%catalogue%' => $catalogue->get('name'))));
         }
         return $this->renderText(url_for1($this->getRouteArrayForAction('index')));
     }
     $action = url_for1($this->getRouteArrayForAction('importSentences', $catalogue));
     return $this->renderText($form->render('.dm_form.list.little action="' . $action . '"'));
 }
 public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     //Création de la collection d'objet EiProjectLang à ajouter
     $collection = new Doctrine_Collection("EiProjectLang");
     $items = $projets->getElementsByTagName("ei_project_langs");
     if ($items->length > 0) {
         //ya t-il des éléments à traiter?
         $ei_project_langs = $items->item(0)->getElementsByTagName("ei_project_lang");
         if ($ei_project_langs->length > 0) {
             foreach ($ei_project_langs as $ei_project_lang) {
                 $lang_id = $ei_project_lang->getAttribute("lang");
                 //recherche du profil en base
                 if ($lang_id != null && $project_ref != null && $project_id != null) {
                     $new_ei_project_lang = new EiProjectLang();
                     $new_ei_project_lang->setLang($lang_id);
                     $new_ei_project_lang->setProjectId($project_id);
                     $new_ei_project_lang->setProjectRef($project_ref);
                     $collection->add($new_ei_project_lang);
                 }
             }
             if ($collection->getFirst()) {
                 $collection->save($conn);
             }
             //Sauvegarde de la collection
             return 1;
         }
         return null;
     }
 }
 /**
  * Returns the SLA Summary (@see IcingaSLASummary) for this filter
  *
  * @param Doctrine_Connection $dbConnection
  * @param type $filter
  * @return Doctrine_Collection
  */
 public static function getSummary(Doctrine_Connection $dbConnection = null, $filter = null)
 {
     if ($dbConnection == null) {
         $dbConnection = AgaviContext::getInstance()->getDatabaseConnection("icinga");
     }
     $driver = $dbConnection->getDriverName();
     $stmt = null;
     switch (strtolower($driver)) {
         case 'pgsql':
             $stmt = self::getPgsqlSummaryQuery($dbConnection, $filter);
             break;
         case 'oracle':
         case 'icingaoracle':
             $stmt = self::getOracleSummaryQuery($dbConnection, $filter);
             break;
         case 'mysql':
             $stmt = self::getMySQLSummaryQuery($dbConnection, $filter);
             break;
         default:
             throw new AppKitDoctrineException("Invalid driver " . $driver);
     }
     $stmt->execute();
     $result = new Doctrine_Collection("IcingaSLASummary");
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $record = new IcingaSLASummary();
         foreach ($row as $key => $value) {
             $record->{strtolower($key)} = $value;
         }
         $result->add($record);
     }
     return $result;
 }
 /**
  *
  * @param <type> $request
  */
 public function execute($request)
 {
     $this->setForm(new CopyActivityForm());
     $projectId = $request->getParameter('projectId');
     $this->form->bind($request->getParameter($this->form->getName()));
     $projectActivityList = $this->getProjectService()->getActivityListByProjectId($projectId);
     if ($this->form->isValid()) {
         $activityNameList = $request->getParameter('activityNames', array());
         $activities = new Doctrine_Collection('ProjectActivity');
         $isUnique = true;
         foreach ($activityNameList as $activityName) {
             foreach ($projectActivityList as $projectActivity) {
                 if (strtolower($activityName) == strtolower($projectActivity->getName())) {
                     $isUnique = false;
                     break;
                 }
             }
         }
         if ($isUnique) {
             foreach ($activityNameList as $activityName) {
                 $activity = new ProjectActivity();
                 $activity->setProjectId($projectId);
                 $activity->setName($activityName);
                 $activity->setIsDeleted(ProjectActivity::ACTIVE_PROJECT);
                 $activities->add($activity);
             }
             $activities->save();
             $this->getUser()->setFlash('templateMessageAct', array('success', __('Successfully Copied')));
         } else {
             $this->getUser()->setFlash('templateMessageAct', array('failure', __('Name Already Exists')));
         }
         $this->redirect('admin/saveProject?projectId=' . $projectId);
     }
 }
 /**
  *
  * @param PetitionApiToken $api_token
  * @return \Doctrine_Collection
  */
 public function fetchOffsetsByToken(PetitionApiToken $api_token)
 {
     $coll = new Doctrine_Collection('ApiTokenOffset', 'country');
     foreach ($this->createQuery('o')->where('o.petition_api_token_id = ?', $api_token->getId())->execute() as $offset) {
         $coll->add($offset);
     }
     return $coll;
 }
 public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     //Création de la collection d'objet EiVersionNotice à ajouter
     $collection = new Doctrine_Collection("EiVersionNotice");
     //Supression des versions de notice qui n'existent plus sur script
     $this->deleteNotFoundVersionNotice($conn);
     $items = $projets->getElementsByTagName("ei_version_notices");
     if ($items->length > 0) {
         //ya t-il des éléments à traiter?
         $ei_version_notices = $items->item(0)->getElementsByTagName("ei_version_notice");
         if ($ei_version_notices->length > 0) {
             foreach ($ei_version_notices as $ei_version_notice) {
                 $notice_id = $ei_version_notice->getAttribute("notice_id");
                 $notice_ref = $ei_version_notice->getAttribute("notice_ref");
                 $version_notice_id = $ei_version_notice->getAttribute("version_notice_id");
                 $lang = $ei_version_notice->getAttribute("lang");
                 //recherche du profil en base
                 if ($notice_id != null && $notice_ref != null && $version_notice_id != null && $lang != null) {
                     $q = Doctrine_Core::getTable('EiVersionNotice')->findOneByNoticeIdAndNoticeRefAndVersionNoticeIdAndLang($notice_id, $notice_ref, $version_notice_id, $lang);
                     if ($q && $q != null) {
                         //si l'element existe , on fait une mise à jour
                         $q->setName($ei_version_notice->getElementsByTagName("name")->item(0)->nodeValue);
                         $q->setDescription($ei_version_notice->getElementsByTagName("description")->item(0)->nodeValue);
                         $q->setExpected($ei_version_notice->getElementsByTagName("expected")->item(0)->nodeValue);
                         $q->setResult($ei_version_notice->getElementsByTagName("result")->item(0)->nodeValue);
                         $q->setIsActive($ei_version_notice->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $q->save($conn);
                     } else {
                         //l'élément n'existe pas encore, et dans ce cas on le crée
                         $new_ei_version_notice = new EiVersionNotice();
                         $new_ei_version_notice->setNoticeId($notice_id);
                         $new_ei_version_notice->setNoticeRef($notice_ref);
                         $new_ei_version_notice->setVersionNoticeId($version_notice_id);
                         $new_ei_version_notice->setLang($lang);
                         $new_ei_version_notice->setDescription($ei_version_notice->getElementsByTagName("description")->item(0)->nodeValue);
                         $new_ei_version_notice->setExpected($ei_version_notice->getElementsByTagName("expected")->item(0)->nodeValue);
                         $new_ei_version_notice->setResult($ei_version_notice->getElementsByTagName("result")->item(0)->nodeValue);
                         $new_ei_version_notice->setName($ei_version_notice->getElementsByTagName("name")->item(0)->nodeValue);
                         $new_ei_version_notice->setIsActive($ei_version_notice->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $collection->add($new_ei_version_notice);
                     }
                 }
             }
             if ($collection->getFirst()) {
                 $collection->save($conn);
             }
             //Sauvegarde de la collection
             return 1;
         }
         return null;
     }
 }
Esempio n. 8
0
 private function _saveEmployeeWorkShift($workShiftId, $empArray)
 {
     $empWorkShiftCollection = new Doctrine_Collection('EmployeeWorkShift');
     for ($i = 0; $i < sizeof($empArray); $i++) {
         $empWorkShift = new EmployeeWorkShift();
         $empWorkShift->setWorkShiftId($workShiftId);
         $empWorkShift->setEmpNumber($empArray[$i]);
         $empWorkShiftCollection->add($empWorkShift);
     }
     $this->getWorkShiftService()->saveEmployeeWorkShiftCollection($empWorkShiftCollection);
 }
 public function getVotosAus()
 {
     $this->getCamara() == 'C.Diputados' ? $camara = 'D' : ($camara = 'S');
     $parlamentarios = Doctrine_Core::getTable('Parlamentario')->createQuery('p')->where('p.senador_diputado = ?', $camara)->andWhere('p.activo = ?', 1)->execute();
     $ausentes = new Doctrine_Collection('Parlamentario');
     foreach ($parlamentarios as $i => $parl) {
         if (Doctrine_Core::getTable('VotacionParlamentario')->find(array($this->getIdVotacion(), $parl->getIdParlamentario())) == null) {
             $ausentes->add($parl);
         }
     }
     return $ausentes;
 }
Esempio n. 10
0
 public function executeDissociate(sfWebRequest $request)
 {
     $this->rfid_groupe = $this->getRoute()->getObject();
     $rfids = Doctrine_Core::getTable('Rfid')->findByGroupeId($this->rfid_groupe->getGuid());
     $collection = new Doctrine_Collection('Rfid');
     foreach ($rfids as $rfid) {
         $rfid->setGroupeId(null);
         $collection->add($rfid);
     }
     $collection->save();
     $this->redirect('@rfid_groupe');
 }
 /**
  * @param $campaign_id
  * @param $orders
  */
 public function getAllCampaignExecutions($campaign_id, $orders = array())
 {
     // Création de la requête SQL de récupération
     $sql = "SELECT * FROM ei_campaign_status_vw WHERE campaign_id = " . $campaign_id . " ORDER BY created_at DESC;";
     // Récupération des résultats.
     $resultats = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll($sql);
     // Création de la collection.
     $collection = new Doctrine_Collection("EiCampaignExecution");
     foreach ($resultats as $resultat) {
         $collection->add($this->createObjectStatusFromArray($resultat));
     }
     return $collection;
 }
Esempio n. 12
0
 public function updateObject($values = null)
 {
     $issues = new Doctrine_Collection('Issue');
     $values = $this->getChangedValues();
     foreach ($this->ids as $id) {
         $issue = Doctrine::getTable('Issue')->getForShow(array('id' => $id));
         $issue->takeSnapshot();
         $issue->fromArray($values);
         $issue->addActivityNote($this->getValue('body'));
         $issues->add($issue);
     }
     $this->object = $issues;
     return $issues;
 }
 public function updatePosition($ids, $campaign_id)
 {
     if (!is_array($ids)) {
         return null;
     }
     //On reconstruit les relations de la table graph_has_graph
     $newStepTab = array();
     $ids = $ids[0];
     if (!is_array($ids)) {
         return null;
     }
     foreach ($ids as $i => $item) {
         if (array_key_exists($i + 1, $ids)) {
             $newStepTab[] = array($ids[$i], $ids[$i + 1]);
         }
     }
     //var_dump($newStepTab);
     if (!is_array($newStepTab)) {
         return null;
     }
     $conn = Doctrine_Manager::connection();
     try {
         $conn->beginTransaction();
         /*On vérifie qu'on est pas en accès concurrent */
         $nb = count(Doctrine_Core::getTable('EiCampaignGraph')->findByCampaignId($campaign_id));
         if ($nb != count($ids)) {
             throw new Exception('Concurrent Access. refresh page ...');
         }
         $conn->delete($this->getInstance(), array('campaign_id' => $campaign_id));
         $collection = new Doctrine_Collection($this->getInstance());
         foreach ($newStepTab as $item) {
             $newItem = new EiCampaignGraphHasGraph();
             $newItem->setParentId($item[0]);
             $newItem->setChildId($item[1]);
             $newItem->setCampaignId($campaign_id);
             $collection->add($newItem);
         }
         $collection->save($conn);
         $conn->commit();
         //  validation globale  de la création
         return 1;
     } catch (Exception $e) {
         $conn->rollback();
         //throw $e('An error occurred while trying to update nodes positions ');
         return -1;
     }
 }
Esempio n. 14
0
 public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     //Création de la collection d'objet View à ajouter
     $collection = new Doctrine_Collection("EiView");
     $items = $projets->getElementsByTagName("ei_views");
     if ($items->length > 0) {
         //ya t-il des éléments à traiter?
         $ei_views = $items->item(0)->getElementsByTagName("ei_view");
         if ($ei_views->length > 0) {
             foreach ($ei_views as $ei_view) {
                 $view_id = $ei_view->getAttribute("view_id");
                 $view_ref = $ei_view->getAttribute("view_ref");
                 //recherche du profil en base
                 if ($view_id != null && $view_ref != null) {
                     $q = Doctrine_Core::getTable('EiView')->findOneByViewIdAndViewRef($view_id, $view_ref);
                     if ($q && $q != null) {
                         //si l'element existe , on fait une mise à jour
                         $q->setDescription($ei_view->getElementsByTagName("description")->item(0)->nodeValue);
                         $q->setIsActive($ei_view->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $q->save($conn);
                     } else {
                         //l'élément n'existe pas encore, et dans ce cas on le crée
                         $new_ei_view = new EiView();
                         $new_ei_view->setViewId($view_id);
                         $new_ei_view->setViewRef($view_ref);
                         $new_ei_view->setDescription($ei_view->getElementsByTagName("description")->item(0)->nodeValue);
                         $new_ei_view->setIsActive($ei_view->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $new_ei_view->setProjectId($project_id);
                         $new_ei_view->setProjectRef($project_ref);
                         //                        $new_ei_view->save($conn);
                         $collection->add($new_ei_view);
                     }
                 }
             }
             if ($collection->getFirst()) {
                 $collection->save($conn);
             }
             //Sauvegarde de la collection
             return 1;
         }
         return null;
         //On a retrouvé aucun élément de ce type
     }
 }
 /**
  * @covers SystemUserService::getNonPredefinedUserRoles
  */
 public function testGetNonPredefinedUserRoles()
 {
     $userRoles = new Doctrine_Collection('UserRole');
     for ($i = 0; $i < 2; $i++) {
         $userRole = new UserRole();
         $userRole->setId($i + 1);
         $userRole->setName("test name" . $i + 1);
         $userRole->setIsAssignable(1);
         $userRole->setIsPredefined(0);
         $userRoles->add($userRole);
     }
     $dao = $this->getMock('SystemUserDao');
     $dao->expects($this->once())->method('getNonPredefinedUserRoles')->will($this->returnValue($userRoles));
     $this->systemUserService->setSystemUserDao($dao);
     $result = $this->systemUserService->getNonPredefinedUserRoles();
     $this->assertEquals($userRoles, $result);
 }
Esempio n. 16
0
 public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     //Création de la collection d'objet EiNotice à ajouter
     $collection = new Doctrine_Collection("EiNotice");
     //Supréssion des notices n'existant plus
     $this->deleteNotFoundNotice();
     $items = $projets->getElementsByTagName("ei_notices");
     if ($items->length > 0) {
         //ya t-il des éléments à traiter?
         $ei_notices = $items->item(0)->getElementsByTagName("ei_notice");
         if ($ei_notices->length > 0) {
             foreach ($ei_notices as $ei_notice) {
                 $notice_id = $ei_notice->getAttribute("notice_id");
                 $notice_ref = $ei_notice->getAttribute("notice_ref");
                 //recherche du profil en base
                 if ($notice_id != null && $notice_ref != null) {
                     $q = Doctrine_Core::getTable('EiNotice')->findOneByNoticeIdAndNoticeRef($notice_id, $notice_ref);
                     if ($q && $q != null) {
                         //si l'element existe , on fait une mise à jour
                         $q->setName($ei_notice->getElementsByTagName("name")->item(0)->nodeValue);
                         $q->save($conn);
                     } else {
                         //l'élément n'existe pas encore, et dans ce cas on le crée
                         $new_ei_notice = new EiNotice();
                         $new_ei_notice->setNoticeId($notice_id);
                         $new_ei_notice->setNoticeRef($notice_ref);
                         $new_ei_notice->setFunctionId($ei_notice->getElementsByTagName("function_id")->item(0)->nodeValue);
                         $new_ei_notice->setFunctionRef($ei_notice->getElementsByTagName("function_ref")->item(0)->nodeValue);
                         $new_ei_notice->setName($ei_notice->getElementsByTagName("name")->item(0)->nodeValue);
                         $collection->add($new_ei_notice);
                     }
                 }
             }
             if ($collection->getFirst()) {
                 $collection->save($conn);
             }
             //Sauvegarde de la collection
             return 1;
         }
         return null;
     }
 }
Esempio n. 17
0
 public function testGetAccessibleEmployees()
 {
     $mockService = $this->getMock('EmployeeService');
     $employeeList = new Doctrine_Collection('Employee');
     for ($i = 0; $i < 2; $i++) {
         $employee = new Employee();
         $employee->setEmployeeId($i + 1);
         $employee->setEmpNumber($i + 1);
         $employee->setFirstName("test name" . $i + 1);
         $employeeList->add($employee);
     }
     $mockService->expects($this->once())->method('getSubordinateList')->with(1, true)->will($this->returnValue($employeeList));
     $this->supervisorUserRole->setEmployeeNumber(1);
     $this->supervisorUserRole->setEmployeeService($mockService);
     $employees = $this->supervisorUserRole->getAccessibleEmployees();
     $this->assertEquals(2, count($employees));
     for ($i = 0; $i < 2; $i++) {
         $this->assertEquals($employees[$i + 1], $employeeList[$i]);
     }
 }
 public function register($hash, $plugins, $version)
 {
     if (strlen($hash) != 32) {
         throw new dmException('Bad hash');
     }
     if (!($report = $this->findOneByHash($hash))) {
         $report = $this->create(array('hash' => $hash));
     }
     $report->set('diem_version', $version);
     $report->save();
     $refTable = dmDb::table('AnonymousReportPlugin');
     $refTable->createQuery('arp')->delete()->where('arp.anonymous_report_id = ?', $report->get('id'))->execute();
     $pluginNames = array_map('trim', explode(',', $plugins));
     if (!empty($pluginNames)) {
         $plugins = dmDb::query('Plugin p')->select('p.name, p.id')->whereIn('p.name', $pluginNames)->fetchArray();
         $refs = new Doctrine_Collection($refTable);
         foreach ($plugins as $plugin) {
             $refs->add($refTable->create(array('anonymous_report_id' => $report->get('id'), 'plugin_id' => $plugin['id'])));
         }
         $refs->save();
     }
 }
 /**
  * @covers CorporateDirectoryWebServiceHelper::getCorporateDirectoryEmployeeDetailsAsArray
  */
 public function testGetCorporateDirectoryEmployeeDetailsAsArrayWithLoationsAndSubunits()
 {
     $location = new Location();
     $location->setId(1);
     $locationCollection = new Doctrine_Collection('Location');
     $locationCollection->add($location);
     $employee = new Employee();
     $employee->setEmpNumber(1);
     $employee->setFirstName('testEmpFirstName');
     $employee->setLastName('testEmpLastName');
     $employee->setLocations($locationCollection);
     $count = 1;
     $employees = array($employee);
     $employeeDirectoryServiceMock = $this->getMock('EmployeeDirectoryService');
     $employeeDirectoryServiceMock->expects($this->once())->method('searchEmployees')->will($this->returnValue($employees));
     $employeeDirectoryServiceMock->expects($this->once())->method('getSearchEmployeeCount')->will($this->returnValue($count));
     $this->corporateDirectoryWebServiceHelper->setEmployeeDirectoryService($employeeDirectoryServiceMock);
     $employeeDetails = $this->corporateDirectoryWebServiceHelper->getCorporateDirectoryEmployeeDetailsAsArray();
     $this->assertEquals(1, count($employeeDetails));
     $this->assertNotNull($employeeDetails[0]['location_id']);
     $this->assertEquals(1, $employeeDetails[0]['location_id']);
 }
 /**
  * @param DOMNode $functionTag
  * @param int $position
  * @param EiIteration $iteration
  */
 public function generateFromXML(DOMNode $functionTag, $position = 0, EiIteration $iteration = null)
 {
     $this->setXpath($functionTag->getAttribute('xpath'));
     $this->setFunctionId($functionTag->getAttribute('function_id'));
     $this->setFunctionRef($functionTag->getAttribute('function_ref'));
     $this->setEiFonctionId($functionTag->getAttribute('ei_fonction_id'));
     $this->setPosition($position);
     if ($functionTag->hasChildNodes() && $functionTag->firstChild->nodeName == 'parameters') {
         $params = new Doctrine_Collection('EiTestSetParam');
         foreach ($functionTag->firstChild->childNodes as $paramNode) {
             $param = new EiTestSetParam();
             $param->setValeur($paramNode->nodeValue);
             $param->setParamId($paramNode->getAttribute('param_id'));
             $param->setFunctionId($this->getFunctionId());
             $param->setFunctionRef($this->getFunctionRef());
             $param->setEiTestSetFunction($this);
             $param->setEiTestSet($this->getEiTestSet());
             $param->setEiIteration($iteration);
             $params->add($param);
         }
         $this->setEiTestSetParams($params);
     }
 }
Esempio n. 21
0
 protected function loadGroups()
 {
     $array = array("developer" => array('description' => "Able to read and update source code", 'permissions' => array('system')), "seo" => array('description' => "Seo knowledge", 'permissions' => array('admin', 'sitemap', 'automatic_metas', 'manual_metas', 'url_redirection', 'google_analytics', 'use_google_analytics', 'google_webmaster_tools', 'use_google_webmaster_tools', 'tool_bar_admin', 'page_bar_admin', 'tool_bar_front', 'page_bar_front', 'see_log', 'config_panel', 'site_view', 'see_chart')), "integrator" => array('description' => "Integrator", 'permissions' => array('admin', 'content', 'code_editor', 'media_library', 'loremize', 'export_table', 'tool_bar_admin', 'page_bar_admin', 'media_bar_admin', 'tool_bar_front', 'page_bar_front', 'media_bar_front', 'zone_add', 'zone_edit', 'zone_delete', 'widget_add', 'widget_edit', 'widget_delete', 'page_add', 'page_edit', 'page_delete', 'config_panel', 'translation', 'layout', 'interface_settings', 'site_view', 'see_chart', 'see_log')), "webmaster 1" => array('description' => "Webmaster level 1", 'permissions' => array('admin', 'content', 'tool_bar_admin', 'page_bar_admin', 'media_bar_admin', 'tool_bar_front', 'page_bar_front', 'media_bar_front', 'search_engine', 'see_log', 'config_panel', 'translation', 'site_view', 'see_chart')), "writer" => array('description' => "Writer", 'permissions' => array('admin', 'content', 'tool_bar_admin', 'page_bar_admin', 'media_bar_admin', 'see_log', 'site_view', 'see_chart')), "front_editor" => array('description' => "Can fast edit front widgets", 'permissions' => array('widget_edit_fast', 'widget_edit_fast_record', 'widget_edit_fast_content_title', 'widget_edit_fast_content_link', 'widget_edit_fast_content_text', 'widget_edit_fast_content_image', 'widget_edit_fast_navigation_menu')));
     $permissions = dmDb::query('DmPermission p INDEXBY name')->select('p.name')->fetchArray();
     $groups = new Doctrine_Collection(dmDb::table('DmGroup'));
     foreach ($array as $name => $params) {
         if (!($group = dmDb::query('DmGroup g')->where('g.name = ?', $name)->fetchRecord())) {
             $group = dmDb::create('DmGroup', array('name' => $name, 'description' => $params['description']))->saveGet();
         }
         $groups->add($group);
         $groupPermissions = array();
         foreach ($params['permissions'] as $permissionName) {
             if (!isset($permissions[$permissionName])) {
                 throw new dmException('There is no permission called ' . $permissionName);
             }
             $groupPermissions[] = $permissions[$permissionName]['id'];
         }
         $group->link('Permissions', $groupPermissions);
     }
     $groups->save();
 }
Esempio n. 22
0
 public function testGenerator()
 {
     $coll = new Doctrine_Collection($this->objTable);
     $coll->setKeyColumn('name');
     $user = new User();
     $user->name = "name";
     $coll->add($user);
     $this->assertTrue($coll["name"] === $user);
     $this->connection->getTable("email")->setAttribute(Doctrine::ATTR_COLL_KEY, "address");
     $emails = $this->connection->getTable("email")->findAll();
     foreach ($emails as $k => $v) {
         $this->assertTrue(gettype($k), "string");
     }
 }
Esempio n. 23
0
 /**
  * Gets filter fields that are selected for a given report and are of type Runtime.
  * @param integer $reportId
  * @return array ( array of FilterFiled )
  */
 public function getSelectedRuntimeFilterFields($reportId)
 {
     $reportGroupId = $this->getReportGroupIdOfAReport($reportId);
     $type = PluginSelectedFilterField::RUNTIME_FILTER_FIELD;
     $runtimeSelectedFilterFields = $this->getReportableService()->getSelectedFilterFieldsByType($reportId, $type, true);
     $runtimeFilterFieldList = new Doctrine_Collection("FilterField");
     foreach ($runtimeSelectedFilterFields as $runtimeSelectedFilterField) {
         $runtimeFilterFieldList->add($runtimeSelectedFilterField->getFilterField());
     }
     return $runtimeFilterFieldList;
 }
 public function testSaveEmployeeLeaveEntitlementCollection()
 {
     $employeeLeaveEntitlementCollection = new Doctrine_Collection('EmployeeLeaveEntitlement');
     $employeeLeaveEntitlementList = array();
     $employeeLeaveEntitlement = new EmployeeLeaveEntitlement();
     $employeeLeaveEntitlement->setLeaveTypeId(1);
     $employeeLeaveEntitlement->setLeavePeriodId(1);
     $employeeLeaveEntitlement->setEmployeeId(1);
     $employeeLeaveEntitlement->setNoOfDaysAllotted(14);
     $employeeLeaveEntitlement->setLeaveBroughtForward(2);
     $employeeLeaveEntitlement->setLeaveCarriedForward(5);
     $employeeLeaveEntitlementCollection->add($employeeLeaveEntitlement);
     $employeeLeaveEntitlementList[] = $employeeLeaveEntitlement;
     $employeeLeaveEntitlement = new EmployeeLeaveEntitlement();
     $employeeLeaveEntitlement->setLeaveTypeId(1);
     $employeeLeaveEntitlement->setLeavePeriodId(1);
     $employeeLeaveEntitlement->setEmployeeId(2);
     $employeeLeaveEntitlement->setNoOfDaysAllotted(20);
     $employeeLeaveEntitlement->setLeaveBroughtForward(3);
     $employeeLeaveEntitlement->setLeaveCarriedForward(4);
     $employeeLeaveEntitlementCollection->add($employeeLeaveEntitlement);
     $employeeLeaveEntitlementList[] = $employeeLeaveEntitlement;
     $leaveEntitlementDao = $this->getMock('LeaveEntitlementDao', array('saveEmployeeLeaveEntitlementCollection'));
     $leaveEntitlementDao->expects($this->once())->method('saveEmployeeLeaveEntitlementCollection')->with($employeeLeaveEntitlementList)->will($this->returnValue($employeeLeaveEntitlementCollection));
     $leaveEntitlementService = new LeaveEntitlementService();
     $leaveEntitlementService->setLeaveEntitlementDao($leaveEntitlementDao);
     $results = $leaveEntitlementService->saveEmployeeLeaveEntitlementCollection($employeeLeaveEntitlementList);
     $this->assertEquals($employeeLeaveEntitlementCollection, $results);
 }
Esempio n. 25
0
 /**
  * @param myDoctrineRecord $record
  * @param mixed $key
  * @return myDoctrineCollection
  */
 public function add($record, $key = null)
 {
     parent::add($record, $key);
     return $this;
 }
 public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     //Création de la collection d'objet KalFunction à ajouter
     $collection = new Doctrine_Collection("KalFunction");
     $items = $projets->getElementsByTagName("ei_functions");
     if ($items->length > 0) {
         //ya t-il des éléments à traiter?
         $ei_functions = $items->item(0)->getElementsByTagName("ei_function");
         if ($ei_functions->length > 0) {
             foreach ($ei_functions as $ei_function) {
                 $function_id = $ei_function->getAttribute("function_id");
                 $function_ref = $ei_function->getAttribute("function_ref");
                 //recherche de la fonction  en base
                 if ($function_id != null && $function_ref != null) {
                     $q = Doctrine_Core::getTable('KalFunction')->findOneByFunctionIdAndFunctionRef($function_id, $function_ref);
                     if ($q && $q != null) {
                         //si l'element existe , on fait une mise à jour
                         $q->setDescription($ei_function->getElementsByTagName("description")->item(0)->nodeValue);
                         $q->setIsActive($ei_function->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $q->save($conn);
                         //On supprime toutes les commandes associées à la fonction
                         Doctrine_Core::getTable('EiFunctionHasCommande')->deleteAssociatedCmd($q, $conn);
                     } else {
                         //l'élément n'existe pas encore, et dans ce cas on le crée
                         $new_ei_function = new KalFunction();
                         $new_ei_function->setFunctionId($function_id);
                         $new_ei_function->setFunctionRef($function_ref);
                         $new_ei_function->setProjectId($project_id);
                         $new_ei_function->setProjectRef($project_ref);
                         $new_ei_function->setDescription($ei_function->getElementsByTagName("description")->item(0)->nodeValue);
                         $new_ei_function->setIsActive($ei_function->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $collection->add($new_ei_function);
                     }
                 }
             }
             if ($collection->getFirst()) {
                 $collection->save($conn);
             }
             //Sauvegarde de la collection
             return 1;
         }
         return null;
     }
 }
Esempio n. 27
0
 public function testGetAccessibleUserRoleIds()
 {
     $mockService = $this->getMock('SystemUserService');
     $roleList = new Doctrine_Collection('SystemUser');
     for ($i = 0; $i < 3; $i++) {
         $userRole = new UserRole();
         $userRole->setId($i + 1);
         $userRole->setName('test' . $i + 1);
         $roleList->add($userRole);
     }
     $mockService->expects($this->once())->method('getAssignableUserRoles')->will($this->returnValue($roleList));
     $this->adminUserRole->setSystemUserService($mockService);
     $roleIds = $this->adminUserRole->getAccessibleUserRoleIds(null, null);
     $this->assertEquals($roleIds, array(1, 2, 3));
 }
Esempio n. 28
0
 /**
  * Populate the relationship $name for all records in the passed collection
  *
  * @param string $name
  * @param Doctrine_Collection $coll
  * @return void
  */
 public function populateRelated($name, Doctrine_Collection $coll)
 {
     $rel = $this->_table->getRelation($name);
     $table = $rel->getTable();
     $foreign = $rel->getForeign();
     $local = $rel->getLocal();
     if ($rel instanceof Doctrine_Relation_LocalKey) {
         foreach ($this->data as $key => $record) {
             foreach ($coll as $k => $related) {
                 if ($related[$foreign] == $record[$local]) {
                     $this->data[$key]->setRelated($name, $related);
                 }
             }
         }
     } elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
         foreach ($this->data as $key => $record) {
             if (!$record->exists()) {
                 continue;
             }
             $sub = new Doctrine_Collection($table);
             foreach ($coll as $k => $related) {
                 if ($related[$foreign] == $record[$local]) {
                     $sub->add($related);
                     $coll->remove($k);
                 }
             }
             $this->data[$key]->setRelated($name, $sub);
         }
     } elseif ($rel instanceof Doctrine_Relation_Association) {
         $identifier = $this->_table->getIdentifier();
         $asf = $rel->getAssociationFactory();
         $name = $table->getComponentName();
         foreach ($this->data as $key => $record) {
             if (!$record->exists()) {
                 continue;
             }
             $sub = new Doctrine_Collection($table);
             foreach ($coll as $k => $related) {
                 if ($related->get($local) == $record[$identifier]) {
                     $sub->add($related->get($name));
                 }
             }
             $this->data[$key]->setRelated($name, $sub);
         }
     }
 }
Esempio n. 29
0
 /**
  * @param EiVersion $copie
  * @param Doctrine_Connection $conn
  * @param null $ei_scenario_id
  * @param array $allowedTypes
  * @return EiVersion
  * @throws Exception
  */
 public function createStructureCopy(EiVersion $copie, Doctrine_Connection $conn = null, $ei_scenario_id = null, array $allowedTypes = array())
 {
     /** @var sfLogger $logger */
     $logger = sfContext::getInstance()->getLogger();
     // Déclaration de la table EiVersionStructure.
     /** @var EiVersionStructureTable $tableVersionStr */
     $tableVersionStr = Doctrine_Core::getTable('EiVersionStructure');
     // Tableau des correspondances.
     $correspondances = array();
     $correspondancesF = array();
     $version_id = $this->old_version_id == false ? $this->getId() : $this->old_version_id;
     $allowedTypes = count($allowedTypes) == 0 ? EiVersionStructure::getAllTypes() : $allowedTypes;
     $ignored = 0;
     //*******************************************************//
     //**********          COPIE STRUCTURE          **********//
     //*******************************************************//
     $logger->info("--------------------------------------------");
     $logger->info("----------     COPIE SCENARIO     ----------");
     $logger->info("--------------------------------------------");
     // Création d'une collection de structure de version.
     /** @var Doctrine_Collection $nouvelleStructure */
     $nouvelleStructure = new Doctrine_Collection('EiVersionStructure');
     // Variable temporaire contenant le noeud père.
     /** @var EiVersionStructure $ei_version_str_prec */
     $ei_version_str_prec = null;
     // Variable temporaire contenant le niveau où l'on se situait dans l'arbre à la boucle précédente.
     $level_prec = 0;
     // Variables temporaires.
     /** @var EiVersionStructure $parent */
     $root_id = $parent = null;
     // On récupère la structure complète de la version actuelle.
     $currentVersionTree = $tableVersionStr->getEiVersionTree($version_id, $allowedTypes);
     // On parcourt chaque élément.
     /** @var EiVersionStructure $ei_version_str */
     foreach ($currentVersionTree as $i => $ei_version_str) {
         $logger->info("----------     PARCOURS ELT STRUCTURE N° " . $ei_version_str->getId() . "     ----------");
         if (in_array($ei_version_str->getType(), $allowedTypes)) {
             //*************************************************************//
             //**********          DETERMINATION DU PERE          **********//
             //*************************************************************//
             // Si le niveau précédent est inférieur au niveau parcouru, alors, le parent est la dernière version structure.
             if ($ei_version_str->getLevel() > $level_prec) {
                 $parent = $ei_version_str_prec;
             } elseif ($ei_version_str->getLevel() < $level_prec) {
                 // On réalise la différence entre les deux niveau.
                 $j = $level_prec - $ei_version_str->getLevel();
                 // On remonte d'autant de fois afin de récupérer le père.
                 while ($j > 0) {
                     $parent = $parent->getNode()->getParent();
                     $j--;
                 }
             }
             //*******************************************************************************//
             //**********          ENREGISTREMENT DES INFORMATIONS DE BASE          **********//
             //*******************************************************************************//
             $strElementCopie = new EiVersionStructure();
             $strElementCopie->setRootId($root_id);
             $strElementCopie->setLft($ei_version_str->getLft());
             $strElementCopie->setRgt($ei_version_str->getRgt());
             $strElementCopie->setLevel($ei_version_str->getLevel());
             $strElementCopie->setName($ei_version_str->getName());
             $strElementCopie->setDescription($ei_version_str->getDescription());
             $strElementCopie->setSlug($ei_version_str->getSlug());
             $strElementCopie->setEiVersion($copie);
             $strElementCopie->setType($ei_version_str->getType());
             // Si l'élément possède un père, on le précise.
             if ($parent) {
                 $strElementCopie->setEiVersionStructureParentId($parent->getId());
             }
             // On sauvegarde l'élément.
             $strElementCopie->save($conn);
             // Mise à jour du tableau des correspondances.
             $correspondances[$ei_version_str->getId()] = $strElementCopie->getId();
             //**********************************************************//
             //**********          CREATION FONCTION          ***********//
             //**********************************************************//
             // S'il s'agit d'une fonction, on crée la copie.
             if ($ei_version_str->isEiFonction()) {
                 $logger->info("----------     CREATION FONCTION     ----------");
                 $fct = $ei_version_str->getEiFonction()->createCopie($strElementCopie, $conn);
                 $strElementCopie->setEiFonctionId($fct->getId());
                 $correspondancesF[$ei_version_str->getEiFonctionId()] = $fct->getId();
             } elseif ($ei_version_str->isEiBlock()) {
                 $logger->info("----------     CREATION BLOCK     ----------");
                 $ei_version_str_prec = $strElementCopie;
             }
             $level_prec = $ei_version_str->getLevel();
             if ($i == 0) {
                 $root_id = $strElementCopie->getId();
                 $strElementCopie->setRootId($root_id);
                 $strElementCopie->save($conn);
             }
             $nouvelleStructure->add($strElementCopie);
         }
     }
     foreach ($currentVersionTree as $i => $ei_version_str) {
         //**********************************************************//
         //**********          CAS BLOCK FOREACH           **********//
         //**********************************************************//
         if ($ei_version_str->getType() == EiVersionStructure::$TYPE_FOREACH) {
             $logger->info("----------     CREATION FOREACH     ----------");
             /** @var EiMappingStructureSyncIn $oldMapping */
             $oldMapping = $ei_version_str->getEiVersionStructureDataSetMapping()->getFirst();
             $mapping = new EiMappingStructureSyncIn();
             $mapping->setEiDatasetStructureId($oldMapping->getEiDatasetStructureId());
             $mapping->setEiVersionStructureId($correspondances[$ei_version_str->getId()]);
             $mapping->save($conn);
         } elseif ($ei_version_str->isEiBlockParam()) {
             $logger->info("----------     CREATION BLOCK PARAM     ----------");
             // Copie des mappings IN et OUT.
             /** @var EiBlockDataSetMapping $oldMappingIn */
             $oldMappingIn = $ei_version_str->getMappingDataSet(EiBlockDataSetMapping::$TYPE_IN);
             /** @var EiBlockDataSetMapping $oldMappingOut */
             $oldMappingOut = $ei_version_str->getMappingDataSet(EiBlockDataSetMapping::$TYPE_OUT);
             if ($oldMappingIn != null) {
                 $logger->info("----------     MAPPING IN :  " . $oldMappingIn->getEiDatasetStructureId() . " / " . $correspondances[$ei_version_str->getId()] . "    ----------");
                 $newMappingIn = new EiMappingStructureSyncIn();
                 $newMappingIn->setEiDatasetStructureId($oldMappingIn->getEiDatasetStructureId());
                 $newMappingIn->setEiVersionStructureId($correspondances[$ei_version_str->getId()]);
                 $newMappingIn->save($conn);
             }
             if ($oldMappingOut != null) {
                 $logger->info("----------     MAPPING OUT :  " . $oldMappingOut->getEiDatasetStructureId() . " / " . $correspondances[$ei_version_str->getId()] . "    ----------");
                 $newMappingOut = new EiMappingStructureSyncOut();
                 $newMappingOut->setEiDatasetStructureId($oldMappingOut->getEiDatasetStructureId());
                 $newMappingOut->setEiVersionStructureId($correspondances[$ei_version_str->getId()]);
                 $newMappingOut->save($conn);
             }
         } elseif ($ei_version_str->isEiFonction() && in_array($ei_version_str->getType(), $allowedTypes)) {
             $logger->info("----------     CREATION PARAM FONCTION     ----------");
             // Récupération de l'ensemble des paramètres OUT.
             /** @var EiParamBlockFunctionMapping[] $outParams */
             $outParams = $ei_version_str->getEiFonction()->getEiFunctionMapping();
             $logger->info("----------     " . count($outParams) . " PARAMS.");
             // Copie de chaque paramètre de mapping OUT.
             /** @var EiParamBlockFunctionMapping $oldMapping */
             foreach ($outParams as $oldMapping) {
                 if ($oldMapping->getEiFunctionId() != "" && $oldMapping->getEiParamFunctionId() != "") {
                     /** @var EiParamBlockFunctionMapping $mapping */
                     $mapping = new EiParamBlockFunctionMapping();
                     $mapping->setEiParamBlockId($oldMapping->getEiParamBlockId() == "" ? null : $correspondances[$oldMapping->getEiParamBlockId()]);
                     $mapping->setEiFunctionId($correspondancesF[$oldMapping->getEiFunctionId()]);
                     $mapping->setEiParamFunctionId($oldMapping->getEiParamFunctionId());
                     $mapping->save($conn);
                 }
             }
         } elseif (!in_array($ei_version_str->getType(), $allowedTypes)) {
             $ignored++;
         }
     }
     // On affecte à la copie la structure complète.
     $copie->setEiVersionStructures($nouvelleStructure);
     // Sauvegarde de la copie de version.
     $copie->save($conn);
     //*****************************************************//
     //**********          VERIFICATIONS          **********//
     //*****************************************************//
     // On récupère l'arbre de la structure de la copie.
     $arbreNouvelleVersion = $tableVersionStr->getEiVersionTree($copie->getId());
     // On vérifie que le nombre d'éléments est le même de chaque côté sinon on lève une exception.
     if (count($currentVersionTree) != count($arbreNouvelleVersion) + $ignored) {
         throw new Exception('Version copie failed');
     }
     return $copie;
 }
 protected function doSave($con)
 {
     if (null === $con) {
         $con = $this->getConnection();
     }
     $pollid = $this->getValue('poll_id');
     // creating a new answer
     $answer = new aPollAnswer();
     $answer->setPollId($pollid);
     $answer->setRemoteAddress($this->getValue('remote_address'));
     $answer->setCulture($this->getValue('culture'));
     $answer->setIsNew(true);
     $answer->save();
     $aid = $answer->getId();
     // recovering all fields that must be saved in the DB
     $answer_fields = new Doctrine_Collection('aPollAnswerField');
     $fields_to_save = $this->getFieldsToSave();
     if (null === $fields_to_save) {
         throw new sfException('To save this form, you must define which fields must be saved using setFieldsToSave()');
     }
     // for each field, we create a new aPollAnswerField, which is linked to a aPollAnswer
     // (and obviously to the poll)
     foreach ($fields_to_save as $field) {
         $v = $this->getValue($field);
         if (is_null($v) || '' === $v) {
             continue;
         }
         $af = new aPollAnswerField();
         $af->setPollId($pollid);
         $af->setAnswerId($aid);
         $af->setName($field);
         if (is_array($v)) {
             $v = serialize($v);
         }
         $af->setValue($v);
         $answer_fields->add($af);
     }
     try {
         // Once all fields set, we save all of them
         if (count($answer_fields)) {
             $answer_fields->save();
         }
     } catch (Exception $e) {
         $answer->delete();
         throw $e;
     }
     return $answer;
 }