~fabiocbalbuquerque/sahana-agasti/web-services

« back to all changes in this revision

Viewing changes to apps/frontend/lib/packages/agStaffPackage/modules/agStaff/actions/actions.class.php

  • Committer: Clayton Kramer
  • Date: 2011-06-02 20:32:55 UTC
  • mto: (1.26.1 push-trunk) (7.1.1 mayon)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: clayton.kramer@mail.cuny.edu-20110602203255-jibrhvvu4193e0sa
Staff import working. Still needs to be hooked to indexer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
  public function executeStafftypes(sfWebRequest $request)
33
33
  {
34
34
    $this->ag_staff_types = Doctrine_Core::getTable('agStaffResourceType')
35
 
            ->createQuery('a')
36
 
            ->execute();
 
35
        ->createQuery('a')
 
36
        ->execute();
37
37
 
38
38
    $this->staffTypeForm = new PluginagStaffTypeForm();
39
39
 
40
40
    if ($request->isMethod(sfRequest::POST)) {
41
41
      $this->staffTypeForm->bind($request->getParameter($this->staffTypeForm->getName()),
42
 
          $request->getFiles($this->staffTypeForm->getName()));
 
42
                                                        $request->getFiles($this->staffTypeForm->getName()));
43
43
      if ($this->staffTypeForm->isValid()) {
44
44
        $this->staffTypeForm->save();
45
45
      }
79
79
 
80
80
    /** @todo take into consideration app_display */
81
81
    $staffStatusOptions = agDoctrineQuery::create()
82
 
            ->select('s.staff_resource_status, s.staff_resource_status')
83
 
            ->from('agStaffResourceStatus s')
84
 
            ->execute(array(), 'key_value_pair');
 
82
        ->select('s.staff_resource_status, s.staff_resource_status')
 
83
        ->from('agStaffResourceStatus s')
 
84
        ->execute(array(), 'key_value_pair');
85
85
    //the above query returns an array of keys matching their values.
86
86
    //ideally the above should exist in a global param,
87
87
    //so the database is not queried all the time
88
88
    $staffStatusOptions['all'] = 'all';
89
89
    if ($request->getParameter('status') && in_array($request->getParameter('status'),
90
 
            $staffStatusOptions)) {
 
90
                                                                            $staffStatusOptions)) {
91
91
      $this->status = $request->getParameter('status');
92
92
    }
93
93
    $this->statusWidget = new sfForm();
114
114
//      $staffArray = apc_fetch('staffArray');
115
115
//    }
116
116
//    else{
117
 
    $staffArray = agListHelper::getStaffList(null, $this->status, $this->sort, $this->order, $this->limit);
 
117
    $staffArray = agListHelper::getStaffList(null, $this->status, $this->sort, $this->order,
 
118
                                             $this->limit);
118
119
//      apc_store('staffArray', $staffArray);
119
120
//    }  this will not work currently on update, there needs to be a hook/callback
120
121
 
126
127
 
127
128
 
128
129
    $this->ag_phone_contact_types = Doctrine::getTable('agPhoneContactType')
129
 
            ->createQuery('c')
130
 
            ->execute();
 
130
        ->createQuery('c')
 
131
        ->execute();
131
132
    $this->ag_email_contact_types = Doctrine::getTable('agEmailContactType')
132
 
            ->createQuery('d')
133
 
            ->execute();
 
133
        ->createQuery('d')
 
134
        ->execute();
134
135
    //p-code
135
136
    //$this->getResponse()->setTitle('Sahana Agasti ' . $this->event_name . ' ');
136
137
    //end p-code
234
235
 
235
236
    $this->forward404Unless(
236
237
        $this->agStaff = Doctrine::getTable('AgStaff')->find($request->getParameter('id')),
237
 
        sprintf('Object ag_staff does not exist (%s).',
238
 
            $request->getParameter('id'))
 
238
                                                                                    sprintf('Object ag_staff does not exist (%s).',
 
239
                                                                                            $request->getParameter('id'))
239
240
    );
240
241
 
241
242
    $this->ag_person_name_types = Doctrine::getTable('agPersonNameType')
242
 
            ->createQuery('b')
