/**
  * Allow to edit the current other data for the owner, you can modify other_name or other_value fields
  *
  * @param integer $id the owner id
  * @param string $new_data The new value which you want to update.
  * @param string $old_data The current value which you want to update.
  * @param string $field_data The field is can be other_name or other_value
  * @param integer $action PHPGW_SQL_RETURN_SQL | PHPGW_SQL_RUN_SQL depending what we want
  * @return string SQL update string
  */
 function edit_other_by_owner($id, $new_data, $old_data, $field_data, $action = PHPGW_SQL_RUN_SQL)
 {
     $other = createObject('phpgwapi.contact_others');
     $criteria = phpgwapi_sql_criteria::append_and(array(phpgwapi_sql_criteria::equal('contact_owner', phpgwapi_sql::integer($id)), phpgwapi_sql_criteria::equal($field_data, phpgwapi_sql::string($old_data))));
     return $other->update(array($field_data => $new_data), $criteria, $action);
 }
 /**
  * Return the SQL select correct for all the entity map.
  *
  * This is the main functionality of this class.
  * @return String with the sql created
  */
 function get_sql()
 {
     if (!is_array($this->entities) || empty($this->entities)) {
         return;
     }
     $this->ldebug('get_sql', array('Entities' => array_keys($this->entities), 'Path' => $this->distance), 'dump');
     $this->sort_by_distances();
     foreach ($this->entities as $name => $class) {
         list($fields, $from, $alias, $lcriteria) = $class->get_select();
         if ($fields) {
             $this->select_fields[] = $fields;
         }
         $fields = '';
         if ($lcriteria && !$this->_criteria_built) {
             $this->all_criteria = phpgwapi_sql_criteria::append_and(array($lcriteria, $this->all_criteria));
         }
     }
     $from = $this->get_join();
     $this->fields = implode(', ', $this->select_fields);
     // hooks for add external things in my queries
     $this->fields = $this->external_select($this->fields);
     $from = $this->external_from($from);
     $this->all_criteria = $this->external_criteria($this->all_criteria);
     $sql = 'SELECT ' . $this->fields . ' FROM ' . $from;
     $sql .= empty($this->all_criteria) ? '' : ' WHERE ' . $this->all_criteria;
     $this->select_fields = NULL;
     $this->all_criteria = NULL;
     $this->entities = NULL;
     $this->path = NULL;
     $this->distance = NULL;
     $this->false_path = NULL;
     $this->_criteria_built = False;
     $sql = $this->set_order($sql);
     $this->order_string = '';
     $this->ldebug('SQL', array('SQL String' => $sql));
     return $sql;
 }
 /**
  * Add criteria to list
  *
  * @param string $new_criteria with the new criteria which was autegenerate.
  * @return string with the criteria.
  */
 function _add_criteria($new_criteria)
 {
     $this->ldebug('_add_criteria', array('New Criteria' => $new_criteria, 'All Criteria Prev' => $this->criteria));
     $this->criteria = phpgwapi_sql_criteria::append_and(array($new_criteria, $this->criteria));
     $this->ldebug('_add_criteria', array('All Criteria Post' => $this->criteria));
 }