public function deleteAction() { //delete fish //delete metadata fish done by DB $request = $this->getRequest(); $fishId = intval($this->getRequest()->getParam(Fish::COL_ID)); $fish = new Fish(); $rowset = $fish->find($fishId); if (count($rowset) == 1) { //note: delete of metadata is executed from db $fish->delete($fish->getAdapter()->quoteInto(Fish::COL_ID . ' = ?', $fishId)); } $redirect = new Zend_Controller_Action_Helper_Redirector(); $redirect->setGoto('search', 'search', 'fish'); }
function __construct($name, $flavor, $record, $species) { parent::__construct(); $this->common_name = $name; $this->flavor = $flavor; $this->record_weight = $record; $this->species = $species; }
public function run() { // clear our database ------------------------------------------ DB::table('bears')->delete(); DB::table('fish')->delete(); DB::table('picnics')->delete(); DB::table('trees')->delete(); DB::table('bears_picnics')->delete(); // seed our bears table ----------------------- // we'll create three different bears // bear 1 is named Lawly. She is extremely dangerous. Especially when hungry. $bearLawly = Bear::create(array('name' => 'Lawly', 'type' => 'Grizzly', 'danger_level' => 8)); // bear 2 is named Cerms. He has a loud growl but is pretty much harmless. $bearCerms = Bear::create(array('name' => 'Cerms', 'type' => 'Black', 'danger_level' => 4)); // bear 3 is named Adobot. He is a polar bear. He drinks vodka. $bearAdobot = Bear::create(array('name' => 'Adobot', 'type' => 'Polar', 'danger_level' => 3)); $this->command->info('The bears are alive!'); // seed our fish table ------------------------ // our fish wont have names... because theyre going to be eaten // we will use the variables we used to create the bears to get their id $fishOne = Fish::create(array('weight' => 5, 'bear_id' => $bearLawly->id)); $fishTwo = Fish::create(array('weight' => 12, 'bear_id' => $bearCerms->id)); $fishThree = Fish::create(array('weight' => 4, 'bear_id' => $bearAdobot->id)); $this->command->info('They are eating fish!'); // seed our trees table --------------------- // give two trees to lawly Tree::create(array('type' => 'Redwood', 'age' => 500, 'bear_id' => $bearLawly->id)); Tree::create(array('type' => 'Oak', 'age' => 400, 'bear_id' => $bearLawly->id)); $this->command->info('Climb bears! Be free!'); // seed our picnics table --------------------- // we will create one picnic and apply all bears to this one picnic $picnicYellowstone = Picnic::create(array('name' => 'Yellowstone', 'taste_level' => 6)); $picnicGrandCanyon = Picnic::create(array('name' => 'Grand Canyon', 'taste_level' => 5)); // link our bears to picnics --------------------- // for our purposes we'll just add all bears to both picnics for our many to many relationship $bearLawly->picnics()->attach($picnicYellowstone->id); $bearLawly->picnics()->attach($picnicGrandCanyon->id); $bearCerms->picnics()->attach($picnicYellowstone->id); $bearCerms->picnics()->attach($picnicGrandCanyon->id); $bearAdobot->picnics()->attach($picnicYellowstone->id); $bearAdobot->picnics()->attach($picnicGrandCanyon->id); $this->command->info('They are terrorizing picnics!'); }
function __construct($name, $flavor, $record, $species) { parent::__construct($name, $flavor, $record); $this->species = $species; }
public function indexAction() { $addFish = false; if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getParams(); if ($this->form->isValid($params)) { //TODO wenn fishsamplecode noch nicht in der datenbank, //dann lege fisch an mit diesem samplecode (erledigt) //und SPRINGE IN Fish_CreateController (am Ende des Controllers) //TODO mit getElement und Konstanten arbeiten $fishSampleCode = $this->form->getValue(Fish::COL_SAMPLE_CODE); $fishTable = new Fish(); $row = $fishTable->fetchRow($fishTable->select()->where(Fish::COL_SAMPLE_CODE . '= ?', $fishSampleCode)); if (is_null($row)) { //echo 'Warnung: Fish Sample Code nicht vorhanden.'; $fishId = $fishTable->insert(array(Fish::COL_SAMPLE_CODE => $fishSampleCode)); $addFish = true; $constFishId = Fish::COL_ID; $fishId->{$constFishId} = $fishId; } else { $addFish = false; $fishId = $row->FISH_ID; } //TODO dateinamen mit leerzeichen //könnte ein problem bei der weiterverarbeitung in linux sein //klären, //ggf. akzeptieren und umwandeln oder verweigern? //don't call $form->getValues() - causes physical upload immediately //look ZFDoc 19.1.3 //note: if using Zend_Form_Element_File (in view) you can't use new instance of Zend_File_Transfer_Adapter_Http in controller! // http://www.zfforums.com/zend-framework-forum-8/general-talks-12/file_transfer-illegal-uploaded-possible-attack-1737.html // http://www.nabble.com/Zend_File_Transfer-td19024470.html //solution: //getTransferAdapter() $upload = $this->form->uploadElement->getTransferAdapter(); // Returns all known internal file informations $files = $upload->getFileInfo(); $imageTable = new Image(); $medimTable = new MetaDataImage(); //look ZFDoc 19.3.3 //iterates over all file elemens $numberImagesUploaded = 0; $userId = AuthQuery::getUserId(); foreach ($files as $file => $info) { /*handle only uploaded files, skip blank file elements store original file in certain path file is saved without excplicit temp directory with Zend Filter image import uses temp directory instead */ if (!$upload->isUploaded($file)) { continue; } $creator_guid = new Ble422_Guid(); $guid = $creator_guid->__toString(); $fileName = $info['name']; $path_parts = pathinfo($fileName); $originalFileName = $path_parts['basename']; //used later to create Image dataset $newFileNameWithGuid = $guid . '.' . strtolower($path_parts['extension']); //save extension in lower-case //relative path with new filename, prefix dot&slash required $completeTarget = './' . Image::RELATIVE_UPLOAD_PATH . '/' . $newFileNameWithGuid; //apply filter only for uploaded file $fileName $upload->addFilter('Rename', array('target' => $completeTarget, 'overwrite' => false), $fileName); $upload->receive($file); //TODO write protect files $upload->clearFilters(); try { $ratio = $this->form->getValue(Image::COL_RATIO_EXTERNAL); $tn_ratio = $imageTable->processImage($completeTarget); //ratio is filled from form $imageId = $imageTable->insertImageDataset($completeTarget, $originalFileName, $fishId, $guid, $userId, $ratio, $tn_ratio); $imageTable->updateImageAndMetadata($this->form, $imageId); $numberImagesUploaded++; } catch (Exception $e) { echo "Exception: " . $e->getMessage(); } } Zend_Registry::set('MESSAGE', $numberImagesUploaded . ' image(s) successfully inserted'); if ($addFish) { $next = array('nextAction' => 'index', 'nextController' => 'upload', 'nextModul' => 'image'); $namespace = new Zend_Session_Namespace('default'); $namespace->next = $next; $redirect = new Zend_Controller_Action_Helper_Redirector(); $redirect->setGotoSimple('update', 'edit', 'fish', array(Fish::COL_ID => $fishId)); } } else { //form isn't valid $this->form->populate($params); $this->view->form = $this->form; } } //$this->view->form = $form; }
public function characteristics() { parent::characteristics(); echo "I am carnivorous<br/>"; }
return "Book Price: " . $this->bookPrice(); } } $book = new book(); $book->title = "Lord of the Rings. "; $book->author = "JR Tolkien"; $book->yearOfPublishing = "1928"; $book->format; // ="Hardcover"; echo "Title: " . $book->title . $book->summary(); //Inheritance class Animal { var $color; var $location = "North America. "; function getColor() { return $this->color; } function getLocation() { return $this->location; } } class Fish extends Animal { } $jellyfish = new Fish(); $jellyfish->location = "Pacific Ocean. "; $jellyfish->color = "blue. "; echo $jellyfish->getColor() . $jellyfish->getLocation();
/** * * @param $key the subdirectory for csv and image files * @return unknown_type importImages/importFishes arrays with the IDs as key to see where dataimport eventually went wrong */ public function beginImport($key) { $this->key = $key; $this->logger = new Ble422_ArrayLogger(self::RELATIVE_PATH_IMPORT_LOGS . $this->key . '_import_log.txt'); $this->loadFromNamespace(); // foreach ($this->rowHasUniqueUploadedFile as $key => $value) { $preparedDatasets[$key] = $this->preparedDatasets[$key]; } // $importedFishes = array(); $importedImages = array(); $i = 0; $j = 0; $fishForm = new Fish_Form_Edit(); $fish = new Fish(); $imageForm = new Image_Form_Edit(); $image = new Image(); $numberCopiedFiles = 0; $dbAdapter = $fish->getAdapter(); $dbAdapter->beginTransaction(); try { //changed to local preparedDatasets to filter datasets with uploaded files used in other datasets of import foreach ($preparedDatasets as $rowNo => $dataset) { if (Default_SimpleQuery::isValueInTableColumn($dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], $fish, Fish::COL_SAMPLE_CODE, 'string')) { //get id from already existing fish dataset and go on if ($values = Default_SimpleQuery::getValuesFromTableColumnWhere($fish, Fish::COL_ID, Fish::COL_SAMPLE_CODE, $dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], 'string')) { //test for amount of values, must be 1 if (count($values) == 1) { $fishId = $values[0]; } else { throw new Zend_Exception('Error: more/less than 1 id found for fish sample code'); } } } else { //create new fish dataset $fishBaseData = array(Fish::COL_SAMPLE_CODE => $dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], Fish::COL_USER_ID => $this->userId); $fishMetaData = $dataset['fishFormDataset']; //unset($fishMetaData[Fish::COL_SAMPLE_CODE]); $fishForm->populate($fishMetaData); //insert fish $fishId = $fish->insert($fishBaseData); //now update fish with fish meta data $fish->updateFishAndMetadata($fishForm, $fishId, $fishBaseData); $importedFishes[$i][Fish::COL_ID] = $fishId; $importedFishes[$i]['sourceCsvRow'] = $rowNo; $i++; } // check wether a image shall be imported ------------------------ $qu = new Default_ReferenceQuery(); $filenames = $qu->getImageNames($dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE]); //case non-sensitive foreach ($filenames as &$file) { $file = strtolower($file); } $importImageFile = false; if (!empty($filenames)) { //case non-sensitive if (in_array(strtolower($dataset['imageFormDataset'][Image::COL_ORIGINAL_FILENAME]), $filenames) != FALSE) { // Image is already in database $importImageFile = false; } else { $importImageFile = true; } } else { $importImageFile = true; } // end check ------------------------------------------------------ // import the images if ($importImageFile) { //copy file to new path and rename $completeSource = self::RELATIVE_PATH_UPLOAD_CACHE . $this->key . '/' . $dataset['imageFormDataset'][Image::COL_ORIGINAL_FILENAME]; $creator_guid = new Ble422_Guid(); $guid = $creator_guid->__toString(); $path_parts = pathinfo($completeSource); $originalFileName = $path_parts['basename']; //used later to create Image dataset $newFileNameWithGuid = $guid . '.' . strtolower($path_parts['extension']); //save extension in lower-case, needed for further processing in flex //relative path with new filename, prefix dot&slash required $completeDestination = './' . Image::RELATIVE_UPLOAD_PATH . '/' . $newFileNameWithGuid; if (!copy($completeSource, $completeDestination)) { throw new Zend_Exception("Error: copy fails, source: {$fileName}, destination: {$completeDestination}"); } $ratio = $dataset['imageFormDataset'][Image::COL_RATIO_EXTERNAL]; $this->logger->log(array('received original file' => $completeSource)); $this->logger->log(array('copied uploaded file' => $completeDestination)); $numberCopiedFiles++; //TODO write protect files //create other image files $tn_ratio = $image->processImage($completeDestination); //case sensibility: original file name is saved like spelled in CSV file $imageId = $image->insertImageDataset($completeDestination, $originalFileName, $fishId, $guid, $this->userId, $ratio, $tn_ratio); //create image base and meta datasets $imageMetaData = $dataset['imageFormDataset']; $imageForm->populate($imageMetaData); //$imageId = $image->insert($imageBaseData); $image->updateImageAndMetadata($imageForm, $imageId); $importedImages[$j]['sourceCsvRow'] = $rowNo; $importedImages[$j][Image::COL_ID] = $imageId; $importedImages[$j][Image::COL_FISH_ID] = $fishId; $importedImages[$j][Image::COL_ORIGINAL_FILENAME] = $originalFileName; $importedImages[$j]['completeDestination'] = $completeDestination; $relativePathAndFileNameWorkingCopy = './' . Image::RELATIVE_PATH_IMAGE_SHRINKED_WORKING_COPIES . '/' . $guid . '.jpg'; $relativePathAndFileNameThumbnail = './' . Image::RELATIVE_PATH_IMAGE_THUMBNAILS . '/' . $guid . '.jpg'; $importedImages[$j]['completeWorkingCopy'] = $relativePathAndFileNameWorkingCopy; $importedImages[$j]['completeThumbnail'] = $relativePathAndFileNameThumbnail; $j++; } } $dbAdapter->commit(); $this->logger->log(array('datasets committed, number of copied files into system' => $numberCopiedFiles)); $returnCode = 'success'; //delete upload cache dir Ble422_FileHelper::delete_directory(self::RELATIVE_PATH_UPLOAD_CACHE . $this->key); } catch (Exception $e) { $returnCode = 'error'; $dbAdapter->rollBack(); //delete copied/created files, else there will be orphaned files foreach ($importedImages as $image) { unlink($image['completeDestination']); unlink($image['completeWorkingCopy']); unlink($image['completeThumbnail']); } $this->logger->log(array('Error exception' => $e->getMessage()), 'ERROR, roll back of imported datasets and unsetting of files, see below'); $this->logger->log(array('Roll back of importedFishes' => $importedFishes)); $this->logger->log(array('Roll back of importedImages' => $importedImages)); //delete upload cache dir Ble422_FileHelper::delete_directory(self::RELATIVE_PATH_UPLOAD_CACHE . $this->key); echo $e->getMessage(); } $returnArray = array('returnCode' => $returnCode, 'importFishes' => $importedFishes, 'importImages' => $importedImages, 'numberCopiedFiles' => $numberCopiedFiles); $this->logger->log(array('data import' => $returnArray)); return $returnArray; }
<?php include 'animal.php'; include 'cat.php'; include 'fish.php'; //$catObj = new cat(); //$catObj->breathe(); $fishObj = new Fish(); $fishObj->move(); $fishObj->breathe();