243
 
            ->execute();
 
243
        ->createQuery('b')
 
244
        ->execute();
244
245
    $this->ag_phone_contact_types = Doctrine::getTable('agPhoneContactType')
245
 
            ->createQuery('c')
246
 
            ->execute();
 
246
        ->createQuery('c')
 
247
        ->execute();
247
248
    $this->ag_email_contact_types = Doctrine::getTable('agEmailContactType')
248
 
            ->createQuery('d')
249
 
            ->execute();
 
249
        ->createQuery('d')
 
250
        ->execute();
250
251
    $this->ag_language_formats = Doctrine::getTable('agLanguageFormat')
251
 
            ->createQuery('e')
252
 
            ->execute();
 
252
        ->createQuery('e')
 
253
        ->execute();
253
254
    $this->ag_address_contact_types = Doctrine::getTable('agAddressContactType')
254
 
            ->createQuery('f')
255
 
            ->execute();
 
255
        ->createQuery('f')
 
256
        ->execute();
256
257
 
257
258
 
258
259
    //$this->agStaff = $this->pager->getResults()->getFirst();
309
310
    $this->forward404unless($request->isXmlHttpRequest());
310
311
    if ($request->hasParameter('staffResourceId')) {
311
312
      $staffResource = agDoctrineQuery::create()
312
 
              ->delete('agStaffResource sr')
313
 
              ->where('id = ?', $request->getParameter('staffResourceId'))
314
 
              ->execute();
 
313
          ->delete('agStaffResource sr')
 
314
          ->where('id = ?', $request->getParameter('staffResourceId'))
 
315
          ->execute();
315
316
    }
316
317
  }
317
318
 
348
349
  {
349
350
    $this->forward404Unless(
350
351
        $ag_staff = Doctrine::getTable('AgStaff')->find($request->getParameter('id')),
351
 
        sprintf('Object ag_staff does not exist (%s).',
352
 
            $request->getParameter('id'))
 
352
                                                                               sprintf('Object ag_staff does not exist (%s).',
 
353
                                                                                       $request->getParameter('id'))
353
354
    );
354
355
 
355
356
    $ag_person = $ag_staff->getAgPerson();
372
373
    );
373
374
    $this->forward404Unless(
374
375
        $ag_staff = Doctrine::getTable('AgStaff')->find($request->getParameter('id')),
375
 
        sprintf('Object ag_staff does not exist (%s).',
376
 
            $request->getParameter('id'))
 
376
                                                                               sprintf('Object ag_staff does not exist (%s).',
 
377
                                                                                       $request->getParameter('id'))
377
378
    );
378
379
 
379
380
    $ag_person = $ag_staff->getAgPerson();
406
407
 
407
408
    $this->forward404Unless(
408
409
        $ag_staff = Doctrine::getTable('AgStaff')->find($request->getParameter('id')),
409
 
        sprintf('Object ag_staff does not exist (%s).',
410
 
            $request->getParameter('id'))
 
410
                                                                               sprintf('Object ag_staff does not exist (%s).',
 
411
                                                                                       $request->getParameter('id'))
411
412
    );
412
413
 
413
414
    $ag_person = $ag_staff->getAgPerson();
476
477
      $ag_staff = $form->save();
477
478
      $refAgStaff = $ag_staff->getAgStaff();
478
479
      $staffObj = agDoctrineQuery::create()
479
 
              ->from('agStaff s')
480
 
              ->where('s.person_id=?', $ag_staff->id)
481
 
              ->fetchOne();
 
480
          ->from('agStaff s')
 
481
          ->where('s.person_id=?', $ag_staff->id)
 
482
          ->fetchOne();
482
483
      LuceneRecord::updateLuceneRecord($staffObj);
483
484
 
484
485
      //$staff_id = $ag_staff->getAgStaff()->getFirst()->getId();
485
486
//not an object? first it's a collection, now not an object if i just get one
486
487
 
487
488
      $staff_id = Doctrine::getTable('agStaff')->createQuery('a')
488
 
              ->select('a.id')
489
 
              ->from('agStaff a')
490
 
              ->where('a.person_id = ?', $ag_staff->id)
491
 
              ->fetchOne();
 
