Skip to content

Commit

Permalink
dss
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltel committed Jan 25, 2012
1 parent 24adcae commit 2fadf3b
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 36 deletions.
31 changes: 4 additions & 27 deletions core/models/class.Content.php
Expand Up @@ -8,8 +8,8 @@
class Content extends Model
{
public $mTargets;
protected $mFields;
protected $mId;
//protected $mFields; in model
//protected $mId; in Model


protected $mContentType; // set by derived class in constructor ex. 'ARTICLE' or 'DOCUMENTATION' used for content_type field
Expand Down Expand Up @@ -58,33 +58,10 @@ class Content extends Model
*/
protected function __construct($params)
{ //print_r($params); die;
$this->mSqlStack = array();

if(is_array($params))
$params = (object) $params;

if(is_object($params))
{
$this->mFields = $params; //echo('create contetn'.$row->title);
$this->mId = ($params->contents_id >0)? $params->contents_id :0;
}
elseif( is_integer($params))
{
$this->mId =$params;
}

parent::__construct($params);
$this->mSqlStack = array();
}


public function __get($field)
{
return $this->mFields->$field;
}

public function getAllFields()
{
return $this->mFields;
}

public function GetExtraTableName()
{
Expand Down
34 changes: 29 additions & 5 deletions core/models/class.Media.php
@@ -1,11 +1,26 @@
<?
class Media
class Media extends Model
{

public function __construct()
{

}
protected static $mContentFieldDescriptions = array(
'contents_clk_id' => array('type'=>'int', 'insert_only'=>true),
'contents_id' => array('type'=>'int', 'insert_only'=>true),
'contents_title' => array('type'=>'varchar', 'label'=>'Title', 'required'=>true),
'contents_display_title' => array('type'=>'varchar', 'label'=>'Display title'),
'contents_create_date' => array('type'=>'datetime', 'insert_only'=>true,'do_not_validate'=>true), // NOW()
// 'contents_mod_date' => array('type'=>'datetime', 'do_not_validate'=>true), // NOW() updated by system
'contents_pub_date' => array('type'=>'datetime', 'label'=>'Publication Date' ),
'contents_type' => array('type'=>'varchar', 'insert_only'=>true, 'required'=>true),
'contents_summary' => array('type'=>'varchar', 'label'=>'Summary'),
'contents_url_name' => array('type'=>'varchar', 'label'=>'URL Name'),
'contents_mod_users_id' => array('type'=>'int', 'required'=>true),
'contents_authors_id' => array('type'=>'int', 'label'=>'Author', 'form_element' =>'select'),
'contents_extra_table' => array('type'=>'varchar', 'insert_only'=>true, 'required'=>true),
'contents_live_rev' => array('type'=>'int', 'do_not_validate'=>true), // could be @newrev
'contents_preview_rev' => array('type'=>'int', 'do_not_validate'=>true), // could be @newrev
'contents_latest_rev' => array('type'=>'int', 'do_not_validate'=>true) // could be @newrev
);


public static function getMediaForContent($contents_id)
{
Expand All @@ -26,4 +41,13 @@ public static function linkMediaToContent($media_id, $contents_id)
return new Query($sql);
}

public static function listMedia()
{
$media_id = intval($media_id);
$contents_id = intval($contents_id);
$sql = "SELECT * FROM media ORDER BY DESC LIMIT 50";

return new Query($sql);
}

}
30 changes: 30 additions & 0 deletions core/models/class.Model.php
Expand Up @@ -5,6 +5,36 @@
*/
class Model
{
protected $mFields;
protected $mId;

protected function __construct($params)
{
if(is_array($params))
$params = (object) $params;

if(is_object($params))
{
$this->mFields = $params; //echo('create contetn'.$row->title);
$this->mId = ($params->contents_id >0)? $params->contents_id :0;
}
elseif( is_integer($params))
{
$this->mId =$params;
}
}


public function __get($field)
{
return $this->mFields->$field;
}

public function getAllFields()
{
return $this->mFields;
}



/**
Expand Down
10 changes: 6 additions & 4 deletions mysql-innodb.sql
@@ -1,4 +1,6 @@
--
-- http://gitref.org/ http://progit.org/
-- git checkout -- mymessedupfile.php , will copy a fresh copy into the working directory
-- http://blog.jbrumond.me/archives/169

-- table name should be one word without unserscores
-- pk should be tablename_id
Expand Down Expand Up @@ -366,14 +368,14 @@ CREATE TABLE modules__pages
-- list of latest revisions per page
CREATE VIEW max_page_revisions as
(
SELECT pages_id AS mpr_pages_id, MAX(pages_rev) AS mpr_pages_rev
FROM pages GROUP BY pages_id
SELECT pages_id AS mpr_pages_id, MAX(pages_rev) AS mpr_pages_rev
FROM pages GROUP BY pages_id
);

-- a list of the latest pages
create view current_pages as
(
SELECT * FROM pages JOIN max_page_revisions ON mpr_pages_id = pages_id AND pages_rev = mpr_pages_rev
SELECT * FROM pages JOIN max_page_revisions ON mpr_pages_id = pages_id AND pages_rev = mpr_pages_rev
);


Expand Down
135 changes: 135 additions & 0 deletions sites/cms/controllers/class.EditMedia.php
@@ -0,0 +1,135 @@
<?php

class EditMedia extends Controller
{



/**
* @param website object
* @param array with the following values
* 0: 'gt', 'gov', or 'all'
* 1: content type (name of the extra_table)
* 2: [optional] id of the content item if 'new' we will create a new item, if blank we will list
*/
public function __construct($websiteObject, $arguments)
{
//dump($_POST);

global $CONFIG;
parent::__construct($websiteObject, $arguments);

$site = $CONFIG->cms_site_code;
$model_name = $arguments[0];
$id = 0 + intval($arguments[1]);
$isNew = $arguments[1] == 'new' ? true :false;

$this->mSmarty->assign('site_code', $site);
$this->mSmarty->assign('site_name', getSiteName($site));
$this->mSmarty->assign('model_name', $model_name);


if(!empty($_POST['contents_title'])) // save content item
{
$this->_save($id, $site, $model_name);
return;
}

if($isNew || $id > 0 )
{
$this->_edit($id, $model_name); // edit new or existing item
return;
}

$this->_list($site, $model_name); // list content items

return;
}


private function _list($site, $model_name)
{
if($_POST['makelive'])
{
Content::setLiveRevision(intval($_POST['id']), intval($_POST['rev']));
}
elseif($_POST['makepreview'])
{
Content::setPreviewRevision(intval($_POST['id']), intval($_POST['rev']));
}

$limit = 50;
$paging = intval($_GET[pg]);
$skip = $paging * $limit;
$items = Content::GetContentByType($model_name, $site, null, $limit, $skip, 'ALL');

// foreach($items as $a) echo $a->contents_id; die;
$this->mSmarty->assign('contents', $items );
$this->mModules['left'] = array(CMS::CreateDummyModule('searchModule.tpl'),
CMS::CreateContentTypesModule(),
CMS::CreateDummyModule('recentlyModifiedModule.tpl') );

$this->mMainTpl = 'listContent.tpl';
$this->mPageTitle = getSiteName($site) . " - List $model_name";
}


private function _save($id, $site,$model_name)
{
//dump($_POST);
$model = new $model_name($_POST);
$id = $model->Save();
$targets = json_decode($_POST['changed_targets']);

foreach($targets as $params)
{
$params->targets_contents_id = $id;
//dump($params);
if($params->record_state != 'CLEAN')
Page::sYaasSaveTarget($params);
}

header("LOCATION: /cms/{$site}/$model_name");
die;
}


private function _edit($id, $model_name)
{

if($id == 0) // new article
{ //die($_SESSION['user_first_name']);
$this->mPageTitle = getSiteName($site) . " - New Article";
}
else // edit existing article
{
$rev = intval($_GET['rev']) > 0 ? intval($_GET['rev']): LATEST_REV ;
$this->mPageTitle = getSiteName($site) . " - Edit Article";
}

$model = new $model_name();
$formData = $model->GetFieldDescriptions(true); // include authors
$content = $model->GetData($id, $rev);


// create the center module
$this->mModules['center'] = array(CMS::CreateTargetsModule($id));

// create the left side modules
$this->mModules['left'] = array(CMS::CreateDummyModule('contentStatusModule.tpl'),
CMS::CreateDummyModule('contentMediaModule.tpl'),
CMS::CreateDummyModule('relatedItemsModule.tpl'),
CMS::CreateRevisionHistoryModule($content)
);
$this->mMainTpl = 'editContent.tpl';

$this->mSmarty->assign('form_data',$formData);
$this->mSmarty->assign('content', $content);
$this->mSmarty->assign('value', $content->ToArray()); // needed in this way for compatibility with formdata
}


protected function _InitCaching(){}
protected function _InitPage(){}

}

0 comments on commit 2fadf3b

Please sign in to comment.