/**
  * Create the google map type.
  */
 protected function create_google_map_type()
 {
     // make sure the cache is clear
     reason_refresh_relationship_names();
     reason_refresh_unique_names();
     $str = '';
     $google_map_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Google Map', $this->google_map_type_details);
     create_default_rels_for_new_type($google_map_id);
     create_reason_table('google_map', $this->google_map_type_details['unique_name'], $this->user_id());
     $ftet = new FieldToEntityTable('google_map', $this->google_map_table_fields);
     $ftet->update_entity_table();
     ob_start();
     $ftet->report();
     $str .= ob_get_contents();
     ob_end_clean();
     // create all the necessary relationships for the google map type
     create_allowable_relationship(id_of('minisite_page'), id_of('google_map_type'), 'page_to_google_map', $this->page_to_google_map_details);
     create_allowable_relationship(id_of('event_type'), id_of('google_map_type'), 'event_to_google_map', $this->event_to_google_map_details);
     $str .= '<p>Created page_to_google_map and even_to_google_map allowable relationships</p>';
     return $str;
 }
 protected function course_template_type_exists()
 {
     reason_refresh_unique_names();
     // force refresh from the database just in case.
     return reason_unique_name_exists('course_template_type');
 }
Example #3
0
/**
 * We use a 1 hour cache for this super common query. We update the cache in admin_actions.php whenever unique names are added or changed.
 */
function reason_get_unique_names()
{
    $cache = new ReasonObjectCache('reason_unique_names', 3600);
    if ($unique_names =& $cache->fetch()) {
        return $unique_names;
    } else {
        return reason_refresh_unique_names();
    }
}
	/**
	 * Updates entity with id = $id with the values of the array $values
	 *
	 * reason_update_entity() provides an easier-to-use interface 
	 * where the updates do not need to be organized by table.
	 *
	 * @todo figure out how to refresh the entity data cache on update
	 *
	 * @param integer $id ID of entity to update
	 * @param integer $user_id Reason ID of user making changes
	 * @param array $updates array of tables with values being array of key-val pairs
	 * @param boolean $archive boolean that determines whether this update will be archived
	 * @return boolean true => entity has changed,  false => entity has not changed
	 */
	function update_entity( $id, $user_id, $raw_updates = array(), $archive = true )
	{
		$original = new entity($id, false);
		if (reason_is_entity($original, true)) // must be an entity of some type.
		{
			if (isset($raw_updates['entity']['type']) && ($raw_updates['entity']['type'] != $original->get_value('type')))
			{
				trigger_error('update_entity cannot be used to change the type of an entity.');
			}
			foreach( $raw_updates AS $table => $raw_fields )
			{
				$updates[$table] = reason_sanitize_values($original->get_value('type'), $raw_fields);
				if (empty($changed))
				{
					foreach ($updates[$table] as $k => $v) // see if this represents a change.
					{
						if ($v != $original->get_value($k))
						{
							$changed = true;
							break;
						}
					}
				}
			}
			if (!empty($changed)) // some change took place
			{
				if (!isset($updates['entity']['last_edited_by'])) $updates['entity']['last_edited_by'] = $user_id;
				if (!isset($updates['entity']['last_modified'])) $updates['entity']['last_modified'] = get_mysql_datetime();
				foreach  ($updates as $table => $fields)
				{
					$GLOBALS['sqler']->update_one( $table, $fields, $id );
				}
				if (!empty($archive))
				{
					$archived_id = duplicate_entity( $original, false, true, array( 'state' => 'Archived' ) );
					$rel_id = reason_get_archive_relationship_id($original->get_value('type'));
					create_relationship( $id, $archived_id, $rel_id );
				}
				$updated_entity = new entity($id, false);
				$updated_entity->get_values();
				// If the unique_name changes on the updated entity, or a uniquely named entity is deleted or undeleted, lets update the unique name cache
				if ($updated_entity->get_value('unique_name') != $original->get_value('unique_name') ||
					($original->get_value('state') != 'Deleted' && $updated_entity->get_value('state') == 'Deleted' && $original->get_value('unique_name')) ||
					($original->get_value('state') == 'Deleted' && $updated_entity->get_value('state') != 'Deleted' && $updated_entity->get_value('unique_name')))
				{
					reason_refresh_unique_names();
				}
				return true;
			}
		}
		else
		{
			trigger_error('update_entity requires a valid entity id (was given ' . $id . ').');
		}
		return false;
	}
 protected function social_account_type_exists()
 {
     reason_refresh_unique_names();
     // force refresh from the database just in case.
     return reason_unique_name_exists('social_account_type');
 }
Example #6
0
function admin_user_exists()
{
    reason_include_once('function_libraries/admin_actions.php');
    reason_refresh_unique_names();
    // lets make sure we pull admin_user from the database not the cache.
    return reason_unique_name_exists('admin_user');
}