/**
  * Returns all MetaDataTypes irrespective of permissions
  * <code>
  * $types = MetaDataTypes::getAll();
  * foreach ($types as $type) { ... } 
  * @return MetaDataTypes
  */
 public static function getAll()
 {
     if (self::$has_init) {
         return self::$types;
     }
     global $db;
     $query = "SELECT * from `meta_types`";
     $results = $db->getAll($query);
     $types = array();
     if ($results) {
         foreach ($results as $result) {
             $type = MetaDataType::fromArray($result);
             $types[] = $type;
         }
     }
     self::$types = new self($types);
     self::$has_init = true;
 }
Exemplo n.º 2
0
function editMetaDataTable_Category($organisation_id = null, $group = null, $role = null, $proxy_id = null, MetaDataType $category)
{
    //for this case we have to get the users which are members of the relevant org, group, role, and where relevant? proxy_id
    $users = Users::get($organisation_id, $group, $role, $proxy_id);
    $types = MetaDataTypes::get($organisation_id, $group, $role, $proxy_id);
    $category_id = $category->getID();
    ob_start();
    foreach ($users as $user) {
        $values = getUserCategoryValues($user, $category);
        //var_dump($values);
        $descendant_type_sets = getDescendentTypesArray($types, $category);
        $label = html_encode($user->getFullname());
        ?>
	<tbody id="user_<?php 
        echo $user->getID();
        ?>
">
		<tr class="user_head" id="user_head_<?php 
        echo $user->getID();
        ?>
">
			<td></td>
			<th colspan="2"><?php 
        echo $label;
        ?>
</th>
			<td class="control" colspan="3"><ul class="page-action"><li class="last"><a href="#" class="add_btn" id="add_btn_<?php 
        echo $category_id;
        ?>
">Add record for <?php 
        echo $label;
        ?>
</a></li></ul></td>
		</tr>
		<?php 
        foreach ($values as $value) {
            echo editMetaDataRow($value, $category, $descendant_type_sets);
        }
        ?>
	</tbody>
	<?php 
    }
    $prepend = getHiddenMetaInputs($organisation_id, $group, $role, $category_id);
    return editMetaDataTable(ob_get_clean(), $prepend);
}
         }
     }
     if (!has_error()) {
         echo "<h2>" . $category->getLabel() . "</h2>";
         echo "<div class=\"content-small\">for " . $organisation->getTitle() . " &gt; " . ucwords($group) . " &gt; " . ucwords($opts["associated_role"]) . "</div><br />";
         echo editMetaDataTable_Category($organisation_id, $group, $role, null, $category);
     } else {
         //if there were any errors, return a 500 and display errors
         header("HTTP/1.0 500 Internal Error");
         echo display_status_messages(false);
     }
     break;
 case 'new_value':
     $cat_id = filter_input(INPUT_POST, "type", FILTER_SANITIZE_NUMBER_INT);
     $proxy_id = filter_input(INPUT_POST, "proxy_id", FILTER_SANITIZE_NUMBER_INT);
     $type = MetaDataType::get($cat_id);
     if ($type) {
         $user = User::get($proxy_id);
         $org_id = $user->getOrganisationId();
         $group = $user->getGroup();
         $role = $user->getRole();
         $types = MetaDataTypes::get($org_id, $group, $role, $proxy_id);
         $value_id = MetaDataValue::create($cat_id, $proxy_id);
         $value = MetaDataValue::get($value_id);
         $descendant_type_sets = getDescendentTypesArray($types, $type);
         header("Content-Type: application/xml");
         echo editMetaDataRow($value, $type, $descendant_type_sets);
     } else {
         header("HTTP/1.0 500 Internal Error");
         echo display_error("Invalid type. Please try again.");
     }
 /**
  * Returns the associated MetaDataType 
  * @return MetaDataType
  */
 public function getType()
 {
     return MetaDataType::get($this->meta_type_id);
 }
 /**
  * Returns the parent type, if any. Returns null if none is found.
  * <code>
  * $type = $value->getType();
  * $parent = $type->getParent();
  * </code>
  * @return MetaDataType
  */
 public function getParent()
 {
     if ($this->parent_type_id) {
         return MetaDataType::get($this->parent_type_id);
     }
 }
 /**
  * Retrieves Multiple values based on provided criteria.  
  * @param $organisation Organisation ID
  * @param $group 
  * @param $role
  * @param $proxy_id User's ID 
  * @param MetaDataType $type
  * @param $options advanced selection criteroa
  * @return MetaDataValues
  */
 public static function get($organisation = null, $group = null, $role = null, $proxy_id = null, MetaDataType $type = null, $include_sub_types = true, $options = array())
 {
     global $db;
     $conditions = array();
     if (array_key_exists('order by', $options)) {
         $order = array();
         if (is_array($options['order by'])) {
             foreach ($options['order by'] as $orders) {
                 $order[] = "`" . $orders[0] . "` " . (isset($orders[1]) ? $orders[1] : "asc");
             }
         }
         $order_by = " ORDER BY " . implode(",", $order);
     } else {
         $order_by = " ORDER BY lastname, firstname";
     }
     if (isset($options['limit'])) {
         $limit = $options['limit'];
     } else {
         $limit = -1;
     }
     if (isset($options['offset'])) {
         $offset = $options['offset'];
     } else {
         $offset = -1;
     }
     if (isset($options['where'])) {
         $conditions[] = $options['where'];
     }
     $query = "SELECT a.*, b.`group`, b.`role`, c.* from `" . AUTH_DATABASE . "`.`user_data` a \n\t\t\t\t\tLEFT JOIN `" . AUTH_DATABASE . "`.`user_access` b on a.`id`=b.`user_id` and b.`app_id`=?\n\t\t\t\t\tLEFT JOIN `meta_values` c on c.`proxy_id`=a.`id`";
     $conditions[] = generateAccessConditions($organisation, $group, $role, $proxy_id, 'b');
     if ($type) {
         $type_id = $type->getID();
         if ($include_sub_types) {
             $types = MetaDataTypes::get($organisation, $group, $role, $proxy_id);
             $desc_type_ids = getUniqueDescendantTypeIDs($types, $type);
             if ($desc_type_ids) {
                 //includes values from the specified type as well as sub types
                 $desc_type_ids[] = $type_id;
                 $conditions[] = "`meta_type_id` IN (" . implode(",", $desc_type_ids) . ")";
             } else {
                 $conditions[] = "`meta_type_id`=" . $db->qstr($type_id);
             }
         } else {
             $conditions[] = "`meta_type_id`=" . $db->qstr($type_id);
         }
     }
     if ($conditions) {
         $query .= " WHERE " . implode(" AND ", $conditions);
     }
     $query .= $order_by;
     $results = $db->SelectLimit($query, $limit, $offset, array(AUTH_APP_ID));
     $values = array();
     if ($results) {
         foreach ($results as $result) {
             //print_r($result);
             //user caching
             //$tmp_user = User::fromArray($result);
             //print_r($tmp_user);
             $values[] = MetaDataValue::fromArray($result);
         }
     }
     return new self($values);
 }