/**
  * findAllForRecord
  * Find all synoyms (including self) of a given table_name and record_id (and group if specified).
  * Also takes the 'name' column of the referenced record
  * @param string $table_name the name of the referenced relation
  * @param int $record_id record id of the referenced item_id
  * @param array $groups array of group ids to filter the research
  * @return array of array of result. each item has keys  id, record_id, group_id, is_basionym, order_by, item_id, name (of the referenced record)
  */
 public function findAllForRecord($table_name, $record_id, $groups = null)
 {
     if ($groups === null) {
         $groups = $this->findGroupsIdsForRecord($table_name, $record_id);
     }
     if (empty($groups)) {
         return array();
     }
     $q = Doctrine_Query::create()->select('s.group_name, s.id, s.record_id, s.group_id, s.is_basionym, s.order_by, t.name, t.id ' . ($table_name == 'taxonomy' ? ', t.extinct' : ''))->from('ClassificationSynonymies s, ' . DarwinTable::getModelForTable($table_name) . ' t')->where('s.referenced_relation = ?', $table_name)->andWhere('s.record_id=t.id')->andwhereIn('s.group_id', $groups)->orderBy('s.group_name ASC, s.order_by ASC')->setHydrationMode(Doctrine::HYDRATE_NONE);
     $items = $q->execute();
     $results = array();
     foreach ($items as $item) {
         $catalogue = DarwinTable::getModelForTable($table_name);
         $cRecord = new $catalogue();
         $cRecord->setName($item[6]);
         $cRecord->setId($item[7]);
         if ($table_name == 'taxonomy') {
             $cRecord->setExtinct($item[8]);
         }
         //group_name
         if (!isset($results[$item[0]])) {
             $results[$item[0]] = array();
         }
         $results[$item[0]][] = array('id' => $item[1], 'record_id' => $item[2], 'group_id' => $item[3], 'is_basionym' => $item[4], 'order_by' => $item[5], 'ref_item' => $cRecord);
     }
     return $results;
 }
 public function configure()
 {
     unset($this['id'], $this['is_basionym'], $this['group_id']);
     $this->widgetSchema['referenced_relation'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['group_name'] = new sfWidgetFormChoice(array('choices' => Doctrine::getTable('ClassificationSynonymies')->findGroupnames(), 'expanded' => false));
     $this->widgetSchema['record_id'] = new widgetFormJQueryDLookup(array('model' => DarwinTable::getModelForTable($this->options['table']), 'method' => 'getName', 'nullable' => false, 'fieldsHidders' => array('classification_synonymies_group_name')), array('class' => 'hidden'));
     $this->widgetSchema['merge'] = new sfWidgetFormInputCheckbox();
     $this->validatorSchema['record_id'] = new sfValidatorInteger(array('required' => true));
     $this->validatorSchema['merge'] = new sfValidatorChoice(array('required' => true, 'choices' => array('true', 't', 'yes', 'y', 'on', 1)));
 }
Example #3
0
 public function executeAdd(sfWebRequest $request)
 {
     if (!$this->getUser()->isA(Users::ADMIN)) {
         if ($request->getParameter('table') == 'loans' || $request->getParameter('table') == 'loan_items') {
             $loan = Doctrine::getTable($request->getParameter('table') == 'loans' ? 'Loans' : 'LoanItems')->find($request->getParameter('id'));
             if (!Doctrine::getTable('loanRights')->isAllowed($this->getUser()->getId(), $request->getParameter('table') == 'loans' ? $loan->getId() : $loan->getLoanRef())) {
                 $this->forwardToSecureAction();
             }
         } elseif ($this->getUser()->isA(Users::REGISTERED_USER)) {
             $this->forwardToSecureAction();
         }
     }
     if ($request->hasParameter('id')) {
         $r = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id'));
         $this->forward404Unless($r, 'No such item');
         if (!$this->getUser()->isA(Users::ADMIN)) {
             if ($request->getParameter('table') == 'specimens') {
                 if (!Doctrine::getTable('Specimens')->hasRights('spec_ref', $request->getParameter('id'), $this->getUser()->getId())) {
                     $this->forwardToSecureAction();
                 }
             }
         }
     }
     $this->property = null;
     if ($request->hasParameter('rid')) {
         $this->property = Doctrine::getTable('Properties')->find($request->getParameter('rid'));
     }
     if (!$this->property) {
         $this->property = new Properties();
         $this->property->setRecordId($request->getParameter('id'));
         $this->property->setReferencedRelation($request->getParameter('table'));
         if ($request->hasParameter('model')) {
             $this->property->setPropertyTemplate($request->getParameter('model'));
         }
     }
     $this->form = new PropertiesForm($this->property, array('ref_relation' => $request->getParameter('table'), 'hasmodel' => $request->getParameter('model') ? true : false));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('properties'));
         if ($this->form->isValid()) {
             try {
                 $this->form->save();
                 return $this->renderText('ok');
             } catch (Exception $ne) {
                 $e = new DarwinPgErrorParser($ne);
                 $error = new sfValidatorError(new savedValidator(), $e->getMessage());
                 $this->form->getErrorSchema()->addError($error);
             }
         }
     }
 }
