/**
	 * As well as removing the borrowing relationship, this removes relationships on the site where the
	 * entity being unborrowed is on the "b" side of the relationship. If the site also owns the entity 
	 * being unborrowed (not a good state) but it can happen, we skip this relationship deletion phase.
	 */
	function delete_borrowed_relationship( $site_id , $id , $rel_id ) // {{{ //{{{
	{
		// if we don't also own the entity, delete associations from the site where our entity is on the b side.
		if (!site_owns_entity( $site_id, $id ))
		{
			$dbq = new DBSelector;
			
			//actual relationships that we are selecting
			$dbq->add_table( 'r' , 'relationship' );
			$dbq->add_table( 'ar' , 'allowable_relationship' );
			$dbq->add_field( 'r' , '*' );
			$dbq->add_relation( 'r.type = ar.id' );
			$dbq->add_relation( 'r.entity_b = ' . $id );
			
			//owns relationship table
			$dbq->add_table( 'r2' , 'relationship' );
			$dbq->add_table( 'ar2' , 'allowable_relationship' );
			
			if (!reason_relationship_names_are_unique())
			{
				$dbq->add_relation( 'ar2.name = "owns"' );
			}
			else
			{
				$dbq->add_relation( 'ar2.type = "owns"' );
			}
			$dbq->add_relation( 'r2.type = ar2.id' );
			$dbq->add_relation( 'r2.entity_a = ' . $site_id );
			$dbq->add_relation( 'r2.entity_b = r.entity_a' );
			
			//current borrowship
			$dbq->add_table( 'r3' , 'relationship' );
			$dbq->add_table( 'ar3' , 'allowable_relationship' );
			
			$dbq->add_relation( 'ar3.id = ' . $rel_id );	
			$dbq->add_relation( 'r3.type = ar3.id' );
			$dbq->add_relation( 'r3.entity_a = ' . $site_id );
			$dbq->add_relation( 'r3.entity_b = ' . $id );
			$x = $dbq->run();
			
			if( $x )
			{
				$first = true;
				$in = '';
				foreach( $x AS $rel )
				{
					if (!$first) $in .= ',';
					else $first = false;
					$in .= $rel[ 'id' ];
				}
				$q = 'DELETE FROM relationship WHERE id IN(' . $in . ')';
				db_query( $q , 'Error removing associations of borrowed item before deleting' );
			}
		}
		
		$q = 'DELETE FROM relationship WHERE entity_a = ' . $site_id . ' AND entity_b = ' . $id . ' AND type = ' . $rel_id;
		db_query( $q , 'Error removing borrowship' );
	}
Example #2
0
 function process()
 {
     $nobody_group = new entity(id_of('nobody_group'));
     //check to see if posting or commenting have been enabled while still being associated with the nobody group
     if ($this->get_value('allow_front_end_posting') && $this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_posting_group')) {
         $this->delete_associations_of_type('publication_to_authorized_posting_group');
     }
     if ($this->get_value('allow_comments') && $this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_commenting_group')) {
         $this->delete_associations_of_type('publication_to_authorized_commenting_group');
     }
     //check to see if posting or commenting have been disabled
     if (!$this->get_value('allow_front_end_posting') || !$this->get_value('allow_comments')) {
         //if they are, check to make sure that we've borrowed or own the nobody group.
         if (!(site_borrows_entity($this->get_value('site_id'), id_of('nobody_group')) || site_owns_entity($this->get_value('site_id'), id_of('nobody_group')))) {
             //if not, borrow it.
             create_relationship($this->get_value('site_id'), id_of('nobody_group'), get_borrows_relationship_id(id_of('group_type')));
         }
         //check to see if we've got the appropriate relationship(s) with the nobody group.	If we don't, create the relationship.
         if (!$this->get_value('allow_front_end_posting') && !$this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_posting_group')) {
             $this->associate_with_nobody_group('publication_to_authorized_posting_group');
         }
         if (!$this->get_value('allow_comments') && !$this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_commenting_group')) {
             $this->associate_with_nobody_group('publication_to_authorized_commenting_group');
         }
     }
     // make sure the group type is available to the site if commenting or front-end posting are available
     if ($this->get_value('allow_front_end_posting') || $this->get_value('allow_comments')) {
         if (!$this->site_has_type(id_of('group_type'))) {
             $this->add_type_to_site(id_of('group_type'));
         }
     }
     if ($this->get_value('allow_comments')) {
         if (!$this->site_has_type(id_of('comment_type'))) {
             $this->add_type_to_site(id_of('comment_type'));
         }
     }
     if ($this->get_value('has_issues') == 'yes' && !$this->site_has_type(id_of('issue_type'))) {
         $this->add_type_to_site(id_of('issue_type'));
     }
     if ($this->get_value('has_sections') == 'yes' && !$this->site_has_type(id_of('news_section_type'))) {
         $this->add_type_to_site(id_of('news_section_type'));
     }
     if (!$this->site_has_type(id_of('news'))) {
         // publicatons don't make much sense without news
         $this->add_type_to_site(id_of('news'));
     }
     parent::process();
 }
Example #3
0
 function leftbar_item()
 {
     echo '<div class="managerNav">';
     echo '<div class="roundedTop"> <img src="' . REASON_ADMIN_IMAGES_DIRECTORY . 'trans.gif" alt="" class="roundedCorner" />';
     echo '</div>' . "\n";
     echo '<div class="managerList">';
     if (!empty($this->request[CM_VAR_PREFIX . 'id'])) {
         $old_name = new entity($this->request[CM_VAR_PREFIX . 'id']);
     }
     $item = new entity($this->id);
     $name = isset($old_name) ? $old_name->get_value('name') : $item->get_value('name');
     $name = ($name or strlen($name) > 0) ? $name : '<em>New Item</em>';
     echo '<strong>' . $name . '</strong><br />';
     echo '<ul class="leftList' . (isset($old_name) ? ' outer' : '') . '">';
     if (site_owns_entity($this->site_id, $this->id)) {
         $this->show_owns_links();
         echo '</ul>';
         if (empty($this->request[CM_VAR_PREFIX . 'type_id'])) {
             $this->show_other_links_item();
         }
     } else {
         $this->show_borrows_links();
         echo '</ul>';
     }
     echo '</div>';
     echo '<div class="roundedBottom"> <img src="' . REASON_ADMIN_IMAGES_DIRECTORY . 'trans.gif" alt="" class="roundedCorner" />';
     echo '</div>';
     echo '</div>';
 }
 function ensure_nobody_group_is_on_site()
 {
     $site_id = $this->get_site_id();
     if ($site_id) {
         if (!(site_borrows_entity($site_id, id_of('nobody_group')) || site_owns_entity($site_id, id_of('nobody_group')))) {
             // borrow it
             create_relationship($site_id, id_of('nobody_group'), get_borrows_relationship_id(id_of('group_type')));
         }
         return true;
     }
     return false;
 }