/**
  * Get multiple conditions and combine them into one condition string
  * 
  * DataManager::combineConditions(array('project_id = ?', $project->getId()), 'is_visible = 1');
  * 
  * Will result in:
  * 
  * (project_id = '12') AND (is_visible = 1)
  * 
  * Empty conditions are ignored
  *
  * @param void
  * @return string
  */
 function combineConditions()
 {
     $args = func_get_args();
     if (!count($args)) {
         return '';
     }
     // if
     $conditions = array();
     foreach ($args as $arg) {
         $prepared = DataManager::prepareConditions($arg);
         if ($prepared) {
             $conditions[] = "({$prepared})";
         }
         // if
     }
     // foeach
     return count($conditions) ? implode(' AND ', $conditions) : '';
 }
 /**
  * Delete records from attachments table that match given $conditions
  * 
  * This function also deletes all files from /upload folder so this function 
  * is not 100% transaction safe
  *
  * @param mixed $conditions
  * @return boolean
  */
 function delete($conditions = null)
 {
     $attachments_table = TABLE_PREFIX . 'attachments';
     $perpared_conditions = DataManager::prepareConditions($conditions);
     $where_string = trim($perpared_conditions) == '' ? '' : "WHERE {$perpared_conditions}";
     $rows = db_execute("SELECT id, location FROM {$attachments_table} {$where_string}");
     if (is_foreachable($rows)) {
         $attachments = array();
         foreach ($rows as $row) {
             if ($row['location']) {
                 $attachments[(int) $row['id']] = $row['location'];
             }
             // if
         }
         // foreach
         // Delete attachments
         $delete = db_execute("DELETE FROM {$attachments_table} WHERE id IN (?)", array_keys($attachments));
         if ($delete && !is_error($delete)) {
             foreach ($attachments as $location) {
                 @unlink(UPLOAD_PATH . '/' . $location);
             }
             // foreach
         }
         // if
         return $delete;
     }
     // if
     return true;
 }