/**
  * @since       1.1.0
  **/
 public static function getFieldsByItemID($option = null, $itemID = null, $fieldsID = null, $getAllextensions = true)
 {
     $app = JFactory::getApplication();
     // Load PluginExtensions Helper
     $extensionsHelper = FieldsandfiltersFactory::getExtensions();
     if (is_null($option)) {
         $option = $app->input->get('option');
     }
     $extensions[] = strtolower($option);
     if ($getAllextensions) {
         $extensions[] = FieldsandfiltersExtensions::EXTENSION_DEFAULT;
     }
     $extensionsID = $extensionsHelper->getExtensionsByOptionColumn('content_type_id', $extensions);
     if (empty($extensionsID)) {
         return self::_returnEmpty();
     }
     // Load elements Helper
     $element = false;
     if (!($isNullItemID = is_null($itemID)) && !($element = FieldsandfiltersFactory::getElements()->getElementsByItemIDPivot('item_id', $extensionsID, $itemID, 1, FieldsandfiltersElements::VALUES_BOTH)->get($itemID))) {
         if (empty($fieldsID)) {
             return self::_returnEmpty();
         }
     }
     if (!($isNullFieldsID = is_null($fieldsID)) && $element) {
         $values = FieldsandfiltersFields::VALUES_BOTH;
     } else {
         if ($isNullFieldsID && $element) {
             $fieldsID = array_merge(array_keys($element->connections->getProperties(true)), array_keys($element->data->getProperties(true)));
             if (empty($fieldsID)) {
                 return self::_returnEmpty();
             }
             $values = FieldsandfiltersFields::VALUES_VALUES;
         } else {
             if (!$isNullFieldsID && $isNullItemID || !empty($fieldsID)) {
                 $values = FieldsandfiltersFields::VALUES_BOTH;
                 if (!$element) {
                     $element = new stdClass();
                     // when element not exist an we have allextension with fields
                 }
             } else {
                 return self::_returnEmpty();
             }
         }
     }
     // Load Fields Helper
     if (!($fields = FieldsandfiltersFactory::getFields()->getFieldsByID($extensionsID, $fieldsID, 1, $values))) {
         return self::_returnEmpty();
     }
     return new JObject(array('element' => $element, 'fields' => $fields));
 }
 /**
  * Method to get a single record.
  *
  * @param    integer    The id of the primary key.
  *
  * @return    mixed    Object on success, false on failure.
  * @since       1.1.0
  */
 public function getItem($pk = null)
 {
     $row = !empty($pk) ? (int) $pk : (int) $this->getState($this->getName() . '.id');
     if (empty($row)) {
         $row = array('item_id' => (int) $this->getState($this->getName() . '.item_id', 0), 'content_type_id' => (int) $this->getState($this->getName() . '.content_type_id', 0));
     }
     $store = md5(serialize($row));
     if (!isset($this->_cache[$store])) {
         $app = JFactory::getApplication();
         $isNew = true;
         $extensionName = false;
         // Get a level row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $table->load($row);
         if (!empty($table->id)) {
             $isNew = false;
             // Load Elements Helper
             if ($element = FieldsandfiltersFactory::getElements()->getElementsByID($table->content_type_id, $table->id, $this->_item_states, FieldsandfiltersElements::VALUES_BOTH)->get($table->id)) {
                 $table->fields = array('connections' => $element->connections->getProperties(true), 'data' => $element->data->getProperties(true));
             }
         } else {
             $table->content_type_id = (int) $this->getState($this->getName() . '.content_type_id', 0);
             $table->item_id = (int) $this->getState($this->getName() . '.item_id', 0);
         }
         if ($table->content_type_id && ($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeID($table->content_type_id, true, true)->get($table->content_type_id))) {
             $extensionName = $extension->name;
         }
         // Convert to the JObject before adding other data.
         $properties = $table->getProperties(true);
         $item = JArrayHelper::toObject($properties, 'JObject');
         if ($extensionName) {
             $item->extension_name = $extension->forms->extension->title;
             // Include the fieldsandfiltersExtensions plugins for the on prepare item events.
             JPluginHelper::importPlugin('fieldsandfiltersextensions');
             JPluginHelper::importPlugin('fieldsandfilterstypes');
             // Trigger the onFieldsandfiltersPrepareElement event.
             $result = $app->triggerEvent('onFieldsandfiltersPrepareElement', array($this->option . '.' . $this->name . '.' . $extensionName, &$item, $isNew, $this->state));
             if (in_array(false, $result, true)) {
                 $this->setError(JText::sprintf('COM_FIELDSANDFILTERS_DATABASE_ERROR_PREPARE_ITEM', $extensionName));
                 return false;
             }
             // Trigger the onFieldsandfiltersPrepareElementFields event.
             $result = $app->triggerEvent('onFieldsandfiltersPrepareElementFields', array($this->option . '.' . $this->name, &$item, $isNew, $this->state));
             if (in_array(false, $result, true)) {
                 $this->setError(JText::sprintf('COM_FIELDSANDFILTERS_DATABASE_ERROR_PREPARE_ITEM', $extensionName));
                 return false;
             }
         }
         $this->_cache[$store] = $item;
     }
     return $this->_cache[$store];
 }
 /**
  * @since       1.1.0
  */
 protected function _onFieldsandfiltersContent($location, &$row, &$params, $page, $context)
 {
     if (!($extensionContent = FieldsandfiltersFactory::getExtensions()->getExtensionsByName($this->_name)->get($this->_name))) {
         return;
     }
     // Load Fields Helper
     $fieldsHelper = FieldsandfiltersFactory::getFields();
     $extensionsParams = new JObject(array('module.off' => true, 'plugin.value' => $this->params->get('use_static_fields')));
     // Load Extensions Helper
     if ($isStaticFields = FieldsandfiltersExtensionsHelper::getParams('use_static_fields', $extensionsParams, true)) {
         // Load Plugin Types Helper
         $staticMode = FieldsandfiltersModes::getMode(FieldsandfiltersModes::MODE_STATIC);
         if ($fieldsStatic = $fieldsHelper->getFieldsByModeIDPivot('location', $extensionContent->content_type_id, $staticMode, 1, 2)->get($location)) {
             $fieldsStatic = is_array($fieldsStatic) ? $fieldsStatic : array($fieldsStatic);
         } else {
             $isStaticFields = false;
         }
     }
     // Load elements Helper
     if (!($element = FieldsandfiltersFactory::getElements()->getElementsByItemIDPivot('item_id', $extensionContent->content_type_id, $row->id, $row->state, 3)->get($row->id)) && !$isStaticFields) {
         return;
     }
     if ($element) {
         $fieldsID = array_merge(array_keys($element->connections->getProperties(true)), array_keys($element->data->getProperties(true)));
         if (empty($fieldsID) && !$isStaticFields) {
             return;
         }
         if (!($fields = $fieldsHelper->getFieldsByIDPivot('location', $extensionContent->content_type_id, $fieldsID, 1, 1)->get($location)) && !$isStaticFields) {
             return;
         }
     } else {
         $fields = false;
     }
     if ($fields && $isStaticFields) {
         $fields = is_array($fields) ? $fields : array($fields);
         $fields = array_merge($fields, $fieldsStatic);
     } else {
         if ($fields) {
             $fields = is_array($fields) ? $fields : array($fields);
         } else {
             if ($isStaticFields) {
                 $fields = $fieldsStatic;
             }
         }
     }
     $fields = new JObject(JArrayHelper::pivot((array) $fields, 'type'));
     $layoutFields = new JObject();
     JPluginHelper::importPlugin('fieldsandfilterstypes');
     // Trigger the onFieldsandfiltersPrepareFormField event.
     JFactory::getApplication()->triggerEvent('getFieldsandfiltersFieldsHTML', array($layoutFields, $fields, $element, $context));
     $layoutFields = $layoutFields->getProperties(true);
     if (empty($layoutFields)) {
         return;
     }
     ksort($layoutFields);
     return implode("\n", $layoutFields);
 }