public function test_deleteTpl()
 {
     $instance = new $this->myclass($this->conn);
     $source = new XoopsTplfile();
     $source->setDirty();
     $source->setNew();
     $source->setVar('tpl_desc', 'TPL_DESC_DUMMY_TEST');
     $value = $instance->insertTpl($source);
     $this->assertSame(true, $value);
     $value = $instance->deleteTpl($source);
     $this->assertSame(true, $value);
 }
Beispiel #2
0
 function &getObjects($criteria = null, $getsource = false, $id_as_key = false)
 {
     $ret = array();
     $limit = $start = 0;
     if ($getsource) {
         $sql = 'SELECT f.*, s.tpl_source FROM ' . $this->db->prefix('tplfile') . ' f LEFT JOIN ' . $this->db->prefix('tplsource') . ' s ON s.tpl_id=f.tpl_id';
     } else {
         $sql = 'SELECT * FROM ' . $this->db->prefix('tplfile');
     }
     if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
         $sql .= ' ' . $criteria->renderWhere() . ' ORDER BY tpl_refid';
         $limit = $criteria->getLimit();
         $start = $criteria->getStart();
     }
     $result = $this->db->query($sql, $limit, $start);
     if (!$result) {
         return $ret;
     }
     while ($myrow = $this->db->fetchArray($result)) {
         $tplfile = new XoopsTplfile();
         $tplfile->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] =& $tplfile;
         } else {
             $ret[$myrow['tpl_id']] =& $tplfile;
         }
         unset($tplfile);
     }
     return $ret;
 }
Beispiel #3
0
 public static function getModuleTemplatePath(XoopsTplfile $tplObj)
 {
     $block = $tplObj->getVar('tpl_type') === 'block' ? '/blocks' : null;
     $dirname = $tplObj->getVar('tpl_module');
     $modulePath = $dirname . '/templates' . $block;
     //Case 1:under public root_path with dirname in template name like 'cat'
     $publicPath = XOOPS_MODULE_PATH . '/' . $modulePath . '/' . $tplObj->getVar('tpl_file');
     if (file_exists($publicPath)) {
         return $publicPath;
     }
     //prepare for Case 2 and Case 3
     if (!($trustDirname = self::getTrustPath($dirname))) {
         return false;
     }
     $filename = preg_replace('/' . $dirname . '/', $trustDirname, $tplObj->getVar('tpl_file'), 1);
     //Case 2:under public root_path with trust_dirname in template name like 'lecat'
     $publicPath = XOOPS_MODULE_PATH . '/' . $modulePath . '/' . $filename;
     if (file_exists($publicPath)) {
         return $publicPath;
     }
     //Case 3:under trust_path
     $trustPath = XOOPS_TRUST_PATH . '/modules/' . $trustDirname . '/templates' . $block . '/' . $filename;
     if (file_exists($trustPath)) {
         return $trustPath;
     }
     return false;
 }
 function &get($id, $getsource = false)
 {
     $id = intval($id);
     if ($id > 0) {
         if (!$getsource) {
             $sql = 'SELECT * FROM ' . $this->db->prefix('tplfile') . ' WHERE tpl_id=' . $id;
         } else {
             $sql = 'SELECT f.*, s.tpl_source FROM ' . $this->db->prefix('tplfile') . ' f LEFT JOIN ' . $this->db->prefix('tplsource') . ' s  ON s.tpl_id=f.tpl_id WHERE f.tpl_id=' . $id;
         }
         if (!($result = $this->db->query($sql))) {
             return false;
         }
         $numrows = $this->db->getRowsNum($result);
         if ($numrows == 1) {
             $tplfile = new XoopsTplfile();
             $tplfile->assignVars($this->db->fetchArray($result));
             return $tplfile;
         }
     }
     return false;
 }
Beispiel #5
0
 /**
  * getTplObjects
  *
  * @param CriteriaElement|null $criteria
  * @param bool                 $getsource
  * @param bool                 $id_as_key
  *
  * @return array
  */
 public function getTplObjects(CriteriaElement $criteria = null, $getsource = false, $id_as_key = false)
 {
     $qb = $this->db2->createXoopsQueryBuilder();
     $eb = $qb->expr();
     $ret = array();
     if (!$getsource) {
         $qb->select('*')->fromPrefix('tplfile', 'f');
     } else {
         $qb->select('f.*')->addSelect('s.tpl_source')->fromPrefix('tplfile', 'f')->leftJoinPrefix('f', 'tplsource', 's', $eb->eq('s.tpl_id', 'f.tpl_id'));
     }
     if (isset($criteria) && $criteria instanceof CriteriaElement) {
         $criteria->renderQb($qb);
     }
     $result = $qb->execute();
     if (!$result) {
         return $ret;
     }
     while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) {
         $tplfile = new XoopsTplfile();
         $tplfile->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] = $tplfile;
         } else {
             $ret[$myrow['tpl_id']] = $tplfile;
         }
         unset($tplfile);
     }
     return $ret;
 }