当前位置: 首页>>代码示例>>PHP>>正文


PHP column_type函数代码示例

本文整理汇总了PHP中column_type函数的典型用法代码示例。如果您正苦于以下问题:PHP column_type函数的具体用法?PHP column_type怎么用?PHP column_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了column_type函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doGetAnnotation

 function doGetAnnotation($id)
 {
     global $CFG;
     // Check whether the range column exists (for backwards compatibility)
     $range = '';
     if (!column_type($this->tablePrefix . 'annotation', 'range')) {
         $range = ', a.range AS range ';
     }
     // Caller should ensure that id is numeric
     $query = "SELECT a.id, a.userid, a.url,\n\t\t\t  a.start_block, a.start_xpath, a.start_word, a.start_char,\n\t\t\t  a.end_block, a.end_xpath, a.end_word, a.end_char,\n\t\t\t  a.note, a.access, a.quote, a.quote_title, a.quote_author,\n\t\t\t  a.link, a.link_title, a.action,\n\t\t\t  a.created, a.modified {$range}\n\t\t\t  FROM {$this->tablePrefix}annotation AS a\n\t\t\tWHERE a.id = {$id}";
     $resultSet = get_record_sql($query);
     if ($resultSet && count($resultSet) != 0) {
         $annotation = AnnotationGlobals::recordToAnnotation($resultSet);
         return $annotation;
     } else {
         return null;
     }
 }
开发者ID:njorth,项目名称:marginalia,代码行数:18,代码来源:annotate.php

示例2: table_column


//.........这里部分代码省略.........
            $default = 'DEFAULT \'' . $default . '\'';
            if (!empty($after)) {
                $after = 'AFTER `' . $after . '`';
            }
            return execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ' . $operation . ' ' . $type . ' ' . $signed . ' ' . $default . ' ' . $null . ' ' . $after);
        case 'postgres7':
            // From Petri Asikainen
            //Check db-version
            $dbinfo = $db->ServerInfo();
            $dbver = substr($dbinfo['version'], 0, 3);
            //to prevent conflicts with reserved words
            $realfield = '"' . $field . '"';
            $field = '"' . $field . '_alter_column_tmp"';
            $oldfield = '"' . $oldfield . '"';
            switch (strtolower($type)) {
                case 'tinyint':
                case 'integer':
                    if ($size <= 4) {
                        $type = 'INT2';
                    }
                    if ($size <= 10) {
                        $type = 'INT';
                    }
                    if ($size > 10) {
                        $type = 'INT8';
                    }
                    break;
                case 'varchar':
                    $type = 'VARCHAR(' . $size . ')';
                    break;
                case 'char':
                    $type = 'CHAR(' . $size . ')';
                    $signed = '';
                    break;
            }
            $default = '\'' . $default . '\'';
            //After is not implemented in postgesql
            //if (!empty($after)) {
            //    $after = "AFTER '$after'";
            //}
            //Use transactions
            execute_sql('BEGIN');
            //Always use temporary column
            execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ADD COLUMN ' . $field . ' ' . $type);
            //Add default values
            execute_sql('UPDATE ' . $CFG->prefix . $table . ' SET ' . $field . '=' . $default);
            if ($dbver >= '7.3') {
                // modifying 'not null' is posible before 7.3
                //update default values to table
                if (strtoupper($null) == 'NOT NULL') {
                    execute_sql('UPDATE ' . $CFG->prefix . $table . ' SET ' . $field . '=' . $default . ' WHERE ' . $field . ' IS NULL');
                    execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ALTER COLUMN ' . $field . ' SET ' . $null);
                } else {
                    execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ALTER COLUMN ' . $field . ' DROP NOT NULL');
                }
            }
            execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ALTER COLUMN ' . $field . ' SET DEFAULT ' . $default);
            if ($oldfield != '""') {
                // We are changing the type of a column. This may require doing some casts...
                $casting = '';
                $oldtype = column_type($table, $oldfield);
                $newtype = column_type($table, $field);
                // Do we need a cast?
                if ($newtype == 'N' && $oldtype == 'C') {
                    $casting = 'CAST(CAST(' . $oldfield . ' AS TEXT) AS REAL)';
                } else {
                    if ($newtype == 'I' && $oldtype == 'C') {
                        $casting = 'CAST(CAST(' . $oldfield . ' AS TEXT) AS INTEGER)';
                    } else {
                        $casting = $oldfield;
                    }
                }
                // Run the update query, casting as necessary
                execute_sql('UPDATE ' . $CFG->prefix . $table . ' SET ' . $field . ' = ' . $casting);
                execute_sql('ALTER TABLE  ' . $CFG->prefix . $table . ' DROP COLUMN ' . $oldfield);
            }
            execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' RENAME COLUMN ' . $field . ' TO ' . $realfield);
            return execute_sql('COMMIT');
        default:
            switch (strtolower($type)) {
                case 'integer':
                    $type = 'INTEGER';
                    break;
                case 'varchar':
                    $type = 'VARCHAR';
                    break;
            }
            $default = 'DEFAULT \'' . $default . '\'';
            if (!empty($after)) {
                $after = 'AFTER ' . $after;
            }
            if (!empty($oldfield)) {
                execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' RENAME COLUMN ' . $oldfield . ' ' . $field);
            } else {
                execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ADD COLUMN ' . $field . ' ' . $type);
            }
            execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ALTER COLUMN ' . $field . ' SET ' . $null);
            return execute_sql('ALTER TABLE ' . $CFG->prefix . $table . ' ALTER COLUMN ' . $field . ' SET ' . $default);
    }
}
开发者ID:pzingg,项目名称:saugus_elgg,代码行数:101,代码来源:datalib.php

示例3: getAlterFieldSQL

 /**
  * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to alter the field in the table
  */
 function getAlterFieldSQL($xmldb_table, $xmldb_field)
 {
     global $db;
     $results = array();
     /// To store all the needed SQL commands
     /// Get the quoted name of the table and field
     $tablename = $this->getTableName($xmldb_table);
     $fieldname = $this->getEncQuoted($xmldb_field->getName());
     /// Take a look to field metadata
     $meta = array_change_key_case($db->MetaColumns($tablename));
     $metac = $meta[$fieldname];
     $oldtype = strtolower($metac->type);
     $oldmetatype = column_type($xmldb_table->getName(), $fieldname);
     $oldlength = $metac->max_length;
     $olddecimals = empty($metac->scale) ? null : $metac->scale;
     $oldnotnull = empty($metac->not_null) ? false : $metac->not_null;
     $olddefault = empty($metac->has_default) ? null : strtok($metac->default_value, ':');
     $typechanged = true;
     //By default, assume that the column type has changed
     $lengthchanged = true;
     //By default, assume that the column length has changed
     /// Detect if we are changing the type of the column
     if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER && substr($oldmetatype, 0, 1) == 'I' || $xmldb_field->getType() == XMLDB_TYPE_NUMBER && $oldmetatype == 'N' || $xmldb_field->getType() == XMLDB_TYPE_FLOAT && $oldmetatype == 'F' || $xmldb_field->getType() == XMLDB_TYPE_CHAR && substr($oldmetatype, 0, 1) == 'C' || $xmldb_field->getType() == XMLDB_TYPE_TEXT && substr($oldmetatype, 0, 1) == 'X' || $xmldb_field->getType() == XMLDB_TYPE_BINARY && $oldmetatype == 'B') {
         $typechanged = false;
     }
     /// Detect if we are changing the length of the column, not always necessary to drop defaults
     /// if only the length changes, but it's safe to do it always
     if ($xmldb_field->getLength() == $oldlength) {
         $lengthchanged = false;
     }
     /// If type or length have changed drop the default if exists
     if ($typechanged || $lengthchanged) {
         $results = $this->getDropDefaultSQL($xmldb_table, $xmldb_field);
     }
     /// Just prevent default clauses in this type of sentences for mssql and launch the parent one
     $this->alter_column_skip_default = true;
     $results = array_merge($results, parent::getAlterFieldSQL($xmldb_table, $xmldb_field));
     // Call parent
     /// Finally, process the default clause to add it back if necessary
     if ($typechanged || $lengthchanged) {
         $results = array_merge($results, $this->getCreateDefaultSQL($xmldb_table, $xmldb_field));
     }
     /// Return results
     return $results;
 }
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:48,代码来源:mssql.class.php

示例4: isset

    $default = isset($value['default']) ? $value['default'] : '';
    $default = is_numeric($default) ? $default : strpos($default, "'") !== false ? $default : "'{$default}'";
    $s_type_options = $s_num_options = '';
    column_type($s_type_options, $s_num_options, $type, $num);
    $template->assign_block_vars('columns', array('TABLE' => isset($value['table']) ? $value['table'] : '', 'ITEM' => $key + 1, 'NAME' => isset($value['name']) ? $value['name'] : '', 'TYPE_OPTIONS' => $s_type_options, 'TYPE' => $type, 'NUM_OPTIONS' => $s_num_options, 'NUM' => $num, 'DEFAULT' => $default, 'OPTION' => isset($value['option']) ? ' checked="checked"' : ''));
}
foreach ($table_add as $key => $value) {
    if (!contains_data($value, array('name', 'type'), $table_name)) {
        continue;
    }
    $type = isset($value['type']) ? $value['type'] : '';
    $num = isset($value['num']) ? $value['num'] : 0;
    $default = isset($value['default']) ? $value['default'] : '';
    $default = is_numeric($default) ? $default : strpos($default, "'") !== false ? $default : "'{$default}'";
    $s_type_options = $s_num_options = '';
    column_type($s_type_options, $s_num_options, $type, $num);
    $template->assign_block_vars('table', array('ITEM' => $key + 1, 'NAME' => isset($value['name']) ? $value['name'] : '', 'TYPE_OPTIONS' => $s_type_options, 'TYPE' => strpos($type, '%d') !== false ? $type . (int) $num : $type, 'NUM_OPTIONS' => $s_num_options, 'NUM' => $num, 'DEFAULT' => $default, 'OPTION' => isset($value['option']) ? ' checked="checked"' : ''));
}
foreach ($table_keys as $key => $value) {
    if (!contains_data($value, array('index', 'type', 'column'))) {
        continue;
    }
    $type = isset($value['type']) ? $value['type'] : '';
    if ($type == 'PRIMARY' && $submit) {
        $template->assign_block_vars('primary_keys', array('MULTIPLE_KEYS' => isset($value['column2']) ? true : false, 'COLUMN' => isset($value['column']) ? $value['column'] : '', 'COLUMN2' => isset($value['column2']) ? $value['column2'] : ''));
    }
    $template->assign_block_vars('table_keys', array('ITEM' => $key + 1, 'INDEX' => isset($value['index']) ? $value['index'] : '', 'TYPE' => $type, 'TYPE_OPTIONS' => index_type($type), 'COLUMN' => isset($value['column']) ? $value['column'] : '', 'COLUMN2' => isset($value['column2']) ? $value['column2'] : ''));
}
foreach ($index_add as $key => $value) {
    if (!contains_data($value, array('table', 'index', 'column'))) {
        continue;
开发者ID:phpbb,项目名称:umil,代码行数:31,代码来源:create.php

示例5: explode

         }
         # Adding the column to the structure table
         $alter_queries[] = "\tADD COLUMN `" . $column->name . "` " . $column->type . $column->default . $column->comment . $column->position;
     }
     break;
     # Changing a column
 # Changing a column
 case 'modify':
     # Making sure we do have the column
     if (isset($exist_data['COLUMN_NAME'])) {
         # Sanatizing the columns
         $column->default = $column->default == 'CURRENT_TIMESTAMP' ? 'CURRENT_TIMESTAMP' : (isset($column->default) && $column->default != '' ? $column->default : "");
         $column->rename = !in_array($column->name, explode(',', NQ_LOCKED_FIELDS)) && isset($column->rename) && $column->rename != '' ? $column->rename : $column->name;
         $renamed = $column->rename;
         $column->rename = "`" . mysqli_escape_string($G_CONTROLLER_DBLINK, $column->rename) . "` ";
         $column->type = column_type($column->type, $column->length, $column->values, $G_CONTROLLER_DBLINK) . " NOT NULL ";
         $column->is_bit = substr($column->type, 0, 3) == 'BIT' ? 'b' : '';
         $column->default = isset($column->default) && $column->default != '' ? " DEFAULT " . $column->is_bit . (substr($column->type, 0, 3) == 'BIT' ? boolval_ext($column->default) ? "'1'" : "'0'" : '"' . $column->default . '"') . " " : '';
         $column->comment = isset($column->comment) ? "COMMENT '" . mysqli_escape_string($G_CONTROLLER_DBLINK, $column->comment) . "'" : '';
         # Positioning the
         if (isset($column->position)) {
             if (strtolower($column->position) == 'first') {
                 $column->position = ' FIRST';
             } elseif (strtolower($column->position) == 'after' && isset($column->position_column)) {
                 $column->position = ' AFTER `' . str_replace('`', '', $column->position_column) . '`';
             }
         }
         # Altering the column in the structure table
         $alter_queries[] = "\tCHANGE COLUMN `" . $column->name . "` " . $column->rename . $column->type . $column->default . $column->comment . $column->position;
     }
     break;
