/*!
\param $asObject If \c true return them as objects.
\param $showInactive If \c true it will include status items that are not active, default is \c false.
\return A list of defined orders sorted by status ID.
356930
static function fetchPolicyList( $showInactive = false )
    {
        $db = eZDB::instance();

        $conditionText = '';
        if ( !$showInactive )
            $conditionText = ' WHERE is_active = 1';

        $rows = $db->arrayQuery( "SELECT status_id AS id, name FROM ezorder_status$conditionText" );
        return $rows;
    }
797902
public static function fetchBySourceURL( $url, $asObject = true )
    {
        return eZPersistentObject::fetchObject( self::definition(),
                                                null,
                                                array( "source_url" => $url ),
                                                $asObject );
    }
440261
public function hasInternalAlias($publicUrl, $asObject = false, $mode = null)
    {
        $ret = null;
        if (isset($this->batch[$publicUrl])) {
            $alias = $this->batch[$publicUrl];
        } else {
            $alias = $this->repository->findOneByPublicUrl($publicUrl, $mode);
        }
        if ($alias) {
            $ret = ($asObject ? $alias : $alias->getInternalUrl());
        }

        return $ret;
    }
848750
public function getOrderByIdentifier($orderBy)
    {
        $objectManager = $this->getObjectManager();
        $classMetadata = $objectManager->getClassMetadata($this->getEntityClass());

        if (strpos($orderBy, '::') === false) {

            if (!$classMetadata->hasField($orderBy)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid order by column: Entity "%s" has no field "%s"',
                    $this->getEntityClass(),
                    $orderBy
                ));
            }

            $orderByIdentifier = $this->getEntityClassAlias()
                               . '.'
                               . $orderBy;
        } else {
            list($association, $assocProperty) = explode('::', $orderBy);

            if (!$classMetadata->hasAssociation($association)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid order by column: Entity "%s" has no association "%s"',
                    $this->getEntityClass(),
                    $association
                ));
            }

            if (in_array($assocProperty, array('count'))) {
                //@FIXME
                $orderByIdentifier = $this->getEntityClassAlias()
                                   . '.id';

            } else {
                $assocTargetClass = $classMetadata->getAssociationTargetClass($association);

                if (!$objectManager->getClassMetadata($assocTargetClass)->hasField($assocProperty)) {
                    throw new \InvalidArgumentException(sprintf(
                        'Invalid order by column: Entity "%s" has no field "%s"',
                        $assocTargetClass,
                        $assocProperty
                    ));
                }

                $joinAlias         = self::JOIN_ALIAS_PREFIX . $association;
                $orderByIdentifier = $joinAlias . '.' . $assocProperty;
            }
        }

        return $orderByIdentifier;
    }
316689
static function active( $asObject = true, $offset, $limit, $sortField = "created", $sortOrder = "asc", $show = eZOrder::SHOW_NORMAL )
    {
        if ( $sortField == "user_name" )
        {
            $db = eZDB::instance();

            $db_params = array();
            $db_params["offset"] =(int) $offset;
            $db_params["limit"] =(int) $limit;
            $sortOrder = $db->escapeString( $sortOrder );

            $query = "SELECT ezorder.*
                      FROM
                            ezorder,
                            ezcontentobject
                      WHERE
                            ".eZOrder::getShowOrdersQuery( $show, "ezorder" )." AND
                            ezorder.is_temporary = '0' AND
                            ezcontentobject.id = ezorder.user_id
                      ORDER BY ezcontentobject.name $sortOrder";
            $orderArray = $db->arrayQuery( $query, $db_params );
            if ( $asObject )
            {
                $retOrders = array();
                foreach ( $orderArray as $order )
                {
                    $order = new eZOrder( $order );
                    $retOrders[] = $order;
                }
                return $retOrders;
            }
            else
            {
                return $orderArray;
            }
        }
        else
        {
            $where['is_temporary'] = 0;
            if ( $show != eZOrder::SHOW_ALL )
            {
                $where['is_archived'] = $show;
            }

            return eZPersistentObject::fetchObjectList( eZOrder::definition(),
                                                        null,
                                                        $where ,
                                                        array( $sortField => $sortOrder ),
                                                        array( 'offset' => $offset,
                                                               'length' => $limit ), $asObject );
        }
    }
493108
static function fetchList( $asObject = true )
    {
        return eZPersistentObject::fetchObjectList( eZRSSExport::definition(),
                                                    null, array( 'status' => self::STATUS_VALID ), null, null,
                                                    $asObject );
    }
1205129
public function orderBy() {
        $args = func_get_args();
        $this->build()->bindExpression('orderBy', $args[0] . " " . (empty($args[1]) ? ' ASC ' : " $args[1]"));

        return $this->connection;
    }
1076787
static function result( $actionName, $asObject = false )
    {
        $ini = eZINI::instance( 'browse.ini' );
        $isNodeSelection = $ini->variable( $actionName, 'ReturnType' ) == 'NodeID';
        if ( $isNodeSelection )
            $postName = 'SelectedNodeIDArray';
        else
            $postName = 'SelectedObjectIDArray';
        $http = eZHTTPTool::instance();
        if ( $http->hasPostVariable( $postName ) && !$http->hasPostVariable( 'BrowseCancelButton' ) )
        {
            $postList = $http->postVariable( $postName );
            $list = array();
            foreach ( $postList as $value )
            {
                if ( !is_numeric( $value ) )
                {
                    eZDebug::writeError( "Non-numeric value ($value) found for POST variable $postName for browse action '$actionName', the value will be excluded",
                                         'eZContentBrowse::result' );
                    continue;
                }
                // Append the value as a real integer, avoids XSS problems.
                $intValue = (int)$value;
                if ( $value != $intValue )
                {
                    eZDebug::writeError( "Non-integer value ($value) found for POST variable $postName for browse action '$actionName', the value will be excluded",
                                         'eZContentBrowse::result' );
                    continue;
                }
                $list[] = $intValue;
            }
            return array_unique( $list );
        }
        return false;
    }
652612
public function convertStatus($order, $statusId, $flush = false, $persist = true)
    {
        if ($order instanceof Order) {
            $order = $order->getEntity();
        }

        // get current status
        $currentStatus = $order->getStatus();
        if ($currentStatus) {
            if ($currentStatus instanceof \Massive\Bundle\Purchase\OrderBundle\Api\OrderStatus) {
                $currentStatus = $order->getStatus()->getEntity();
            }

            // if status has not changed, skip
            if ($currentStatus->getId() === $statusId) {
                return;
            }
        }

        // get desired status
        $statusEntity = $this->em
            ->getRepository(self::$orderStatusEntityName)
            ->find($statusId);
        if (!$statusEntity) {
            throw new EntityNotFoundException(self::$orderStatusEntityName, $statusId);
        }

        // ACTIVITY LOG
        $orderActivity = new OrderActivityLog();
        $orderActivity->setOrder($order);
        if ($currentStatus) {
            $orderActivity->setStatusFrom($currentStatus);
        }
        $orderActivity->setStatusTo($statusEntity);
        $orderActivity->setCreated(new \DateTime());
        if ($persist) {
            $this->em->persist($orderActivity);
        }

        // BITMASK
        $currentBitmaskStatus = $order->getBitmaskStatus();
        // if desired status already is in bitmask, remove current state
        // since this is a step back
        if ($currentBitmaskStatus && $currentBitmaskStatus & $statusEntity->getId()) {
            $order->setBitmaskStatus($currentBitmaskStatus & ~$currentStatus->getId());
        } else {
            // else increment bitmask status
            $order->setBitmaskStatus($currentBitmaskStatus | $statusEntity->getId());
        }

        // check if status has changed
        if ($statusId === OrderStatusEntity::STATUS_CREATED) {
            // TODO: re-edit - do some business logic
        }
        $order->setStatus($statusEntity);

        if ($flush === true) {
            $this->em->flush();
        }
    }
1154510
public function presence($status = null, $show = 'available', $to = null, $type='available', $priority=0) {
		if($type == 'available') $type = '';
		$to	 = htmlspecialchars($to);
		$status = htmlspecialchars($status);
		if($show == 'unavailable') $type = 'unavailable';
		
		$out = "<presence";
		if($to) $out .= " to=\"$to\"";
		if($type) $out .= " type='$type'";
		if($show == 'available' and !$status) {
			$out .= "/>";
		} else {
			$out .= ">";
			if($show != 'available') $out .= "<show>$show</show>";
			if($status) $out .= "<status>$status</status>";
			if($priority) $out .= "<priority>$priority</priority>";
			$out .= "</presence>";
		}
		
		$this->send($out);
	}
1352045
static function fetchFilteredList( $cond, $asObject = true, $status = eZRSSExport::STATUS_VALID )
    {
        return eZPersistentObject::fetchObjectList( eZRSSExportItem::definition(),
                                                    null, $cond, array( 'id' => 'asc',
                                                                        'status' => $status ), null,
                                                    $asObject );
    }
657115
public static function getList($sorted = false, $activeOnly = false)
    {
        $list = [];
        $db = Loader::db();
        $q = $db->query('SELECT * FROM AuthenticationTypes'
            . ($activeOnly ? ' WHERE authTypeIsEnabled=1 ' : '')
            . ' ORDER BY ' . ($sorted ? 'authTypeDisplayOrder' : 'authTypeID'));
        while ($row = $q->fetchRow()) {
            $list[] = self::load($row);
        }

        return $list;
    }
697467
static function fetchCount( $orderID, $asObject = true )
    {
        $db = eZDB::instance();

        $orderID = (int)$orderID;
        $countArray = $db->arrayQuery(  "SELECT count( * ) AS count FROM ezorder_status_history WHERE order_id = $orderID" );
        return $countArray[0]['count'];
    }
245731
static function fetchAllClasses( $asObject = true, $includeFilter = true, $groupList = false )
    {
        $filterTableSQL = '';
        $filterSQL = '';
        if ( is_array( $groupList ) )
        {
            $filterTableSQL = ', ezcontentclass_classgroup ccg';
            $filterSQL = ( " AND" .
                           "      cc.id = ccg.contentclass_id AND" .
                           "      ccg.group_id " );
            $groupText = implode( ', ', $groupList );
            if ( $includeFilter )
                $filterSQL .= "IN ( $groupText )";
            else
                $filterSQL .= "NOT IN ( $groupText )";
        }

        $classNameFilter = eZContentClassName::sqlFilter( 'cc' );

        $classList = array();
        $db = eZDB::instance();
        // If $asObject is true we fetch all fields in class
        $fields = $asObject ? "cc.*" : "cc.id, $classNameFilter[nameField]";
        $rows = $db->arrayQuery( "SELECT DISTINCT $fields " .
                                 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from] " .
                                 "WHERE cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . "$filterSQL AND $classNameFilter[where]" .
                                 "ORDER BY $classNameFilter[nameField] ASC" );

        $classList = eZPersistentObject::handleRows( $rows, 'eZContentClass', $asObject );
        return $classList;
    }
859920
public static function finds($condition = NULL, $rows = 0, $start = 0, $order='', $fields = '*', $object = true) {
        return static::dao($object)->finds($condition,$rows,$start,$order,$fields);
    }
913885
def show
      @order = Effective::Order.find(params[:id])
      EffectiveOrders.authorize!(self, :show, @order)

      @page_title ||= ((@order.user == current_user && !@order.purchased?) ? 'Checkout' : @order.to_s)
    end
1022
public function getPosibleTransitions(StatableInterface $object =  null, $objectIdentifier = 'id')
    {
        if (empty($object)) {
            return;
        }

        $sm = $this->factory->get($object, $object->getStateGraph());

        if (empty($sm)) {
            return;
        }

        $tasks = array();
        $accessor = PropertyAccess::createPropertyAccessor();

        foreach ($object->getStateTransitions() as $transition) {
            if ($sm->can($transition)) {

                $color = $this->getTransitionColor($transition);
                $tasks[] = array(
                    'id' => $accessor->getValue($object, $objectIdentifier),
                    'name' => $transition,
                    'color' => $color,
                    'graph' => $object->getStateGraph(),
                    'label' => $this->getTransition($transition),
                    'negative' => $this->isNegativeColor($color, 'transition'),
                    'positive' => $this->isPositiveColor($color, 'transition'),
                );
            }
        }

        return empty($tasks) ? null : $tasks;
    }