Changeset 1403


Ignore:
Timestamp:
Jan 4, 2014, 1:40:04 AM (4 years ago)
Author:
dkg
Message:

attempt to make proposal translation work

Location:
trunk/jpdd
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/jpdd/class.jpdd.php

    r1396 r1403  
    395395       
    396396
     397    function handleAcceptProposal() {
     398      if (($this->_type) != 'proposal') {
     399        $this->addWarning('You can only accept a proposal.');
     400        return '';
     401      }
     402
     403      $proposal = $this->getItem('proposal', $this->_identifier);
     404     
     405      // must POST
     406      if ($_SERVER['REQUEST_METHOD'] != 'POST') {
     407        $x = $this->Path('proposal', (int)$proposal->getID());
     408        $this->redirectLocal($x);
     409        exit;
     410      }
     411      if (!($this->isAuthenticated() && $this->_authenticated_user->hasAllOfThesePrivileges('Update Workshops'))) {
     412        $this->permissionDenied('Not allowed to update workshops!');
     413      }
     414      // must match form token
     415      if (!$this->verifyFormToken()) {
     416        $this->addWarning('Form token did not match.');
     417        return $proposal->getDetailView();
     418      }
     419      $workshop = $proposal->createWorkshop();
     420      $x = $this->Path('workshop', (int)$workshop->getID());
     421      $this->redirectLocal($x);
     422      exit;
     423    }
     424
     425
    397426    function handleSignup() {
    398427      if (($this->_type) != 'workshop') {
     
    523552      } elseif ($this->_action == 'open') {
    524553        return $this->getOpenWorkshops();
     554      } elseif ($this->_action == 'accept') {
     555        return $this->acceptProposal();
    525556      } elseif ($this->_action == 'printout') {
    526557        $pdf = NULL;
  • trunk/jpdd/class.jpdd.proposal.php

    r1402 r1403  
    140140          global $jpdd;
    141141      $editor = $jpdd->isAuthenticated() && $jpdd->_authenticated_user->canEdit($this);
     142      $canaccept = $jpdd->isAuthenticated() && $jpdd->_authenticated_user->hasAllOfThesePrivileges('Update Workshops');
    142143
    143144      $ret = '';
     
    158159        $ret .= "</ul>\n";
    159160      }
     161
     162      if ($canaccept or $editor) {
     163        // indicate whether any other workshops are already generated from this proposal:
     164        $workshops = $this->getAssociatedWorkshops();
     165        if (count($workshops)) {
     166          $ret .= "<div>Workshops based on this proposal<ul>";
     167          while(list(,$workshop) = each($workshops)) {
     168            $ret .= '<li>'.$workshop->getLinkedTitle().'</li>';
     169          }
     170          $ret .= '</ul></div>';
     171        } else {
     172          if ($canaccept) {
     173            $ret .= $this->getAcceptanceForm();
     174          }
     175        }
     176      }
    160177          return $ret;
    161178        }
     179
     180    function getAcceptanceForm() {
     181      global $jpdd;
     182      $categories = '';
     183      $cats = $this->getM2MPeers('category', 'proposal_category');
     184      reset($cats);
     185      while(list(,$cat) = each($cats))
     186        $categories .= '<input type="hidden" name="add_workshop_category[]" value="'.$cat->getID().'"/>';
     187     
     188      return '<form action="'.$jpdd->Path('accept', 'proposal', $this->getID()).'" method="post">
     189'.$jpdd->getFormTokenHiddenInput().'
     190<input type="hidden" name="add_presenter[]" value="'.(int)$this->_proposer_id.'/>'.
     191        $categories.
     192'<input class="submit" type="submit" name="xx" value="Create a workshop from this proposal"/>
     193</form>';
     194    }
     195
     196    function createWorkshop() {
     197      global $jpdd;
     198      // create the workshop based on this proposal
     199      $map = $jpdd->prepClass('workshop');
     200      $workshop = $map['classname'](array());
     201      $workshop->_title = $this->_title;
     202      $workshop->_short_title = $this->_short_title;
     203      $workshop->_description = $this->_description;
     204      $workshop->_private_notes = $this->_private_notes;
     205      $workshop->_min_attendees = $this->_min_attendees;
     206      $workshop->_max_attendees = $this->_max_attendees;
     207      $workshop->_event_id = $this->_event_id;
     208      $workshop->_proposal_id = $this->_proposal_id;
     209      $workshop->handleCreation();
     210
     211      // FIXME: add a presenter based on the proposal author
     212    }
     213
     214    function getAssociatedWorkshops() {
     215      // return a list of all associated workshops.
     216      global $jpdd;
     217      $sql = 'SELECT * from workshop WHERE proposal_id = '.(int)$this->getID();
     218      return $jpdd->getSeriesFromSQL($sql, 'JPDD_Workshop');
     219    }
    162220
    163221    function canBeEditedBy($person) {
  • trunk/jpdd/class.jpdd.workshop.php

    r1374 r1403  
    152152          global $jpdd;
    153153          $this->applyPostForm();
    154           $res = $jpdd->executeSQL('INSERT INTO '.$this->getSingletonTable().' (title, short_title, description, private_notes, min_attendees, max_attendees, event_id, room_id) VALUES ('.
     154          $res = $jpdd->executeSQL('INSERT INTO '.$this->getSingletonTable().' (title, short_title, description, private_notes, min_attendees, max_attendees, event_id, room_id, proposal_id) VALUES ('.
    155155                                                           $jpdd->stringOrDefault($this->_title).', '.
    156156                                                           $jpdd->stringOrDefault($this->_short_title).', '.
     
    160160                                                           $jpdd->intOrDefault($this->_max_attendees).', '.
    161161                               $jpdd->getActiveEventID().', '.
    162                                $jpdd->intOrDefault($this->_room_id).')', false);
     162                               $jpdd->intOrDefault($this->_room_id).', '.
     163                               $jpdd->intOrDefault($this->_proposal_id).', '.
     164                               ')', false);
    163165          if (false === $res) {
    164166        $logid = $jpdd->log('create workshop failed with pg error: '.pg_last_error($jpdd->_db));
  • trunk/jpdd/sql/db.sql

    r1397 r1403  
    10661066
    10671067ALTER TABLE proposal ADD COLUMN proposer_id integer not null REFERENCES person(id);
     1068
     1069ALTER TABLE workshop ADD COLUMN proposal_id integer REFERENCES proposal(id);
Note: See TracChangeset for help on using the changeset viewer.