Skip to content

Instantly share code, notes, and snippets.

View crisu83's full-sized avatar
🎩
Coding

Christoffer Niska crisu83

🎩
Coding
View GitHub Profile
<?php
/**
* TbThumbnails class file.
* @author Christoffer Niska <christoffer.niska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.widgets
*/
Yii::import('bootstrap.widgets.TbListView');
@crisu83
crisu83 / ModelGroupForm.php
Last active December 12, 2015 06:38
Yii form model that allows for using multiple models in the same form.
<?php
/**
* Class ModelGroupForm
*
* Note! Attributes must be defined as "modelName.attributeName", e.g. "user.name" in forms.
*/
class ModelGroupForm extends CFormModel {
/**
* @var CModel[] $models the model instances (name=>config).
@crisu83
crisu83 / global.php
Created February 18, 2013 14:46
Global shorthand functions for commonly used Yii methods.
<?php
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
/**
* Returns the application instance.
* @return CWebApplication
*/
function app() {
return Yii::app();
@crisu83
crisu83 / namespaceInputIDIssue.php
Last active December 13, 2015 22:48
Namespaces and input ID selector issue.
<?php
// Attribute id:
frontend\models\UserRegisterForm_profile:availabilityDate
// jQuery selector before escaping:
#frontend\models\UserRegisterForm_profile:availabilityDate
// jQuery selector after escaping using the snippet below:
frontend\\\\models\\\\UserRegisterForm_profile\\:availabilityDate
@crisu83
crisu83 / ConfigBuilder.php
Last active December 13, 2015 23:09
Helper for building Yii application configurations.
<?php
/**
* ConfigBuilder class file.
* @author Christoffer Niska <christoffer.niska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/
/**
* Helper for building application configurations.
@crisu83
crisu83 / Hijo.php
Last active December 13, 2015 23:19
Random recursive method.
<?php
public function buildMenuRecursive($parentID = 0) {
$result = array();
$menus = Menus::model()->getMenusUsuarios($parentID);
foreach ($menus as $key => $value) {
$result[$key] = array(
'name' => $value['title'],
'link' => $value['url'] ? Yii::app()->createUrl($value['url']) : '',
'visible' => $value['status'],
@crisu83
crisu83 / Facebook.php
Created February 19, 2013 23:01
Facebook application component for Yii.
<?php
/**
* FacebookConnect class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/
/**
* Facebook connection application component.
<?php
/**
* @return array the behavior configurations (behavior name=>behavior configuration)
*/
public function behaviors() {
return array(
'audit' => array('class' => 'common.extensions.audit.behaviors.AuditBehavior'),
'image' => array('class' => 'vendor.crisu83.yii-image.behaviors.ImageBehavior'),
);
@crisu83
crisu83 / DateFormatterBehavior.php
Created February 28, 2013 08:24
Active record behavior for automatic formatting of date columns.
<?php
class DateFormatterBehavior extends CActiveRecordBehavior {
const WIDTH_SHORT = 'short';
const WIDTH_MEDIUM = 'medium';
const WIDTH_LONG = 'long';
public $dates = array();
public function afterFind($event) {
@crisu83
crisu83 / AuditBehavior.php
Created February 28, 2013 08:38
Audit active record behavior.
<?php
require(__DIR__ . '/../models/AuditAttribute.php');
require(__DIR__ . '/../models/AuditModel.php');
class AuditBehavior extends CActiveRecordBehavior {
// Audit actions
const ACTION_CREATE = 'create';
const ACTION_DELETE = 'delete';