public static function renderControlSelectAllAuthoritativePlants($default_selected = 0)
 {
     if (is_object($default_selected)) {
         $default_selected = $default_selected->authoritative_plant_id;
     }
     global $DB;
     $all_ap = Authoritative_Plant::getAllFromDb(['flag_active' => true, 'flag_delete' => FALSE], $DB);
     usort($all_ap, 'Authoritative_Plant::cmp');
     $rendered = '<select name="authoritative_plant_id" id="authoritative-plant-id">' . "\n";
     foreach ($all_ap as $ap) {
         $rendered .= '  ' . $ap->renderAsOption($ap->authoritative_plant_id == $default_selected) . "\n";
     }
     $rendered .= '</select>';
     return $rendered;
 }
 function testViewNotEditable()
 {
     $this->doLoginBasic();
     $this->goToNotebookPageView(1104);
     $this->checkBasicAsserts();
     // NOTE: most of the messy details of this are checked in the notebook_page object tests of renderAsView - see app_infrastructure_tests/TestOfNotebookPage.class.php
     // this just makes sure that the plant lable is actually showing up and that the appropriate edit buttons are there
     $ap1 = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB);
     // page heading text
     $this->assertText($ap1->renderAsShortText());
     // NO 'edit' control
     $this->assertNoLink(util_lang('edit'));
     // NO 'add field' control
     $this->assertNoLink(util_lang('add_notebook_page_field'));
     // no 'add specimen' control
     $this->assertNoLink(util_lang('add_specimen'));
     $this->assertNoText('IMPLEMENTED');
 }
 function testViewNotEditable()
 {
     $this->doLoginBasic();
     $this->goToNotebookView(1004);
     $this->checkBasicAsserts();
     $n = Notebook::getOneFromDb(['notebook_id' => 1004], $this->DB);
     //        util_prePrintR($n);
     $ap1 = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB);
     // page heading text
     $this->assertText(ucfirst(util_lang('notebook')));
     $this->assertText($n->name);
     $this->assertText($n->notes);
     // NO 'edit' control
     $this->assertNoLink(util_lang('edit'));
     // number of notebook pages
     $this->assertEltByIdHasAttrOfValue('list-of-notebook-pages', 'data-notebook-page-count', '1');
     $this->assertEltByIdHasAttrOfValue('notebook-page-item-1', 'data-notebook_page_id', '1104');
     $this->assertLink($ap1->renderAsShortText());
     // NO 'add page' control
     $this->assertNoLink(util_lang('add_notebook_page'));
 }
 public function getLinked()
 {
     if ($this->link_to_type == 'authoritative_plant') {
         return Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => $this->link_to_id], $this->dbConnection);
     }
     if ($this->link_to_type == 'notebook_page') {
         return Notebook_Page::getOneFromDb(['notebook_page_id' => $this->link_to_id], $this->dbConnection);
     }
     return 0;
 }
    }
    $action = 'view';
}
if ($action == 'list') {
    echo '<h2>' . ucfirst(util_lang('authoritative_plants')) . '</h2>' . "\n";
    if ($USER->canActOnTarget($ACTIONS['edit'], $ap)) {
        ?>
            <a href="<?php 
        echo APP_ROOT_PATH . '/app_code/authoritative_plant.php?action=create&user_id=' . $USER->user_id;
        ?>
" class="btn" id="btn-add-authoritative_plant"><?php 
        echo util_lang('add_authoritative_plant');
        ?>
</a><?php 
    }
    $all_ap = Authoritative_Plant::getAllFromDb(['flag_delete' => false], $DB);
    echo '<ul id="list-of-authoritative-plants" class="all-authoritative-plants">' . "\n";
    foreach ($all_ap as $ap) {
        if ($USER->canActOnTarget($ACTIONS['view'], $ap)) {
            echo $ap->renderAsListItem();
        }
    }
    echo '</ul>' . "\n";
    //        echo 'TODO: implement list action';
}
if ($action == 'view') {
    if ($USER->canActOnTarget($ACTIONS['edit'], $ap)) {
        echo '<div id="actions">' . $ap->renderAsButtonEdit() . '</div>' . "\n";
    }
    echo $ap->renderAsView();
    echo '<script src="' . APP_ROOT_PATH . '/js/plant_image_viewer.js"></script>' . "\n";
 function testCanActOnTarget()
 {
     $n1 = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB);
     // owned by 101
     $n2 = Notebook::getOneFromDb(['notebook_id' => 1003], $this->DB);
     // owned by 102
     $n3 = Notebook::getOneFromDb(['notebook_id' => 1004], $this->DB);
     // owned by 110
     $np1 = Notebook_Page::getOneFromDb(['notebook_page_id' => 1101], $this->DB);
     // part of notebook 101
     $s1 = Specimen::getOneFromDb(['specimen_id' => 8001], $this->DB);
     // owned by 110
     $s2 = Specimen::getOneFromDb(['specimen_id' => 8002], $this->DB);
     // owned by 101
     $mds = Metadata_Structure::getOneFromDb(['metadata_structure_id' => 6004], $this->DB);
     $mdts = Metadata_Term_Set::getOneFromDb(['metadata_term_set_id' => 6101], $this->DB);
     $mdtv = Metadata_Term_Value::getOneFromDb(['metadata_term_value_id' => 6211], $this->DB);
     $ap = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB);
     $actions_list = Action::getAllFromDb([], $this->DB);
     $actions = [];
     foreach ($actions_list as $act_elt) {
         $actions[$act_elt->name] = $act_elt;
     }
     // basic, field user
     $u = User::getOneFromDb(['user_id' => 101], $this->DB);
     $this->assertTrue($u->canActOnTarget($actions['view'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['view'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['view'], $np1));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $np1));
     $this->assertTrue($u->canActOnTarget($actions['create'], $np1));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $np1));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $np1));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $np1));
     $this->assertTrue($u->canActOnTarget($actions['view'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['create'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['view'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $s2));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['create'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['create'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['create'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['view'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['create'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $ap));
     // basic user on arbitrary object
     $this->assertTrue($u->canActOnTarget($actions['view'], new Authoritative_Plant(['DB' => $this->DB])));
     // system admin
     $u->flag_is_system_admin = true;
     $this->assertTrue($u->canActOnTarget($actions['view'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['view'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['view'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['create'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['view'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['create'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['create'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['create'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['view'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['create'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $ap));
     // public user
     $u = User::getOneFromDb(['user_id' => 109], $this->DB);
     $this->assertFalse($u->canActOnTarget($actions['view'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['create'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n1));
     $this->assertFalse($u->canActOnTarget($actions['view'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['create'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['create'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n3));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['view'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['create'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $s1));
     $this->assertFalse($u->canActOnTarget($actions['view'], $s2));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $s2));
     $this->assertFalse($u->canActOnTarget($actions['create'], $s2));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $s2));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $s2));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['create'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $mds));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['create'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $mdts));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['create'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $mdtv));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['view'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['create'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $ap));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $ap));
     // manager
     $u = User::getOneFromDb(['user_id' => 110], $this->DB);
     // manager user
     $this->assertTrue($u->canActOnTarget($actions['view'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $n1));
     $this->assertTrue($u->canActOnTarget($actions['view'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $n3));
     $this->assertTrue($u->canActOnTarget($actions['view'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['create'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $s1));
     $this->assertTrue($u->canActOnTarget($actions['view'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $s2));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['create'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $mds));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['create'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $mdts));
     $this->assertTrue($u->canActOnTarget($actions['view'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['create'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $mdtv));
     $this->assertTrue($u->canActOnTarget($actions['view'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['edit'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['create'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['delete'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['publish'], $ap));
     $this->assertTrue($u->canActOnTarget($actions['verify'], $ap));
 }
 function testLoadSpecimens()
 {
     $ap = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB);
     $this->assertEqual(0, count($ap->specimens));
     $ap->loadSpecimens();
     $this->assertEqual(1, count($ap->specimens));
     $this->assertEqual(8001, $ap->specimens[0]->specimen_id);
 }
 function testViewNotLoggedIn()
 {
     //        $this->doLoginBasic();
     $ap = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB);
     $this->goToView($ap->authoritative_plant_id);
     $this->checkBasicAsserts();
     //        $this->showContent();
     // page heading
     $this->assertLink(util_lang('authoritative_plant'));
     // NO 'edit' control
     $this->assertNoLink(util_lang('edit'));
     // MORE!!!!
     // NOTE: assuming that if one relevant piece of info shows up then they're all there - detailed testing is handled in the class test suite renderAsViewTest
     //        $this->todo("check for auth plant info");
     $this->assertText('AP_A_order');
     //        $this->todo("check for extras info");
     $this->assertText("AP_A common a american chestnut");
     //        $this->todo("check for notebook pages");
     $this->assertLink('in notebook testnotebook4');
 }
 public function getAuthoritativePlant()
 {
     if ($this->notebook_page_id == 'NEW') {
         return '';
     }
     return Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => $this->authoritative_plant_id], $this->dbConnection);
 }
    function testRenderAsEdit_newNotebookPage()
    {
        $np = Notebook_Page::createNewNotebookPageForNotebook(1001, $this->DB);
        $n = $np->getNotebook();
        global $USER, $DB;
        $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB);
        $DB = $this->DB;
        $canonical = '<div id="rendered_notebook_page_NEW" class="rendered_notebook_page edit_rendered_notebook_page" ' . $np->fieldsAsDataAttribs() . ' data-can-edit="1">
<form id="form-edit-notebook-page-base-data" action="' . APP_ROOT_PATH . '/app_code/notebook_page.php">
  <input type="hidden" name="action" value="update"/>
  <input type="hidden" id="notebook_page_id" name="notebook_page_id" value="NEW"/>
  <input type="hidden" id="notebook_id" name="notebook_id" value="1001"/>
  <div id="actions"><button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control" value="update"><i class="icon-ok-sign icon-white"></i> Save</button>
  <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=edit&notebook_id=1001"><i class="icon-remove"></i> Cancel</a></div>
<h4>In notebook <a href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=view&notebook_id=1001" id="parent-notebook-link">testnotebook1</a></h4>
  <div id="select_new_authoritative_plant_NEW" class="NEW_select_new_authoritative_plant">' . Authoritative_Plant::renderControlSelectAllAuthoritativePlants() . '</div>
  <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($np->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($np->updated_at) . '</span></div>
  <div class="info-owner">owned by <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=101">' . htmlentities($USER->screen_name) . '</a></div>
<div class="control-workflows">  <span class="published_state workflow-info">' . util_lang('published_false') . '</span>, <span class="verified_state verified_state_false workflow-info">' . util_lang('verified_false') . '</span></div>
  <div class="notebook_page_notes"><textarea id="notebook-page-notes" name="notes" rows="4" cols="120">' . util_lang('new_notebook_page_notes') . '</textarea></div>
</form>
</div>';
        $rendered = $np->renderAsEdit();
        //            echo "<pre>
        //-----------
        //".htmlentities($canonical)."
        //-----------
        //".htmlentities($rendered)."
        //-----------
        //</pre>";
        $this->assertEqual($canonical, $rendered);
        $this->assertNoPattern('/IMPLEMENTED/', $rendered);
    }
 function testCreationOfNewPlant()
 {
     $this->doLoginAdmin();
     $this->get('http://localhost/digitalfieldnotebooks/app_code/authoritative_plant.php?action=create');
     $this->checkBasicAsserts();
     $this->assertTrue($this->setField('authoritative_plant-genus_NEW', 'uniquenewgenus'));
     $this->assertTrue($this->setField('authoritative_plant-species_NEW', 'uniquenewspecies'));
     $this->assertTrue($this->setField('flag_active', true));
     ///////////////////////////////
     //// submit the form
     $this->click('<i class="icon-ok-sign icon-white"></i> ' . util_lang('update', 'properize'));
     $new_ap = Authoritative_Plant::getOneFromDb(['species' => 'uniquenewspecies'], $this->DB);
     $this->assertTrue($new_ap->matchesDb);
     $this->assertTrue($new_ap->flag_active);
 }
 public function getAuthoritativePlant()
 {
     return Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => $this->authoritative_plant_id, 'flag_delete' => FALSE], $this->dbConnection);
 }
 function testRenderSpecimenListBlock()
 {
     $ap = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB);
     $ap->cacheSpecimens();
     $canonical = '';
     $canonical .= '  <h4>' . ucfirst(util_lang('specimens')) . "</h4>\n" . '  <ul class="specimens">' . "\n";
     $canonical .= '    <li><a href="#" id="add_new_specimen_button" class="btn">' . util_lang('add_specimen') . '</a></li>' . "\n";
     if ($ap->specimens) {
         foreach ($ap->specimens as $specimen) {
             $canonical .= '    <li id="list_item-specimen_' . $specimen->specimen_id . '">' . $specimen->renderAsEditEmbed() . "</li>\n";
         }
     } else {
         $canonical .= '<li>' . util_lang('no_metadata', 'ucfirst') . '</li>' . "\n";
     }
     $canonical .= "  </ul>\n";
     $rendered = Specimen::renderSpecimenListBlock($ap->specimens);
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
 }
 public function getTargets()
 {
     switch ($this->target_type) {
         case 'global_notebook':
             return Notebook::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_metadata':
             return Metadata_Structure::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_plant':
             return Authoritative_Plant::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_specimen':
             return Specimen::getAllFromDb([], $this->dbConnection);
             break;
         case 'notebook':
             return array(Notebook::getOneFromDb(['notebook_id' => $this->target_id], $this->dbConnection));
             break;
         case 'metadata_structure':
             return array(Metadata_Structure::getOneFromDb(['metadata_structure_id' => $this->target_id], $this->dbConnection));
             break;
         case 'plant':
             return array(Authoritative_Plant::getOneFromDb(['authoritative_id' => $this->target_id], $this->dbConnection));
             break;
         case 'specimen':
             return array(Specimen::getOneFromDb(['specimen_id' => $this->target_id], $this->dbConnection));
             break;
         default:
             return array();
     }
 }