开发者ID:nuQuery,项目名称:v1m0-api-all,代码行数:31,代码来源:table.php

示例6: getAlterFieldSQL

 /**
  * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to alter the field in the table
  * Oracle has some severe limits:
  *     - clob and blob fields doesn't allow type to be specified
  *     - error is dropped if the null/not null clause is specified and hasn't changed
  *     - changes in precision/decimals of numeric fields drop an ORA-1440 error
  */
 function getAlterFieldSQL($xmldb_table, $xmldb_field)
 {
     global $db;
     $results = array();
     /// To store all the needed SQL commands
     /// Get the quoted name of the table and field
     $tablename = $this->getTableName($xmldb_table);
     $fieldname = $this->getEncQuoted($xmldb_field->getName());
     /// Take a look to field metadata
     $meta = array_change_key_case($db->MetaColumns($tablename));
     $metac = $meta[$fieldname];
     $oldtype = strtolower($metac->type);
     $oldmetatype = column_type($xmldb_table->getName(), $fieldname);
     $oldlength = $metac->max_length;
     /// To calculate the oldlength if the field is numeric, we need to perform one extra query
     /// because ADOdb has one bug here. http://phplens.com/lens/lensforum/msgs.php?id=15883
     if ($oldmetatype == 'N') {
         $uppertablename = strtoupper($tablename);
         $upperfieldname = strtoupper($fieldname);
         if ($col = get_record_sql("SELECT cname, precision\n                                   FROM col\n                                   WHERE tname = '{$uppertablename}'\n                                     AND cname = '{$upperfieldname}'")) {
             $oldlength = $col->precision;
         }
     }
     $olddecimals = empty($metac->scale) ? null : $metac->scale;
     $oldnotnull = empty($metac->not_null) ? false : $metac->not_null;
     $olddefault = empty($metac->default_value) || strtoupper($metac->default_value) == 'NULL' ? null : $metac->default_value;
     $typechanged = true;
     //By default, assume that the column type has changed
     $precisionchanged = true;
     //By default, assume that the column precision has changed
     $decimalchanged = true;
     //By default, assume that the column decimal has changed
     $defaultchanged = true;
     //By default, assume that the column default has changed
     $notnullchanged = true;
     //By default, assume that the column notnull has changed
     $from_temp_fields = false;
     //By default don't assume we are going to use temporal fields
     /// Detect if we are changing the type of the column
     if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER && substr($oldmetatype, 0, 1) == 'I' || $xmldb_field->getType() == XMLDB_TYPE_NUMBER && $oldmetatype == 'N' || $xmldb_field->getType() == XMLDB_TYPE_FLOAT && $oldmetatype == 'F' || $xmldb_field->getType() == XMLDB_TYPE_CHAR && substr($oldmetatype, 0, 1) == 'C' || $xmldb_field->getType() == XMLDB_TYPE_TEXT && substr($oldmetatype, 0, 1) == 'X' || $xmldb_field->getType() == XMLDB_TYPE_BINARY && $oldmetatype == 'B') {
         $typechanged = false;
     }
     /// Detect if precision has changed
     if ($xmldb_field->getType() == XMLDB_TYPE_TEXT || $xmldb_field->getType() == XMLDB_TYPE_BINARY || $oldlength == -1 || $xmldb_field->getLength() == $oldlength) {
         $precisionchanged = false;
     }
     /// Detect if decimal has changed
     if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER || $xmldb_field->getType() == XMLDB_TYPE_CHAR || $xmldb_field->getType() == XMLDB_TYPE_TEXT || $xmldb_field->getType() == XMLDB_TYPE_BINARY || !$xmldb_field->getDecimals() || !$olddecimals || $xmldb_field->getDecimals() == $olddecimals) {
         $decimalchanged = false;
     }
     /// Detect if we are changing the default
     if ($xmldb_field->getDefault() === null && $olddefault === null || $xmldb_field->getDefault() === $olddefault || "'" . $xmldb_field->getDefault() . "'" === $olddefault) {
         //Equality with quotes because ADOdb returns the default with quotes
         $defaultchanged = false;
     }
     /// Detect if we are changing the nullability
     if ($xmldb_field->getNotnull() === $oldnotnull) {
         $notnullchanged = false;
     }
     /// If type has changed or precision or decimal has changed and we are in one numeric field
     ///     - create one temp column with the new specs
     ///     - fill the new column with the values from the old one
     ///     - drop the old column
     ///     - rename the temp column to the original name
     if ($typechanged || $oldmetatype == 'N' && ($precisionchanged || $decimalchanged)) {
         $tempcolname = $xmldb_field->getName() . '_alter_column_tmp';
         /// Prevent temp field to have both NULL/NOT NULL and DEFAULT constraints
         $this->alter_column_skip_notnull = true;
         $this->alter_column_skip_default = true;
         $xmldb_field->setName($tempcolname);
         /// Create the temporal column
         $results = array_merge($results, $this->getAddFieldSQL($xmldb_table, $xmldb_field));
         /// Copy contents from original col to the temporal one
         $results[] = 'UPDATE ' . $tablename . ' SET ' . $tempcolname . ' = ' . $fieldname;
         /// Drop the old column
         $xmldb_field->setName($fieldname);
         //Set back the original field name
         $results = array_merge($results, $this->getDropFieldSQL($xmldb_table, $xmldb_field));
         /// Rename the temp column to the original one
         $results[] = 'ALTER TABLE ' . $tablename . ' RENAME COLUMN ' . $tempcolname . ' TO ' . $fieldname;
         /// Mark we have performed one change based in temp fields
         $from_temp_fields = true;
         /// Re-enable the notnull and default sections so the general AlterFieldSQL can use it
         $this->alter_column_skip_notnull = false;
         $this->alter_column_skip_default = false;
         /// Dissable the type section because we have done it with the temp field
         $this->alter_column_skip_type = true;
         /// If new field is nullable, nullability hasn't changed
         if (!$xmldb_field->getNotnull()) {
             $notnullchanged = false;
         }
         /// If new field hasn't default, default hasn't changed
         if ($xmldb_field->getDefault() === null) {
//.........这里部分代码省略.........
开发者ID:Br3nda,项目名称:mahara,代码行数:101,代码来源:oci8po.class.php

示例7: getAlterFieldSQL

 /**
  * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to alter the field in the table
  */
 function getAlterFieldSQL($xmldb_table, $xmldb_field)
 {
     global $db;
     $results = array();
     /// To store all the needed SQL commands
     /// Get the quoted name of the table and field
     $tablename = $this->getTableName($xmldb_table);
     $fieldname = $this->getEncQuoted($xmldb_field->getName());
     /// Take a look to field metadata
     $meta = array_change_key_case($db->MetaColumns($tablename));
     $metac = $meta[$fieldname];
     $oldtype = strtolower($metac->type);
     $oldmetatype = column_type($xmldb_table->getName(), $fieldname);
     $oldlength = $metac->max_length;
     $olddecimals = empty($metac->scale) ? null : $metac->scale;
     $oldnotnull = empty($metac->not_null) ? false : $metac->not_null;
     $olddefault = empty($metac->has_default) ? null : strtok($metac->default_value, ':');
     $typechanged = true;
     //By default, assume that the column type has changed
     $lengthchanged = true;
     //By default, assume that the column length has changed
     /// Detect if we are changing the type of the column
     if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER && substr($oldmetatype, 0, 1) == 'I' || $xmldb_field->getType() == XMLDB_TYPE_NUMBER && $oldmetatype == 'N' || $xmldb_field->getType() == XMLDB_TYPE_FLOAT && $oldmetatype == 'F' || $xmldb_field->getType() == XMLDB_TYPE_CHAR && substr($oldmetatype, 0, 1) == 'C' || $xmldb_field->getType() == XMLDB_TYPE_TEXT && substr($oldmetatype, 0, 1) == 'X' || $xmldb_field->getType() == XMLDB_TYPE_BINARY && $oldmetatype == 'B') {
         $typechanged = false;
     }
     /// If the new (and old) field specs are for integer, let's be a bit more specific diferentiating
     /// types of integers. Else, some combinations can cause things like MDL-21868
     if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER && substr($oldmetatype, 0, 1) == 'I') {
         if ($xmldb_field->getLength() > 9) {
             // Convert our new lenghts to detailed meta types
             $newmssqlinttype = 'I8';
         } else {
             if ($xmldb_field->getLength() > 4) {
                 $newmssqlinttype = 'I';
             } else {
                 $newmssqlinttype = 'I2';
             }
         }
         if ($metac->type == 'bigint') {
             // Convert current DB type to detailed meta type (adodb metatype is buggy!)
             $oldmssqlinttype = 'I8';
         } else {
             if ($metac->type == 'smallint') {
                 $oldmssqlinttype = 'I2';
             } else {
                 $oldmssqlinttype = 'I';
             }
         }
         if ($newmssqlinttype != $oldmssqlinttype) {
             // Compare new and old meta types
             $typechanged = true;
             // Change in meta type means change in type at all effects
         }
     }
     /// Detect if we are changing the length of the column, not always necessary to drop defaults
     /// if only the length changes, but it's safe to do it always
     if ($xmldb_field->getLength() == $oldlength) {
         $lengthchanged = false;
     }
     /// If type or length have changed drop the default if exists
     if ($typechanged || $lengthchanged) {
         $results = $this->getDropDefaultSQL($xmldb_table, $xmldb_field);
     }
     /// Just prevent default clauses in this type of sentences for mssql and launch the parent one
     $this->alter_column_skip_default = true;
     $results = array_merge($results, parent::getAlterFieldSQL($xmldb_table, $xmldb_field));
     // Call parent
     /// Finally, process the default clause to add it back if necessary
     if ($typechanged || $lengthchanged) {
         $results = array_merge($results, $this->getCreateDefaultSQL($xmldb_table, $xmldb_field));
     }
     /// Return results
     return $results;
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:77,代码来源:mssql.class.php

示例8: sql

 /**
  * This takes a list of handlers, each of which corresponds to a particular type of
  * query (e.g. discussion forum), along with search fields for performing a search.
  * It returns the SQL query string.
  *
  * $searchAccess can be public, private, or empty.  Public annotations are available to
  *  *everyone*, not just course members or Moodle users.
  */
 function sql($orderby)
 {
     global $CFG, $USER;
     // The query is a UNION of separate queries, one for each type of annotation
     // This is unfortunate:  with a common table structure, one for parent-child
     // URL relationships, another with URL properties (title and owner would
     // suffice), would forgo UNIONs and simplify this code.
     // Users can only see their own annotations or the public annotations of others
     // This is an awfully complex combination of conditions.  I'm wondering if that's
     // a design flaw.
     $access_cond = null;
     $desc_users = '';
     // this was originally intended to allow more than one handler to respond to a request.
     // That may still be necessary someday, but perhaps a compound handler would be the
     // best way to respond to it.  I eliminated the handler list because YAGNI.
     $handler = $this->handler;
     // Conditions under which someone else's annotation would be visible to this user
     $access_visible = "a.access='public'";
     if (array_key_exists('username', $USER)) {
         $access_visible .= " OR a.userid='" . addslashes($USER->username) . "'" . " OR a.access like '%author%' AND a.quote_author='" . addslashes($USER->username) . "'";
         $handler->fetchMetadata();
         // Don't know how this should work due to changes between Moodle 1.6 and Moodle 1.8:
         //if ( $USER->teacher[ $handler->courseId ] )
         //	$access_visible .= " OR a.access like '%teacher%'";
     }
     // Filter annotations according to their owners
     if (null == $this->searchUser) {
         $access_cond = " ({$access_visible}) ";
     } elseif ('*students' == $this->searchUser) {
         $access_cond = " ({$access_visible}) AND a.userid in (" . "SELECT stu.username FROM mdl_user stu " . "INNER JOIN mdl_user_students AS sts ON stu.id=sts.userid " . "WHERE sts.course=" . $handler->courseId . ")";
     } elseif ('*teachers' == $this->searchUser) {
         $access_cond = " ({$access_visible}) AND a.userid in (" . "SELECT teu.username FROM mdl_user AS teu " . "INNER JOIN mdl_user_teachers tet ON teu.id=tet.userid " . "WHERE tet.course=" . $handler->courseId . ")";
     } else {
         if (!array_key_exists('username', $USER) || $USER->username != $this->searchUser) {
             $access_cond = "({$access_visible})";
         }
         if ($access_cond) {
             $access_cond .= ' AND ';
         }
         $access_cond .= "a.userid='" . addslashes($this->searchUser) . "'";
     }
     // These are the fields to use for a search;  specific annotations may add more fields
     $std_search_fields = array('a.note', 'a.quote', 'u.firstname', 'u.lastname');
     $prefix = $CFG->prefix;
     // Do handler-specific stuff
     // Check whether the range column exists (for backwards compatibility)
     $range = '';
     if (!column_type($CFG->prefix . 'annotation', 'range')) {
         $range = ', a.range AS range ';
     }
     // These that follow are standard fields, for which no page type exceptions can apply
     $q_std_select = "SELECT a.id AS id, a.url AS url, a.userid AS userid, " . "a.start_block, a.start_xpath, a.start_word, a.start_char, " . "a.end_block, a.end_xpath, a.end_word, a.end_char, " . "a.link AS link, a.link_title AS link_title, a.action AS action, " . "a.access AS access, a.created, a.modified {$range}" . ",\n concat(u.firstname, ' ', u.lastname) AS note_author" . ",\n concat('{$CFG->wwwroot}/user/view.php?id=',u.id) AS note_author_url" . ",\n a.note note, a.quote, a.quote_title AS quote_title" . ",\n concat(qu.firstname, ' ', qu.lastname) AS quote_author" . ",\n concat('{$CFG->wwwroot}/user/view.php?id=',qu.id) AS quote_author_url";
     // Standard tables apply to all (but note the outer join of user, which if gone
     // should not steal the annotation from its owner):
     $q_std_from = "\nFROM {$prefix}annotation AS a" . "\n INNER JOIN {$prefix}user u ON u.username=a.userid" . "\n LEFT OUTER JOIN {$prefix}user qu on qu.username=a.quote_author";
     // This search is always limited by access
     $q_std_where = "\nWHERE ({$access_cond})";
     // Searching limits also;  fields searched are not alone those of the annotation:
     // add to them also those a page of this type might use.
     if (null != $this->searchQuery && '' != $this->searchQuery) {
         $search_cond = '';
         $add_search_fields = $handler->getSearchFields();
         $search_cond = '';
         $queryWords = split(' ', $this->searchQuery);
         foreach ($queryWords as $word) {
             $sWord = addslashes($word);
             foreach ($std_search_fields as $field) {
                 $search_cond .= $search_cond == '' ? "{$field} LIKE '%{$sWord}%'" : " OR {$field} LIKE '%{$sWord}%'";
             }
             foreach ($add_search_fields as $field) {
                 $search_cond .= " OR {$field} LIKE '%{$sWord}%'";
             }
         }
         $q_std_where .= "\n   AND ({$search_cond})";
     }
     // The handler must construct the query, which might be a single SELECT or a UNION of multiple SELECTs
     $q = $handler->getSql($q_std_select, $q_std_from, $q_std_where, $orderby);
     return $q;
 }
开发者ID:njorth,项目名称:marginalia,代码行数:87,代码来源:AnnotationSummaryQuery.php

示例9: view

 function view()
 {
     global $CFG, $USER;
     $edit = optional_param('edit', 0, PARAM_BOOL);
     $saved = optional_param('saved', 0, PARAM_BOOL);
     $print = optional_param('print', 0, PARAM_BOOL);
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     require_capability('mod/assignment:view', $context);
     $submission = $this->get_submission();
     //We need to add an extra field to the submissions table, for feedback using video or audio
     //we check if it exists here, and if not we add it. Justin 20100324
     if ($submission) {
         if (!column_type('assignment_submissions', 'poodllfeedback')) {
             // add field to store media comments (audio or video) filename to students submissions
             $sql = "ALTER TABLE " . $CFG->prefix . "assignment_submissions ADD poodllfeedback TEXT";
             $result = execute_sql($sql);
         }
     }
     //Justin
     //Are we printing this or not
     if ($print) {
         if (TCPPDF_OLD) {
             require_once $CFG->libdir . '/tcpdf/tcpdf.php';
         } else {
             require_once $CFG->libdir . '/newtcpdf/tcpdf.php';
         }
         $pdf = new tcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
         // remove default header/footer
         //old version of tcppdf
         if (TCPPDF_OLD) {
             $pdf->print_header = false;
             $pdf->print_footer = false;
         } else {
             //new version of tcppdf
             $pdf->setPrintHeader(false);
             $pdf->setPrintFooter(false);
         }
         //set margins
         $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
         //set auto page breaks
         $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
         $pdf->setFont('freeserif', '', 10);
         //make page
         $pdf->AddPage();
         //prepare html content
         $options = new object();
         $options->smiley = false;
         $options->filter = false;
         $strHtml = format_text($submission->data1, FORMAT_HTML, $options);
         //print the thing
         $pdf->writeHTML($strHtml, true, 0, true, 0);
         //The I is for inline, meaning tell the browser to shopw not download it.
         $pdf->output('document.pdf', 'I');
         //$pdf->output();
         return;
     }
     //Guest can not submit nor edit an assignment (bug: 4604)
     if (!has_capability('mod/assignment:submit', $context)) {
         $editable = null;
     } else {
         $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
     }
     //modify Justin 20090305, we don't want to add this extra step for users.
     //If they can edit, and they haven't submitted anything, then lets just show the form.
     //If they have submitted something, lets give them an extra step if ytthey want to submit
     //to protect accidental overwrite of their submission.
     // $editmode = ($editable and $edit);
     $editmode = ($editable and !$submission || $edit);
     if ($editmode) {
         //guest can not edit or submit assignment
         if (!has_capability('mod/assignment:submit', $context)) {
             print_error('guestnosubmit', 'assignment');
         }
     }
     add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
     /// prepare form and process submitted data
     //load it with some info it needs to determine the params for chosho recorder.
     //for voice then text, we need to know if we already have voice or not
     if (empty($submission)) {
         $mediapath = "";
     } else {
         $mediapath = $submission->data2;
     }
     $mform = new mod_assignment_poodllonline_edit_form(null, array("cm" => $this->cm, "assignment" => $this->assignment, "mediapath" => $mediapath));
     $defaults = new object();
     $defaults->id = $this->cm->id;
     if (!empty($submission)) {
         //we always use html editor: Justin 20090225
         //if ($this->usehtmleditor) {
         if (true) {
             $options = new object();
             $options->smiley = false;
             $options->filter = false;
             $defaults->text = format_text($submission->data1, FORMAT_HTML, $options);
             $defaults->format = FORMAT_HTML;
         } else {
             $defaults->text = $submission->data1;
             $defaults->format = $submission->data2;
         }
     }
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:poodll,代码行数:101,代码来源:assignment.class.php

示例10: post_check_14

function post_check_14()
{
    global $dbh;
    $coltype = column_type("maia_mail", "contents");
    if (is_mysql()) {
        $desired_type = 'longblob';
    } else {
        $desired_type = 'bytea';
    }
    if ($coltype != $desired_type) {
        return array(false, "Column 'contents' is still type " . strtoupper($coltype));
    } else {
        return array(true, "");
    }
}
开发者ID:einheit,项目名称:mailguard_legacy,代码行数:15,代码来源:14.php


注:本文中的column_type函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。