Example #4
0
 /**
  * Return a code mask for a given collection
  * @param \sfWebRequest $request
  * @return string $codeMask The code mask defined for the collection passed as request parameter
  */
 protected function getCodeMask(sfWebRequest $request)
 {
     $codeMask = '';
     $collId = intval($request->getParameter('collection_id', '0'));
     if ($collId === 0 && $request->getParameter('module', '') === 'specimen' && $request->getParameter('id', 0) !== 0) {
         $specimen = Doctrine_Core::getTable(DarwinTable::getModelForTable('specimens'))->find($request->getParameter('id'));
         $collId = $specimen->getCollectionRef();
     }
     if ($collId > 0) {
         $collTmp = Doctrine_Core::getTable('Collections')->find($collId);
         if ($collTmp) {
             $codeMask = $collTmp->getCodeMask();
         }
     }
     return $codeMask;
 }
 public function getRelationsForTable($table, $id, $type = null)
 {
     $model = DarwinTable::getModelForTable($table);
     $q = Doctrine_Query::create()->select('r.id, r.referenced_relation, r.record_id_1, r.record_id_2, r.relationship_type , t.id, t.name' . ($table == 'taxonomy' ? ', t.extinct' : ''))->from('CatalogueRelationships r, ' . $model . ' t')->andwhere('r.referenced_relation = ?', $table)->andWhere('r.record_id_1=?', $id)->andWhere('t.id=r.record_id_2')->setHydrationMode(Doctrine::HYDRATE_NONE);
     if ($type !== null) {
         $q->andWhere('r.relationship_type = ?', $type);
     }
     $items = $q->execute();
     $results = array();
     foreach ($items as $item) {
         $cRecord = new $model();
         $cRecord->setName($item[6]);
         $cRecord->setId($item[5]);
         if ($table == 'taxonomy') {
             $cRecord->setExtinct($item[7]);
         }
         $results[] = array('id' => $item[0], 'referenced_relation' => $item[1], 'record_id_1' => $item[2], 'record_id_2' => $item[3], 'relationship_type' => $item[4], 'ref_item' => $cRecord);
     }
     return $results;
 }
Example #6
0
 public function executeVernacularnames(sfWebRequest $request)
 {
     if (!$this->getUser()->isAtLeast(Users::ENCODER)) {
         $this->forwardToSecureAction();
     }
     $this->forward404Unless($request->hasParameter('id') && $request->hasParameter('table'));
     $this->ref_object = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id'));
     $this->forward404Unless($this->ref_object);
     $this->form = new GroupedVernacularNamesForm(null, array('table' => $request->getParameter('table'), 'id' => $request->getParameter('id')));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('grouped_vernacular'));
         if ($this->form->isValid()) {
             try {
                 $this->form->save();
                 return $this->renderText('ok');
             } catch (Doctrine_Exception $ne) {
                 $e = new DarwinPgErrorParser($ne);
                 $error = new sfValidatorError(new savedValidator(), $e->getMessage());
                 $this->form->getErrorSchema()->addError($error);
             }
         }
     }
 }
Example #7
0
 public function executeExtLinks(sfWebRequest $request)
 {
     if ($this->getUser()->isA(Users::REGISTERED_USER)) {
         $this->forwardToSecureAction();
     }
     if ($request->hasParameter('id')) {
         $r = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id'));
         $this->forward404Unless($r, 'No such item');
         if (in_array($request->getParameter('table'), array_keys($this->ref_id))) {
             if (!Doctrine::getTable('Specimens')->hasRights($this->ref_id[$request->getParameter('table')], $request->getParameter('id'), $this->getUser()->getId())) {
                 $this->forwardToSecureAction();
             }
         }
     }
     if ($request->hasParameter('cid')) {
         $this->links = Doctrine::getTable('ExtLinks')->find($request->getParameter('cid'));
     } else {
         $this->links = new ExtLinks();
         $this->links->setRecordId($request->getParameter('id'));
         $this->links->setReferencedRelation($request->getParameter('table'));
     }
     $this->form = new ExtLinksForm($this->links, array('table' => $request->getParameter('table')));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('ext_links'));
         if ($this->form->isValid()) {
             try {
                 if ($this->form->getObject()->isNew()) {
                     $this->form->setRecordRef($request->getParameter('table'), $request->getParameter('id'));
                 }
                 $this->form->save();
             } catch (Exception $e) {
                 return $this->renderText($e->getMessage());
             }
             return $this->renderText('ok');
         }
     }
 }
Example #8
0
 public function executeComment(sfWebRequest $request)
 {
     if ($this->getUser()->isA(Users::REGISTERED_USER)) {
         $this->forwardToSecureAction();
     }
     if ($request->hasParameter('id')) {
         $r = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id'));
         $this->forward404Unless($r, 'No such item');
         if (!$this->getUser()->isA(Users::ADMIN)) {
             if ($request->getParameter('table') == 'specimens') {
                 if (!Doctrine::getTable('Specimens')->hasRights('spec_ref', $request->getParameter('id'), $this->getUser()->getId())) {
                     $this->forwardToSecureAction();
                 }
             }
         }
     }
     if ($request->hasParameter('cid')) {
         $this->comment = Doctrine::getTable('Comments')->find($request->getParameter('cid'));
     } else {
         $this->comment = new Comments();
         $this->comment->setRecordId($request->getParameter('id'));
         $this->comment->setReferencedRelation($request->getParameter('table'));
     }
     $this->form = new CommentsForm($this->comment, array('table' => $request->getParameter('table')));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('comments'));
         if ($this->form->isValid()) {
             try {
                 $this->form->save();
             } catch (Exception $e) {
                 return $this->renderText($e->getMessage());
             }
             return $this->renderText('ok');
         }
     }
 }
