Package structure

Permalink
Hi there

I am currently creating a package. It startet as a simple thing but is getting more and more complex. And now I do not know where to put which code.

This package is based on several single pages. At the end, it is a kind of a CRM.

In this package is a singlepage with customer details. Inter alia a part with tasks (see attachment).

What you see is a part of the page, with the customers closed tasks. There is a similar part for open parts. The whole part is coded into the singlepage php file. Somthing like this.
$tsk = Loader::helper('tasks','steff_report');
$clsTsk = $tsk->getClosedTasks($customerinfo['adrID']);
<div id="cTasks">
   <div id="cTasksHeader">
      Closed Tasks
   </div>
   <div id="cTasksBody">
      <table id="cTasksTable">
         <thead>
            <tr>
               <th width="50px">taskID</th>
               <th>Titel</th>
               <th width="100px">Erledigt von</th>
               <th width="100px">Datum</th>
               <td width="100px"></td>


As you can see, i allready started with a taskHelper which looks something like that:
class TasksHelper{
   public function getClosedTasks($adrID = ''){
      $db = Loader::db();
      $vals[] = $adrID;
      $vals[] = $uID;
      $query = 'SELECT * FROM table WHERE tskFKAdrID=? AND tskComplete IS NOT NULL';
      $res = $db->getArray($query, $vals);
      return $res;
   }   
}


In the controller i then call the helper with
public function addTask(){
   $tsk = Loader::helper('tasks','steff_report');
   echo $tsk->addTask();
}


OK. This works great.

But now i have a package home page, where you start when you logged in to the package main singlepage. There I would like to show, for example, all closed tasks assigned to the logged in user.
I think the thing with the helper is ok.

But i now would like to remove the part in the screenshot out of the customers page. otherwise i will have to copy this to every page, i would like to add these part.

But how can i realize this? Do i have to put the part into a file in the elements folder? And what is the structure of this elements folder? And how to include the elements into the page where this part should be displayed?

I hope it's clear enough to understand what i mean.

Thanks very much.

Steff

1 Attachment

Steff
 
xaritas replied on at Permalink Reply
Well, the documentation defines an element as:

/elements
The elements directory is a place for you to keep snippets of PHP code reused throughout your site. Examples of this might include a header menu or a reused sidebar. Elements are presentational in nature; if you have special functions or libraries you want to reuse for your website, these should go in ”/libraries” or ”/helpers.” (http://www.concrete5.org/documentation/developers/system/directory-structure)

So if I understand what you are trying to do correctly (extract presentation code for reuse), then yes, an element seems appropriate. You just put an /elements directory in your package base. When you load it, you need to use this:

Loader::packageElement($file, $pkgHandle, $args = null)


Note that, if you want to load an element from the Concrete installation, you use a different method:
Loader::element($file, $args = null)


This can bite you if you're relying on any elements in /concrete/elements or /elements and decide to move/override them. See more here:http://www.concrete5.org/documentation/developers/system/loading-ob...