예제 #1
0
 public function testDeleteTagsByItem()
 {
     $tag = new Phprojekt_Tags();
     $tag->deleteTagsByItem(1, 1);
     $tags = $tag->getTagsByModule(1, 1);
     $this->assertTrue(empty($tags));
 }
예제 #2
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 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();
         }
     }
 }
예제 #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 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);
 }
예제 #4
0
 /**
  * Deletes all events in this series beginning with this one.
  *
  * @return void.
  */
 public function delete()
 {
     $db = $this->getAdapter();
     if ($this->_isFirst) {
         $db->delete('calendar2_user_relation', $db->quoteInto('calendar2_id = ?', $this->id));
         $db->delete('calendar2_excluded_dates', $db->quoteInto('calendar2_id = ?', $this->id));
         $tag = new Phprojekt_Tags();
         $tag->deleteTagsByItem(Phprojekt_Module::getId('Calendar2'), $this->id);
         parent::delete();
     } else {
         $first = clone $this;
         $first->find($this->id);
         $start = new Datetime('@' . Phprojekt_Converter_Time::userToUtc($this->start));
         // Adjust the rrule.
         $helper = $first->getRruleHelper();
         $split = $helper->splitRrule($start);
         $first->rrule = $split['old'];
         $first->save();
         // Delete all excludes after this event.
         $where = $db->quoteInto('calendar2_id = ?', $this->id);
         $where .= $db->quoteInto('AND date >= ?', $start->format('Y-m-d H:i:s'));
         $db->delete('calendar2_excluded_dates', $where);
     }
 }