/**
  * Method to get files data
  *
  * @access public
  * @return array
  */
 function getData()
 {
     // Get items using files VIA (single property) field types (that store file ids) by using main query
     $s_assigned_via_main = false;
     // Files usage my single / multi property Fields.
     // (a) Single property field types: store file ids
     // (b) Multi property field types: store file id or filename via some property name
     $s_assigned_fields = array('file', 'minigallery');
     $m_assigned_fields = array('image');
     $m_assigned_props = array('image' => 'originalname');
     $m_assigned_vals = array('image' => 'filename');
     // Lets load the files if it doesn't already exist
     if (empty($this->_data)) {
         $query = $s_assigned_via_main ? $this->_buildQuery($s_assigned_fields) : $this->_buildQuery();
         $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
         if ($this->_db->getErrorNum()) {
             JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error');
         }
         $this->_db->setQuery("SELECT FOUND_ROWS()");
         $this->_total = $this->_db->loadResult();
         $this->_data = flexicontent_images::BuildIcons($this->_data);
         // Single property fields, get file usage (# assignments), if not already done by main query
         if (!$s_assigned_via_main && $s_assigned_fields) {
             foreach ($s_assigned_fields as $field_type) {
                 $this->countFieldRelationsSingleProp($this->_data, $field_type);
             }
         }
         // Multi property fields, get file usage (# assignments)
         if ($m_assigned_fields) {
             foreach ($m_assigned_fields as $field_type) {
                 $field_prop = $m_assigned_props[$field_type];
                 $value_prop = $m_assigned_vals[$field_type];
                 $this->countFieldRelationsMultiProp($this->_data, $value_prop, $field_prop, $field_type = 'image');
             }
         }
         $session = JFactory::getSession();
         $fileid_to_itemids = $session->get('fileid_to_itemids', array(), 'flexicontent');
         foreach ($this->_data as $row) {
             // we have multiple item list indexed by field type, concatanate these
             $itemids_list = !empty($row->item_list) ? implode(',', $row->item_list) : '';
             // now create a item ids array that contains duplicates
             $itemids_dup = $itemids_list == '' ? array() : explode(',', $itemids_list);
             // make an array of unique item ids
             $itemids = array();
             $n = 0;
             foreach ($itemids_dup as $itemid) {
                 $itemids[$itemid] = $n++;
             }
             $fileid_to_itemids[$row->id] = $row->itemids = array_flip($itemids);
         }
         $session->set('fileid_to_itemids', $fileid_to_itemids, 'flexicontent');
     }
     return $this->_data;
 }
Example #2
0
 /**
  * Method to get files data
  *
  * @access public
  * @return array
  */
 function getData()
 {
     // Get items using files VIA (single property) field types (that store file ids) by using main query
     $s_assigned_via_main = false;
     $s_assigned_fields = false;
     //array('file', 'minigallery');
     $m_assigned_fields = false;
     //array('image');
     $m_assigned_props = array('image' => 'originalname');
     $m_assigned_vals = array('image' => 'filename');
     // Lets load the files if it doesn't already exist
     if (empty($this->_data)) {
         $query = $s_assigned_via_main ? $this->_buildQuery($s_assigned_fields) : $this->_buildQuery();
         $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
         if ($this->_db->getErrorNum()) {
             JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error');
         }
         $this->_db->setQuery("SELECT FOUND_ROWS()");
         $this->_total = $this->_db->loadResult();
         $this->_data = flexicontent_images::BuildIcons($this->_data);
         // Single property fields, get file usage (# assignments), if not already done by main query
         if (!$s_assigned_via_main && $s_assigned_fields) {
             foreach ($s_assigned_fields as $field_type) {
                 $this->countFieldRelationsSingleProp($this->_data, $field_type);
             }
         }
         // Multi property fields, get file usage (# assignments)
         if ($m_assigned_fields) {
             foreach ($m_assigned_fields as $field_type) {
                 $field_prop = $m_assigned_props[$field_type];
                 $value_prop = $m_assigned_vals[$field_type];
                 $this->countFieldRelationsMultiProp($this->_data, $value_prop, $field_prop, $field_type = 'image');
             }
         }
     }
     return $this->_data;
 }