/** * * Connect to the database. * * @param array $data the data to connect the database. * @param string $login the login (if not provided in the $data array) * @param string $password the password (if not provided in the $data array) * @throws DAOException a DAOException (or a SQLException). */ protected function connect($data, $login = null, $password = null) { if (!is_array($data)) { // Apply as an array $data = ['dsn' => $data]; } try { $dsn = $data['dsn']; $this->db = parent::connect($data, $login, $password); if (Concerto\std::beginsWith($dsn, "mysql:")) { $this->converter = new MySQLConverter(); } else { $this->log("Unknown database converter -- using basic converter instead"); $this->converter = new BasicConverter(); } } catch (SQLException $e) { throw new DAOException("Can not connect to database.", SQL::CONNECT_ERROR, $e); } }
/** * Convert a DateTime (or a timestamp) into a SQL * DATE compatible value. * * @param DateTime $ts the date to convert. NULL * will use the current date. */ public function sqltime($ts) { $ts = \Concerto\std::timestamp($ts); return $this->sqlstr(date("H:i:s", $ts)); }
/** * * @param string $text the text to ellipsis * @param int $max_length the maximum length you accept. */ public static function ellipsis($text, $max_length) { if ($max_length < 10) { $max_length = 10; } if (std::len($text) > $max_length) { $text = mb_substr($text, 0, $max_length - 5, 'utf-8'); $text = trim($text); $text .= "..."; } return $text; }
protected function encapsule($btns) { $ret = ""; if ($this->mode == self::HORIZONTAL) { $ret .= std::tagln("div", ['class' => "form-group"]); $ret .= std::tag('div', array('class' => $this->horiz_label_class)) . " </div>\n"; $ret .= std::tagln('div', array('class' => $this->horiz_field_class)) . "{$btns}</div>\n"; $ret .= "</div>\n"; } else { $ret .= $btns; } return $ret; }
/** * Retrieve or compute the label of the column. * * @param string $k the key (property name) of the column. * @param DBColumn $col the column itself * @return the label for this column. * */ protected function getLabel($k, $col) { $info = std::capitalizeFirst($k); if ($col->getLabel()) { $info = $col->getLabel(); } return $info; }