Exemplo n.º 1
0
 /**
  * Delete a tree and all the sub-itemes.
  *
  * @param Phprojekt_ActiveRecord_Abstract $model Model to delete.
  *
  * @throws Exception If validation fails.
  *
  * @return boolean True for a sucessful delete.
  */
 protected static function _deleteTree(Phprojekt_ActiveRecord_Abstract $model)
 {
     $id = $model->id;
     // Checks
     if ($id == 1) {
         throw new Phprojekt_PublishedException('You can not delete the root project');
     } else {
         if (!self::_checkItemRights($model, 'Project')) {
             throw new Phprojekt_PublishedException('You do not have access to do this action');
         } else {
             $relations = Phprojekt_Loader::getModel('Project', 'ProjectModulePermissions');
             $where = sprintf('project_id = %d', (int) $id);
             // Delete related items
             $modules = $relations->getProjectModulePermissionsById($id);
             $tag = Phprojekt_Tags::getInstance();
             foreach ($modules['data'] as $moduleData) {
                 if ($moduleData['inProject']) {
                     $module = Phprojekt_Loader::getModel($moduleData['name'], $moduleData['name']);
                     if ($module instanceof Phprojekt_ActiveRecord_Abstract) {
                         $records = $module->fetchAll($where);
                         if (is_array($records)) {
                             foreach ($records as $record) {
                                 $tag->deleteTagsByItem($moduleData['id'], $record->id);
                                 self::delete($record);
                             }
                         }
                     }
                 }
             }
             // Delete module-project relaton
             $records = $relations->fetchAll($where);
             if (is_array($records)) {
                 foreach ($records as $record) {
                     $record->delete();
                 }
             }
             // Delete user-role-projetc relation
             $relations = Phprojekt_Loader::getModel('Project', 'ProjectRoleUserPermissions');
             $records = $relations->fetchAll($where);
             if (is_array($records)) {
                 foreach ($records as $record) {
                     $record->delete();
                 }
             }
             // Delete the project itself
             return null === $model->delete();
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Test json convertion of tags
  */
 public function testConvertTags()
 {
     $tagObj = Phprojekt_Tags::getInstance();
     $tags = $tagObj->getTags(1);
     $fields = $tagObj->getFieldDefinition();
     $result = Phprojekt_Converter_Json::convert($tags, $fields);
     $converted = '{}&&({"metadata":[{"key":"string","label":"Tag"},{"key":"count","label":"Count"}],"data":[{"';
     $this->assertEquals($converted, substr($result, 0, strlen($converted)));
 }
Exemplo n.º 3
0
 /**
  * Delete the tags for one item.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - string <b>moduleName</b> Name of the module.
  * </pre>
  *
  * If there is an error, the delete will return a Phprojekt_PublishedException,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - code    => 0.
  *  - id      => 0.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On missing or wrong id.
  *
  * @return void
  */
 public function jsonDeleteTagsAction()
 {
     $tagObj = Phprojekt_Tags::getInstance();
     $id = (int) $this->getRequest()->getParam('id');
     if (empty($id)) {
         throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
     }
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', 'Project'));
     $moduleId = (int) Phprojekt_Module::getId($module);
     $tagObj->deleteTagsByItem($moduleId, $id);
     $message = Phprojekt::getInstance()->translate('The Tags were deleted correctly');
     $return = array('type' => 'success', 'message' => $message, 'code' => 0, 'id' => 0);
     Phprojekt_Converter_Json::echoConvert($return);
 }
Exemplo n.º 4
0
 /**
  * Test get relations
  *
  * @return void
  */
 public function testGetRelationIdByModule()
 {
     $tag = Phprojekt_Tags::getInstance();
     $result = array('1', '3');
     $this->assertEquals($tag->getRelationIdByModule(1, 1), $result);
 }
Exemplo n.º 5
0
 /**
  * Prevent delete modules from the Frontend.
  * For delete modules use safeDelete.
  *
  * @return void
  */
 public function delete()
 {
     // Delete all the project-module relations
     $project = Phprojekt_Loader::getModel('Project', 'ProjectModulePermissions');
     $project->deleteModuleRelation($this->id);
     // Delete all the role-module relations
     $role = Phprojekt_Loader::getLibraryClass('Phprojekt_Role_RoleModulePermissions');
     $role->deleteModuleRelation($this->id);
     // Delete the items and tags
     $tag = Phprojekt_Tags::getInstance();
     $model = Phprojekt_Loader::getModel($this->name, $this->name);
     $results = $model->fetchAll();
     foreach ($results as $record) {
         $tag->deleteTagsByItem($this->id, $record->id);
         $record->delete();
     }
     // Delete Files
     $this->_deleteFolder(PHPR_CORE_PATH . DIRECTORY_SEPARATOR . $this->name);
     // Delete module entry
     parent::delete();
 }