Exemplo n.º 1
0
 /**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemplo n.º 2
0
 /**
  * Handle drawing results tag
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_ResultsList($tag_params, $children)
 {
     $manager = LeadsEntriesManager::getInstance();
     $data_manager = LeadsEntryDataManager::getInstance();
     $types_manager = LeadsTypesManager::getInstance();
     $conditions = array();
     $type_id = null;
     if (isset($tag_params['type'])) {
         $type_id = fix_id($tag_params['type']);
     } else {
         if (isset($_REQUEST['type'])) {
             $type_id = fix_id($_REQUEST['type']);
         }
     }
     if (is_null($type_id)) {
         return;
     }
     $fields = $types_manager->getItemValue('fields', array('id' => $type_id));
     $fields = array_slice(explode(',', $fields), 0, leads::COLUMN_COUNT);
     // add type to the conditions
     $conditions['type'] = $type_id;
     // get items from database
     $items = $manager->getItems(array('id'), $conditions);
     // load template
     $template = $this->loadTemplate($tag_params, 'list_item.xml');
     if (count($items) > 0) {
         // prepare list of entries
         $item_ids = array();
     }
     $data = array();
     foreach ($items as $item) {
         $item_ids[] = $item->id;
     }
     // get data from database
     $raw_data = $data_manager->getItems($data_manager->getFieldNames(), array('entry' => $item_ids));
     // pack data
     if (count($raw_data) > 0) {
         foreach ($raw_data as $raw_item_data) {
             $id = $raw_item_data->entry;
             $name = $raw_item_data->name;
             if (!array_key_exists($id, $data)) {
                 $data[$id] = array();
             }
             if (in_array($name, $fields)) {
                 $number = array_search($name, $fields);
                 $data[$id]["field_{$number}"] = $raw_item_data->value;
             }
         }
         // display data
         foreach ($data as $id => $params) {
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }