예제 #1
0
 /**
  * Deletes the appropriate records from the join table and the domain table (if requested).
  */
 function delete($values)
 {
     /*
      * Next we construct an IO object to write to the domain table.
      */
     $domainTable =& $this->getDomainTable();
     $domainIO = new Dataface_IO($domainTable->tablename);
     $records =& $this->getSelectedRecords();
     $messages = array();
     $confirmations = array();
     $warnings = array();
     $table =& $this->_record->_table;
     // This is the table of the parent record.
     $io = new Dataface_IO($table->tablename);
     $removePermission = $this->_record->checkPermission('remove related record', array('relationship' => $this->_relationshipName));
     //if ($removePermission ){
     //	$mask = array('delete'=>1);
     //} else {
     //	$mask = array();
     //}
     $deleteRequired = $this->deleteRequired();
     // Do we have to delete the domain record
     // to make the removal effective
     foreach ($records as $record) {
         // If deletion is required, we will do ou
         $res = $io->removeRelatedRecord($record, @$values['delete'], true);
         if (PEAR::isError($res)) {
             $warnings[] = $res->getMessage();
         } else {
             $confirmations[] = $confirmations[] = df_translate('Successfully deleted record', "Successfully deleted entry for record '" . $record->getTitle() . "' in table '" . $table->tablename . "'", array('title' => $record->getTitle(), 'table' => $table->tablename));
         }
     }
     return array('confirmations' => $confirmations, "warnings" => $warnings);
 }
예제 #2
0
파일: IOTest.php 프로젝트: Zunair/xataface
 function test_removeRelatedRecord()
 {
     $this->assertTrue(xf_db_num_rows(xf_db_query("SELECT * FROM `Appointments` where `id`=2")) == 1);
     $record =& Dataface_IO::loadRecordById('Profiles/appointments?id=10&appointments::id=2');
     $res = Dataface_IO::removeRelatedRecord($record);
     // This should fail to remove the record because it is a one-to-many relationship,
     // and you can only remove the record if you add the 'delete' flag to allow it
     // to delete the domain record.
     $this->assertTrue(!$res);
     $this->assertTrue(xf_db_num_rows(xf_db_query("SELECT * FROM `Appointments` where `id`=2")) == 1);
     $res = Dataface_IO::removeRelatedRecord($record, true);
     $this->assertTrue($res);
     $this->assertTrue(xf_db_num_rows(xf_db_query("SELECT * FROM `Appointments` where `id`=2")) == 0);
 }
예제 #3
0
 function save($values)
 {
     // Which ones were checked
     $checked = array_keys($values['--related-checkboxes']);
     // Which ones are currently part of the relationship
     $default = array_keys($this->getCheckedRecordsDefaults());
     // Which ones need to be added?
     $toAdd = array_diff($checked, $default);
     // Which ones need to be removed?
     $toRemove = array_diff($default, $checked);
     // Now we go through and remove the ones that need to be removed.
     $io = new Dataface_IO($this->record->_table->tablename);
     $messages = array();
     $successfulRemovals = 0;
     foreach ($toRemove as $id) {
         $res = $io->removeRelatedRecord($this->id2record($id));
         if (PEAR::isError($res)) {
             $messages[] = $res->getMessage();
         } else {
             $sucessfulRemovals++;
         }
     }
     // Now we go through and add the ones that need to be added.
     foreach ($toAdd as $id) {
         $res = $io->addExistingRelatedRecord($this->id2record($id));
         if (PEAR::isError($res)) {
             $messages[] = $res->getMessage();
         } else {
             $successfulAdditions++;
         }
     }
     array_unshift($messages, df_translate('scripts.Dataface_RelationshipCheckboxForm.MESSAGE_NUM_RECORDS_ADDED', $successfulAdditions . ' records were successfully added to the relationship.', array('num_added' => $successfulAdditions)), df_translate('scripts.Dataface_RelationshipCheckboxForm.MESSAGE_NUM_RECORDS_REMOVED', $successfulRemovals . ' records were successfully removed from the relationship.', array('num_removed' => $successfulRemovals)));
     $_SESSION['msg'] = '<ul><li>' . implode('</li><li>', $messages) . '</li></ul>';
     header('Location: ' . $values['--query']);
     exit;
 }
 function save($values)
 {
     $app = Dataface_Application::getInstance();
     // Which ones were checked
     $checked = array();
     foreach ($values['--related-checkboxes'] as $k => $v) {
         if ($v) {
             $checked[] = $k;
         }
     }
     // Which ones are currently part of the relationship
     $default = array_keys($this->getCheckedRecordsDefaults());
     // Which ones need to be added?
     $toAdd = array_diff($checked, $default);
     // Which ones need to be removed?
     $toRemove = array_diff($default, $checked);
     // Now we go through and remove the ones that need to be removed.
     $io = new Dataface_IO($this->record->_table->tablename);
     $messages = array();
     $successfulRemovals = 0;
     $successfulAdditions = 0;
     foreach ($toRemove as $id) {
         $res = $io->removeRelatedRecord($this->id2record($id), false, true);
         if (PEAR::isError($res)) {
             $messages[] = $res->getMessage();
         } else {
             $successfulRemovals++;
         }
     }
     // Now we go through and add the ones that need to be added.
     foreach ($toAdd as $id) {
         $res = $io->addExistingRelatedRecord($this->id2record($id), true);
         if (PEAR::isError($res)) {
             $messages[] = $res->getMessage();
         } else {
             $successfulAdditions++;
         }
     }
     array_unshift($messages, df_translate('scripts.Dataface_RelationshipCheckboxForm.MESSAGE_NUM_RECORDS_ADDED', $successfulAdditions . ' records were successfully added to the relationship.', array('num_added' => $successfulAdditions)), df_translate('scripts.Dataface_RelationshipCheckboxForm.MESSAGE_NUM_RECORDS_REMOVED', $successfulRemovals . ' records were successfully removed from the relationship.', array('num_removed' => $successfulRemovals)));
     $_SESSION['--msg'] = '<ul><li>' . implode('</li><li>', $messages) . '</li></ul>';
     $url = $values['--query'];
     $urlparts = parse_url($url);
     if ($urlparts and $urlparts['host'] and $urlparts['host'] != $_SERVER['HTTP_HOST']) {
         throw new Exception('Failed to redirect after action due to an invalid query parameter.', E_USER_ERROR);
     }
     $app->redirect($values['--query']);
 }