489
          ->select('a.id')
 
490
          ->from('agStaff a')
 
491
          ->where('a.person_id = ?', $ag_staff->id)
 
492
          ->fetchOne();
492
493
 
493
494
      //get id of STAFF person from the saved, extended agpersonform.
494
495
      // Check if the Save and Create Another button was used to submit. If it was, redirect to staff/new.
512
513
    // Free up some memory by getting rid of the agFacilityExporter object.
513
514
    unset($staffExporter);
514
515
    $this->getResponse()->setHttpHeader('Content-Type', 'application/vnd.ms-excel');
515
 
    $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment;filename="' . $exportResponse['fileName'] . '"');
 
516
    $this->getResponse()->setHttpHeader('Content-Disposition',
 
517
                                        'attachment;filename="' . $exportResponse['fileName'] . '"');
516
518
 
517
519
    $exportFile = file_get_contents($exportResponse['filePath']);
518
520
 
526
528
  //TODO: put this in the global actions file?
527
529
  public function executeCancelimport(sfWebRequest $request)
528
530
  {
529
 
    $abortFlagId = 'aborted';//implode('_', array('abort', $this->moduleName, 'import'));
 
531
    $abortFlagId = 'aborted'; //implode('_', array('abort', $this->moduleName, 'import'));
530
532
    //$this->getContext()->set($abortFlagId, TRUE);
531
 
 
532
533
    //TODO: get import data directory root info from global param
533
534
    $importDataRoot = sfConfig::get('sf_upload_dir');
534
535
    $importDir = $importDataRoot . DIRECTORY_SEPARATOR . $this->moduleName;
550
551
 
551
552
  public function executeImport(sfWebRequest $request)
552
553
  {
553
 
//    $this->timer = time();
 
554
    //    $this->timer = time();
554
555
 
555
556
    $uploadedFile = $_FILES['import'];
556
557
 
557
 
    $importPath = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $uploadedFile['name'];
558
 
    if (!move_uploaded_file($uploadedFile['tmp_name'], $importPath)) {
559
 
      return sfView::ERROR;
 
558
    print("<pre>" . print_r($_FILES, true) . "</pre>");
 
559
 
 
560
    $this->importPath = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $uploadedFile['name'];
 
561
 
 
562
    print("<pre>Move {$uploadedFile['tmp_name']} to " . $this->importPath . "</pre>");
 
563
    if (!move_uploaded_file($uploadedFile['tmp_name'], $this->importPath)) {
 
564
      print("<pre>Failed to move {$uploadedFile['tmp_name']} to ".$this->importPath."</pre>");
 
565
      //return sfView::ERROR;
560
566
    }
561
567
 
562
 
    $this->importPath = $importPath;
563
 
 
564
568
 
565
569
    // fires event so listener will process the file (see ProjectConfiguration.class.php)
566
 
//    $this->dispatcher->notify(new sfEvent($this, 'import.staff_file_ready'));
 
570
    //$this->dispatcher->notify(new sfEvent($this, 'import.staff_file_ready'));
567
571
    // TODO: eventually use this ^^^ to replace this vvv.
568
572
 
569
573
    $this->importer = agStaffImportNormalization::getInstance(NULL, agEventHandler::EVENT_DEBUG);
 
574
    
570
575
    $this->importer->processXlsImportFile($this->importPath);
 
576
 
571
577
    $left = 1;
572
 
    while ($left > 0)
573
 
    {
 
578
    while ($left > 0) {
574
579
      $left = $this->importer->processBatch();
575
580
      print_r($left);
576
581
    }
577
582
    $this->importer->concludeImport();
578
583
 
579
584
    // removes the file from the server
580
 
    unlink($this->importPath);
581
 
 
582
 
 
583
 
//    $this->dispatcher->notify(new sfEvent($this, 'import.start'));
584
 
 
 
585
    //unlink($this->importPath);
 
586
    
 
587
    //$this->dispatcher->notify(new sfEvent($this, 'import.start'));
585
588
    //unset($this->importer);
586
 
//    $this->timer = (time() - $this->timer);
 
589
    //$this->timer = (time() - $this->timer);
587
590
  }
588
591
 
589
592
}