function subTree($params, $nodeID, $countChildren = false)
 {
     $nodeListArray = array();
     // sorting params
     $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($params['SortBy']);
     // node params
     $notEqParentString = '';
     $pathStringCond = '';
     eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, 1, false);
     // class filter
     $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($params['ClassFilterType'], $params['ClassFilterArray']);
     if ($classCondition === false) {
         return $nodeListArray;
     }
     // permissions
     $limitationParams = false;
     $limitationList = eZContentObjectTreeNode::getLimitationList($limitationParams);
     if ($limitationList === false) {
         return $nodeListArray;
     }
     $permissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
     // version
     $useVersionName = true;
     $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString($useVersionName);
     $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString($useVersionName);
     $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString($useVersionName);
     // invisible nodes.
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(false, $params['FetchHidden']);
     $query = '';
     if ($countChildren) {
         $query = "SELECT count(*) as count\n                          FROM\n                               ezcontentobject_tree,\n                               ezcontentobject,ezcontentclass\n                               {$versionNameTables}\n                               {$permissionChecking['from']}\n                          WHERE {$pathStringCond}\n                                {$classCondition}\n                                ezcontentclass.version=0 AND\n                                {$notEqParentString}\n                                ezcontentobject_tree.contentobject_id = ezcontentobject.id  AND\n                                ezcontentclass.id = ezcontentobject.contentclass_id\n                                {$versionNameJoins}\n                                {$permissionChecking['where']} ";
     } else {
         $query = "SELECT ezcontentobject.*,\n                             ezcontentobject_tree.*,\n                             ezcontentclass.serialized_name_list as class_serialized_name_list,\n                             ezcontentclass.identifier as class_identifier,\n                             ezcontentclass.is_container as is_container\n                             {$versionNameTargets}\n                      FROM\n                             ezcontentobject_tree,\n                             ezcontentobject,ezcontentclass\n                             {$versionNameTables}\n                             {$sortingInfo['attributeFromSQL']}\n                             {$permissionChecking['from']}\n                      WHERE\n                             {$pathStringCond}\n                             {$sortingInfo['attributeWhereSQL']}\n                             ezcontentclass.version=0 AND\n                             {$notEqParentString}\n                             ezcontentobject_tree.contentobject_id = ezcontentobject.id  AND\n                             ezcontentclass.id = ezcontentobject.contentclass_id AND\n                             {$classCondition}\n                             ezcontentobject_tree.contentobject_is_published = 1\n                             {$versionNameJoins}\n                             {$showInvisibleNodesCond}\n                             {$permissionChecking['where']}\n                      ORDER BY {$sortingInfo['sortingFields']}";
     }
     $db = eZDB::instance();
     $nodeListArray = $db->arrayQuery($query);
     // cleanup temp tables
     $db->dropTempTableList($permissionChecking['temp_tables']);
     if ($countChildren) {
         return $nodeListArray[0]['count'];
     } else {
         foreach ($nodeListArray as $key => $row) {
             $nodeListArray[$key]['path_identification_string'] = eZContentObjectTreeNode::fetch($row['node_id'])->pathWithNames();
         }
         return $nodeListArray;
     }
 }
 static function calendar($params = false, $nodeID = 0)
 {
     if (!is_numeric($nodeID) and !is_array($nodeID)) {
         return array();
     }
     if ($params === false) {
         $params = array('Depth' => false, 'Offset' => false, 'Limit' => false, 'AttributeFilter' => false, 'ExtendedAttributeFilter' => false, 'ClassFilterType' => false, 'ClassFilterArray' => false, 'GroupBy' => false);
     }
     $offset = isset($params['Offset']) && is_numeric($params['Offset']) ? $params['Offset'] : false;
     $limit = isset($params['Limit']) && is_numeric($params['Limit']) ? $params['Limit'] : false;
     $depth = isset($params['Depth']) && is_numeric($params['Depth']) ? $params['Depth'] : false;
     $depthOperator = isset($params['DepthOperator']) ? $params['DepthOperator'] : false;
     $groupBy = isset($params['GroupBy']) ? $params['GroupBy'] : false;
     $mainNodeOnly = isset($params['MainNodeOnly']) ? $params['MainNodeOnly'] : false;
     $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false;
     if (!isset($params['ClassFilterType'])) {
         $params['ClassFilterType'] = false;
     }
     $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($params['ClassFilterType'], $params['ClassFilterArray']);
     $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings($params['AttributeFilter'], $sortingInfo);
     $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['ExtendedAttributeFilter']);
     $mainNodeOnlyCond = eZContentObjectTreeNode::createMainNodeConditionSQLString($mainNodeOnly);
     $pathStringCond = '';
     $notEqParentString = '';
     eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator);
     $groupBySelectText = '';
     $groupBySQL = $extendedAttributeFilter['group_by'];
     if (!$groupBySQL) {
         eZContentObjectTreeNode::createGroupBySQLStrings($groupBySelectText, $groupBySQL, $groupBy);
     } else {
         if ($groupBy) {
             eZDebug::writeError("Cannot use group_by parameter together with extended attribute filter which sets group_by!", __METHOD__);
         }
     }
     $limitation = isset($params['Limitation']) && is_array($params['Limitation']) ? $params['Limitation'] : false;
     $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
     $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
     // Determine whether we should show invisible nodes.
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility);
     $query = "SELECT DISTINCT\n                         ezcontentobject.published as published\n                         {$groupBySelectText}\n                   FROM\n                      ezcontentobject_tree\n                      INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)\n                      INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                      INNER JOIN ezcontentobject_name ON (\n                          ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n                          ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n                      )\n\n                      {$attributeFilter['from']}\n                      {$extendedAttributeFilter['tables']}\n                      {$sqlPermissionChecking['from']}\n                   WHERE\n                      {$pathStringCond}\n                      {$extendedAttributeFilter['joins']}\n                      {$attributeFilter['where']}\n                      ezcontentclass.version = 0 AND\n                      {$notEqParentString}\n                      {$mainNodeOnlyCond}\n                      {$classCondition}\n                      " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n                      {$showInvisibleNodesCond}\n                      {$sqlPermissionChecking['where']}\n                {$groupBySQL}";
     $db = eZDB::instance();
     $server = count($sqlPermissionChecking['temp_tables']) > 0 ? eZDBInterface::SERVER_SLAVE : false;
     if (!$offset && !$limit) {
         $nodeListArray = $db->arrayQuery($query, array(), $server);
     } else {
         $nodeListArray = $db->arrayQuery($query, array('offset' => $offset, 'limit' => $limit), $server);
     }
     // cleanup temp tables
     $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
     return $nodeListArray;
 }
