/** * Search for words. * * Returns a list of items that have the word, sorted by module with: * <pre> * - id => id of the item found. * - moduleId => id of the module. * - moduleName => Name of the module. * - moduleLabel => Display for the module. * - firstDisplay => Firts display for the item (Ej. title). * - secondDisplay => Second display for the item (Ej. notes). * - projectId => Parent project id of the item. * </pre> * * REQUIRES request parameters: * <pre> * - string <b>words</b> An string of words (Will be separated by the spaces). * </pre> * * OPTIONAL request parameters: * <pre> * - integer <b>count</b> Number of results. * </pre> * * The return is in JSON format. * * @return void */ public function jsonSearchAction() { $words = (string) $this->getRequest()->getParam('words'); $count = (int) $this->getRequest()->getParam('count', null); $offset = (int) $this->getRequest()->getParam('start', null); $search = new Phprojekt_Search(); $tags = new Phprojekt_Tags(); $searchresults = $search->search($words, $count); $tagresults = $tags->search($words, $count); $results = array('search' => $searchresults, 'tags' => $tagresults); Phprojekt_Converter_Json::echoConvert($results); }
/** * Test of jsonDeleteTagsAction */ public function testJsonDeleteTagsAction() { $tag = new Phprojekt_Tags(); $tags = $tag->search("this"); $this->assertEquals(array(array('id' => 2, 'moduleId' => 1, 'moduleName' => 'Project', 'moduleLabel' => 'Project', 'firstDisplay' => '', 'secondDisplay' => '', 'projectId' => 1)), $tags); $this->setRequestUrl('Default/Tag/jsonDeleteTags/'); $this->request->setParam('moduleName', 'Project'); $this->request->setParam('id', 2); $response = $this->getResponse(); $this->assertEquals('{}&&({"type":"success","message":"The Tags were deleted correctly","id":0})', $response); $tags = $tag->search("this"); $this->assertTrue(empty($tags)); }
/** * 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 Zend_Controller_Action_Exception('You can not delete the root project', 422); } else { if (!self::_checkItemRights($model, 'Project')) { throw new Zend_Controller_Action_Exception('You do not have access to do this action', 403); } else { $relations = new Project_Models_ProjectModulePermissions(); $where = sprintf('project_id = %d', (int) $id); // Delete related items $modules = $relations->getProjectModulePermissionsById($id); $tag = new Phprojekt_Tags(); 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 = new Project_Models_ProjectRoleUserPermissions(); $records = $relations->fetchAll($where); if (is_array($records)) { foreach ($records as $record) { $record->delete(); } } // Delete the project itself return null === $model->delete(); } } }
/** * Return this class only one time. * * @return Phprojekt_Tags_Users An instance of Phprojekt_Tags_Users. */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * 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 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 missing or wrong id. * * @return void */ public function jsonDeleteTagsAction() { $tagObj = new Phprojekt_Tags(); $id = (int) $this->getRequest()->getParam('id'); if (empty($id)) { throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400); } $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, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }
/** * 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))); }
/** * Saves this object to a new row, even if it is already backed by the * database. After a call to this function, the id will be different. * * @return int The id of the saved row. */ private function _saveToNewRow() { $tagsObject = new Phprojekt_Tags(); $moduleId = Phprojekt_Module::getId('Calendar2'); $tags = array(); foreach ($tagsObject->getTagsByModule($moduleId, $this->id) as $val) { $tags[] = $val; } $this->_fetchParticipantData(); $excludedDates = $this->getExcludedDates(); $this->_storedId = null; $this->_data['id'] = null; $this->_participantDataInDb = array(); $this->_isFirst = true; $this->save(); $tagsObject->saveTags($moduleId, $this->id, implode(' ', $tags)); return $this->id; }
/** * Prevent delete modules from the Frontend. * For delete modules use safeDelete. * * @return void */ public function delete() { // Delete all the project-module relations $project = new Project_Models_ProjectModulePermissions(); $project->deleteModuleRelation($this->id); // Delete all the role-module relations $role = new Phprojekt_Role_RoleModulePermissions(); $role->deleteModuleRelation($this->id); // Delete the items and tags $tag = new Phprojekt_Tags(); $model = Phprojekt_Loader::getModel($this->name, $this->name); if ($model instanceof Phprojekt_ActiveRecord_Abstract) { $results = $model->fetchAll(); if (is_array($results)) { foreach ($results as $record) { $tag->deleteTagsForModuleItem($this->id, $record->id); // @todo: Improve the delete routine for modules with a lot of entries. $record->delete(); } } } // Delete Files $this->_deleteFolder(PHPR_USER_CORE_PATH . $this->name); // Delete module entry parent::delete(); }
/** * Test get relations * * @return void */ public function testGetRelationIdByModule() { $tag = Phprojekt_Tags::getInstance(); $result = array('1', '3'); $this->assertEquals($tag->getRelationIdByModule(1, 1), $result); }
/** * 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(); }
public function testGetFieldDefinition() { $tag = new Phprojekt_Tags(); $fdef = $tag->getFieldDefinition(); $this->assertEquals(array(array('key' => 'string', 'label' => 'Tags'), array('key' => 'count', 'label' => 'Count')), $fdef); }