/**
  * Method to get a JDatabaseQuery object for retrieving the data set from a database.
  *
  * @param   string  $component  - the component that we want to get the custom fields for (e.x. com_hotspots.xxx where xxx is the item type)
  * @param   int     $catid      - the category id
  * @param   string  $operator   - Operator for component (defaults to =)
  *
  * @return  JDatabaseQuery   A JDatabaseQuery object to retrieve the data set.
  */
 public function getFields($component, $catid = null, $operator = "=")
 {
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $cats = array();
     $query->select('f.*, c.catid as catid')->from('#__compojoom_customfields as f')->leftJoin('#__compojoom_customfields_cats AS c ON f.id = c.compojoom_customfields_id')->where($db->qn('f.show') . '=' . $db->q('all'))->where($db->qn('f.enabled') . ' = ' . $db->q(1));
     if ($operator == "LIKE") {
         $query->where($db->qn('f.component') . ' LIKE ' . $db->q($component));
     } else {
         $query->where($db->qn('f.component') . ' = ' . $db->q($component));
     }
     $all = $db->setQuery($query)->loadObjectList();
     if ($catid) {
         $query->clear();
         $query->select('f.*')->from('#__compojoom_customfields AS f')->where($db->qn('f.show') . '=' . $db->q('category'))->innerJoin('#__compojoom_customfields_cats AS c ON f.id = c.compojoom_customfields_id')->where(CompojoomQueryHelper::in('c.catid', is_array($catid) ? $catid : array($catid), $db))->where($db->qn('f.enabled') . ' = ' . $db->q(1));
         if ($operator == "LIKE") {
             $query->where($db->qn('f.component') . ' LIKE ' . $db->q($component));
         } else {
             $query->where($db->qn('f.component') . ' = ' . $db->q($component));
         }
         $cats = $db->setQuery($query)->loadObjectList();
     }
     if (count($cats)) {
         $allFields = array_merge($all, $cats);
     } else {
         $allFields = $all;
     }
     // Sort by ordering
     usort($allFields, function ($a, $b) {
         return $a->ordering - $b->ordering;
     });
     foreach ($allFields as $i => $field) {
         // JSON decode params column
         $allFields[$i]->params = json_decode($field->params);
     }
     return $allFields;
 }
Example #2
0
 /**
  * Get the already stored files in the database
  *
  * @param   array   $ids  - array with item ids to fetch
  * @param   string  $key  - the sort key
  *
  * @return mixed
  */
 public function getFilesFromDb($ids, $key = '')
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $ids = (array) $ids;
     $query->select('*')->from('#__compojoom_multimedia')->where(CompojoomQueryHelper::in('item_id', $ids, $db))->where('type_alias = ' . $db->q($this->typeAlias));
     $db->setQuery($query);
     return $db->loadObjectList($key);
 }
Example #3
0
 /**
  * Publish / Unpublish an custom field
  *
  * @return  mixed
  *
  * @since   5.1.2
  */
 public function publish()
 {
     $input = JFactory::getApplication()->input;
     $db = JFactory::getDbo();
     $task = $input->getCmd('task');
     $cid = $input->get('cid', array(), 'Array');
     $query = $db->getQuery(true);
     $enabled = $task == 'unpublish' ? 0 : 1;
     $query->update('#__compojoom_customfields')->set('enabled = ' . $db->quote($enabled))->where(CompojoomQueryHelper::in('id', $cid, $db));
     $db->setQuery($query);
     return $db->execute();
 }
Example #4
0
 /**
  * Get the ids of any Joomla users we already have on our list
  *
  * @param   array  $emails  - emails to search for
  *
  * @return array|mixed
  */
 public static function getJoomlaUsers($emails)
 {
     $users = array();
     if (count($emails)) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('id, email')->from('#__users')->where(CompojoomQueryHelper::in('email', $emails, $db));
         $db->setQuery($query);
         return $db->loadObjectList('email');
     }
     return $users;
 }