Permalink
Browse files

Enhance codepad adn add 2 example sub-pojects

  • Loading branch information...
1 parent c760fdb commit f09263ad302a33d1002090e0dea9ca83e8a682b9 @romaninsh romaninsh committed Jun 12, 2012
View
136 doc/dbupdates/codepad.001.sql
@@ -0,0 +1,136 @@
+-- MySQL dump 10.13 Distrib 5.5.9, for osx10.6 (i386)
+--
+-- Host: localhost Database: codepad
+-- ------------------------------------------------------
+-- Server version 5.5.9
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `library_staff`
+--
+
+DROP TABLE IF EXISTS `library_staff`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `library_staff` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `library_staff`
+--
+
+LOCK TABLES `library_staff` WRITE;
+/*!40000 ALTER TABLE `library_staff` DISABLE KEYS */;
+INSERT INTO `library_staff` VALUES (1,'Dennis Ritchie'),(2,'Will Smith');
+/*!40000 ALTER TABLE `library_staff` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `library_member`
+--
+
+DROP TABLE IF EXISTS `library_member`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `library_member` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) DEFAULT NULL,
+ `card_number` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `library_member`
+--
+
+LOCK TABLES `library_member` WRITE;
+/*!40000 ALTER TABLE `library_member` DISABLE KEYS */;
+INSERT INTO `library_member` VALUES (1,'Joe Blogs','029982'),(2,'Ken Thompson','00777');
+/*!40000 ALTER TABLE `library_member` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `library_book`
+--
+
+DROP TABLE IF EXISTS `library_book`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `library_book` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) DEFAULT NULL,
+ `issn` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `library_book`
+--
+
+LOCK TABLES `library_book` WRITE;
+/*!40000 ALTER TABLE `library_book` DISABLE KEYS */;
+INSERT INTO `library_book` VALUES (1,'Adaptation as Compendium: Tim Burton\'s Alice in Wonderland','1755-0637'),(2,'The Ultimate Hitchhiker\'s Guide to the Galaxy','0345391802');
+/*!40000 ALTER TABLE `library_book` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `library_borrowing`
+--
+
+DROP TABLE IF EXISTS `library_borrowing`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `library_borrowing` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `library_book_id` int(11) NOT NULL,
+ `library_member_id` int(11) NOT NULL,
+ `verified_by` int(11) NOT NULL,
+ `borrowed` date DEFAULT NULL,
+ `is_returned` varchar(255) DEFAULT NULL,
+ `returned` date DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `fk_library_borrowing_book1` (`library_book_id`),
+ KEY `fk_library_borrowing_library_member1` (`library_member_id`),
+ KEY `fk_library_borrowing_library_staff1` (`verified_by`),
+ CONSTRAINT `fk_library_borrowing_book1` FOREIGN KEY (`library_book_id`) REFERENCES `library_book` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
+ CONSTRAINT `fk_library_borrowing_library_member1` FOREIGN KEY (`library_member_id`) REFERENCES `library_member` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
+ CONSTRAINT `fk_library_borrowing_library_staff1` FOREIGN KEY (`verified_by`) REFERENCES `library_staff` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `library_borrowing`
+--
+
+LOCK TABLES `library_borrowing` WRITE;
+/*!40000 ALTER TABLE `library_borrowing` DISABLE KEYS */;
+INSERT INTO `library_borrowing` VALUES (2,1,1,1,'2012-06-12','1','2012-06-12'),(4,2,2,1,'2012-06-12','1','2012-06-12'),(5,2,1,1,'2012-06-12','0',NULL);
+/*!40000 ALTER TABLE `library_borrowing` ENABLE KEYS */;
+UNLOCK TABLES;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2012-06-12 2:38:09
View
5 example/learn1/config-default.php
@@ -0,0 +1,5 @@
+<?php
+
+$config['atk']['base_path']='/codepad/atk4/';
+$config['url_postfix']='';
+$config['url_prefix']='?page=';
View
4 example/learn1/index.php
@@ -0,0 +1,4 @@
+<?php
+include '../../atk4/loader.php';
+$api=new Frontend('learn1');
+$api->main();
View
12 example/learn1/lib/Frontend.php
@@ -0,0 +1,12 @@
+<?php
+class Frontend extends ApiFrontend {
+ function init(){
+ parent::init();
+
+ $this->add('jUI');
+
+ $menu=$this->add('Menu',null,'Menu');
+ $menu->addMenuItem('register');
+
+ }
+}
View
22 example/learn1/page/register.php
@@ -0,0 +1,22 @@
+<?php
+class page_register extends Page {
+ function init(){
+ parent::init();
+
+ $form = $this->add('Form');
+ $form->addField('line','email');
+ $form->addField('password','password');
+ $form->addSubmit();
+ $form->addButton('Cancel')->js('click')
+ ->univ()->location($this->api->url('/'));
+
+ if($form->isSubmitted()){
+ $form->js()->univ()->alert('Thank you, '.$form->get('email').
+ ', but this example is not ready yet')->execute();
+
+ }
+ }
+ function defaultTemplate(){
+ return array('page/register');
+ }
+}
View
15 example/learn1/templates/default/page/index.html
@@ -0,0 +1,15 @@
+<p>
+ This is your first Agile Toolkit application. It may contain static page just like a regular site.
+</p>
+
+
+<p>
+ Inside a static page you may use <b>HTML</b> and it will be passed to the frontend-unmodified
+</p>
+
+<div class="atk-notification ui-state-highlight ui-corner-all ">
+ <div class="atk-notification-text">
+ <i class="ui-icon ui-icon-info"></i>You may take advantage of a jQuery UI
+ ThemeRoller and Agile Toolkit CSS Frameworks!
+ </div>
+</div>
View
12 example/learn1/templates/default/page/register.html
@@ -0,0 +1,12 @@
+<h1>Registration form</h1>
+<div id="<?$_name?>" class="atk-row">
+ <div class="span8">
+ <?$Content?>
+ </div><div class="span4">
+ <div class="atk-notification ui-state-highlight ui-corner-all ">
+ <div class="atk-notification-text">
+ <i class="ui-icon ui-icon-info"></i>You must apply for new account before you can use this application.
+ </div>
+ </div>
+</div>
+</div>
View
5 example/learn2/index.php
@@ -0,0 +1,5 @@
+<?php
+// This is a standard catch-all file
+include '../../atk4/loader.php';
+$api=new Frontend('learn1');
+$api->main();
View
33 example/learn2/lib/Frontend.php
@@ -0,0 +1,33 @@
+<?php
+class Frontend extends ApiFrontend {
+ function init(){
+ parent::init();
+
+ // Add jQuery UI and connect to database
+ $this->add('jUI');
+ $this->dbConnect();
+
+ // Creates menu on top
+ $menu=$this->add('Menu',null,'Menu');
+ $menu->addMenuItem('books');
+ $menu->addMenuItem('members');
+ $menu->addMenuItem('staff');
+ $menu->addMenuItem('history');
+ }
+
+ function page_index(){
+ $this->add('View_Info')->set('This example data is available for public edit. If you find that content on the pages is empty or is vandalized, please click this button to re-initialize database');
+ if($this->add('Button')->set('Reset Database')->isClicked()){
+ $this->db->query('delete from library_borrowing');
+ $this->db->query('delete from library_book');
+ $this->db->query('delete from library_member');
+ $this->db->query('delete from library_staff');
+ $this->db->query("INSERT INTO `library_book` VALUES (1,'Adaptation as Compendium: Tim Burton\'s Alice in Wonderland','1755-0637'),(2,'The Ultimate Hitchhiker\'s Guide to the Galaxy','0345391802')");
+ $this->db->query("INSERT INTO `library_member` VALUES (1,'Joe Blogs','029982'),(2,'Ken Thompson','00777')");
+ $this->db->query("INSERT INTO `library_staff` VALUES (1,'Dennis Ritchie'),(2,'Will Smith')");
+ $this->db->query("INSERT INTO `library_borrowing` VALUES (2,1,1,1,'2012-06-12','1','2012-06-12'),(4,2,2,1,'2012-06-12','1','2012-06-12'),(5,2,1,1,'2012-06-12','0',NULL)");
+ $this->js()->univ()->successMessage('Database cleaned up successfully')->execute();
+ }
+
+ }
+}
View
18 example/learn2/lib/Model/Book.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Base class implementing book
+ */
+class Model_Book extends Model_Table {
+ public $table="library_book";
+ function init(){
+ parent::init();
+
+ $this->addField('name');
+ $this->addField('issn')->sortable(true);
+
+ // hasMany does not impact logic or performance of the model
+ // so we can have multiple in here.
+ $this->hasMany('Borrowing');
+ $this->hasMany('Borrower');
+ }
+}
View
15 example/learn2/lib/Model/BookAvailable.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * A dedicated model for books which are available to borrow
+ */
+class Model_BookAvailable extends Model_Book {
+ function init(){
+ parent::init();
+
+ // We must select books which are either never been borrowed or have been returned
+ $f=$this->join('library_borrowing.library_book_id',null,'left')->addField('is_returned')->system(true);
+
+ // Now that our relation is defined we can add custom condition with the OR clause.
+ $this->addCondition($this->dsql()->orExpr()->where($f,'is',null)->where($f,'1'));
+ }
+}
View
27 example/learn2/lib/Model/Borrower.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Models can be defined in either way and can be based on as many tables as you wish. Borrower shows
+ * members which currently have got some books
+ */
+class Model_Borrower extends Model_Member {
+ public $b;
+ function init(){
+ parent::init();
+
+ $this->b=$this->join('library_borrowing.library_member_id');
+
+ $this->b->hasOne('Staff','verified_by');
+ $this->b->addField('borrowed');
+ $this->b->addField('is_returned');
+ $this->b->addField('returned');
+
+ $this->b->join('library_book')->addField('book_name','name');
+
+ // Showing only if borrowed
+ //$this->addCondition('is_returned',false);
+
+ // We don't want anyone to accidentally insert into this model as it will impact both
+ // joined tables, so we create validation to avoid that.
+ $this->addHook('beforeInsert',function($m){ throw $m->exception('Do not add borrower directly');});
+ }
+}
View
22 example/learn2/lib/Model/Borrowing.php
@@ -0,0 +1,22 @@
+<?php
+class Model_Borrowing extends Model_Table {
+ public $table="library_borrowing";
+ function init(){
+ parent::init();
+
+ $this->hasOne('Book');
+ $this->hasOne('Member');
+ $this->hasOne('Staff','verified_by');
+
+ $this->addField('borrowed')->type('date')->defaultValue(date('Y-m-d'));
+
+ $this->addField('is_returned')->type('boolean')->defaultValue(false);
+ $this->addField('returned')->type('date');
+ }
+ function returnBook(){
+ if($this['is_returned'])throw $this->exception('Book was already returned');
+ $this['is_returned']=true;
+ $this['returned']=date('Y-m-d');
+ return $this->save();
+ }
+}
View
11 example/learn2/lib/Model/BorrowingNow.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Anohter handy model which shows only current borrowings
+ */
+class Model_BorrowingNow extends Model_Borrowing {
+ function init(){
+ parent::init();
+
+ $this->addCondition('is_returned',false);
+ }
+}
View
17 example/learn2/lib/Model/Member.php
@@ -0,0 +1,17 @@
+<?php
+class Model_Member extends Model_Table {
+ public $table="library_member";
+ function init(){
+ parent::init();
+
+ $this->addField('name');
+ $this->addField('card_number');
+
+ // We can define theese only if we plan to reference them. While it makes sense to see curent
+ // member's borrowed book, there is no need to see all the preious borrowings, so i commented
+ // that relation
+
+ //$this->hasMany('Borrowing');
+ $this->hasMany('BorrowingNow');
+ }
+}
View
13 example/learn2/lib/Model/Staff.php
@@ -0,0 +1,13 @@
+<?php
+class Model_Staff extends Model_Table {
+ public $table="library_staff";
+ function init(){
+ parent::init();
+
+ $this->addField('name');
+
+ // Reference for showing books issued by that member of staff. Consider this your practice excercise
+ // to create a page which would show all the books which were issued by a certain member
+ $this->hasMany('Borrowing');
+ }
+}
View
22 example/learn2/page/books.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Showing list of books
+ */
+class page_books extends Page {
+ function init(){
+ parent::init();
+
+ // Will show 2 tabs on a page, one for all books, other for books available to borrow
+ $tt=$this->add('Tabs');
+
+ $cr=$tt->addTab('All')->add('CRUD');
+ $cr->setModel('Book');
+ if($cr->grid)$cr->grid->addQuickSearch(array('name','issn'));
+
+ $cr=$tt->addTab('Available to Borrow')->add('CRUD');
+ $cr->setModel('BookAvailable');
+ if($cr->grid)$cr->grid->addQuickSearch(array('name','issn'));
+
+ // We also include quicksearch for easier search
+ }
+}
View
11 example/learn2/page/history.php
@@ -0,0 +1,11 @@
+<?php
+class page_history extends Page {
+ function init(){
+ parent::init();
+
+ // Simply display contents of a model with pagination
+ $grid=$this->add('Grid');
+ $grid->setModel('Borrower');
+ $grid->addPaginator();
+ }
+}
View
110 example/learn2/page/members.php
@@ -0,0 +1,110 @@
+<?php
+class page_members extends Page {
+
+ // This page consists of 3 sub-pages. I placed them in the same file for easire access.
+
+ function page_index(){
+
+ $m=$this->add('Model_Member');
+
+ // Dynamically add expression showing number of currently borrowed books by member
+ $m->addExpression('books')->set($m->refSQL('BorrowingNow')->count())
+ ->caption('Borrowed');
+
+ // Add CRUD for managing members
+ $cr=$this->add('CRUD');
+ $cr->setModel($m);
+
+ // Enhance CRUD
+ if($cr->grid){
+
+ // Add quick-search by name and issn and also convert 'Borrowed' column into expander
+ $cr->grid->addQuickSearch(array('name','issn'));
+ $cr->grid->addFormatter('books','expander');
+
+ // Add button allowing for a member to borrow a book
+ $cr->grid->addColumn('button','borrow');
+
+ // Grid's button will execute AJAX request with borrow=<id>
+ if($_GET['borrow']){
+
+ // Get the name of currently selected member
+ $name = $cr->grid->model->load($_GET['borrow'])->get('name');
+
+ // Open frame with member's name in the title. Load content through AJAX from subpage
+ $this->js()->univ()->frameURL('New borrowing by '.$name,
+ $this->api->url('./borrow',array('id'=>$_GET['borrow'])))
+ ->execute();
+ }
+ }
+
+ }
+
+ function page_books(){
+ $m=$this->add('Model_Book');
+
+ // Dynamically change model to include only related entires
+ $bor=$m->join('library_borrowing.library_book_id');
+
+ // We might need more fields from joined table
+ $bor->addField('library_member_id');
+ $bor->addField('is_returned')->type('boolean');
+ $bor->addField('library_borrowing_id','id')->system(true);
+ // System fields will not appear in froms and grids by defaultt
+
+ // We are only interested in currently borrowed book by this specific member
+ $m->addCondition('library_member_id',$_GET['library_member_id']);
+ $m->addCondition('is_returned',false);
+ // Normally all this should be stored in model! Keep your UI logic clean
+
+ // Clicking on grid buttons should also pass library_member_id
+ $this->api->stickyGET('library_member_id');
+
+ // Place grid in a box with grayish background
+ $g=$this->add('View')->addStyle('background','#eee')
+ ->add('Grid');
+
+ $g->setModel($m,array('name','issn'));
+ $g->addColumn('button','return');
+ if($_GET['return']){
+
+ // Returning borrowed book by book_id and calling custom model method
+ $this->add('Model_Borrowing')->loadBy('library_book_id',$_GET['return'])->returnBook();
+ $g->js()->univ()->location($this->api->url('..'))->execute();
+ }
+
+
+ }
+
+ function page_borrow(){
+
+ // This page for borrowing new book
+ $m=$this->add('Model_Borrowing');
+
+ // Substitute model for existing field, because we want to show only
+ // available books
+ $m->getElement('library_book_id')->refModel('Model_BookAvailable');
+
+ // Perform quick check to make sure there are some books to borrow
+ if(!$m->ref('library_book_id')->count()->getOne()){
+ $this->add('View_Error')->set('No Books to Borrow');
+ $this->add('Button')->set('Close')->js('click')->univ()->closeDialog();
+ return;
+ }
+
+ // Change look of the form, will place labels above fields
+ $f=$this->add('Form')->addClass('stacked');
+ $f->setModel($m,array('library_book_id','library_member_id','verified_by'));
+
+ // Set default value for a field
+ $f->set('library_member_id',$_GET['id']);
+ $f->addSubmit();
+ if($f->isSubmitted()){
+
+ // will create new record in the database
+ $f->update();
+ $f->js()->univ()->location($this->api->url('..'))->execute();
+ }
+ }
+
+}
View
9 example/learn2/page/staff.php
@@ -0,0 +1,9 @@
+<?php
+class page_staff extends Page {
+ function init(){
+ parent::init();
+
+ // The most trivial usage of CRUD
+ $this->add('CRUD')->setModel('Staff');
+ }
+}
View
11 index.php
@@ -1,15 +1,4 @@
<?php
-
-// DO NOT ADD ANYTHING TO THIS FILE!!
-
-// This is a catch-all file for your project. You can change
-// some of the values here, which are going to have affect
-// on your project
-
-// AgileProject - change to your own API name.
-// agile_project - this is realm. It should be unique per-project
-// jui - this is theme. Keep it jui unless you want to make your own theme
-
include 'atk4/loader.php';
$api=new Frontend('codepad');
$api->main();
View
10 lib/Frontend.php
@@ -1,6 +1,8 @@
<?php
class Frontend extends ApiFrontend {
public $example_cut;
+ public $tree;
+
function init(){
parent::init();
$this->dbConnect();
@@ -14,9 +16,6 @@ function init(){
$this->add('jUI');
- if($this->template->hasTag('SubMenu'))
- $this->add('TreeView',null,'SubMenu',array('submenu'))
- ->setModel('Menu');
}
function page_back($p){
$this->redirect('http://agiletoolkit.org/doc/');
@@ -28,6 +27,11 @@ function initLayout(){
$page->template->eachTag('Silent',function($a,$b) use($page){ $page->add('View_Example',null,$b)->set($a,true); });
$page->template->eachTag('ExecuteTrigger',function($a,$b) use($page){ $page->add('View_ExecuteTrigger',null,$b)->set($a,'trigger'); });
+
+ if(!$this->tree && $this->template->hasTag('SubMenu')){
+ $tree=$this->add('TreeView',null,'SubMenu',array('submenu'));
+ $tree->setModel('Menu');
+ }
}
function render(){
$this->js(true)->_load('myuniv')->univ()->softScroll();
View
3 lib/TreeView.php
@@ -25,9 +25,12 @@ function setModel($m){
parent::setModel($m);
$this->child_ref=$this->model->hierarchy_controller->child_ref;
+ return $this->model;
}
function formatRow(){
+ if($this->current_row['page'] instanceof URL)return;
+ if($this->stack[0] instanceof Model)return;
$this->current_row['page']=$this->api->url($this->stack[0]['page'].'/'.$this->current_row['page']);
}
View
116 page/projectview.php
@@ -0,0 +1,116 @@
+<?php
+class page_projectview extends Page {
+ function init(){
+ parent::init();
+ $this->api->stickyGET('e');
+ $this->api->template->trySet('title',strtoupper($_GET['e']));
+
+ $base='example/'.$_GET['e'];
+ if($this->api->template->hasTag('SubMenu')){
+ $this->api->tree=$this->api->add('TreeView',null,'SubMenu',array('submenu'));
+ $this->api->tree->setModel('Directory')
+ ->sub('templates','templates/default/page')
+ ->setBasePath($base);
+ }
+
+ // only show files from the example directories
+
+ if($_GET['p']){
+ if(substr($_GET['p'],0,strlen($base)) != $base)exit;
+ $this->api->stickyGET('p');
+ if(!preg_match('/^[\/a-z1-9A-Z-]*(\.php|\.html)?$/',$_GET['p']))exit;
+
+ $this->add('ViewSource')->setFile($_GET['p']);
+
+ }else{
+ $this->add('P')->set('You are exploring project files. Select the files on the left to see the source');
+ $this->add('P')->setHTML('You can also browse this on github');
+ }
+ }
+}
+
+/**
+ * Traverses into directories producing model with all files
+ */
+class Model_Directory extends hierarchy\Model_Array {
+
+ public $substitute=array();
+
+ function sub($dir,$dir2){
+ $this->substitute[$dir]=$dir2;
+ return $this;
+ }
+
+ function setBasePath($path,$depth=5){
+ if(!preg_match('/^[\/a-z1-9A-Z]*$/',$path))exit;
+ $x=$this->traverse($path,$depth);
+
+ foreach($x as $k1=>&$top)if($top['children']){
+ foreach($top['children'] as $k2=>&$l2)if($l2['children']){
+ $x[]=array(
+ 'name'=>$top['name'].'/'.$l2['name'],
+ 'page'=>$l2['page'],
+ 'children'=>$l2['children']
+ );
+ unset($top['children'][$k2]);
+ }
+
+ }
+
+ $this->setSource($x);
+ }
+
+ function traverse($path,$depth){
+ if(!$depth)return array();
+ $res=array();
+ $d=opendir($path);
+ while($file=readdir($d)){
+ if($file[0]=='.')continue;
+
+ if($this->substitute[$file])$file=$this->substitute[$file];
+
+ $item=array();
+ $item['name']=$file;
+ if(is_dir($path.'/'.$file)){
+ $item['children']=$this->traverse($path.'/'.$file,$depth-1);
+ }else{
+ $item['page']=$this->api->url(null,array('p'=>$path.'/'.$file));
+ }
+ $res[]=$item;
+ }
+ return $res;
+ }
+}
+
+class ViewSource extends View {
+
+
+ function setFile($f){
+ $brush='Php';
+ if($this->template->is_set('brush')){
+ $brush=$this->template->get('brush');
+ $this->template->del('brush');
+ }
+
+ $this->template->set('Code',file_get_contents($f));
+
+ if(!@$this->api->highlighter_initialized){
+ $this->api->jui->addStaticInclude('syntaxhighlighter/scripts/shCore');
+ $this->api->jui->addStaticInclude('syntaxhighlighter/scripts/shBrush'.$brush);
+ $this->api->jui->addStaticInclude('shJQuery');
+ $this->api->jui->addStaticStylesheet('shCoreDefault','.css','js');
+ $this->api->highlighter_initialized=true;
+ }
+
+ $this->js(true)->_selector('#'.$this->name.'_ex')->syntaxhighlighter(array('lang'=>$brush));
+
+ $this->template->tryDel('has_demo');
+ }
+
+ function defaultTemplate(){
+ if($_GET['cut'])return array('view/example_cut');
+ return array('view/example');
+ }
+
+
+}
View
1 templates/default/css/atk-codepad.css
@@ -1380,7 +1380,6 @@ input.ui-button,
.sidebar > ul > li > a {
font-size: 10px !important;
font-weight: bold;
- text-transform: uppercase;
color: #2C3F53;
padding: 6px 10px;
background-color: #ecf3f9;
View
2 templates/default/css/atk-codepad.less
@@ -30,7 +30,7 @@
>ul {
>li {border-bottom:1px solid #c3ced9;border-top:1px solid #fff;
>a {
- font-size:10px !important;font-weight:bold;text-transform:uppercase;color:#2C3F53;padding:6px 10px;
+ font-size:10px !important;font-weight:bold;color:#2C3F53;padding:6px 10px;
#gradient > .vertical(#f2f8fc,#ecf3f9);
i {float:left;margin-right:2px;}
&:hover {}
View
5 templates/default/page/learning/model.html
@@ -76,7 +76,7 @@
$item->tryLoadAny();
$item['price'] = 14.99;
-$item['name'] = 'Mouse Pad';
+$item['name'] = 'Mouse Pad '.rand(1,100);
$item->save();
<?/?>
@@ -95,7 +95,10 @@
$form->update();
$form->js(null,$page->js()->reload())->univ()->successMessage('Order added')->execute();
}
+<?/?>
+<?ExecuteTrigger?>Clean Up Orders
+$page->add('Model_Order')->deleteAll();
<?/?>
<a name="test"></div>
View
19 templates/default/page/learning/model/1.html
@@ -0,0 +1,19 @@
+<?Silent?>
+$page->api->redirect('..');
+<?/?>
+
+<?Silent?>Sample 1b
+$item = $this->add('Model_Item');
+
+$item->tryLoadAny();
+
+$order = $item->ref('Order');
+
+$order['amount']=5;
+$order->save();
+
+$item->reload();
+
+$res = $item['successful_orders']; // will increment by 5
+<?/?>
+
View
9 templates/default/page/learning/model/2.html
@@ -1,3 +1,7 @@
+<?Silent?>
+$page->api->redirect('..');
+<?/?>
+
<?Silent?>lib/Model/Item.php
class Model_Item extends Model_Table {
public $table='item';
@@ -11,7 +15,7 @@
<?/?>
<?Silent?>Sample 1b
-$item = $htis->add('Model_Item');
+$item = $this->add('Model_Item');
$item->tryLoadAny();
@@ -25,6 +29,3 @@
$res = $item['successful_orders']; // will increment by 5
<?/?>
-<?Silent?>
-$page->api->redirect('..');
-<?/?>
View
2 templates/default/shared.html
@@ -55,6 +55,8 @@
</div>
</div>
</div>
+
+ <h1><?$title?></h1>
<div class="atk-row">
<div class="atk-flexy main">

0 comments on commit f09263a

Please sign in to comment.