public function executeDelete() { $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber'); $this->bikeid = $this->getRequestParameter('bikeid'); if ($this->getRequest()->getMethod() == sfRequest::POST) { //delete user_stat and equipment $c = new Criteria(); $c->add(UserStatsPeer::USER_ID, $userId); $c->add(UserStatsPeer::BIKE_ID, $this->bikeid); $s = UserStatsPeer::doSelectJoinAll($c); foreach ($s as $stat) { foreach ($stat->getUserStatEquips() as $equip) { $equip->delete(); } $stat->delete(); } //move equipment to shelf $c = new Criteria(); $c->add(UserEquipementPeer::USER_ID, $userId); $c->add(UserEquipementPeer::BIKE_ID, $this->bikeid); $equip = UserEquipementPeer::doSelect($c); foreach ($equip as $e) { $e->setBikeId(null); $e->save(); } //now delete bike $user_bikes = UserBikesPeer::retrieveByPk($this->bikeid); $user_bikes->delete(); return $this->redirect('userbike/index'); } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $u_id = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', '-1', 'subscriber'); $this->year = $this->getRequestParameter('year'); $this->month = $this->getRequestParameter('month'); if (!$this->year) { $this->year = Date("Y"); } if (!$this->month) { $this->month = Date("m"); } $curTime = mktime(0, 0, 0, $this->month, 1, $this->year); //check which way to navigate if any $navdir = $this->getRequestParameter('navdir'); if ($navdir) { if ($navdir == 'next') { $curTime = mktime(0, 0, 0, $this->month + 1, 1, $this->year); } else { $curTime = mktime(0, 0, 0, $this->month - 1, 1, $this->year); } } //get new year and month $this->year = date("Y", $curTime); $this->month = Date("m", $curTime); $this->weekArray = $this->buildCalendarArray($this->year, $this->month); $to_date = mktime(0, 0, 0, $this->month, date("t", $curTime), $this->year); $from_date = mktime(0, 0, 0, $this->month, 1, $this->year); $this->monthText = date("F", $curTime); if ($u_id) { $c = new Criteria(); $c->add(UserStatsPeer::USER_ID, $u_id); $criterion = $c->getNewCriterion(UserStatsPeer::RIDE_DATE, date('Y-m-d', $from_date), Criteria::GREATER_EQUAL); $criterion->addAnd($c->getNewCriterion(UserStatsPeer::RIDE_DATE, date('Y-m-d', $to_date), Criteria::LESS_EQUAL)); $c->add($criterion); $user_stats = UserStatsPeer::doSelectJoinAll($c); $this->statsByDay = array(); if ($user_stats) { foreach ($user_stats as $i => $value) { $rideDate = Date("j", strtotime($value->getRideDate())); if (array_key_exists($rideDate, $this->statsByDay)) { $tempArray = $this->statsByDay[$rideDate]; array_push($tempArray, $value); $this->statsByDay[$rideDate] = $tempArray; } else { $tempArray = array(); array_push($tempArray, $value); $this->statsByDay[$rideDate] = $tempArray; } } } } else { $this->statsByDay = null; } }
public function executeDelete() { $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber'); $rId = $this->getRequestParameter('rideid'); $this->rideid = $rId; sfContext::getInstance()->getLogger()->info('@@@@@@@@@@@@@@@Deleeting ride ' . $this->rideid); if ($this->getRequest()->getMethod() == sfRequest::POST) { //delete user maps $c = new Criteria(); $c->add(UserRideMapPeer::USER_RIDE_ID, $rId); $mapPoints = UserRideMapPeer::doSelect($c); if ($mapPoints) { foreach ($mapPoints as $p) { $p->delete(); } } //delete user_stat and equipment $c = new Criteria(); $c->add(UserStatsPeer::USER_ID, $userId); $c->add(UserStatsPeer::RIDE_KEY, $rId); $s = UserStatsPeer::doSelectJoinAll($c); foreach ($s as $stat) { foreach ($stat->getUserStatEquips() as $equip) { $equip->delete(); } $stat->delete(); } //now delete userride $c = new Criteria(); $c->add(UserRidesPeer::USER_ID, $userId); $c->add(UserRidesPeer::USER_RIDE_ID, $rId); $rides = UserRidesPeer::doSelect($c); foreach ($rides as $r) { $r->delete(); } return $this->redirect('userrides/index'); } }