Exemple #1
0
function mycomments_advanced_search($queryarray, $andor, $limit, $offset, $userid, $moduleid, $items)
{
    global $xoopsDB;
    include_once XOOPS_ROOT_PATH . "/modules/mycomments/class/comment.php";
    $sql = "SELECT * FROM " . $xoopsDB->prefix("xoopscomments") . " WHERE com_id>0 ";
    if ($moduleid != 0) {
        $sql .= " AND com_modid=" . $moduleid . " ";
    }
    if ($userid != 0) {
        $sql .= " AND com_uid=" . $userid . " ";
    }
    // because count() returns 1 even if a supplied variable
    // is not an array, we must check if $querryarray is really an array
    if (is_array($queryarray) && ($count = count($queryarray))) {
        $sql .= " AND ((com_title LIKE '%{$queryarray['0']}%' OR com_text LIKE '%{$queryarray['0']}%')";
        for ($i = 1; $i < $count; $i++) {
            $sql .= " {$andor} ";
            $sql .= "(com_title LIKE '%{$queryarray[$i]}%' OR com_text LIKE '%{$queryarray[$i]}%')";
        }
        $sql .= ") ";
    }
    if (is_array($items) && count($items) > 0) {
        $sql .= ' AND com_itemid IN (' . implode(',', $items) . ')';
    }
    $sql .= "ORDER BY com_created DESC";
    $result = $xoopsDB->query($sql, $limit, $offset);
    $module_handler =& xoops_gethandler('module');
    $modules =& $module_handler->getObjects(new Criteria('hascomments', 1), true);
    $ret = array();
    $i = 0;
    while ($myrow = $xoopsDB->fetchArray($result)) {
        $id_as_key = false;
        $comment = new MycommentsComment();
        $comment->assignVars($myrow);
        if (!$id_as_key) {
            $ret[] =& $comment;
        } else {
            $ret[$myrow['com_id']] =& $comment;
        }
        unset($comment);
    }
    return $ret;
}
Exemple #2
0
 /**
  * Get some {@link XoopsComment}s
  *
  * @param   object  $criteria
  * @param   bool    $id_as_key  Use IDs as keys into the array?
  *
  * @return  array   Array of {@link XoopsComment} objects
  **/
 function getObjects($criteria = null, $id_as_key = false)
 {
     $ret = array();
     $limit = $start = 0;
     $sql = 'SELECT c.* ,m.* FROM ' . $this->db->prefix('xoopscomments') . ' c, ' . $this->db->prefix('modules') . ' m';
     if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
         $sql .= ' ' . $criteria->renderWhere();
         $sql .= ' AND c.com_modid = m.mid';
         $sort = $criteria->getSort() != '' ? $criteria->getSort() : 'com_id';
         $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
         $limit = $criteria->getLimit();
         $start = $criteria->getStart();
     }
     $result = $this->db->query($sql, $limit, $start);
     if (!$result) {
         return $ret;
     }
     while ($myrow = $this->db->fetchArray($result)) {
         $comment = new MycommentsComment();
         $comment->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] =& $comment;
         } else {
             $ret[$myrow['com_id']] =& $comment;
         }
         unset($comment);
     }
     return $ret;
 }