public function testSaveMultipleTags() { $tag = new Phprojekt_Tags(); $tag->saveTags(1, 1, "love phprojekt"); $tag->saveTags(1, 2, "admire phprojekt"); $tags = $tag->search("love"); $this->assertEquals(array(array('id' => 1, 'moduleId' => 1, 'moduleName' => 'Project', 'moduleLabel' => 'Project', 'firstDisplay' => 'Hallo Welt', 'secondDisplay' => null, 'projectId' => 1)), $tags); $tags = $tag->search("phprojekt"); $this->assertEquals(array(array('id' => 1, 'moduleId' => 1, 'moduleName' => 'Project', 'moduleLabel' => 'Project', 'firstDisplay' => 'Hallo Welt', 'secondDisplay' => null, 'projectId' => 1), array('id' => 2, 'moduleId' => 1, 'moduleName' => 'Project', 'moduleLabel' => 'Project', 'firstDisplay' => '', 'secondDisplay' => '', 'projectId' => 1)), $tags); $tags = $tag->search("admire phprojekt"); $this->assertEquals(array(array('id' => 2, 'moduleId' => 1, 'moduleName' => 'Project', 'moduleLabel' => 'Project', 'firstDisplay' => '', 'secondDisplay' => '', 'projectId' => 1)), $tags); }
/** * Saves the tags for the current item. * * REQUIRES request parameters: * <pre> * - integer <b>id</b> id of the item. * </pre> * * OPTIONAL request parameters: * <pre> * - string <b>string</b> An string of words (Will be separated by the spaces). * - string <b>moduleName</b> Name of the module. * </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 missing or wrong id. * * @return void */ public function jsonSaveTagsAction() { $tagObj = new Phprojekt_Tags(); $id = (int) $this->getRequest()->getParam('id'); $string = (string) $this->getRequest()->getParam('string', ''); 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->saveTags($moduleId, $id, $string); $message = Phprojekt::getInstance()->translate('The Tags were added correctly'); $return = array('type' => 'success', 'message' => $message, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }
/** * 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; }