include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(14, new lime_output_color());
$taxs = Doctrine::getTable('Taxonomy')->findOneByName('Falco Peregrinus eliticus');
$t->info('findWithParents($id)');
$taxa = Doctrine::getTable('Taxonomy')->findWithParents($taxs->getId());
$t->isnt($taxa, null, 'we got a taxa');
$t->is($taxa->count(), 9, 'we got all parent of the taxa');
$t->is($taxa[7]->getId(), $taxs->getParentRef(), 'Parent is correct');
$t->is($taxa[1]->Level->__toString(), 'kingdom', 'get Level');
$t->is($taxs->getNameWithFormat(), '<i>Falco Peregrinus eliticus</i>', 'get Name without extinct');
$taxs->setExtinct('true');
$t->is($taxs->getNameWithFormat(), '<i>Falco Peregrinus eliticus</i> †', 'get Name without extinct');
$t->is(DarwinTable::getFilterForTable('classification_syonymies'), "ClassificationSyonymiesFormFilter", 'Filter Form name');
$t->is(DarwinTable::getFormForTable('classification_syonymies'), "ClassificationSyonymiesForm", 'Form Name');
$t->is(DarwinTable::getModelForTable('classification_syonymies'), "ClassificationSyonymies", 'Model Name');
$t->is(Doctrine::getTable('Taxonomy')->find(4)->toArray(), true, 'We got the record with find');
$t->is(Doctrine::getTable('Taxonomy')->find(-1)->toArray(), true, 'Record bellow 0 are found  with find');
$keywords = Doctrine::getTable('ClassificationKeywords')->findForTable('taxonomy', 4);
$t->is(count($keywords), 0, 'No KW per default');
$kw_full = ClassificationKeywords::getTags('taxonomy');
$avail_kw = array_keys($kw_full);
$kw = new ClassificationKeywords();
$kw->setReferencedRelation('taxonomy');
$kw->setRecordId(4);
$kw->setKeywordType($avail_kw[1]);
$kw->setKeyword('Falco Peregrinus');
$kw->save();
$keywords = Doctrine::getTable('ClassificationKeywords')->findForTable('taxonomy', 4);
$t->is(count($keywords), 1, 'The new Keyword');
$t->is($keywords[0]->getKeywordType(), $avail_kw[1], 'We get the new keyword');
Example #10
0
 public function executeTree(sfWebRequest $request)
 {
     $this->items = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->findWithParents($request->getParameter('id'));
 }
Example #11
0
 public function executeDeleteSavedSearch(sfWebRequest $request)
 {
     $r = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('table')))->find($request->getParameter('id'));
     $this->forward404Unless($r, 'No such item');
     try {
         $is_spec_search = $r->getIsOnlyId();
         $r->delete();
         if (!$request->isXmlHttpRequest()) {
             if ($is_spec_search) {
                 return $this->redirect('savesearch/index?specimen=true');
             } else {
                 return $this->redirect('savesearch/index');
             }
         }
     } catch (Doctrine_Exception $ne) {
         $e = new DarwinPgErrorParser($ne);
         $this->renderText($e->getMessage());
     }
     return $this->renderText("ok");
 }
Example #12
0
 /**
  * Renders table row for the table located underneath the button ref multiple button
  * @param \sfWebRequest $request The HTTP request passed (GET or POST)
  * @return sfView::NONE
  */
 public function executeRenderTableRowForButtonRefMultiple(sfWebRequest $request)
 {
     if (!$this->getUser()->isAtLeast(Users::ENCODER)) {
         $this->forwardToSecureAction();
     }
     $this->forward404Unless($request->hasParameter('row_data') && $request->hasParameter('field_id') && is_array($request->getParameter('row_data')) && count($request->getParameter('row_data')) > 0);
     $row_data = $request->getParameter('row_data');
     $catalogue_parameter = $request->getParameter('catalogue', '');
     if ($request->getParameter('from_db', '') == '1' && !empty($catalogue_parameter)) {
         $ids_to_retrieve = array();
         foreach ($row_data as $row_key => $row_val) {
             $this->forward404Unless(isset($row_val["id"]) && is_numeric($row_val["id"]));
             $ids_to_retrieve[] = $row_val["id"];
         }
         $row_data = Doctrine::getTable(DarwinTable::getModelForTable($request->getParameter('catalogue')))->getCatalogueUnits($ids_to_retrieve);
         return $this->getPartial('catalogue/button_ref_multiple_table_row', array('field_id' => $request->getParameter('field_id'), 'row_data' => $row_data));
     }
     return $this->renderPartial('catalogue/button_ref_multiple_table_row', array('field_id' => $request->getParameter('field_id'), 'row_data' => $row_data));
 }