Exemplo n.º 1
0
 /**
  * Method to (un)archive a template
  * --> when unarchiving it is called by the archive-controller
  *
  * @access	public
  *
  * @param	array $cid      template IDs
  * @param	int $archive    Task --> 1 = archive, 0 = unarchive
  *
  * @return	boolean
  *
  * @since 1.1.0
  */
 public function archive($cid = array(), $archive = 1)
 {
     $_db = $this->_db;
     $app = JFactory::getApplication();
     $date = JFactory::getDate();
     $uid = JFactory::getUser()->get('id');
     if ($archive == 1) {
         $time = $date->toSql();
         // Access check.
         foreach ($cid as $i) {
             if (!BwPostmanHelper::allowArchive($i, 0, 'template')) {
                 $app->enqueueMessage(JText::_('COM_BWPOSTMAN_TPL_ARCHIVE_RIGHTS_MISSING'), 'error');
                 return false;
             }
         }
     } else {
         $time = '0000-00-00 00:00:00';
         $uid = 0;
         // Access check.
         foreach ($cid as $i) {
             if (!BwPostmanHelper::allowRestore($i, 0, 'template')) {
                 $app->enqueueMessage(JText::_('COM_BWPOSTMAN_TPL_RESTORE_RIGHTS_MISSING'), 'error');
                 return false;
             }
         }
     }
     if (count($cid)) {
         JArrayHelper::toInteger($cid);
         $query = $_db->getQuery(true);
         $query->update($_db->quoteName('#__bwpostman_templates'));
         $query->set($_db->quoteName('archive_flag') . " = " . $_db->Quote((int) $archive));
         $query->set($_db->quoteName('archive_date') . " = " . $_db->Quote($time, false));
         $query->set($_db->quoteName('archived_by') . " = " . (int) $uid);
         $query->where($_db->quoteName('id') . ' IN (' . implode(',', $cid) . ')');
         $_db->setQuery($query);
         if (!$_db->query()) {
             $this->setError($_db->getErrorMsg());
             return false;
         }
     }
     return true;
 }