Example #1
0
 public function testSaveRights()
 {
     $this->markTestSkipped('Do not use Helpdesk model outside of Helpdesk tests');
     $model = new Helpdesk_Models_Helpdesk(array('db' => $this->sharedFixture));
     $model->title = 'test';
     $model->projectId = 1;
     $model->ownerId = 1;
     $model->attachments = '3bc3369dd33d3ab9c03bd76262cff633|LICENSE';
     $model->status = 3;
     $model->author = 1;
     $model->save();
     $model->saveRights(array(1 => 255));
     $rights = new Phprojekt_Item_Rights();
     $this->assertEquals(255, $rights->getItemRight(10, $model->id, 1));
     $this->assertEquals(0, $rights->getItemRight(10, $model->id, 10));
 }
 /**
  * Saves the new values of the projects dates.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - array <b>projects</b> Array with projectId,startDate and endDate by comma separated
  * </pre>
  *
  * If there is an error, the save will return a Zend_Controller_Action_Exception,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => 0.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On error in the action save or wrong parameters.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $projects = (array) $this->getRequest()->getParam('projects', array());
     $activeRecord = new Project_Models_Project();
     $rights = new Phprojekt_Item_Rights();
     $userId = Phprojekt_Auth::getUserId();
     $this->setCurrentProjectId();
     // Error check: no project received
     if (empty($projects)) {
         $label = Phprojekt::getInstance()->translate('Projects');
         $message = Phprojekt::getInstance()->translate('No project info was received');
         throw new Zend_Controller_Action_Exception($label . ': ' . $message, 400);
     }
     foreach ($projects as $project) {
         list($id, $startDate, $endDate) = explode(",", $project);
         // Check: are the three values available?
         if (empty($id) || empty($startDate) || empty($endDate)) {
             $label = Phprojekt::getInstance()->translate('Projects');
             $message = Phprojekt::getInstance()->translate('Incomplete data received');
             throw new Zend_Controller_Action_Exception($label . ': ' . $message, 400);
         }
         $id = (int) $id;
         $activeRecord->find($id);
         // Check: project id exists?
         if (empty($activeRecord->id)) {
             $label = Phprojekt::getInstance()->translate('Project');
             $message = Phprojekt::getInstance()->translate('Id not found #') . $id;
             throw new Zend_Controller_Action_Exception($label . ': ' . $message, 400);
         }
         // Check: dates are valid?
         $validStart = Cleaner::validate('date', $startDate, false);
         $validEnd = Cleaner::validate('date', $endDate, false);
         if (!$validStart || !$validEnd) {
             $label = Phprojekt::getInstance()->translate('Project id #') . $id;
             if (!$validStart) {
                 $message = Phprojekt::getInstance()->translate('Start date invalid');
             } else {
                 $message = Phprojekt::getInstance()->translate('End date invalid');
             }
             throw new Zend_Controller_Action_Exception($label . ': ' . $message, 400);
         }
         // Check: start date after end date?
         $startDateTemp = strtotime($startDate);
         $endDateTemp = strtotime($endDate);
         if ($startDateTemp > $endDateTemp) {
             $label = Phprojekt::getInstance()->translate('Project id #') . $id;
             $message = Phprojekt::getInstance()->translate('Start date can not be after End date');
             throw new Zend_Controller_Action_Exception($label . ': ' . $message, 400);
         }
         $activeRecord->startDate = $startDate;
         $activeRecord->endDate = $endDate;
         if ($rights->getItemRight(1, $id, $userId) >= Phprojekt_Acl::WRITE) {
             $activeRecord->parentSave();
         }
     }
     $message = Phprojekt::getInstance()->translate(self::EDIT_MULTIPLE_TRUE_TEXT);
     $return = array('type' => 'success', 'message' => $message, 'id' => 0);
     Phprojekt_Converter_Json::echoConvert($return);
 }