/**
  * Test add a default relation
  */
 public function testAddModuleToAdminRole()
 {
     $roleModel = new Phprojekt_Role_RoleModulePermissions();
     $roleModel->addModuleToAdminRole(1);
     $return = $roleModel->getRoleModulePermissionsById(1);
     $this->assertEquals(ksort($this->_expected), ksort($return));
 }
示例#2
0
 /**
  * Help to save a model by setting the models properties.
  * Validation is based on the ModelInformation implementation.
  *
  * @param Phprojekt_Model_Interface $model  The model.
  * @param array                     $params The parameters used to feed the model.
  *
  * @throws Zend_Controller_Action_Exception On no valid parameters.
  *
  * @return boolean True for a sucessful save.
  */
 public function saveModule(array $params)
 {
     $this->name = ucfirst($params['name']);
     $this->label = $params['label'];
     $this->active = (int) $params['active'];
     $this->saveType = (int) $params['saveType'];
     $this->version = Phprojekt::getInstance()->getVersion();
     if ($this->recordValidate()) {
         $saveNewModule = false;
         if ($this->id == 0) {
             $saveNewModule = true;
         }
         $this->save();
         // Add the new module to the root project
         if ($saveNewModule) {
             $project = new Project_Models_Project();
             $project = $project->find(1);
             $project->addModule($this->id);
             // Save Module into the role 1 with 255 access
             $role = new Phprojekt_Role_RoleModulePermissions();
             $role->addModuleToAdminRole($this->id);
             // Get the first and second fields
             $field = Phprojekt_DatabaseManager::COLUMN_NAME;
             $db = Phprojekt::getInstance()->getDb();
             $select = $db->select()->from('database_manager')->where(sprintf('table_name = %s AND status = 1 AND %s != %s', $db->quote($this->name), $field, $db->quote('project_id')));
             $results = $db->query($select)->fetchAll();
             $firstField = isset($results[0][$field]) ? $results[0][$field] : 'id';
             $secondField = isset($results[1][$field]) ? $results[1][$field] : 'id';
             // Copy Templates files
             $this->_copyTemplates(array('Template'), $firstField, $secondField);
             // Change SQL file
             $this->_createSqlFile();
         }
         return $this->id;
     } else {
         $errors = $this->getError();
         $error = array_pop($errors);
         throw new Zend_Controller_Action_Exception($error['field'] . ' ' . $error['message'], 400);
     }
 }