public function indexDirectory($dir) { if (!file_exists($dir)) { throw new Doctrine_Search_Indexer_Exception('Unknown directory ' . $dir); } $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY); $files = array(); foreach ($it as $file) { $name = $file->getPathName(); if (strpos($name, '.svn') === false) { $files[] = $name; } } $q = new Doctrine_Query(); $q->delete()->from('Doctrine_File f')->where('f.url LIKE ?', array($dir . '%'))->execute(); // clear the index $q = new Doctrine_Query(); $q->delete()->from('Doctrine_File_Index i')->where('i.file_id = ?')->execute(); $conn = Doctrine_Manager::connection(); $coll = new Doctrine_Collection('Doctrine_File'); foreach ($files as $file) { $coll[]->url = $file; } $coll->save(); }
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; } }
/** * * @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); } }
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; } }
/** * Add a group of wiki pages selected to a category * @param integer $category_id * @param array $wikiIDS * @param integer $locale */ public static function addWikiPages2Categories($category_id, $wikiIDS) { $records = new Doctrine_Collection('Wikilinks'); self::removeWikiCategoriesPages($category_id); for ($i = 0; $i < count($wikiIDS); $i++) { $records[$i]->category_id = $category_id; $records[$i]->wiki_id = $wikiIDS[$i]; } $records->save(); return true; }
public function testInit() { $user = new BookmarkUser(); $user['name'] = 'Anonymous'; $user->save(); $pages = new Doctrine_Collection('Page'); $pages[0]['name'] = 'Yahoo'; $pages[0]['url'] = 'http://www.yahoo.com'; $pages->save(); $this->assertEqual(count($pages), 1); }
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'); }
public function testMultiplePrimaryKeys() { $r = new Doctrine_Collection('NestReference'); $r[0]->parent_id = 1; $r[0]->child_id = 2; $r[1]->parent_id = 2; $r[1]->child_id = 3; $r->save(); $r->delete(); $this->conn->clear(); $q = new Doctrine_Query(); $coll = $q->from('NestReference')->execute(); $this->assertEqual(count($coll), 0); }
public function testInitData() { // Since the tests do a $this->objTable()->clear() before each method call // using the User model is not recommended for this test $albums = new Doctrine_Collection('Album'); $albums[0]->name = 'Revolution'; $albums[0]->Song[0]->title = 'Revolution'; $albums[0]->Song[1]->title = 'Hey Jude'; $albums[0]->Song[2]->title = 'Across the Universe'; $albums[0]->Song[3]->title = 'Michelle'; $albums->save(); $this->assertEqual(count($albums[0]->Song), 4); $this->_albums = $albums; }
public function testInitData() { $users = new Doctrine_Collection('User'); $users[0]->name = 'John'; $users[0]->Phonenumber[0]->phonenumber = '123 123'; $users[0]->Phonenumber[1]->phonenumber = '222 222'; $users[0]->Phonenumber[2]->phonenumber = '333 333'; $users[1]->name = 'John'; $users[2]->name = 'James'; $users[2]->Phonenumber[0]->phonenumber = '222 344'; $users[2]->Phonenumber[1]->phonenumber = '222 344'; $users[3]->name = 'James'; $users[3]->Phonenumber[0]->phonenumber = '123 123'; $users->save(); }
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; } }
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 } }
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; } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $quiet = (bool) $options['quiet']; $domain = $arguments['domain']; if (!$quiet) { echo "Creating deadlines..."; } $subreddit = SubredditTable::getInstance()->findOneBy('domain', $domain); /* @var $subreddit Subreddit */ if (!$subreddit) { return new sfException("Cannot find subreddit by the domain name {$domain}.", 404); } if (count($subreddit->getDeadlines())) { return new sfException("Subreddit has deadlines already."); } $authortype_one = AuthorTypeTable::getInstance()->findOneBy('type', 'first_place'); $authortype_two = AuthorTypeTable::getInstance()->findOneBy('type', 'second_place'); $authortype_three = AuthorTypeTable::getInstance()->findOneBy('type', 'third_place'); $authortype_four = AuthorTypeTable::getInstance()->findOneBy('type', 'sudden_death'); $deadlines = new Doctrine_Collection('Deadline'); $deadlines[0] = new Deadline(); $deadlines[0]->setAuthorType($authortype_one); $deadlines[0]->setSubreddit($subreddit); $deadlines[0]->setSeconds(259200); $deadlines[1] = new Deadline(); $deadlines[1]->setAuthorType($authortype_two); $deadlines[1]->setSubreddit($subreddit); $deadlines[1]->setSeconds(172800); $deadlines[2] = new Deadline(); $deadlines[2]->setAuthorType($authortype_three); $deadlines[2]->setSubreddit($subreddit); $deadlines[2]->setSeconds(86400); $deadlines[3] = new Deadline(); $deadlines[3]->setAuthorType($authortype_four); $deadlines[3]->setSubreddit($subreddit); $deadlines[3]->setSeconds(0); $deadlines->save(); if (!$quiet) { echo "\nFinished.\n"; } }
/** * Saving dns zones * * * @params integer $id * @params array $zones * @return ARRAY Record */ public static function saveZone($domainId, $zones) { Doctrine::getTable('Dns_Zones')->findBy('domain_id', $domainId)->delete(); if (count($zones) > 0) { $myzone = new Doctrine_Collection('Dns_Zones'); $i = 0; foreach ($zones as $zone) { $dnszonetype = Dns_Zones_Types::getType($zone['fieldtype']); $myzone[$i]->domain_id = $domainId; $myzone[$i]->subdomain = $zone['subdomain']; $myzone[$i]->type_id = $dnszonetype; $myzone[$i]->target = $zone['target']; $myzone[$i]->updating_date = date('Y-m-d H:i:s'); $i++; } $myzone->save(); return true; } return false; }
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(); } }
public static function saveAll($data, $product_id) { if (empty($data['group_id'])) { return false; } $i = 0; $attrs = new Doctrine_Collection('ProductsAttributesIndexes'); self::deleteAll($product_id); // Get all the product attributes $attributes = ProductsAttributesGroups::getAttributesProfiles($data['group_id']); // Loop of the posted variables foreach ($data as $var => $value) { // Loop of all the attributes foreach ($attributes as $attribute) { if ($attribute['ProductsAttributes']['code'] == $var) { $attrs[$i]->product_id = $product_id; $attrs[$i]->attribute_id = $attribute['attribute_id']; $attrs[$i]->value = $value; $i++; } } } $attrs->save(); }
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(); }
public function prepareData() { $groups = new Doctrine_Collection($this->connection->getTable('Group')); $groups[0]->name = 'Drama Actors'; $groups[1]->name = 'Quality Actors'; $groups[2]->name = 'Action Actors'; $groups[2]['Phonenumber'][0]->phonenumber = '123 123'; $groups->save(); $users = new Doctrine_Collection('User'); $users[0]->name = 'zYne'; $users[0]['Email']->address = '*****@*****.**'; $users[0]['Phonenumber'][0]->phonenumber = '123 123'; $users[1]->name = 'Arnold Schwarzenegger'; $users[1]->Email->address = '*****@*****.**'; $users[1]['Phonenumber'][0]->phonenumber = '123 123'; $users[1]['Phonenumber'][1]->phonenumber = '456 456'; $users[1]->Phonenumber[2]->phonenumber = '789 789'; $users[1]->Group[0] = $groups[2]; $users[2]->name = 'Michael Caine'; $users[2]->Email->address = '*****@*****.**'; $users[2]->Phonenumber[0]->phonenumber = '123 123'; $users[3]->name = 'Takeshi Kitano'; $users[3]->Email->address = '*****@*****.**'; $users[3]->Phonenumber[0]->phonenumber = '111 222 333'; $users[4]->name = 'Sylvester Stallone'; $users[4]->Email->address = '*****@*****.**'; $users[4]->Phonenumber[0]->phonenumber = '111 555 333'; $users[4]['Phonenumber'][1]->phonenumber = '123 213'; $users[4]['Phonenumber'][2]->phonenumber = '444 555'; $users[5]->name = 'Kurt Russell'; $users[5]->Email->address = '*****@*****.**'; $users[5]->Phonenumber[0]->phonenumber = '111 222 333'; $users[6]->name = 'Jean Reno'; $users[6]->Email->address = '*****@*****.**'; $users[6]->Phonenumber[0]->phonenumber = '111 222 333'; $users[6]['Phonenumber'][1]->phonenumber = '222 123'; $users[6]['Phonenumber'][2]->phonenumber = '123 456'; $users[7]->name = 'Edward Furlong'; $users[7]->Email->address = '*****@*****.**'; $users[7]->Phonenumber[0]->phonenumber = '111 567 333'; $this->users = $users; $this->users->save(); }
private static function AddUpgradeProducts($id, $upgradeproducts) { $i = 0; // Delete all the products related before adding the new one ProductsUpgrades::delItemsbyProductID($id); $upgrade = new Doctrine_Collection('ProductsUpgrades'); if (!empty($upgradeproducts)) { foreach ($upgradeproducts as $item) { $upgrade[$i]->upgrade_product_id = $item; $upgrade[$i]->product_id = $id; $i++; } $upgrade->save(); } }
/** * * Save the Cms page data */ public static function saveAll($id, $params, $locale = 1) { $i = 0; // Set the new values if (is_numeric($id)) { $cmspages = Doctrine::getTable('Cmspages')->find($id); } else { $cmspages = new CmsPages(); $cmspages->publishedat = date('Y-m-d H:i:s'); } $cmspages->title = $params['title']; $cmspages->body = $params['body']; $cmspages->keywords = $params['keywords']; $cmspages->blocks = $params['blocks']; $cmspages->layout = $params['layout']; $cmspages->xmllayout = $params['xmllayout']; $cmspages->var = !empty($params['var']) ? Shineisp_Commons_UrlRewrites::format($params['var']) : Shineisp_Commons_UrlRewrites::format($params['title']); $cmspages->pagelayout = $params['pagelayout']; $cmspages->parent_id = $params['parent_id']; $cmspages->showinmenu = $params['showinmenu'] ? true : false; $cmspages->showonrss = $params['showonrss'] ? true : false; $cmspages->blog = $params['blog'] ? true : false; $cmspages->showonrss = $params['showonrss'] ? true : false; $cmspages->active = $params['active'] ? true : false; if ($cmspages->trySave()) { if (is_numeric($cmspages['page_id'])) { // Clear old reference records by page_id CmsPagesData::deleteItems($cmspages['page_id']); // Save the page translation references $PageData = new Doctrine_Collection('CmsPagesData'); foreach ($params['language_id'] as $idlang) { $PageData[$i]->page_id = $cmspages['page_id']; $PageData[$i]->language_id = $idlang; $i++; } $PageData->save(); } } $id = is_numeric($id) ? $id : $cmspages->getIncremented(); return $id; }
/** * saveRecord * save the setting record group parameters * @param integer $groupid * @param integer $isp */ public static function saveRecord($groupid, $post, $isp = 1) { $i = 0; if (!empty($post)) { $records = new Doctrine_Collection('Settings'); foreach ($post as $field => $value) { // Get the old setting parameter value $setting = self::findRecord($field, $isp); if (!empty($setting)) { // Delete the old record self::deleteItem($setting['setting_id']); } // Get the parameter record $paramenter = SettingsParameters::getParameterbyVar($field); // Create the collection of records $records[$i]->isp_id = $isp; $records[$i]->parameter_id = $paramenter->get('parameter_id'); $records[$i]->value = $value; $i++; } // Save the records $records->save(); // Refresh the parameters SettingsParameters::loadParams(null, true); } return true; }
public function advanceEpisodeAssignments() { // We grab the Deadlines in descending order for the Subreddit; $deadline_rules = $this->getDeadlineRules(); $first_deadline_id = $this->getFirstDeadlineId(); $first_deadline = DeadlineTable::getInstance()->find($first_deadline_id); // We establish the pool of emails we'll be sending. // First to those who pass their deadline $passed_deadline_assignments = array(); // And to the new episode assignments that are reassigned $newly_assigned_assignments = array(); // Now we can start on the assignments that are misassigned $assignments = EpisodeAssignmentTable::getInstance()->getMisassignedEpisodes($this->getIncremented()); $episodes = new Doctrine_Collection('Episode'); $e = -1; for ($i = 0; $i < count($assignments); $i++) { $passed_deadline_assignments[] = $assignments[$i]; $assignments[$i]->setMissedDeadline(true); $episodes[++$e] = $assignments[$i]->getEpisode(); // Clean up the Episode for any new user to use. $episodes[$e]->setEpisodeAssignmentId(null); $audio_file = $episodes[$e]->getAudioFile(); $nice_filename = $episodes[$e]->getNiceFilename(); $graphic_file = $episodes[$e]->getGraphicFile(); $episodes[$e]->setAudioFile(null); $episodes[$e]->setNiceFilename(null); $episodes[$e]->setGraphicFile(null); $episodes[$e]->setIsNsfw(false); $episodes[$e]->setTitle(null); $episodes[$e]->setDescription(null); $episodes[$e]->setIsSubmitted(false); $episodes[$e]->setSubmittedAt(null); $episodes[$e]->setFileIsRemote(null); $episodes[$e]->setRemoteUrl(null); $episodes[$e]->setRedditPostUrl(null); } $episodes->save(); $assignments->save(); /* Now we make sure that all assignments past deadline are marked as * such. If the assignment is here, however, then it hasn't ever * actually BEEN assigned and isn't added to the list of emails to send * out. */ $assignments = EpisodeAssignmentTable::getInstance()->getUnmarkedEpisodesThatMissedDeadlines($this->getIncremented()); for ($i = 0; $i < count($assignments); $i++) { $assignments[$i]->setMissedDeadline(true); } $assignments->save(); /* Now all episodes are cleared and we need to see if they need to be * reassigned to an existing asignment. */ /* Returns assignments closest to the front for each unassigned episode, * in order of closeness. */ $assignments = EpisodeAssignmentTable::getInstance()->getEpisodesPossiblyNeedingAssignment($this->getIncremented()); $episodes_affected = array(); foreach ($assignments as $assignment) { if (!in_array($assignment->getEpisodeId(), $episodes_affected)) { /* Ignore all subsequent assignments for an episode after the * first! We should only be dealing with assignments that have * not missed their deadlines! */ $episodes_affected[] = $assignment->getEpisodeId(); $episode = $assignment->getEpisode(); $assign_to_episode = false; /* If the *first* assignment is in the first spot, then assign * it. */ if ($assignment->getAuthorTypeId() == $first_deadline->getAuthorTypeId()) { $assign_to_episode = true; } else { /* Otherwise, check if we are past the deadline for the * previous deadline. */ $previous_author_type_id = DeadlineTable::getInstance()->getFirstAuthorTypeIdBySubredditWhereDeadlineIsGreaterThan($deadline_rules[$assignment->getAuthorTypeId()], $episode->getSubredditId()); $past_deadline_for_previous = strtotime($episode->getReleaseDate()) - $deadline_rules[$previous_author_type_id] <= time(); if ($past_deadline_for_previous) { $assign_to_episode = true; } } if ($assign_to_episode) { $episode->setEpisodeAssignmentId($assignment->getIncremented()); $episode->save(); $newly_assigned_assignments[] = $assignment; } } } // We send the emails for the current deadline we're checking. foreach ($passed_deadline_assignments as $assignment) { $this->sendEmailAboutPassedDeadline($assignment->getSfGuardUserId(), $assignment->getEpisodeId()); } foreach ($newly_assigned_assignments as $assignment) { $episode = $assignment->getEpisode(); $release_date = strtotime($episode->getReleaseDate()); $seconds = $deadline_rules[$assignment->getAuthorTypeId()]; $deadline = $release_date - $seconds; $this->sendEmailAboutNewAssignment($assignment->getSfGuardUserId(), $episode->getIncremented(), $deadline); } }
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; } }
/** * Sauvegarde, pour tous les profils du projet passé en paramètres, * les relations ei_profil_scenario afin que tous les profils soit associé à * à la version par défaut. * * @param EiProjet $ei_project */ public function saveProfilsForVersions(EiProjet $ei_project, $def_version, $conn) { $profils = $ei_project->getProfils(); $toSave = new Doctrine_Collection('EiProfilScenario'); foreach ($profils as $profil) { $profil_scenario = new EiProfilScenario(); $profil_scenario->setProfileId($profil->getProfileId()); $profil_scenario->setProfileRef($profil->getProfileRef()); $profil_scenario->setEiScenario($this); $profil_scenario->setEiVersionId($def_version); $toSave->add($profil_scenario); } $toSave->save($conn); }
/** * Reorders a set of sortable objects based on a list of id/position * Beware that there is no check made on the positions passed * So incoherent positions will result in an incoherent list * * @param array id/position pairs * * @return Boolean true if the reordering took place, false if a database problem prevented it **/ public function doSort(array $order) { if (!$this->hasField('position')) { throw new dmException(sprintf('%s table has no position field', $this->getComponentName())); } $records = $this->createQuery('q INDEXBY q.id')->whereIn('q.id', array_keys($order))->fetchRecords(); $modifiedRecords = new Doctrine_Collection($this); foreach ($order as $id => $position) { if ($position != $records[$id]->get('position')) { $records[$id]->set('position', $position); $modifiedRecords[] = $records[$id]; } } $modifiedRecords->save(); unset($records, $modifiedRecords); }
public function advanceEpisodeAssignments() { $subreddit_first_deadlines = array(); $subreddit_deadline_rules = array(); // We establish the pool of emails we'll be sending. // First to those who pass their deadline $passed_deadline_assignments = array(); // And to the new episode assignments that are reassigned $newly_assigned_assignments = array(); // Now we can start on the assignments that are misassigned $assignments = EpisodeAssignmentTable::getInstance()->getMisassignedEpisodes(); $episodes = new Doctrine_Collection('Episode'); $e = -1; for ($i = 0; $i < count($assignments); $i++) { $passed_deadline_assignments[] = $assignments[$i]; $assignments[$i]->setMissedDeadline(true); $episodes[++$e] = $assignments[$i]->getEpisode(); // Clean up the Episode for any new user to use. $episodes[$e]->setEpisodeAssignmentId(null); $audio_file = $episodes[$e]->getAudioFile(); $nice_filename = $episodes[$e]->getNiceFilename(); $graphic_file = $episodes[$e]->getGraphicFile(); $episodes[$e]->setAudioFile(null); $episodes[$e]->setNiceFilename(null); $episodes[$e]->setGraphicFile(null); $episodes[$e]->setIsNsfw(false); $episodes[$e]->setTitle(null); $episodes[$e]->setDescription(null); $episodes[$e]->setIsSubmitted(false); $episodes[$e]->setSubmittedAt(null); $episodes[$e]->setFileIsRemote(null); $episodes[$e]->setRemoteUrl(null); $episodes[$e]->setRedditPostUrl(null); } $episodes->save(); $assignments->save(); /* Now we make sure that all assignments past deadline are marked as * such. If the assignment is here, however, then it hasn't ever * actually BEEN assigned and isn't added to the list of emails to send * out. */ $assignments = EpisodeAssignmentTable::getInstance()->getUnmarkedEpisodesThatMissedDeadlines(); for ($i = 0; $i < count($assignments); $i++) { $assignments[$i]->setMissedDeadline(true); } $assignments->save(); /* Now all episodes are cleared and we need to see if they need to be * reassigned to an existing asignment. */ /* Returns assignments closest to the front for each unassigned episode, * in order of closeness. */ $assignments = EpisodeAssignmentTable::getInstance()->getEpisodesPossiblyNeedingAssignment(); $subreddit_ids = EpisodeAssignmentTable::getInstance()->getSubrbedditsOfEpisodesPossiblyNeedingAssignment(); $deadlines = DeadlineTable::getInstance()->getDeadlinesForGivenSubreddits($subreddit_ids); $subreddit_first_authortypes = array(); $subreddit_deadline_rules = array(); $begun = false; $prev_subreddit_id = null; foreach ($deadlines as $deadline) { $subreddit_id = $deadline['subreddit_id']; if ($prev_subreddit_id != $subreddit_id && $begun) { $begun = false; $prev_subreddit_id = $subreddit_id; } if (!$begun) { $subreddit_deadline_rules[$subreddit_id] = array($deadline['author_type_id'] => $deadline['seconds']); $subreddit_first_authortypes[$subreddit_id] = $deadline['author_type_id']; $begun = true; } else { $author_type_id = $deadline['author_type_id']; $subreddit_deadline_rules[$subreddit_id][$author_type_id] = $deadline['seconds']; } } $episodes_affected = array(); // Things used from assignment: episode_id, epsiode, author_type_id, id, sf_guard_user_id // Things used from episode: subreddit_id, surbeddit, release_date, // Things used from subreddit: getFirstDeadlineId(), getDeadlineRules() foreach ($assignments as $assignment) { if (!in_array($assignment['episode_id'], $episodes_affected)) { /* Ignore all subsequent assignments for an episode after the * first! We should only be dealing with assignments that have * not missed their deadlines! */ $episodes_affected[] = $assignment['episode_id']; $assign_to_episode = false; $subreddit_id = $assignment['subreddit_id']; $subreddit = SubredditTable::getInstance()->find($subreddit_id); /* If the *first* assignment is in the first spot, then assign * it. */ $deadline_rules = $subreddit_deadline_rules[$subreddit_id]; $author_type_id = $assignment['author_type_id']; if ($author_type_id == $subreddit_first_authortypes[$subreddit_id]) { $assign_to_episode = true; } else { /* Otherwise, check if we are past the deadline for the * previous deadline. */ /*$previous_author_type_id = DeadlineTable::getInstance() ->getFirstAuthorTypeIdBySubredditWhereDeadlineIsGreaterThan( $deadline_rules[$author_type_id], $subreddit_id);*/ $inverse_deadline_rules = array_reverse($deadline_rules, true); $previous_author_type_id = null; foreach ($inverse_deadline_rules as $author_type => $seconds) { if ($seconds > $deadline_rules[$author_type_id]) { $previous_author_type_id = $author_type; break; } } $past_deadline_for_previous = strtotime($assignment['release_date']) - $deadline_rules[$previous_author_type_id] <= time(); if ($past_deadline_for_previous) { $assign_to_episode = true; } } if ($assign_to_episode) { $saved_episode = EpisodeTable::getInstance()->find($assignment['episode_id']); $saved_episode->setEpisodeAssignmentId($assignment['id']); $saved_episode->save(); $newly_assigned_assignments[] = $assignment; } } } // We send the emails for the current deadline we're checking. foreach ($passed_deadline_assignments as $assignment) { $this->sendEmailAboutPassedDeadline($assignment['sf_guard_user_id'], $assignment['episode_id']); } foreach ($newly_assigned_assignments as $assignment) { $release_date = strtotime($assignment['release_date']); $author_type_id = $assignment['author_type_id']; $seconds = $deadline_rules[$author_type_id]; $deadline = $release_date - $seconds; $this->sendEmailAboutNewAssignment($assignment['sf_guard_user_id'], $assignment['episode_id'], $deadline); } }
public function testLoadRelatedForNormalAssociation() { $resource = new Doctrine_Collection('Resource'); $resource[0]->name = 'resource 1'; $resource[0]->Type[0]->type = 'type 1'; $resource[0]->Type[1]->type = 'type 2'; $resource[1]->name = 'resource 2'; $resource[1]->Type[0]->type = 'type 3'; $resource[1]->Type[1]->type = 'type 4'; $resource->save(); $this->connection->clear(); $resources = $this->connection->query('FROM Resource'); $count = $this->connection->count(); $resources->loadRelated('Type'); $this->assertEqual($count + 1, $this->connection->count()); $this->assertEqual($resources[0]->name, 'resource 1'); $this->assertEqual($resource[0]->Type[0]->type, 'type 1'); $this->assertEqual($resource[0]->Type[1]->type, 'type 2'); $this->assertEqual($count + 1, $this->connection->count()); $this->assertEqual($resource[1]->name, 'resource 2'); $this->assertEqual($resource[1]->Type[0]->type, 'type 3'); $this->assertEqual($resource[1]->Type[1]->type, 'type 4'); $this->assertEqual($count + 1, $this->connection->count()); }
function reactivateAllAccounts() { $user_collection = new Doctrine_Collection(Doctrine_Core::getTable("UserAccount")); $users = $this->getUsers(); //debugMessage($users->toArray()); if ($users->count() > 0) { foreach ($users as $user) { if ($user->isUserInActive() && $user->getActivationKey() == md5($this->getCompanyID())) { $user->setStatus(1); $user->setActivationKey(''); $user_collection->add($user); } } // debugMessage($user_collection->toArray()); } if ($user_collection->count() > 0) { try { $user_collection->save(); } catch (Exception $e) { debugMessage("An error occured in updating status. " . $e->getMessage()); } } return true; }