Skip to content

Instantly share code, notes, and snippets.

@romaninsh
Created April 8, 2013 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romaninsh/5335964 to your computer and use it in GitHub Desktop.
Save romaninsh/5335964 to your computer and use it in GitHub Desktop.
Example of hierarchy add-on use in agile toolkit
<?php
class View_CommentTree extends hierarchy\View_Tree {
function init(){
parent::init();
$this->time_ctl=$this->add('Controller_RoundTiming');
}
function formatRow(){
$this->current_row['added']=$this->time_ctl->fancy_datetime($this->current_row['added']).' ago';
$this->current_row_html['descr']=nl2br($this->makeUrls($this->current_row['descr']));
$this->current_row_html['profile_link']=
$this->api->url('profile/'.$this->current_row['profile_id'],array('endowment_id'=>null));
}
function renderModel($m){
$el=$m->leftJoin('element','profile_id');
$el->addField('profile_name','name');
$image=$m->add('filestore/Field_Image', array(
'name'=>'owner_picture_id',
'use_model'=>'Image_Element'
))->from($el)->actual('picture_id');
$image
->addThumb('thumb', 'thumb_64')
;
return parent::renderModel($m);
}
function makeUrls($text) {
$text = preg_replace(
array(
'/((https:\/\/|http:\/\/)\S*)/',
'/(\s)((www.)\S*)/',
),
array(
'<a href="$1" target="_blank">$0</a>',
'$1<a href="http://$2" target="_blank">$2</a>',
),
$text
);
return $text;
}
}
@romaninsh
Copy link
Author

Model definition:

    $this->setController('hierarchy/Table')->useField('parent_comment_id');
    $this->hasOne('Element')->mandatory(true)->caption('Commented on');
    $this->hasOne('Profile','profile_id')->mandatory(true)->caption('Author');

    $this->addField('descr')->type('text');
    $this->addField('added')->defaultValue(date('Y-m-d H:i:s'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment