Permalink
Browse files

fixed object association methods

  • Loading branch information...
1 parent b148f94 commit 322a9539b1f73fd38f1a6fe68c5e2a1c4ce6fd9b @damko committed Dec 18, 2011
Showing with 120 additions and 38 deletions.
  1. +15 −9 models/objectcommon.php
  2. +62 −5 models/organization.php
  3. +43 −24 models/person.php
View
@@ -61,28 +61,34 @@ public function getRequiredProperties() {
return $output;
}
- public function read(array $input) { //, $filter, $wanted_attributes, $sort_by, $flow_order, $wanted_page, $items_page) {
-
- $wanted_attributes = array();
+ public function read($input) {
+ //input fields: $filter, array $wanted_attributes, $sort_by = null, $flow_order = null, $wanted_page = null, $items_page = null) {
$pagination_settings = pagination_setup($input);
+
if(is_array($pagination_settings)) extract($pagination_settings);
- if(!empty($input['attributes']) and is_array($input['attributes'])) $wanted_attributes = $input['attributes'];
-
- //checks
- if(empty($filter))
+ if(!empty($input['wanted_attributes']) and is_array($input['wanted_attributes']))
+ {
+ $wanted_attributes = $input['wanted_attributes'];
+ } else {
+ $wanted_attributes = array();
+ }
+
+ if(empty($input['filter']) || is_array($input['filter']))
{
//TODO this should be a RI function handling the error
+ $return = array();
$return['error'] = 'Method "'.__FUNCTION__.'" requires a filter in input';
return $return;
+ } else {
+ $filter = $input['filter'];
}
//perform the search
$ldap_result = $this->ri_ldap->CEsearch($this->baseDn, $filter, $wanted_attributes, 0, null, $sort_by, $flow_order, $wanted_page, $items_page);
//saving and removing info about the ldap query
- //$info = array_pop($ldap_result);
if(!empty($ldap_result['RestStatus']))
{
$rest_status = $ldap_result['RestStatus'];
@@ -96,7 +102,7 @@ public function read(array $input) { //, $filter, $wanted_attributes, $sort_by,
foreach ($ldap_result as $ldap_item) {
//TODO probably it would be wiser to return the whole result without parsing everysingle entry. Don't know yet
- $this->bindLdapValuesWithClassProperties($ldap_item);
+ $this->bindLdapValuesWithClassProperties($ldap_item,$strict);
$output[] = $this->toRest($empty_fields);
}
View
@@ -62,16 +62,18 @@ public function create(array $input)
public function read(array $input)
{
+ extract(&$input,$extract_type = EXTR_OVERWRITE);
+
if(!empty($input['filter']))
{
$filter = $input['filter'];
} else {
if(!empty($input['oid'])) $filter = '(oid='.$input['oid'].')';
- if(!empty($input['dbId'])) $filter = '(dbId='.$input['dbId'].')';
+ if(!empty($input['dbId'])) $filter = '(dbId='.$input['dbId'].')'; //TODO maybe I can remove this
}
//TODO why this switch?
- switch ($input['emptyfields']) {
+/* switch ($input['emptyfields']) {
case true:
$empty_fields = TRUE;
break;
@@ -83,11 +85,17 @@ public function read(array $input)
default:
$empty_fields = TRUE;
break;
- }
+ } */
- if(empty($filter)) return false;
+ $output = array();
+ $output['filter'] = $filter;
+ $output['wanted_attributes'] = $wanted_attributes;
+ $output['sort_by'] = $sort_by;
+ $output['flow_order'] = $flow_order;
+ $output['wanted_page'] = $wanted_page;
+ $output['items_page'] = $items_page;
- return parent::read($input); //, $filter, $wanted_attributes, $sort_by, $flow_order, $wanted_page, $items_page);
+ return parent::read($output);
}
public function update(array $input)
@@ -115,6 +123,55 @@ public function delete($input)
$dn = 'oid='.$input['oid'].','.$this->baseDn;
return $this->ri_ldap->CEdelete($dn);
}
+
+ public function associate(array $input) {
+
+ $data = array();
+
+ if(empty($input['to'])) $data['error'] = 'Missing input "to". Possible values: organization, location';
+
+ if(empty($input['oid'])) $data['error'] = 'Missing input "oid".';
+
+ if($data['error']) return $data;
+
+ //we need to get a precise organization not a set of people
+ unset($input['filter']);
+
+ //let's get the get the organization's data
+ $data = $this->read($input);
+
+ if($data['error']) return $data;
+
+ //let's add the new location
+ $to = $input['to'];
+ switch ($to) {
+ case location:
+
+ if(empty($input['locId']) or is_array($input['locId']))
+ {
+ $data['error'] = 'Missing input "locId".';
+ return $data;
+ }
+
+ if(!in_array($input['locId'], $this->locRDN))
+ {
+ //add location to the previous locations
+ array_push($this->locRDN, $input['locId']);
+ $data['locRDN'] = $this->locRDN;
+ } else {
+ return true; //TODO maybe something more meaningful here
+ }
+
+ break;
+
+ default:
+ return false; //association not defined
+ break;
+ }
+
+ $data['oid'] = $this->oid;
+ return $this->update($data);
+ }
}
/* End of organization.php */
View
@@ -80,20 +80,26 @@ public function create(array $input)
* @return array containing all the entries found
*/
public function read(array $input)
- {
- $return = array();
-
- //extract(&$input,$extract_type = EXTR_OVERWRITE); //FIXME why this doesn't work at all?
+ {
+ extract(&$input,$extract_type = EXTR_OVERWRITE);
if(!empty($input['filter']))
{
$filter = $input['filter'];
} else {
if(!empty($input['uid'])) $filter = '(uid='.$input['uid'].')';
- if(!empty($input['dbId'])) $filter = '(dbId='.$input['dbId'].')';
+ if(!empty($input['dbId'])) $filter = '(dbId='.$input['dbId'].')'; //TODO maybe I can remove this
}
- return parent::read($input); //, $filter, $wanted_attributes, $sort_by, $flow_order, $wanted_page, $items_page);
+ $output = array();
+ $output['filter'] = $filter;
+ $output['wanted_attributes'] = $wanted_attributes;
+ $output['sort_by'] = $sort_by;
+ $output['flow_order'] = $flow_order;
+ $output['wanted_page'] = $wanted_page;
+ $output['items_page'] = $items_page;
+
+ return parent::read($output);
}
/**
@@ -147,44 +153,53 @@ private function getUid()
}
public function associate(array $input) {
- if(empty($input['to']))
- {
- $data = array();
- $data['error'] = 'Missing input "to". Possible values: organization, location';
- }
- if(empty($input['uid']))
- {
- $data = array();
- $data['error'] = 'Missing input "uid".';
- }
+ $data = array();
+
+ if(empty($input['to'])) $data['error'] = 'Missing input "to". Possible values: organization, location';
+
+ if(empty($input['uid'])) $data['error'] = 'Missing input "uid".';
+
+ if($data['error']) return $data;
//we need to get a precise person not a set of people
unset($input['filter']);
//let's get the get the person's data
- $this->read($input);
+ $data = $this->read($input);
- if(empty($this->cn)) return false; //person not found
+ if($data['error']) return $data;
//let's add the new location
$to = $input['to'];
switch ($to) {
case location:
- if(empty($input['locId']) or is_array($input['locId'])) return false;
+
+ if(empty($input['locId']) or is_array($input['locId']))
+ {
+ $data['error'] = 'Missing input "locId".';
+ return $data;
+ }
+
if(!in_array($input['locId'], $this->locRDN))
{
- $entry= array('locRDN' => $input['locId']);
+ //add location to the previous locations
+ array_push($this->locRDN, $input['locId']);
+ $data['locRDN'] = $this->locRDN;
} else {
return true; //TODO maybe something more meaningful here
}
+
break;
case organization:
if(empty($input['oid']) or is_array($input['oid'])) return false;
if(!in_array($input['oid'], $this->oRDN))
{
- $entry= array('oRDN' => $input['oid']);
+ //add organization to the previous locations
+ array_push($this->oRDN, $input['oid']);
+ $data['oRDN'] = $this->oRDN;
+
} else {
return true; //TODO maybe something more meaningful here
}
@@ -196,9 +211,13 @@ public function associate(array $input) {
break;
}
- $dn = 'uid='.$this->getUid().','.$this->baseDn;
- unset($entry['uid']); //never mess with the id during an update cause it has to do with dn
- return $this->ri_ldap->CEupdate($dn,$entry) ? $this->getUid() : false;
+// $dn = 'uid='.$this->getUid().','.$this->baseDn;
+// unset($entry['uid']); //never mess with the id during an update cause it has to do with dn
+// return $this->ri_ldap->CEupdate($dn,$entry) ? $this->getUid() : false;
+
+ $data['uid'] = $this->uid;
+ return $this->update($data);
+
}
}

0 comments on commit 322a953

Please sign in to comment.