function test_Coins_returnChange()
 {
     // arrange
     $test_Coins = new Coins();
     $input = 96;
     // act
     $result = $test_Coins->returnChange($input);
     // assert
     $this->assertEquals(array('quarters' => 3, 'dimes' => 2, 'nickels' => 0, 'pennies' => 1), $result);
 }
Beispiel #2
0
 function test_coins_pennies()
 {
     //Arrange
     $test_Coin = new Coins();
     $input = 7;
     //Act
     $result = $test_Coin->coinSort($input);
     //Assert
     $this->assertEquals("quarters:0 dimes:0 nickels:1 pennies:2", $result);
 }
 /** The constructor
  * @access public
  * @param array $options
  * @return void
  */
 public function __construct(array $options = null)
 {
     //Get the coins columns from the table's schema
     $finds = new Coins();
     $schema = $finds->info();
     //Flip the array of columns
     $fields = array_flip($schema['cols']);
     //Which fields to remove from this as they aren't editable by the staff
     $remove = array('id', 'secuid', 'old_findID', 'updated', 'created', 'updatedBy', 'createdBy', 'institution', 'secwfstage', 'secowner', 'sectag', 'old_candidate', 'old_finderID', 'objdate2subperiod_old', 'objdate1subperiod_old', 'finder2ID', 'datefound2flag', 'datefound1flag', 'findID', 'phase_date_1', 'phase_date_2', 'context', 'depositionDate', 'volume', 'reference', 'classification');
     //What are the friendly labels?
     $labels = array('geographyID' => 'Iron Age geographical region', 'geography_qualifier' => 'Geographical qualifier', 'greekstateID' => 'Greek state', 'ruler_id' => 'Primary ruler', 'ruler2_id' => 'Secondary ruler', 'ruler_qualifier' => 'primary ruler qualifier', 'ruler2_qualifier' => 'Secondary ruler qualifier', 'tribe_qualifier' => 'Ascribed culture', 'denomination_qualifier' => 'Denomination qualifier', 'mint_id' => 'Mint', 'mint_qualifier' => 'Mint qualifier', 'categoryID' => 'Medieval category', 'typeID' => 'Medieval type', 'status_qualifier' => 'Status qualifier', 'obverse_description' => 'Obverse description', 'obverse_inscription' => 'Obverse inscription', 'initial_mark' => 'Initial mark', 'reverse_description' => 'Reverse description', 'reverse_inscription' => 'Reverse inscription', 'reverse_mintmark' => 'Reverse mintmark', 'revtypeID' => 'Reverse type', 'revTypeID_qualifier' => 'Reverse type qualifier', 'degree_of_wear' => 'Degree of wear', 'die_axis_measurement' => 'Die axis', 'die_axis_certainty' => 'Die axis certainty', 'cciNumber' => 'CCI number', 'allen_type' => 'Allen type', 'mack_type' => 'Mack type', 'bmc_type' => 'BMC type', 'rudd_type' => 'Ancient British Coinage type', 'va_type' => 'Van Arsdell type', 'numChiab' => 'CHIAB number', 'reeceID' => 'Reece period');
     //Remove the unwanted fields from the array of fields
     foreach ($remove as $rem) {
         unset($fields[$rem]);
     }
     parent::__construct($options);
     $this->setName('configureCoinCopy');
     $elements = array();
     foreach (array_keys($fields) as $field) {
         $label = $field;
         $field = new Zend_Form_Element_Checkbox($field);
         if (array_key_exists($label, $labels)) {
             $clean = ucfirst($labels[$label]);
         } else {
             $clean = ucfirst($label);
         }
         $field->setLabel($clean)->setRequired(false)->addValidator('NotEmpty', 'boolean');
         $elements[] = $field;
         $this->addElement($field);
     }
     $this->addDisplayGroup($elements, 'details');
     //Submit button
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel('Submit coin form configuration');
     $this->addElement($submit);
     $this->details->setLegend('Choose fields: ');
     parent::init();
 }
 /** Display individual record
  * @access public
  * @return void
  */
 public function recordAction()
 {
     if ($this->getParam('id', false)) {
         $this->view->recordID = $this->getParam('id');
         $id = $this->getParam('id');
         $finds = $this->getFinds()->getAllData($id);
         $this->_helper->availableOrNot($finds);
         $this->view->finds = $finds;
         $coins = new Coins();
         $this->view->coins = $coins->getCoinData($id);
         $coinRefs = new CoinClassifications();
         $this->view->coinrefs = $coinRefs->getAllClasses($id);
         $thumbs = new Slides();
         $this->view->thumbs = $thumbs->getThumbnails($id, 'artefacts');
         $refs = new Publications();
         $this->view->refs = $refs->getReferences($id);
         $this->view->comments = $this->getComments()->getFindComments($id);
         $models = new SketchFab();
         $this->view->sketchfab = $models->getModels($id);
     } else {
         throw new Pas_Exception_Param($this->_missingParameter, 500);
     }
 }
 /** Display a report in pdf format
  */
 public function reportAction()
 {
     if ($this->_getParam('id', false)) {
         $this->view->recordID = $this->_getParam('id');
         $id = $this->_getParam('id');
         $finds = new Finds();
         $findsdata = $finds->getIndividualFind($id, $this->getRole());
         if (count($findsdata)) {
             $this->view->finds = $findsdata;
         } else {
             throw new Pas_Exception_NotAuthorised('You are not authorised to view this record');
         }
         $findsdata = new Finds();
         $this->view->findsdata = $findsdata->getFindData($id);
         $this->view->findsmaterial = $findsdata->getFindMaterials($id);
         $this->view->temporals = $findsdata->getFindTemporalData($id);
         $this->view->peoples = $findsdata->getPersonalData($id);
         $rallyfind = new Rallies();
         $this->view->rallyfind = $rallyfind->getFindRallyNames($id);
         $coins = new Coins();
         $this->view->coins = $coins->getCoinData($id);
         $thumbs = new Slides();
         $this->view->thumbs = $thumbs->getThumbnails($id);
         $refs = new Publications();
         $this->view->refs = $refs->getReferences($id);
         $findspotsdata = new Findspots();
         $this->view->findspots = $findspotsdata->getFindSpotData($id);
     } else {
         throw new Pas_Exception_Param($this->_missingParameter, 500);
     }
 }
 /** Display individual record
  * @todo move comment functionality to a model
  */
 public function recordAction()
 {
     if ($this->_getParam('id', false)) {
         $this->view->recordID = $this->_getParam('id');
         $id = $this->_getParam('id');
         $findsdata = $this->_finds->getIndividualFind($id, $this->getRole());
         if ($findsdata) {
             $this->view->finds = $findsdata;
         } else {
             throw new Pas_Exception_NotAuthorised('You are not authorised to view this record');
         }
         $contexts = array('xml', 'rss', 'json', 'atom', 'kml', 'georss', 'ics', 'rdf', 'xcs', 'vcf', 'csv', 'pdf');
         if (!in_array($this->_cs->getCurrentContext(), $contexts)) {
             $this->view->findsdata = $this->_finds->getFindData($id);
             $this->view->findsmaterial = $this->_finds->getFindMaterials($id);
             $this->view->temporals = $this->_finds->getFindTemporalData($id);
             $this->view->nexts = $this->_finds->getNextObject($id);
             $this->view->recordsprior = $this->_finds->getPreviousObject($id);
             $this->view->peoples = $this->_finds->getPersonalData($id);
             $this->view->findotherrefs = $this->_finds->getFindOtherRefs($id);
             $findspotsdata = new Findspots();
             $this->view->findspots = $findspotsdata->getFindSpotData($id);
             $rallyfind = new Rallies();
             $this->view->rallyfind = $rallyfind->getFindToRallyNames($id);
             $coins = new Coins();
             $this->view->coins = $coins->getCoinData($id);
             $coinrefs = new Coinclassifications();
             $this->view->coinrefs = $coinrefs->getAllClasses($id);
             $thumbs = new Slides();
             $this->view->thumbs = $thumbs->getThumbnails($id);
             $refs = new Publications();
             $this->view->refs = $refs->getReferences($id);
             $comments = new Comments();
             $this->view->comments = $comments->getFindComments($id);
             $response = $this->getResponse();
             if (in_array($this->getRole(), $this->_higherLevel) && !in_array($this->_cs->getCurrentContext(), array('xml', 'json', 'qrcode'))) {
                 $wform = new WorkflowStageForm();
                 $wform->id->setValue($id);
                 $wform->submit->setLabel('Change workflow');
                 $this->view->wform = $wform;
                 $response->insert('workflow', $this->view->render('structure/workflow.phtml'));
             } else {
                 $findspotsdata = new Findspots();
                 $this->view->findspots = $findspotsdata->getFindSpotData($id);
             }
             $form = new CommentFindForm();
             $form->submit->setLabel('Add a new comment');
             $this->view->form = $form;
             if ($this->getRequest()->isPost() && $form->isValid($this->_request->getPost())) {
                 if ($form->isValid($form->getValues())) {
                     $data = $form->getValues();
                     if ($this->getHelper->getAkismet()->isSpam($data)) {
                         $data['comment_approved'] = 'spam';
                     } else {
                         $data['comment_approved'] = 'moderation';
                     }
                     $comments = new Comments();
                     $insert = $comments->insert($data);
                     $this->_flashMessenger->addMessage('Your comment has been entered and will appear shortly!');
                     $this->_redirect(self::REDIRECT . 'record/id/' . $this->_getParam('id'));
                     $this->_request->setMethod('GET');
                 } else {
                     $this->_flashMessenger->addMessage('There are problems with your comment submission');
                     $form->populate($formData);
                 }
             }
         } else {
             $this->_helper->layout->disableLayout();
             //disable layout
             $record = $this->_finds->getAllData($id);
             if ($this->_auth->hasIdentity()) {
                 $user = $this->_auth->getIdentity();
                 if (in_array($user->role, $this->_restricted)) {
                     $record['0']['gridref'] = NULL;
                     $record['0']['easting'] = NULL;
                     $record['0']['northing'] = NULL;
                     $record['0']['lat'] = NULL;
                     $record['0']['lon'] = NULL;
                     $record['0']['finder'] = NULL;
                     $record['0']['address'] = NULL;
                     $record['0']['postcode'] = NULL;
                     $record['0']['findspotdescription'] = NULL;
                 }
             } else {
                 $record['0']['gridref'] = NULL;
                 $record['0']['easting'] = NULL;
                 $record['0']['northing'] = NULL;
                 $record['0']['lat'] = NULL;
                 $record['0']['lon'] = NULL;
                 $record['0']['finder'] = NULL;
                 $record['0']['address'] = NULL;
                 $record['0']['postcode'] = NULL;
                 $record['0']['findspotdescription'] = NULL;
                 if (!is_null($record['0']['knownas'])) {
                     $record['0']['parish'] = NULL;
                     $record['0']['fourFigure'] = NULL;
                 }
             }
             $this->view->record = $record;
         }
     } else {
         throw new Pas_Exception_Param($this->_missingParameter);
     }
 }
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Coins.php";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get("/return_results", function () use($app) {
    $my_coins = new Coins();
    if ($_GET['coin'] >= 0) {
        $results = $my_coins->returnChange($_GET['coin']);
    } else {
        echo "dummy";
        $results = false;
    }
    return $app['twig']->render('index.html.twig', array('results' => $results));
});
return $app;