protected function execute($arguments = array(), $options = array()) { // initialize the database connection for RdvZ 1.x database $opt = array('dsn' => $arguments['dsn'], 'username' => $arguments['username'], 'password' => $arguments['password']); $d2 = new sfPDODatabase($opt); $rdvz1 = $d2->getConnection(); $this->logSection('rdvz', sprintf('Retrieving datas from RdvZ 1.x database "%s"', $opt['dsn'])); /** * This part is about fetching the datas from the old database * and formatting them before inserting into the new one. */ // initialize the database connection for RdvZ 2.0 database $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $res = $rdvz1->query('select * from meeting')->fetchAll(); foreach ($res as $meet) { // If the user doesn't exists in the new database, we have to retrieve his information // from the ldap server. if (sfConfig::get('app_authentication_type') == 'ldap') { $user = $this->getUserFromDatabase($meet['uid']); $user_id = $user->getId(); $user->free(); unset($user); } $meeting = new meeting(); $meeting->setHash($meet['mid']); $meeting->setTitle($meet['title']); $meeting->setDescription($meet['description']); $meeting->setUid($user_id); $meeting->setClosed($meet['closed']); $meeting->setDateDel($meet['date_del']); $meeting->setDateEnd($meet['date_end']); $meeting->setNotif($meet['notif'] == 'Y' ? 1 : 0); $meeting->save(null, false); $meeting_id = $meeting->getId(); $meeting->free(); unset($meeting); $res2 = $rdvz1->query("select * from meeting_date where mid = '" . $meet['mid'] . "'")->fetchAll(); foreach ($res2 as $date) { $meeting_date = new meeting_date(); $meeting_date->setMid($meeting_id); $meeting_date->setDate($date['date']); $meeting_date->setComment($date['comment']); $meeting_date->save(); $meeting_date_id = $meeting_date->getId(); $meeting_date->free(); unset($meeting_date); $res3 = $rdvz1->query("select * from meeting_poll where pollid = " . $date['pollid'])->fetchAll(); foreach ($res3 as $poll) { $meeting_poll = new meeting_poll(); $meeting_poll->setDateId($meeting_date_id); $meeting_poll->setPoll($poll['poll']); if ($poll['user_comment']) { $meeting_poll->setComment($poll['user_comment']); } if ($poll['uid'] != '') { $poll_user = $this->getUserFromDatabase($poll['uid']); $meeting_poll->setUid($poll_user->getId()); $poll_user->free(); unset($poll_user); } if ($poll['participant_name'] != '') { $meeting_poll->setParticipantName($poll['participant_name']); } $meeting_poll->save(); $meeting_poll->free(); unset($meeting_poll); } } } $this->logSection('rdvz', "The RdvZ 2.0 database is now filled with your former datas. You can now delete the old database."); }
/** * Prepares all the variables used in the showSuccess view. * * @return array Set of variables. */ public function processShow($user_culture) { $meeting_dates = Doctrine::getTable('meeting_date')->retrieveByMid($this->getId()) ; $languages = sfConfig::get('app_languages') ; setlocale(LC_TIME,$languages[$user_culture].'.utf8',$user_culture) ; $dates = array() ; $months = array() ; $comments = array() ; $votes = array() ; foreach($meeting_dates as $d) { // Generating verbose dates. $f = strtotime($d->getDate()) ; $months[] = strftime("%B %Y",$f) ; $dates[strftime("%B %Y", $f)][$d->getId()] = strftime("%a %d", $f) ; $comments[] = $d->getComment() ; $v = Doctrine::getTable('meeting_poll')->retrieveByDateId($d->getId()) ; if(!count($v)) { // Little trick : if there is no vote associated to this date, it means that // the owner of the meeting probably added it afterwards. // We have to handle it and create 'fake' votes which are blanks and penalized. // To do this, we retrieve all the users who already voted for this meeting // and add them this 'fake' vote. $u = Doctrine::getTable('meeting_poll')->retrieveUidByMeetingId($this->getId()) ; $n = Doctrine::getTable('meeting_poll')->retrieveNameByMeetingId($this->getId()) ; foreach($u as $uid) { // If this is a database user. $p = new meeting_poll() ; $p->setPoll(1000) ; $p->setDateId($d->getId()) ; $p->setUid($uid) ; $p->save() ; $votes[$uid][$d->getId()] = $p ; } foreach($n as $name) { // If this is an extern user. $p = new meeting_poll() ; $p->setPoll(1000) ; $p->setDateId($d->getId()) ; $p->setParticipantName($name) ; $p->save() ; $votes[$name][$d->getId()] = $p ; } } else { // Retrieving the votes for this date. foreach($v as $poll) { if(is_null($poll->getUid())) $votes[$poll->getParticipantName()][$d->getId()] = $poll ; else $votes[$poll->getUid()][$d->getId()] = $poll ; } } } // For the view. $months = array_unique($months) ; // Finding the best dates : we have to sum all the votes for each date // and then compare them. We keep the dates with the max vote counts. $t = Doctrine::getTable('meeting_poll')->getVotesByMeeting($this->getId()) ; $max = 0 ; foreach($t as $res) if ($res->getCnt()%1000 > $max) $max = $res->getCnt()%1000 ; $bests = array() ; $md = $meeting_dates ; $counts = array() ; foreach($t as $res) { if($res->getCnt()%1000 == $max) $bests[] = $res->getDateId() ; $counts[$res->getDateId()] = $res->getCnt()%1000 ; // $total += $res->getCnt()%1000 ; } $counts['max'] = $max ; return array('dates' => $dates, 'comments' => $comments, 'bests' => $bests, 'md' => $md, 'months' => $months, 'votes' => $votes, 'counts' => $counts) ; }
/** * Normal vote of a user. */ public function executeVote(sfWebRequest $request) { $this->meeting = Doctrine::getTable('meeting')->getByHash($request->getParameter('h')); $this->forward404Unless($this->meeting); $votes = $request->getPostParameters(); if ($this->getUser()->hasCredential('invite') && $votes['name'] == "") { sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N')); $this->getUser()->setFlash('error', __('Vous devez entrer votre nom pour voter.')); $this->redirect('meeting/showua?h=' . $this->meeting->getHash()); } $this->meeting_dates = Doctrine::getTable('meeting_date')->retrieveByMid($this->meeting->getId()); foreach ($this->meeting_dates as $date) { $poll = new meeting_poll(); if ($this->getUser()->hasCredential('member')) { $poll->setUid($this->getUser()->getProfileVar(sfConfig::get('app_user_id'))); } else { $poll->setParticipantName($votes['name']); $this->getUser()->setAttribute('participant_name', $votes['name']); } $poll->setDateId($date->getId()); if (in_array($date->getId(), array_keys($votes))) { $poll->setPoll(1); } else { $poll->setPoll(0); } $poll->save(); } // If the creator wants to know when there is a new vote, send him a // mail right now ! if ($this->meeting->getNotif() && $this->getUser()->getProfileVar(sfConfig::get('app_user_id')) != $this->meeting->getUid()) { if ($this->getUser()->hasCredential('member')) { $user = Doctrine::getTable('user')->find($this->getUser()->getProfileVar(sfConfig::get('app_user_id'))); $u_name = $user->getSurname() . ' ' . $user->getName(); } else { $u_name = $this->getUser()->getAttribute('participant_name'); } $this->sendNotifMail($this->meeting, $u_name); } // Different redirection depending on the credentials of the user. if ($this->getUser()->hasCredential('invite')) { $this->redirect('meeting/showua?h=' . $this->meeting->getHash()); } elseif ($this->getUser()->hasCredential('member')) { // Auto bookmarking for authenticated users. $follow = new is_following(); $follow->setMid($this->meeting->getId()); $follow->setUid($this->getUser()->getProfileVar(sfConfig::get('app_user_id'))); $follow->save(); $this->redirect('meeting/show?h=' . $this->meeting->getHash()); } else { $this->forward404(); } }