Esempio n. 1
0
File: tag.php Progetto: 01J/topm
 /**
  * Method to get a list of tags
  *
  * @return  array  The field option objects.
  *
  * @since   3.1
  */
 protected function getOptions()
 {
     $options = array();
     $published = $this->element['published'] ? $this->element['published'] : array(0, 1);
     $name = (string) $this->element['name'];
     $db = F0FPlatform::getInstance()->getDbo();
     $query = $db->getQuery(true)->select('a.id AS value, a.path, a.title AS text, a.level, a.published')->from('#__tags AS a')->join('LEFT', $db->quoteName('#__tags') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
     $item = $this->form->getModel()->getItem();
     if ($item instanceof F0FTable) {
         // Fake value for selected tags
         $keyfield = $item->getKeyName();
         $content_id = $item->{$keyfield};
         $type = $item->getContentType();
         $selected_query = $db->getQuery(true);
         $selected_query->select('tag_id')->from('#__contentitem_tag_map')->where('content_item_id = ' . (int) $content_id)->where('type_alias = ' . $db->quote($type));
         $db->setQuery($selected_query);
         $this->value = $db->loadColumn();
     }
     // Ajax tag only loads assigned values
     if (!$this->isNested()) {
         // Only item assigned values
         $values = (array) $this->value;
         F0FUtilsArray::toInteger($values);
         $query->where('a.id IN (' . implode(',', $values) . ')');
     }
     // Filter language
     if (!empty($this->element['language'])) {
         $query->where('a.language = ' . $db->quote($this->element['language']));
     }
     $query->where($db->quoteName('a.alias') . ' <> ' . $db->quote('root'));
     // Filter to only load active items
     // Filter on the published state
     if (is_numeric($published)) {
         $query->where('a.published = ' . (int) $published);
     } elseif (is_array($published)) {
         F0FUtilsArray::toInteger($published);
         $query->where('a.published IN (' . implode(',', $published) . ')');
     }
     $query->group('a.id, a.title, a.level, a.lft, a.rgt, a.parent_id, a.published, a.path')->order('a.lft ASC');
     // Get the options.
     $db->setQuery($query);
     try {
         $options = $db->loadObjectList();
     } catch (RuntimeException $e) {
         return false;
     }
     // Prepare nested data
     if ($this->isNested()) {
         $this->prepareOptionsNested($options);
     } else {
         $options = JHelperTags::convertPathsToNames($options);
     }
     return $options;
 }
Esempio n. 2
0
 /**
  * Publish or unpublish records
  *
  * @param   integer|array  $cid      The primary key value(s) of the item(s) to publish/unpublish
  * @param   integer        $publish  1 to publish an item, 0 to unpublish
  * @param   integer        $user_id  The user ID of the user (un)publishing the item.
  *
  * @return  boolean  True on success, false on failure (e.g. record is locked)
  */
 public function publish($cid = null, $publish = 1, $user_id = 0)
 {
     $enabledName = $this->getColumnAlias('enabled');
     $locked_byName = $this->getColumnAlias('locked_by');
     // Mhm... you called the publish method on a table without publish support...
     if (!in_array($enabledName, $this->getKnownFields())) {
         return false;
     }
     //We have to cast the id as array, or the helper function will return an empty set
     if ($cid) {
         $cid = (array) $cid;
     }
     F0FUtilsArray::toInteger($cid);
     $user_id = (int) $user_id;
     $publish = (int) $publish;
     $k = $this->_tbl_key;
     if (count($cid) < 1) {
         if ($this->{$k}) {
             $cid = array($this->{$k});
         } else {
             $this->setError("No items selected.");
             return false;
         }
     }
     if (!$this->onBeforePublish($cid, $publish)) {
         return false;
     }
     $query = $this->_db->getQuery(true)->update($this->_db->qn($this->_tbl))->set($this->_db->qn($enabledName) . ' = ' . (int) $publish);
     $checkin = in_array($locked_byName, $this->getKnownFields());
     if ($checkin) {
         $query->where(' (' . $this->_db->qn($locked_byName) . ' = 0 OR ' . $this->_db->qn($locked_byName) . ' = ' . (int) $user_id . ')', 'AND');
     }
     // TODO Rewrite this statment using IN. Check if it work in SQLServer and PostgreSQL
     $cids = $this->_db->qn($k) . ' = ' . implode(' OR ' . $this->_db->qn($k) . ' = ', $cid);
     $query->where('(' . $cids . ')');
     $this->_db->setQuery((string) $query);
     if (version_compare(JVERSION, '3.0', 'ge')) {
         try {
             $this->_db->execute();
         } catch (Exception $e) {
             $this->setError($e->getMessage());
         }
     } else {
         if (!$this->_db->execute()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
     }
     if (count($cid) == 1 && $checkin) {
         if ($this->_db->getAffectedRows() == 1) {
             $this->checkin($cid[0]);
             if ($this->{$k} == $cid[0]) {
                 $this->{$enabledName} = $publish;
             }
         }
     }
     $this->setError('');
     return true;
 }
Esempio n. 3
0
 /**
  * Makes a copy of the record, inserting it as the last child of the given node's parent.
  *
  * @param   integer|array  $cid  The primary key value (or values) or the record(s) to copy. 
  *                               If null, the current record will be copied
  * 
  * @return self|F0FTableNested	 The last copied node
  */
 public function copy($cid = null)
 {
     //We have to cast the id as array, or the helper function will return an empty set
     if ($cid) {
         $cid = (array) $cid;
     }
     F0FUtilsArray::toInteger($cid);
     $k = $this->_tbl_key;
     if (count($cid) < 1) {
         if ($this->{$k}) {
             $cid = array($this->{$k});
         } else {
             // Even if it's null, let's still create the record
             $this->create($this->getData());
             return $this;
         }
     }
     foreach ($cid as $item) {
         // Prevent load with id = 0
         if (!$item) {
             continue;
         }
         $this->load($item);
         $this->create($this->getData());
     }
     return $this;
 }