/**
  * Delete all objects
  *
  * This creates a single delete query using the complete keys of 
  * each of the dbobjects that has been registered
  */
 function delete()
 {
     if (count($this->dbobjects) && is_array($this->dbobjects)) {
         $clause = new Clause();
         $class_name = $this->class_name;
         $obj = new $class_name();
         DbObject::cascadeDelete($this->dbobjects);
         foreach ($this->dbobjects as $dbobj) {
             /**$sub_clause = new Clause();
             
                                 foreach($dbobj->primaryKeys() as $field)
                                 {
                                     $sub_clause->addTableCondition($obj->tableName(),$field->name(),$field->value());
                                 }*/
             if ($dbobj->db_clause) {
                 $clause->addSubClause($dbobj->db_clause, Clause::OR_REL, Clause::LAST);
             } else {
                 $clause->addSubClause($dbobj->uniqueClause(), Clause::OR_REL, Clause::LAST);
             }
         }
         $query = new DeleteQuery($obj->tableName());
         $query->setClause($clause);
         Session::unRegister($this->class_name . '_rel_deleteregister');
         $query->doQuery();
     }
 }
Ejemplo n.º 2
0
 /**
  * Create a unique clause from the field values in this object. Used by
  * {@link uniqueClause()}
  * @return Clause
  * @see Clause,uniqueClause
  * @access private
  */
 private function generateUniqueClause()
 {
     $key_fields = $this->primaryKeys();
     $ret = new Clause();
     foreach ($key_fields as $field) {
         if ($field->value()) {
             $ret->addCondition($this->tableName() . '.' . $field->name(), $field->value());
         }
         //else
         /*throw new Exception('Tried to build a unique clause with uninitialised field value '.$field->name().' in class: '.$this->getClass().' in method uniqueClause()');*/
     }
     return $ret;
 }
 public function havingString()
 {
     $ret = '';
     if (is_array($this->having) && count($this->having)) {
         foreach ($this->having as $having_data) {
             if (is_numeric($having_data['value'])) {
                 $value = $having_data['value'];
             } else {
                 $value = '\'' . $having_data['value'] . '\'';
             }
             if ($having_data['table']) {
                 $field_string = $having_data['table'] . '.' . $having_data['field'];
             } else {
                 $field_string = $having_data['field'];
             }
             if ($having_data['function']) {
                 $field_string = $having_data['function'] . '(' . $field_string . ')';
             }
             $cur_str = $field_string . ' ' . Clause::getStringSeparator($having_data['type']) . ' ' . $value;
             if ($ret) {
                 $ret = '(' . $ret . ') ' . Clause::relateHowToString($having_data['relate_how']) . ' (' . $cur_str . ')';
             } else {
                 $ret = $cur_str;
             }
         }
         $ret = ' HAVING(' . $ret . ')';
     } else {
         if ($this->having) {
             throw new Exception('Incorrect having clause: ' . $this->having);
         }
     }
     return $ret;
 }