Example #1
0
 public function loadColumns()
 {
     $sql = 'SHOW COLUMNS FROM `' . $this->getTableName() . '`';
     $result = $this->query($sql);
     while ($row = mysql_fetch_assoc($result)) {
         $column = new SchemaColumn();
         $column->setTable($this);
         $column->setColumnName($row['Field']);
         $column->setIsNullAllowed(strtolower($row['Null']) == 'yes');
         $column->setDefaultValue($row['Default']);
         // value from MySQL will be PHP null, false, true, or a string
         $column->setIsPrimaryKey($row['Key'] == 'PRI');
         // Set type and size of column
         $typePieces = preg_split('/[\\(\\)]/', $row['Type']);
         $column->setType($typePieces[0]);
         if (count($typePieces) > 1) {
             $column->setSize($typePieces[1]);
         }
         $this->addColumn($column);
     }
     $sql = 'SHOW CREATE TABLE `' . $this->getTableName() . '`';
     $result = $this->query($sql);
     while ($row = mysql_fetch_assoc($result)) {
         if (isset($row['Create Table'])) {
             $this->parseCreateStatement($row['Create Table']);
         }
     }
 }
	/**
	 * Get an array of the form element attributes for this column.
	 *
	 * @return array
	 */
	public function getFormElementAttributes(){
		$na = parent::getFormElementAttributes();

		$na['options'] = ['yes' => t('STRING_YES'), 'no' => t('STRING_NO')];

		return $na;
	}
	/**
	 * Get an array of the form element attributes for this column.
	 *
	 * @return array
	 */
	public function getFormElementAttributes(){
		if($this->formAttributes['type'] == 'datetime'){
			$defaults = [ 
				'datetimepicker_dateformat' => 'yy-mm-dd',
				'datetimepicker_timeformat' => 'HH:mm',
				'displayformat' => 'Y-m-d H:i',
				'saveformat' => 'U',
			];
		}
		else{
			$defaults = [];
		}
		
		$na = parent::getFormElementAttributes();
		
		return array_merge($defaults, $na);
	}
	/**
	 * Get an array of the form element attributes for this column.
	 *
	 * @return array
	 */
	public function getFormElementAttributes(){
		$na = parent::getFormElementAttributes();
		
		// Add special functionality here to allow passing in "this" as a valid reference for the "source" attribute.
		// This will allow the instantiated Model object as a whole to be used as a reference when retrieving options.
		if(isset($na['source'])){
			if(strpos($na['source'], 'this::') === 0){
				$na['source'] = [$this->parent, substr($na['source'], 6)];
			}
		}
		elseif(!isset($na['options'])){
			$opts = $this->options;
			if($this->null){
				$opts = array_merge(['' => '-- Select One --'], $opts);
			}
			$na['options'] = $opts;
		}

		return $na;
	}
Example #5
0
 /**
  * Set a column
  *
  * @param SchemaColumn $column
  */
 public function setColumn($column)
 {
     $this->columns[$column->getName()] = $column;
 }
Example #6
0
 private function getDefaultValueStringForColumn(SchemaColumn $column)
 {
     $defaultValue = $column->getDefaultValue();
     if (in_array(strtolower($column->getType()), array('int', 'tinyint'))) {
         if ($defaultValue === null) {
             return 'null';
         } else {
             if (strlen($defaultValue) == 0) {
                 return '""';
             } else {
                 return $defaultValue;
             }
         }
     } else {
         return $this->getStringFromPhpValue($defaultValue);
     }
 }
Example #7
0
 /**
  * Is equals foreign to another column?
  *
  * @param SchemaColumn $c
  * @return bool
  */
 public function equalsForeign(SchemaColumn $c)
 {
     return $this->getForeignTable() == $c->getForeignTable() && $this->getForeignColumn() == $c->getForeignColumn();
     /*
     && $this -> getForeignDelete() == $c -> getForeignDelete()
     && $this -> getForeignUpdate() == $c -> getForeignUpdate();
     */
 }