Exemplo n.º 1
0
  public function executeIndex(sfWebRequest $request)
  {

  $this->form = new sfForm();
  $this->form->setWidgets(array(
    'input'    => new sfWidgetFormTextArea( array(), array( 
      'rows' => 10, 'class' => 'span9'
      )),
    'role'     => new sfWidgetFormChoice( array(
      'choices' => array( 'leader' => 'leader', 'follower' => 'follower')
    )),
    'type'     => new sfWidgetFormChoice( array(
      'choices' => Doctrine::getTable('dsClassStudent')->getTypes()
      )) 
  ));

  $this->form->setDefault('input', $this->getUser()->getAttribute('import_raw'));

  // Deal with the request
  if ($request->isMethod('post'))
  {
    // Handle the form submission
    $input = $request->getPostParameter('input');
    $role = $request->getPostParameter('role');
    $this->type = $request->getPostParameter('type');

    $this->getUser()->setAttribute('import_raw', $this->input);

    // Do stuff
    $array = Swingmachine::csvstring_to_array($input, "\t");

    // validate emails
    $this->array = array();
    foreach( $array as $row ):
      // $valid = 1;
      $newrow = array(
        'firstname' => array_key_exists(0, $row) ? $row[0] : null,
        'lastname' => array_key_exists(1, $row) ? $row[1] : null,
        'email' => array_key_exists(2, $row) ? $row[2] : null,
        'student' => array_key_exists(3, $row) ? $row[3] : null,
        'note' => array_key_exists(4, $row) ? $row[4] : null
      );
      $test = $newrow['email']."";
      $newrow['email-valid'] = Swingmachine::isValidEmail($test);
      array_push($this->array, $newrow);
    endforeach;

    $this->role = $role;
    $this->new = $this->array;

    $this->getUser()->setAttribute('import_data', $this->array);
    $this->getUser()->setAttribute('import_role', $this->role);
    $this->getUser()->setAttribute('import_type', $this->type);

    $this->redirect('import_preview');

    //$this->array = $new;
    //$this->redirect('ds_class_student_import_preview');
  }

  }
Exemplo n.º 2
0
  public function executeImport(sfWebRequest $request)
  {

  $this->form = new sfForm();
  $this->form->setWidgets(array(
    'input'    => new sfWidgetFormTextArea(),
    'role'     => new sfWidgetFormChoice( array('choices' => array( 'lead' => 'lead', 'follow' => 'follow'))) 
  ));

  $this->form->setDefault('input', $this->getUser()->getAttribute('import_raw'));

  // Deal with the request
  if ($request->isMethod('post'))
  {
    // Handle the form submission
    $input = $request->getPostParameter('input');
    $role = $request->getPostParameter('role');

    $this->getUser()->setAttribute('import_raw', $this->input);

    // Do stuff
    $array = Swingmachine::csvstring_to_array($input, "\t");

    // validate emails
    $this->array = array();
    foreach( $array as $row ):
      // $valid = 1;
      $test = $row[2]."";
      $valid = Swingmachine::isValidEmail($test);
      $row['email-valid'] = $valid;
      array_push($this->array, $row);
    endforeach;

    $this->role = $role;
    $this->new = $this->array;

    $this->getUser()->setAttribute('import_data', $this->array);
    $this->getUser()->setAttribute('import_role', $this->role);

    $this->redirect('@ds_class_students_importPreview?class_id='.$this->class->getId() );

    //$this->array = $new;
    //$this->redirect('ds_class_student_import_preview');
  }

  }