File: /home/assibfaf/public_html/prox-classes/Presenter/Order/OrderLazyArray.php
<?php
/**
* @package Proxim
* @author Davison Pro <davis@davisonpro.dev | https://davisonpro.dev>
* @copyright 2020 Proxim
* @version 1.0
* @since File available since Release 1.0
*/
namespace Proxim\Presenter\Order;
use Proxim\Presenter\AbstractLazyArray;
use Doctrine\Common\Annotations\AnnotationException;
use Proxim\Application;
use Proxim\Configuration;
use Proxim\Currency;
use Proxim\Order\Order;
use Proxim\Preference\PaperFormat;
use Proxim\Preference\PaperType;
use Proxim\Util\ArrayUtils;
use Proxim\Util\DateUtils;
use Proxim\Validate;
class OrderLazyArray extends AbstractLazyArray {
/** @var Application */
public $application;
/** @var Order */
public $order;
/** @var Currency */
public $currency;
/** @var array $orderFiles */
public $orderFiles = array();
/** @var array $customerFiles */
public $customerFiles = array();
/** @var array $writerFiles */
public $writerFiles = array();
/** @var array $pdSchedule */
public $pdSchedule = array();
/** @var array $customerFilesCount */
public $customerFilesCount = 0;
/** @var array $writerFilesCount */
public $writerFilesCount = 0;
/** @var array $orderFilesCount */
public $orderFilesCount = 0;
/** @var array $unseenFilesCount */
public $unseenFilesCount = 0;
/** @var array $allMessagesCount */
public $allMessagesCount = 0;
/** @var array $countUnreadMessages */
public $countUnreadMessages = 0;
/** @var bool $latestFileIsDownloaded */
public $latestFileIsDownloaded = false;
/**
* OrderArray constructor.
*
* @throws AnnotationException
* @throws ReflectionException
*/
public function __construct(Order $order)
{
$this->application = Application::getInstance();
$this->order = $order;
$currency = new Currency( (int) $order->currency_id );
if(!Validate::isLoadedObject($currency)) {
$default_currency_id = (int) Configuration::get('CURRENCY_DEFAULT');
$currency = new Currency( $default_currency_id );
}
$this->currency = $currency;
/** Order Messages */
$orderMessages = $order->getMessages();
$countUnreadMessages = 0;
foreach( $orderMessages as $message ) {
if (
$message->sender_id != $order->customer_id &&
!$message->is_viewed
) {
$countUnreadMessages++;
}
}
$this->countUnreadMessages = $countUnreadMessages;
$this->allMessagesCount = count($orderMessages);
$orderFiles = $order->getFiles();
$writerFiles = $customerFiles = array();
$customerFilesCount = $writerFilesCount = $unseenFilesCount = 0;
foreach( $orderFiles as $file ) {
// customer files
if ($file->uploader_id == $order->customer_id) {
$customerFiles[] = $file;
$customerFilesCount++;
// writer files
} else {
if( $this->order->status_id == Order::DELIVERED ||
$this->order->status_id == Order::FINISHED
) {
// unseen files
if ( !$file->downloaded ) {
$unseenFilesCount++;
}
$writerFiles[] = $file;
$writerFilesCount++;
}
}
}
if ( $writerFilesCount > 0 ) {
$lastFile = ArrayUtils::shift($writerFiles);
if( Validate::isLoadedObject($lastFile) ) {
$this->latestFileIsDownloaded = (bool) $lastFile->downloaded;
}
}
$this->orderFilesCount = $customerFilesCount+$writerFilesCount;
$this->customerFilesCount = $customerFilesCount;
$this->writerFilesCount = $writerFilesCount;
$this->unseenFilesCount = $unseenFilesCount;
$this->customerFiles = $customerFiles;
$this->writerFiles = $writerFiles;
$this->orderFiles = $orderFiles;
parent::__construct();
}
/**
* @arrayAccess
*
* @return int
*/
public function getId()
{
return (int) $this->order->id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getParentId()
{
return (int) $this->order->parent_id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getTrackingId()
{
return (string) $this->order->tracking_id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getCustomerId()
{
return (int) $this->order->customer_id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getCurrencyId()
{
return (int) $this->currency->id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getCurrencyRate()
{
return (float) $this->currency->conversion_rate;
}
/**
* @arrayAccess
*
* @return int
*/
public function getWriterCategoryId()
{
return (int) $this->order->writer_category_id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getRequestedWriterId()
{
return (int) $this->order->requested_writer_id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getServiceType()
{
return (int) $this->order->service_type;
}
/**
* @arrayAccess
*
* @return string
*/
public function getServiceTypeTitle()
{
global $globals;
$service_type = ArrayUtils::get($globals['serviceTypes'], (int) $this->order->service_type);
return (string) ArrayUtils::get($service_type, 'title');
}
/**
* @arrayAccess
*
* @return int
*/
public function getStatus()
{
return (int) $this->order->status_id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getStatusId()
{
return (int) $this->order->status_id;
}
/**
* @arrayAccess
*
* @return string
*/
public function getStatusTitle()
{
global $globals;
$status = ArrayUtils::get($globals['orderStatuses'], (int) $this->order->status_id);
return (string) ArrayUtils::get($status, 'title');
}
/**
* @arrayAccess
*
* @return string
*/
public function getStatusDescription()
{
global $globals;
$status = ArrayUtils::get($globals['orderStatuses'], (int) $this->order->status_id);
return (string) ArrayUtils::get($status, 'description');
}
/**
* @arrayAccess
*
* @return string
*/
public function getTitle()
{
return (string) $this->order->title;
}
/**
* @arrayAccess
*
* @return int
*/
public function getAcademicLevel()
{
return (int) $this->order->academic_level_id;
}
/**
* @arrayAccess
*
* @return string
*/
public function getAcademicLevelTitle()
{
global $globals;
$academicLevel = ArrayUtils::get($globals['academicLevels'], (int) $this->order->academic_level_id);
return (string) ArrayUtils::get($academicLevel, 'title');
}
/**
* @arrayAccess
*
* @return int
*/
public function getPaperType()
{
return (int) $this->order->paper_type_id;
}
/**
* @arrayAccess
*
* @return string
*/
public function getPaperTypeTitle()
{
$paperType = new PaperType( (int) $this->order->paper_type_id );
if(Validate::isLoadedObject($paperType)) {
return (string) $paperType->title;
}
return "Other";
}
/**
* @arrayAccess
*
* @return string
*/
public function getPaperTypeOption() {
return $this->order->paper_type_option;
}
/**
* @arrayAccess
*
* @return int
*/
public function getTopicCategoryId() {
return (int) $this->order->topic_category_id;
}
/**
* @arrayAccess
*
* @return string
*/
public function getTopicCategory() {
return $this->order->topic_category_option;
}
/**
* @arrayAccess
*
* @return int
*/
public function getPaperFormat() {
return (int) $this->order->paper_format_id;
}
/**
* @arrayAccess
*
* @return string
*/
public function getPaperFormatTitle() {
$paperFormat = new PaperFormat( (int) $this->order->paper_format_id );
if(Validate::isLoadedObject($paperFormat)) {
return (string) $paperFormat->title;
}
return "Other";
}
/**
* @arrayAccess
*
* @return string
*/
public function getPaperFormatTypeOption() {
return $this->order->paper_type_option;
}
/**
* @arrayAccess
*
* @return int
*/
public function getPages() {
return (int) $this->order->pages;
}
/**
* @arrayAccess
*
* @return int
*/
public function getSlides() {
return (int) $this->order->slides;
}
/**
* @arrayAccess
*
* @return int
*/
public function getCharts() {
return (int) $this->order->charts;
}
/**
* @arrayAccess
*
* @return int
*/
public function getSources() {
return (int) $this->order->sources;
}
/**
* @arrayAccess
*
* @return string
*/
public function getSpacing() {
return $this->order->spacing;
}
/**
* @arrayAccess
*
* @return string
*/
public function getPaperDetails() {
return (string) $this->order->paper_details;
}
/**
* @arrayAccess
*
* @return string
*/
public function getComments() {
return (string) $this->order->comments;
}
/**
* @arrayAccess
*
* @return int
*/
public function getTariffId() {
return (int) $this->order->tariff_id;
}
/**
* @arrayAccess
*
* @return int
*/
public function getTariffHrs() {
return (int) $this->order->hrs_customer;
}
/**
* @arrayAccess
*
* @return float
*/
public function getTariffPricePerPage() {
return (float) $this->order->price_per_page;
}
/**
* @arrayAccess
*
* @return float
*/
public function getPrice() {
return (float) $this->order->total;
}
/**
* @arrayAccess
*
* @return float
*/
public function getTax() {
return (float) $this->order->tax;
}
/**
* @arrayAccess
*
* @return float
*/
public function getNoDiscountPrice() {
return (float) $this->order->raw_cost;
}
/**
* @arrayAccess
*
* @return int
*/
public function getCouponType() {
return (int) $this->order->discount_type;
}
/**
* @arrayAccess
*
* @return float
*/
public function getCouponValue() {
return (float) $this->order->discount;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getProgressiveDeliveryHidden() {
return (bool) $this->order->progressive_delivery;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getAreSamplesRequired() {
return (bool) $this->order->writer_samples;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getAreSourcesRequired() {
return (bool) $this->order->used_sources;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getExpertProofreading() {
return (bool) $this->order->expert_proofreading;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getVipSupport() {
return (bool) $this->order->vip_support;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getPlagiarismReport() {
return (bool) $this->order->plagiarism_report;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getDraftOutline() {
return (bool) $this->order->draft_outline;
}
/**
* @arrayAccess
*
* @return array
*/
public function getServices() {
/** Additional Services **/
$additionalServices = array();
if($this->order->service_type == Order::COMPLEX_ASSIGNMENT ) {
$additionalServices = $this->order->getAdditionalServices();
}
return $additionalServices;
}
/**
* @arrayAccess
*
* @return array
*/
public function getAdditionalPayments() {
return $this->order->getAdditionalPayments();
}
/**
* @arrayAccess
*
* @return int
*/
public function getAllFilesCount() {
return (int) $this->orderFilesCount;
}
/**
* @arrayAccess
*
* @return int
*/
public function getNewFilesCount() {
return (int) $this->unseenFilesCount;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getWithAdditionalMaterials() {
return count($this->customerFiles) > 0 ? true : false;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getLatestFileIsDownloaded() {
return (bool) $this->latestFileIsDownloaded;
}
/**
* @arrayAccess
*
* @return int
*/
public function getAllMessagesCount() {
return (int) $this->allMessagesCount;
}
/**
* @arrayAccess
*
* @return int
*/
public function getNewMessagesCount() {
return (int) $this->countUnreadMessages;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getPdSchedule() {
return $this->pdSchedule;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getIsPdScheduleAccepted() {
return false;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getIsPdScheduleRejected() {
return false;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getShowScheduleApproveRejectButton() {
return false;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getIsOnTimeQuestionNeeded() {
return true;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getHasReassignments() {
return false;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getIsWriterAvailableForRevision() {
return false;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getFullRefundAllowed() {
return false;
}
/**
* @arrayAccess
*
* @return bool
*/
public function getIsAvailableTrustpilot() {
return (bool) Configuration::get('TRUST_PILOT_ENABLED');
}
/**
* @arrayAccess
*
* @return bool
*/
public function getIsLeaveTipButtonVisible() {
return (bool) $this->order->leaveTipButtonVisible();
}
/**
* @arrayAccess
*
* @return string
*/
public function getCancelledAt() {
if( $this->order->status_id == Order::CANCELLED ) {
return DateUtils::convertToISOFormat($this->order->cancelled_at);
}
return;
}
/**
* @arrayAccess
*
* @return string
*/
public function getApprovedAt() {
if( $this->order->status_id == Order::FINISHED ) {
return DateUtils::convertToISOFormat($this->order->approved_at);
}
return;
}
/**
* @arrayAccess
*
* @return string
*/
public function getRealDeadline() {
return DateUtils::convertToISOFormat($this->order->customer_deadline);
}
/**
* @arrayAccess
*
* @return string
*/
public function getWhenIt() {
return DateUtils::convertToISOFormat($this->order->customer_deadline);
}
/**
* @arrayAccess
*
* @return string
*/
public function getCreatedAt() {
return DateUtils::convertToISOFormat($this->order->date_add);
}
}