Esempio n. 3
0
 /**
  * Fetch top/bottom content (nodes) by rating++
  * 
  * @param array $params (see inline doc for details)
  * @return array Returs array of nodes (either objects or raw db output based on as_object param)
  */
 static function fetchNodeByRating($params)
 {
     /**
      * Works like fetch list/tree, except:
      * 1. Attribute filter is not supported (because of dependency on normal sort_by param)
      * 2. Supported sorting: rating, rating_count, object_count, published, modified and view_count.
      * 3. parent_node_id only works for list fetch, if you want tree fetch use 
      *    parent_node_path (format is like $node.path_string, as in '/1/2/144/256/').
      * 4. depth and depth_operator are not supported (so parent_node_path gives you unlimited depth).
      * 5. There are additional advance params to see rating, rating_count, object_count pr user / group
      *    see group_by_owner, owner_parent_node_id, owner_parent_node_path and owner_id.
      * 6. param 'include_not_rated' when set to true will use left join to also include unrated content
      */
     $ret = array();
     $whereSql = array();
     $offset = false;
     $limit = false;
     $fromSql = '';
     $asObject = isset($params['as_object']) ? $params['as_object'] : true;
     $loadDataMap = isset($params['load_data_map']) ? $params['load_data_map'] : false;
     $mainNodeOnly = isset($params['main_node_only']) ? $params['main_node_only'] : false;
     $ignoreVisibility = isset($params['ignore_visibility']) ? $params['ignore_visibility'] : false;
     $classFilterType = isset($params['class_filter_type']) ? $params['class_filter_type'] : false;
     $classFilterArray = isset($params['class_filter_array']) ? $params['class_filter_array'] : false;
     $includeNotRated = isset($params['include_not_rated']) ? $params['include_not_rated'] : false;
     $selectSql = 'ezcontentobject.*, ezcontentobject_tree.*,';
     $groupBySql = 'GROUP BY ezcontentobject_tree.node_id';
     $orderBySql = 'ORDER BY rating DESC, rating_count DESC';
     // default sorting
     // WARNING: group_by_owner only works as intended if user is owner of him self..
     if (isset($params['group_by_owner']) && $params['group_by_owner']) {
         // group by owner instead of content object and fetch users instead of content objects
         $selectSql = 'ezcontentobject.*, owner_tree.*,';
         $groupBySql = 'GROUP BY owner_tree.node_id';
     }
     if (isset($params['owner_parent_node_id']) and is_numeric($params['owner_parent_node_id'])) {
         // filter by parent node of owner (main user group)
         $parentNodeId = $params['owner_parent_node_id'];
         $whereSql[] = 'owner_tree.parent_node_id = ' . $parentNodeId;
     } else {
         if (isset($params['owner_parent_node_path']) and is_string($params['owner_parent_node_path'])) {
             // filter recursivly by parent node id
             // supported format is /1/2/144/256/ ( $node.path_string )
             $parentNodePath = $params['owner_parent_node_path'];
             $whereSql[] = "owner_tree.path_string != '{$parentNodePath}'";
             $whereSql[] = "owner_tree.path_string like '{$parentNodePath}%'";
         } else {
             if (isset($params['owner_id']) and is_numeric($params['owner_id'])) {
                 // filter by owner_id ( user / contentobject id)
                 $ownerId = $params['owner_id'];
                 $whereSql[] = 'ezcontentobject.owner_id = ' . $ownerId;
             }
         }
     }
     if (isset($params['parent_node_id']) and is_numeric($params['parent_node_id'])) {
         // filter by main parent node id
         $parentNodeId = $params['parent_node_id'];
         $whereSql[] = 'ezcontentobject_tree.parent_node_id = ' . $parentNodeId;
     } else {
         if (isset($params['parent_node_path'])) {
             if (is_string($params['parent_node_path'])) {
                 // filter recursivly by main parent node id
                 // supported format is /1/2/144/256/ ( $node.path_string )
                 $parentNodePath = $params['parent_node_path'];
                 $whereSql[] = "ezcontentobject_tree.path_string != '{$parentNodePath}'";
                 $whereSql[] = "ezcontentobject_tree.path_string like '{$parentNodePath}%'";
             } else {
                 eZDebug::writeError("Parameter 'parent_node_path' needs to be node path_string, was '{$params['parent_node_path']}'.", __METHOD__);
             }
         }
     }
     $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($classFilterType, $classFilterArray);
     if ($classCondition === false) {
         eZDebug::writeNotice("Class filter returned false", __MEHOD__);
         return null;
     }
     if (isset($params['limit'])) {
         $limit = (int) $params['limit'];
     }
     if (isset($params['offset'])) {
         $offset = (int) $params['offset'];
     }
     if ($includeNotRated) {
         $ratingFromSql = 'LEFT JOIN ezstarrating
                          ON ezstarrating.contentobject_id = ezcontentobject.id';
         $ratingWhereSql = '';
     } else {
         $ratingFromSql = ', ezstarrating';
         $ratingWhereSql = 'ezstarrating.contentobject_id = ezcontentobject.id AND';
     }
     if (isset($params['sort_by']) && is_array($params['sort_by'])) {
         $orderBySql = 'ORDER BY ';
         $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by'];
         foreach ($orderArr as $key => $order) {
             $orderBySqlPart = false;
             $direction = isset($order[1]) ? $order[1] : false;
             switch ($order[0]) {
                 case 'rating':
                     $orderBySqlPart = 'rating ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'rating_count':
                     $orderBySqlPart = 'rating_count ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'object_count':
                     $selectSql .= 'COUNT( ezcontentobject.id ) as object_count,';
                     $orderBySqlPart = 'object_count ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'published':
                     $orderBySqlPart = 'ezcontentobject.published ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'modified':
                     $orderBySqlPart = 'ezcontentobject.modified ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 case 'view_count':
                     // notice: will only fetch nodes that HAVE a entry in the ezview_counter table!!!
                     $selectSql .= 'ezview_counter.count as view_count,';
                     $fromSql .= ', ezview_counter';
                     $whereSql[] = 'ezcontentobject_tree.node_id = ezview_counter.node_id';
                     $orderBySqlPart = 'view_count ' . ($direction ? 'ASC' : 'DESC');
                     break;
                 default:
                     if (isset($params['extended_attribute_filter'])) {
                         $orderBySqlPart = $order[0] . ' ' . ($direction ? 'ASC' : 'DESC');
                     } else {
                         eZDebug::writeError("Unsuported sort type '{$order['0']}', for fetch_by_starrating().", __METHOD__);
                     }
                     break;
             }
             if ($orderBySqlPart) {
                 if ($key !== 0) {
                     $orderBySql .= ',';
                 }
                 $orderBySql .= $orderBySqlPart;
             }
         }
     }
     $whereSql = $whereSql ? implode($whereSql, ' AND ') . ' AND ' : '';
     $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['extended_attribute_filter']);
     $limitation = isset($params['limitation']) && is_array($params['limitation']) ? $params['limitation'] : false;
     $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
     $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
     $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject');
     $useVersionName = true;
     $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString($useVersionName);
     $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString($useVersionName);
     $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString($useVersionName, false);
     $mainNodeOnlyCond = eZContentObjectTreeNode::createMainNodeConditionSQLString($mainNodeOnly);
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility);
     $db = eZDB::instance();
     $sql = "SELECT\n                             {$selectSql}\n                             AVG( ezstarrating.rating_average ) as rating,\n                             SUM( ezstarrating.rating_count ) as rating_count,\n                             ezcontentclass.serialized_name_list as class_serialized_name_list,\n                             ezcontentclass.identifier as class_identifier,\n                             ezcontentclass.is_container as is_container\n                             {$versionNameTargets}\n                             {$extendedAttributeFilter['columns']}\n                            FROM\n                             ezcontentobject_tree,\n                             ezcontentobject_tree owner_tree,\n                             ezcontentclass\n                             {$fromSql}\n                             {$versionNameTables}\n                             {$extendedAttributeFilter['tables']}\n                             {$sqlPermissionChecking['from']}\n                             ,ezcontentobject\n                             {$ratingFromSql}\n                            WHERE\n                             {$extendedAttributeFilter['joins']}\n                             {$ratingWhereSql}\n                             ezcontentobject.id = ezcontentobject_tree.contentobject_id AND\n                             ezcontentobject.owner_id = owner_tree.contentobject_id AND\n                             owner_tree.node_id = owner_tree.main_node_id AND\n                             ezcontentclass.version=0 AND\n                             ezcontentclass.id = ezcontentobject.contentclass_id AND\n                             {$mainNodeOnlyCond}\n                             {$classCondition}\n                             {$whereSql}\n\t                         {$versionNameJoins}\n\t                         {$showInvisibleNodesCond}\n\t                         {$sqlPermissionChecking['where']}\n\t                         {$languageFilter}\n                            {$groupBySql}\n                            {$orderBySql}";
     $server = isset($sqlPermissionChecking['temp_tables'][0]) ? eZDBInterface::SERVER_SLAVE : false;
     if ($offset !== false || $limit !== false) {
         $rows = $db->arrayQuery($sql, array('offset' => $offset, 'limit' => $limit), $server);
     } else {
         $rows = $db->arrayQuery($sql, null, $server);
     }
     $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
     unset($db);
     if (isset($rows[0]) && is_array($rows)) {
         if ($asObject) {
             $ret = ezsrRatingObjectTreeNode::makeObjectsArray($rows);
             if ($loadDataMap) {
                 eZContentObject::fillNodeListAttributes($ret);
             }
         } else {
             $ret = $rows;
         }
     } else {
         if ($rows === false) {
             eZDebug::writeError('The ezstarrating table seems to be missing,
                       contact your administrator', __METHOD__);
             $ret = array();
         } else {
             $ret = array();
         }
     }
     return $ret;
 }
    static function calendar( $params = false, $nodeID = 0 )
    {
        if ( !is_numeric( $nodeID ) and !is_array( $nodeID ) )
        {
            return array();
        }

        if ( $params === false )
        {
            $params = array( 'Depth'                    => false,
                             'Offset'                   => false,
                             'Limit'                    => false,
                             'AttributeFilter'          => false,
                             'ExtendedAttributeFilter'  => false,
                             'ClassFilterType'          => false,
                             'ClassFilterArray'         => false,
                             'GroupBy'                  => false );
        }

        $offset           = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset']             : false;
        $limit            = ( isset( $params['Limit']  ) && is_numeric( $params['Limit']  ) ) ? $params['Limit']              : false;
        $depth            = ( isset( $params['Depth']  ) && is_numeric( $params['Depth']  ) ) ? $params['Depth']              : false;
        $depthOperator    = ( isset( $params['DepthOperator']     ) )                         ? $params['DepthOperator']      : false;
        $groupBy          = ( isset( $params['GroupBy']           ) )                         ? $params['GroupBy']            : false;
        $mainNodeOnly     = ( isset( $params['MainNodeOnly']      ) )                         ? $params['MainNodeOnly']       : false;
        $ignoreVisibility = ( isset( $params['IgnoreVisibility']  ) )                         ? $params['IgnoreVisibility']   : false;
        if ( !isset( $params['ClassFilterType'] ) )
            $params['ClassFilterType'] = false;

        $classCondition          = eZContentObjectTreeNode::createClassFilteringSQLString( $params['ClassFilterType'], $params['ClassFilterArray'] );
        $attributeFilter         = eZContentObjectTreeNode::createAttributeFilterSQLStrings( $params['AttributeFilter'], $sortingInfo );
        $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings( $params['ExtendedAttributeFilter'] );
        $mainNodeOnlyCond        = eZContentObjectTreeNode::createMainNodeConditionSQLString( $mainNodeOnly );

        $pathStringCond     = '';
        $notEqParentString  = '';
        eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings( $pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator );

        $groupBySelectText  = '';
        $groupBySQL         = $extendedAttributeFilter['group_by'];
        if ( !$groupBySQL )
        {
            eZContentObjectTreeNode::createGroupBySQLStrings( $groupBySelectText, $groupBySQL, $groupBy );
        }
        else if ( $groupBy )
        {
            eZDebug::writeError( "Cannot use group_by parameter together with extended attribute filter which sets group_by!", __METHOD__ );
        }

        $useVersionName     = true;
        $versionNameTables  = eZContentObjectTreeNode::createVersionNameTablesSQLString( $useVersionName );
        $versionNameJoins   = eZContentObjectTreeNode::createVersionNameJoinsSQLString( $useVersionName, false );

        $limitation = ( isset( $params['Limitation']  ) && is_array( $params['Limitation']  ) ) ? $params['Limitation']: false;
        $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation );
        $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList );

        // Determine whether we should show invisible nodes.
        $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( !$ignoreVisibility );

        $query = "SELECT DISTINCT
                         ezcontentobject.published as published
                         $groupBySelectText
                   FROM
                      ezcontentobject_tree,
                      ezcontentobject,ezcontentclass
                      $versionNameTables
                      $attributeFilter[from]
                      $extendedAttributeFilter[tables]
                      $sqlPermissionChecking[from]
                   WHERE
                      $pathStringCond
                      $extendedAttributeFilter[joins]
                      $attributeFilter[where]
                      ezcontentclass.version=0
                      AND
                      $notEqParentString
                      $mainNodeOnlyCond
                      ezcontentobject_tree.contentobject_id = ezcontentobject.id AND
                      ezcontentclass.id = ezcontentobject.contentclass_id AND
                      $classCondition
                      $versionNameJoins
                      $showInvisibleNodesCond
                      $sqlPermissionChecking[where]
                $groupBySQL";


        $db = eZDB::instance();

        $server = count( $sqlPermissionChecking['temp_tables'] ) > 0 ? eZDBInterface::SERVER_SLAVE : false;

        if ( !$offset && !$limit )
        {
            $nodeListArray = $db->arrayQuery( $query, array(), $server );
        }
        else
        {
            $nodeListArray = $db->arrayQuery( $query, array( 'offset' => $offset,
                                                              'limit'  => $limit ),
                                                      $server );
        }

        // cleanup temp tables
        $db->dropTempTableList( $sqlPermissionChecking['temp_tables'] );

        return $nodeListArray;
    }