public function actionDeletePicture($id) { $this->checkOwner($id); if (isset($_POST['Content_ID'])) { $contentID = $_POST['Content_ID']; ExperienceToContent::model()->deleteAll('Experience_ID=:Experience_ID AND Content_ID=:Content_ID', array(':Experience_ID' => $id, ':Content_ID' => $contentID)); } }
public function save() { $isSaved = null; $experience = new Experience(); $transaction = $experience->dbConnection->beginTransaction(); try { if (isset($this->free) && $this->free === true) { unset($this->Price); } $experience->Name = $this->Name; $experience->ExperienceType = $this->ExperienceType; $experience->Audience = $this->Audience; $experience->Category_ID = $this->Category_ID; $experience->Start = $this->Start; $experience->End = $this->End; $experience->Description = $this->Description; $experience->Offering = $this->Offering; $experience->FinePrint = $this->FinePrint; $experience->Price = $this->Price; $experience->Min_occupancy = $this->Min_occupancy; $experience->Max_occupancy = $this->Max_occupancy; $experience->MaxPerPerson = $this->MaxPerPerson; $experience->MultipleAllowed = $this->MultipleAllowed; $appropriateAges = 0; if (isset($this->AppropriateAges) && is_array($this->AppropriateAges)) { foreach ($this->AppropriateAges as $age) { $appropriateAges += $age; } } $experience->AppropriateAges = $appropriateAges; $location = $this->getLocation(); $experience->Location_ID = $location->Location_ID; $experience->save(); $this->experience = $experience; if ($this->imageFiles != null) { foreach ($this->imageFiles as $imageFile) { $content = Content::AddContent($imageFile, 'Class Image', ContentType::ImageID); $experienceToContent = new ExperienceToContent(); $experienceToContent->Experience_ID = $this->experience->Experience_ID; $experienceToContent->Content_ID = $content->Content_ID; $experienceToContent->save(); } } if (isset($this->fromRequest_ID) && is_numeric($this->fromRequest_ID)) { $request = Request::model()->findByPk($this->fromRequest_ID); if ($request != null) { $request->Created_Experience_ID = $this->experience->Experience_ID; $request->save(); // Notify the students foreach ($request->requestors as $user) { if ($user->User_ID != $this->experience->Create_User_ID) { $userName = CHtml::link($this->experience->createUser->fullName, array('//user/view', 'id' => $this->experience->createUser->User_ID)); $requestName = CHtml::link($request->Name, array('//request/view', 'id' => $request->Request_ID)); $experienceName = CHtml::link($this->experience->Name, array('//experience/view', 'id' => $this->experience->Experience_ID)); Message::SendNotification($user->User_ID, "{$userName} has picked up the request \"{$requestName}\" and created the experience \"{$experienceName}\"."); } } } } $tagsArray = Tag::model()->string2array($this->tags); foreach ($tagsArray as $tagName) { $tag = Tag::model()->findOrCreate($tagName); $experienceToTag = new ExperienceToTag(); $experienceToTag->Experience_ID = $this->experience->Experience_ID; $experienceToTag->Tag_ID = $tag->Tag_ID; $experienceToTag->save(); } if (isset($this->sessions) && strlen($this->sessions) > 0) { $sessionData = json_decode($this->sessions); foreach ($sessionData as $sessionItem) { $session = new Session(); $session->Experience_ID = $this->experience->Experience_ID; $session->Start = $sessionItem->Start; $session->End = $sessionItem->End; $session->save(); } } $transaction->commit(); $isSaved = true; } catch (Exception $e) { $isSaved = false; $transaction->rollback(); } return $isSaved; }