function marketplaces() { $objs = new Marketplace(); $objs->get(); $data = array('marketplaces' => $objs); $this->load->view('backend/marketplaces', $data); }
function update() { $params = $this->input->post(); $obj = new Marketplace(); $obj->where('id', $params['id'])->update($params); echo $obj->check_last_query(); }
public static function instance() { if (is_null(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
public function getLatestAvailableVersionNumber() { if (defined('MULTI_SITE') && MULTI_SITE == 1) { $updates = Update::getLocalAvailableUpdates(); $multiSiteVersion = 0; foreach($updates as $up) { if (version_compare($up->getUpdateVersion(), $multiSiteVersion, '>')) { $multiSiteVersion = $up->getUpdateVersion(); } } Config::save('APP_VERSION_LATEST', $multiSiteVersion); return $multiSiteVersion; } $d = Loader::helper('date'); // first, we check session $queryWS = false; Cache::disableCache(); $vNum = Config::get('APP_VERSION_LATEST', true); Cache::enableCache(); if (is_object($vNum)) { $seconds = strtotime($vNum->timestamp); $version = $vNum->value; if (is_object($version)) { $versionNum = $version->version; } else { $versionNum = $version; } $diff = time() - $seconds; if ($diff > APP_VERSION_LATEST_THRESHOLD) { // we grab a new value from the service $queryWS = true; } } else { $queryWS = true; } if ($queryWS) { Loader::library('marketplace'); $mi = Marketplace::getInstance(); if ($mi->isConnected()) { Marketplace::checkPackageUpdates(); } $update = Update::getLatestAvailableUpdate(); $versionNum = $update->version; if ($versionNum) { Config::save('APP_VERSION_LATEST', $versionNum); if (version_compare($versionNum, APP_VERSION, '>')) { Loader::model('system_notification'); SystemNotification::add(SystemNotification::SN_TYPE_CORE_UPDATE, t('A new version of concrete5 is now available.'), '', $update->notes, View::url('/dashboard/system/update')); } } else { // we don't know so we're going to assume we're it Config::save('APP_VERSION_LATEST', APP_VERSION); } } return $versionNum; }
public function view() { $tp = new TaskPermission(); if ($tp->canInstallPackages()) { $mi = Marketplace::getInstance(); if ($mi->isConnected()) { Marketplace::checkPackageUpdates(); } } }
/** * Loads all details about a package. * * @return void */ public function load() { if ($this->loaded) { return; } $data = $this->loader->getPackageDetails($this->name); $this->fillFromArray($data['package']); $this->loaded = true; }
public static function getSlotContents() { if (!isset(self::$slots)) { $fh = Loader::helper('file'); Loader::library('marketplace'); $cfToken = Marketplace::getSiteToken(); $r = $fh->getContents(NEWSFLOW_SLOT_CONTENT_URL . '?cfToken=' . $cfToken); self::$slots = NewsflowSlotItem::parseResponse($r); } return self::$slots; }
public function download_update() { if (MULTI_SITE == 1) { return false; } $vt = Loader::helper('validation/token'); if (!$vt->validate('download_update')) { $this->error->add($vt->getErrorMessage()); } if (!is_dir(DIR_APP_UPDATES)) { $this->error->add(t('The directory %s does not exist.', DIR_APP_UPDATES)); } else { if (!is_writable(DIR_APP_UPDATES)) { $this->error->add(t('The directory %s must be writable by the web server.', DIR_APP_UPDATES)); } } if (!$this->error->has()) { $remote = Update::getApplicationUpdateInformation(); if (is_object($remote)) { // try to download Loader::library("marketplace"); $r = Marketplace::downloadRemoteFile($remote->url); if (empty($r) || $r == Package::E_PACKAGE_DOWNLOAD) { $response = array(Package::E_PACKAGE_DOWNLOAD); } else { if ($r == Package::E_PACKAGE_SAVE) { $response = array($r); } } if (isset($response)) { $errors = Package::mapError($response); foreach ($errors as $e) { $this->error->add($e); } } if (!$this->error->has()) { // the file exists in the right spot Loader::library('archive'); $ar = new UpdateArchive(); try { $ar->install($r); } catch (Exception $e) { $this->error->add($e->getMessage()); } } } else { $this->error->add(t('Unable to retrieve software from update server.')); } } $this->view(); }
public function download_update() { $p = new \Permissions(); if (!$p->canUpgrade()) { return false; } $vt = Loader::helper('validation/token'); if (!$vt->validate('download_update')) { $this->error->add($vt->getErrorMessage()); } if (!is_dir(DIR_CORE_UPDATES)) { $this->error->add(t('The directory %s does not exist.', DIR_CORE_UPDATES)); } else { if (!is_writable(DIR_CORE_UPDATES)) { $this->error->add(t('The directory %s must be writable by the web server.', DIR_CORE_UPDATES)); } } if (!$this->error->has()) { $remote = \Concrete\Core\Updater\Update::getApplicationUpdateInformation(); if (is_object($remote)) { // try to download $r = \Marketplace::downloadRemoteFile($remote->getDirectDownloadURL()); if (empty($r) || $r == \Package::E_PACKAGE_DOWNLOAD) { $response = array(\Package::E_PACKAGE_DOWNLOAD); } else { if ($r == \Package::E_PACKAGE_SAVE) { $response = array($r); } } if (isset($response)) { $errors = \Package::mapError($response); foreach ($errors as $e) { $this->error->add($e); } } if (!$this->error->has()) { // the file exists in the right spot $ar = new UpdateArchive(); try { $ar->install($r); } catch (Exception $e) { $this->error->add($e->getMessage()); } } } else { $this->error->add(t('Unable to retrieve software from update server.')); } } $this->view(); }
/** * Runs through all packages on the marketplace, sees if they're installed here, and updates the available version number for them */ public static function checkPackageUpdates() { Loader::model('system_notification'); $items = Marketplace::getAvailableMarketplaceItems(false); foreach ($items as $i) { $p = Package::getByHandle($i->getHandle()); if (is_object($p)) { // we only add a notification if it's newer than the last one we know about if (version_compare($p->getPackageVersionUpdateAvailable(), $i->getVersion(), '<') && version_compare($p->getPackageVersion(), $i->getVersion(), '<')) { SystemNotification::add(SystemNotification::SN_TYPE_ADDON_UPDATE, t('An updated version of %s is available.', $i->getName()), t('New Version: %s.', $i->getVersion()), '', View::url('/dashboard/extend/update'), $i->getRemoteURL()); } $p->updateAvailableVersionNumber($i->getVersion()); } } }
public function view($updated = false, $aux = false) { $u = new User(); $this->set('site_tracking_code', Config::get('SITE_TRACKING_CODE')); $this->set('url_rewriting', URL_REWRITING); $this->set('marketplace_enabled_in_config', Config::get('ENABLE_MARKETPLACE_SUPPORT')); $this->set('site', SITE); $this->set('ui_breadcrumb', $u->config('UI_BREADCRUMB')); $this->set('ui_filemanager', $u->config('UI_FILEMANAGER')); $this->set('ui_sitemap', $u->config('UI_SITEMAP')); $this->set('api_key_picnik', Config::get('API_KEY_PICNIK')); $txtEditorMode = Config::get('CONTENTS_TXT_EDITOR_MODE'); $this->set('txtEditorMode', $txtEditorMode); $this->set('rewriteRules', $this->getRewriteRules()); $textEditorWidth = Config::get('CONTENTS_TXT_EDITOR_WIDTH'); $this->set('textEditorWidth', $textEditorWidth); $textEditorHeight = Config::get('CONTENTS_TXT_EDITOR_HEIGHT'); $this->set('textEditorHeight', $textEditorHeight); $txtEditorCstmCode = Config::get('CONTENTS_TXT_EDITOR_CUSTOM_CODE'); if (!strlen($txtEditorCstmCode) || $txtEditorMode != 'CUSTOM') { $txtEditorCstmCode = $this->get_txt_editor_default(); } $this->set('txtEditorCstmCode', $txtEditorCstmCode); Loader::library('marketplace'); $mi = Marketplace::getInstance(); if ($mi->isConnected()) { $this->set('marketplacePageURL', Marketplace::getSitePageURL()); } if ($updated) { switch ($updated) { case 'statistics_saved': $this->set('message', t('Statistics tracking preference saved.')); break; case "tracking_code_saved": $this->set('message', t('Your tracking code has been saved.')); break; /* //moved to set_permissions case "maintenance_enabled"; $this->set('message', t('Maintenance Mode turned on. Your site is now private.')); break; case "maintenance_disabled": $this->set('message', t('Maintenance Mode turned off. Your site is public.')); break; */ /* //moved to set_permissions case "maintenance_enabled"; $this->set('message', t('Maintenance Mode turned on. Your site is now private.')); break; case "maintenance_disabled": $this->set('message', t('Maintenance Mode turned off. Your site is public.')); break; */ case "marketplace_turned_on": $this->set('message', t('Marketplace support is now enabled.')); break; case "marketplace_turned_off": $this->set('message', t('Marketplace support is now disabled.')); break; case "favicon_saved": $this->set('message', t('Bookmark icon saved.')); break; case "favicon_removed": $this->set('message', t('Bookmark icon removed.')); break; case "editing_preferences_saved": $this->set('message', t('Editing preferences saved.')); break; case "sitename_saved": $this->set('message', t("Your site's name has been saved.")); break; case "image_editing_saved": $this->set('message', t("Image editing options have been saved.")); break; case "debug_saved": $this->set('message', t('Debug configuration saved.')); break; case "cache_cleared": $this->set('message', t('Cached files removed.')); break; case "cache_updated": $this->set('message', t('Cache settings saved.')); break; case "txt_editor_config_saved": $this->set('message', t('Content text editor settings saved.')); break; case "rewriting_saved": if (URL_REWRITING) { if ($aux == 0) { $this->set('message', t('URL rewriting enabled. Make sure you copy the lines below these URL Rewriting settings area and place them in your .htaccess or web server configuration file.')); } else { $this->set('message', t('URL rewriting enabled. .htaccess file updated.')); } } else { $this->set('message', t('URL rewriting disabled.')); } break; } } }
public function execute() { $params = $this->params; $params['version'] = APP_VERSION; $params['itemsPerPage'] = $this->itemsPerPage; Loader::library("marketplace"); $mi = Marketplace::getInstance(); $params['csToken'] = $mi->getSiteToken(); if ($this->includeInstalledItems) { $params['includeInstalledItems'] = 1; } else { $params['includeInstalledItems'] = 0; $list = Package::getInstalledList(); foreach ($list as $pkg) { $params['installedPackages'][] = $pkg->getPackageHandle(); } } if (isset($_REQUEST[$this->queryStringPagingVariable])) { $params[$this->queryStringPagingVariable] = $_REQUEST[$this->queryStringPagingVariable]; } $uh = Loader::helper('url'); $url = $uh->buildQuery(MARKETPLACE_REMOTE_ITEM_LIST_WS . $this->type . '/-/get_remote_list', $params); $r = Loader::helper('file')->getContents($url); $r2 = @Loader::helper('json')->decode($r); $total = 0; $items = array(); if (is_object($r2)) { $items = $r2->items; $total = $r2->total; } $this->total = $total; $this->setItems($items); }
public function view() { $tp = new TaskPermission(); $mi = Marketplace::getInstance(); if ($mi->isConnected() && $tp->canInstallPackages()) { Loader::model('marketplace_remote_item'); $mri = new MarketplaceRemoteItemList(); $mri->setItemsPerPage(9); $sets = MarketplaceRemoteItemList::getItemSets('themes'); $setsel = array('' => t('All Items'), 'FEATURED' => t('Featured Items')); if (is_array($sets)) { foreach ($sets as $s) { $setsel[$s->getMarketplaceRemoteSetID()] = $s->getMarketplaceRemoteSetName(); } } $sortBy = array('' => t('Recommended'), 'popular' => t('Popular'), 'recent' => t('Recently Added'), 'rating' => t('Highest Rated'), 'price_low' => t('Price: Low to High'), 'price_high' => t('Price: High to Low')); $mri->setIncludeInstalledItems(false); if (isset($_REQUEST['marketplaceRemoteItemSetID'])) { $set = $_REQUEST['marketplaceRemoteItemSetID']; } if (isset($_REQUEST['mpID'])) { $mri->filterByMarketplaceItemID($_REQUEST['mpID']); } if (isset($_REQUEST['marketplaceRemoteItemSortBy'])) { $this->set('selectedSort', Loader::helper('text')->entities($_REQUEST['marketplaceRemoteItemSortBy'])); $mri->sortBy($_REQUEST['marketplaceRemoteItemSortBy']); } else { $mri->sortBy('recommended'); } if (isset($_REQUEST['marketplaceIncludeOnlyCompatibleAddons']) && $_REQUEST['marketplaceIncludeOnlyCompatibleAddons'] == 1) { $mri->filterByCompatibility(1); } if (isset($_REQUEST['marketplaceRemoteItemKeywords']) && $_REQUEST['marketplaceRemoteItemKeywords']) { $keywords = $_REQUEST['marketplaceRemoteItemKeywords']; $sortBy = array('relevance' => t('Relevance')) + $sortBy; } if ($keywords != '') { $mri->filterByKeywords($keywords); } if ($set == 'FEATURED') { $mri->filterByIsFeaturedRemotely(1); } else { if ($set > 0) { $mri->filterBySet($set); } } $mri->setType('themes'); $mri->execute(); $items = $mri->getPage(); $this->set('sortBy', $sortBy); $this->set('selectedSet', $set); $this->set('list', $mri); $this->set('items', $items); $this->set('form', Loader::helper('form')); $this->set('sets', $setsel); $this->set('pagination', $mri->getPagination()); $this->set('type', $what); } else { $this->redirect('/dashboard/extend/connect'); } }
public function addByIDAction() { $request = $this->request; $response = $this->response; $flash = $this->flash; if ($request->isPost()) { $product_id = $request->getPost('product_id', 'int'); $mplace_id = $request->getPost('mplace_id', 'int'); $lang = $request->getPost('lang', 'string'); $product = PProductMain::findFirst($product_id); $mplace = Marketplace::findFirst($mplace_id); // Validations if (!$product) { $flash->error('Ошибка: товар не найден!'); return $response->redirect('seller/addbyid'); } if ($product->hold == 1) { $flash->error('Ошибка: товар на холде!'); return $response->redirect('seller/addbyid'); } if (!$mplace) { $flash->error('Ошибка: площадка не найдена!'); return $response->redirect('seller/addbyid'); } if (!preg_match("/{$lang}/", $mplace->prefs)) { $flash->error('Ошибка: язык не соответствует площадке!'); return $response->redirect('seller/addbyid'); } // Check for appropriate marketseller $marketseller = Marketseller::findFirst("user_id={$this->auth->id} AND marketplace_id={$mplace_id} AND tmaterial_id={$product->tmaterial_id} AND langcode LIKE '%{$lang}%'"); // If there is no marketseller or if the product is already placed create a new marketseller if (!$marketseller or MPlacement::findFirst("marketseller_id={$marketseller->id} AND product_id={$product->id}")) { $mseller = new Marketseller(); $mseller->id = $mseller->id(); $mseller->created = time(); $mseller->updated = time(); $mseller->fio = "{$product->PCategoryGroup->title} на {$mplace->title}"; $mseller->user_id = $this->auth->id; $mseller->marketplace_id = $mplace_id; $mseller->tmaterial_id = $product->tmaterial_id; $mseller->langcode = $mplace->prefs; if (!$mseller->create()) { $flash->error('Ошибка при создании нового виртуального магазина!'); return $response->redirect('seller/addbyid'); } else { return $response->redirect("seller/product/{$mseller->id}/{$product_id}/{$lang}"); } } else { return $response->redirect("seller/product/{$marketseller->id}/{$product_id}/{$lang}"); } } }
$blueprint->makeAction(['name' => 'getDetails', 'pattern' => '{vendor}/{package}', 'routeParametersCallback' => function ($action, array $options) { return [$options['vendor'], $options['package']]; }]); $blueprint->makeToolbarItem(['action' => 'getDetails', 'label' => 'Show Details', 'icon' => 'info-circle']); $blueprint->makeAction(['name' => 'postRequire', 'pattern' => '{vendor}/{package}/require/{version?}', 'method' => 'POST', 'routeParametersCallback' => function ($action, array $options) { return [$options['vendor'], $options['package']]; }]); $blueprint->makeToolbarItem(['action' => 'postRequire', 'label' => 'Require', 'icon' => 'plus', 'color' => 'green'])->addDynamicCallback(function ($item, $arguments) { $installer = Marketplace::getInstaller(); $package = $arguments['vendor'] . '/' . $arguments['package']; if ($installer->isRequired($package)) { $item->color = 'red'; $item->icon = 'trash-o'; $item->label = 'Remove'; } }); $blueprint->makeAction(['name' => 'getInstalled', 'pattern' => 'installed']); $blueprint->makeToolbarItem(['action' => 'getInstalled', 'label' => 'Installed Packages', 'icon' => 'list', 'color' => 'white']); $blueprint->makeAction(['name' => 'postToggleProvider', 'pattern' => 'provider/toggle/{class}', 'method' => 'POST', 'routeParametersCallback' => function ($action, array $options) { return [$options['provider']]; }]); $blueprint->makeToolbarItem(['action' => 'postToggleProvider', 'label' => 'Enable', 'icon' => 'check', 'color' => 'white', 'shouldRenderCallback' => function (ActionToolbarItem $item, array $arguments) { return $item->shouldRenderBasic($arguments) && !Marketplace::getProviderRepository()->isCore($arguments['provider']); }])->addDynamicCallback(function ($item, $arguments) { $repository = Marketplace::getProviderRepository(); if ($repository->isEnabled($arguments['provider'])) { $item->icon = 'power-off'; $item->label = 'Disable'; } }); });
</div> @endif </div> <div class="Cell-twoThirds Cell--last"> <h1 class="heading-alpha">{{{ $package->getPrettyName() }}}</h1> @if($package->getPrettyName() !== $package->getName()) <h2 class="heading-gamma"><code>{{{ $package->getName() }}}</code></h2> @endif <div class="Header-toolbar Header-toolbar--alignLeft Header-toolbar--padding"> <?php $item = $blueprint->getToolbarItem('postRequire'); $arguments = ['vendor' => $package->getSplitName()[0], 'package' => $package->getSplitName()[1]]; if ($item->shouldRender($arguments)) { echo $item->render($arguments); } $item = new DisabledToolbarItem('Status: ' . Marketplace::getInstaller()->getStatus($package->getName())); echo $item->render(); ?> </div> </div> </div> <div class="Row Row--alignTop Row--border Row--singleLine"> <div class="Cell-oneThird"> <ul class="List--bordered"> <li><span class="Icon Icon--pushRight Icon-fw Icon-star"></span>{{{ $package->favers }}} stars</li> <li><span class="Icon Icon--pushRight Icon-fw Icon-download"></span>{{{ $package->downloads['total'] }}} downloads</li> <li><span class="Icon Icon--pushRight Icon-fw Icon-user"></span>Authored by {{{ $package->getAuthorsAsSentence() }}}</li> <li><span class="Icon Icon--pushRight Icon-fw Icon-clock-o"></span>Added on {{{ $package->time->toFormattedDateString() }}}</li> <li><span class="Icon Icon--pushRight Icon-fw Icon-info-circle"></span><code>{{{ $package->getName() }}}</code></li> <li><span class="Icon Icon--pushRight Icon-fw Icon-code-fork"></span>Latest Version: <code>{{{ $package->getLatestVersion()['version'] }}}</code></li> @if(isset($package->homepage) && $package->homepage !== '')
$coreBlockTypes[] = $_bt; } else { $webBlockTypes[] = $_bt; } } } $availableArray = array_merge($btAvailableArray, $pkgAvailableArray); usort($availableArray, 'sortAvailableArray'); /* Load featured add-ons from the marketplace. */ Loader::model('collection_attributes'); $db = Loader::db(); if(ENABLE_MARKETPLACE_SUPPORT && $tp->canInstallPackages()){ $purchasedBlocksSource = Marketplace::getAvailableMarketplaceItems(); }else{ $purchasedBlocksSource = array(); } // now we iterate through the purchased items (NOT BLOCKS, THESE CAN INCLUDE THEMES) list and removed ones already downloaded // This really should be made into a more generic object since it's not block types anymore. $skipHandles = array(); foreach($availableArray as $ava) { foreach($purchasedBlocksSource as $pi) { if ($pi->getHandle() == $ava->getPackageHandle()) { $skipHandles[] = $ava->getPackageHandle(); } } }
<?php defined('C5_EXECUTE') or die("Access Denied."); session_write_close(); // first, we check to see if the dashboard image data has been set in the cache if (DASHBOARD_BACKGROUND_INFO != false) { if ($_REQUEST['image'] && preg_match('/([0-9]+)\\.jpg/i', $_REQUEST['image'])) { $imageData = Cache::get('dashboard_image_data', $_REQUEST['image']); if (!$imageData) { // call out to the server to grab the data Loader::library('marketplace'); $cfToken = Marketplace::getSiteToken(); $imageData = Loader::helper('file')->getContents(DASHBOARD_BACKGROUND_INFO . '?image=' . $_REQUEST['image'] . '&cfToken=' . $cfToken); Cache::set('dashboard_image_data', $_REQUEST['image'], $imageData); } } print $imageData; }
public function update($pkgHandle = false) { $tp = new TaskPermission(); if ($tp->canInstallPackages()) { if ($pkgHandle) { $tests = Package::testForInstall($pkgHandle, false); if (is_array($tests)) { $tests = Package::mapError($tests); $this->set('error', $tests); } else { $p = Package::getByHandle($pkgHandle); try { $p->upgradeCoreData(); $p->upgrade(); $this->set('message', t('The package has been updated successfully.')); } catch(Exception $e) { $this->set('error', $e); } } } else { $mi = Marketplace::getInstance(); if ($mi->isConnected()) { Marketplace::checkPackageUpdates(); } } } }
<?php defined('C5_EXECUTE') or die("Access Denied."); $valt = Loader::helper('validation/token'); $ci = Loader::helper('concrete/urls'); $ch = Loader::helper('concrete/ui'); $tp = new TaskPermission(); if ($tp->canInstallPackages()) { $mi = Marketplace::getInstance(); } $pkgRemote = array(); $pkgLocal = array(); if (Config::get('concrete.marketplace.enabled') && is_object($mi)) { if ($mi->isConnected()) { $pkgArray = Package::getInstalledList(); foreach ($pkgArray as $pkg) { if ($pkg->isPackageInstalled() && version_compare($pkg->getPackageVersion(), $pkg->getPackageVersionUpdateAvailable(), '<')) { $pkgRemote[] = $pkg; } } } } $pkgAvailableArray = Package::getLocalUpgradeablePackages(); foreach ($pkgAvailableArray as $pkg) { if (!in_array($pkg, $pkgRemote)) { $pkgLocal[] = $pkg; } } ?> <?php echo Loader::helper('concrete/dashboard')->getDashboardPaneHeaderWrapper(t('Update Add-Ons'));
/** * Common function for gathering stats * * @param string $input_role - user role * @param string $selspec - identificator for various types of seller stats (marketplaces, lang) */ private function stats($input_role = null, $selspec = null) { // If there is no role specified this is a regular type of stats (phorocoder, translators, moderators...) $user_roles = $input_role == null ? $this->user_roles : $input_role; $months = $this->months; $days_ru = $this->days_ru; $month_and_year = date('m.Y', time()); // Current month and year // Change month and year to ones selected by user if ($this->request->isPost() && !empty($this->request->getPost('month_and_year', 'string'))) { $month_and_year = $this->request->getPost('month_and_year', 'string'); } $first_day_of_month = strtotime("01.{$month_and_year}"); $first_day_of_next_month = strtotime("01.{$month_and_year} + 1 month"); $num_of_days = (int) (($first_day_of_next_month - $first_day_of_month) / 86400); // Number of days in the month // Array of days in the selected month in unix timestamp for ($i = 1; $i <= $num_of_days; $i++) { $days[] = strtotime("{$i}.{$month_and_year}"); } $days[] = $first_day_of_next_month; // Find stats for a month // photocoder, copywriter/moder, translator/moder if ($input_role == null) { $tasks = new PTasks(); // @todo remove + 7200 !!!!!!!!!!!!!!!! set db server to correct time $sql = "SELECT COUNT(t1.id) AS count, FROM_UNIXTIME(t1.tstart + 7200, '%Y-%m-%d') AS cdate, t1.tstart, t1.trole, t1.tlang, t1.tassignee, t1.tprodid\n FROM p_tasks AS t1\n WHERE t1.tstart BETWEEN {$first_day_of_month} AND {$first_day_of_next_month} AND (t1.tstatus = 3 OR t1.tstatus = 5)\n GROUP BY t1.trole, t1.tlang, t1.tassignee, t1.tprodid, cdate\n ORDER BY t1.tassignee DESC;"; $stats = new Resultset(null, $tasks, $tasks->getReadConnection()->query($sql)); $stats = $stats->toArray(); // seller } elseif ($input_role == 'seller') { $field = "user_id"; if ($selspec == 'mplace') { $field = "marketplace_id"; } // Marketplaces stats if ($selspec == 'lang') { $field = "langcode"; } // Langs stats $tasks = new MPlacement(); $sql = "SELECT COUNT(mp.id) AS count, FROM_UNIXTIME(mp.created + 7200, '%Y-%m-%d') AS cdate, mp.created, mp.user_id, mp.marketplace_id, mp.langcode\n FROM mplacement AS mp\n WHERE mp.created BETWEEN {$first_day_of_month} AND {$first_day_of_next_month}\n GROUP BY mp.{$field}, cdate\n ORDER BY mp.{$field}, cdate"; $stats = new Resultset(null, $tasks, $tasks->getReadConnection()->query($sql)); $stats = $stats->toArray(); } // Find regular sellers and APIs if ($input_role == 'seller' && $selspec == null) { $all_sellers = Accounts::getUsersByRole('seller', false, 'name'); $this->view->regular_sellers = $regular_sellers = preg_grep('/^(?!API)/', $all_sellers); $this->view->api_sellers = $api_sellers = preg_grep('/^API/', $all_sellers); } // All marketplaces if ($input_role == 'seller' && $selspec == 'mplace') { $all_marketplaces = array_column(Marketplace::find(['columns' => 'title, id', 'order' => 'title'])->toArray(), 'title', 'id'); } // All langs if ($input_role == 'seller' && $selspec == 'lang') { $all_langs = array_column(PLangs::find(['columns' => 'alias', 'order' => 'id'])->toArray(), 'alias', 'alias'); } $roles = []; $assignee = []; foreach ($stats as $stat) { // Regular stats if ($input_role == null) { $roles[$stat['trole']][$stat['tlang']][$stat['tassignee']][] = $stat['tstart']; // Seller stats } elseif ($input_role == 'seller' && $selspec == null) { $seller_stats[$stat['user_id']][$stat['cdate']] = (int) $stat['count']; // Seller marketplaces stats } elseif ($input_role == 'seller' && $selspec == 'mplace') { $seller_stats[$stat['marketplace_id']][$stat['cdate']] = (int) $stat['count']; // Seller langs stats } elseif ($input_role == 'seller' && $selspec == 'lang') { $seller_stats[$stat['langcode']][$stat['cdate']] = (int) $stat['count']; } // Link user_id to his name if it's not already linked // Regular stats if ($input_role == null) { if (empty($assignee[$stat['tassignee']])) { if ($acc_name = Accounts::findFirst($stat['tassignee'])) { $assignee[$stat['tassignee']] = $acc_name->name; } } // Seller stats } elseif ($input_role == 'seller' && $selspec == null) { if (empty($assignee[$stat['user_id']])) { foreach ($all_sellers as $seller_id => $seller_name) { if ($stat['user_id'] == $seller_id) { $assignee[$stat['user_id']] = $seller_name; } } } // Seller marketplaces stats } elseif ($input_role == 'seller' && $selspec == 'mplace') { if (empty($assignee[$stat['marketplace_id']])) { foreach ($all_marketplaces as $marketplace_id => $marketplace_name) { if ($stat['marketplace_id'] == $marketplace_id) { $assignee[$stat['marketplace_id']] = $marketplace_name; } } } // Seller langs stats } elseif ($input_role == 'seller' && $selspec == 'lang') { if (empty($assignee[$stat['langcode']])) { foreach ($all_langs as $k => $v) { if ($stat['langcode'] == $v) { $assignee[$stat['langcode']] = $v; } } } } } $day_count = []; $time_array = []; // Regular stats (photocoder, copywriter/moder, translator/moder) if ($input_role == null) { // Array of roles/langs/users/days/tasks foreach ($roles as $role => $langs) { foreach ($langs as $lang => $data) { foreach ($data as $user => $times) { $day_index = 0; foreach ($days as $day) { foreach ($times as $time) { // If task time is between the selected day and the next day if ($time >= $day && $time < $days[$day_index + 1]) { $time_array[$role][$lang][$user][$day][] = $time; } } $day_index++; // Number of user's tasks for a day $day_count[$role][$lang][$user][$day] = !empty($time_array[$role][$lang][$user][$day]) ? count($time_array[$role][$lang][$user][$day]) : null; } } } } // Stats for sellers } elseif ($input_role == 'seller' && $selspec == null) { // Array of users/days/count foreach ($seller_stats as $seller => $seller_info) { foreach ($seller_info as $seller_day => $seller_count) { $day_index = 0; foreach ($days as $day) { $unixts = strtotime($seller_day); if ($unixts == $day) { if (isset($regular_sellers[$seller])) { $time_array['seller'][$seller][$day] = $seller_count; } if (isset($api_sellers[$seller])) { $time_array['api'][$seller][$day] = $seller_count; } } $day_index++; // Number of user's tasks for a day $day_count['seller'][$seller][$day] = !empty($time_array['seller'][$seller][$day]) ? $time_array['seller'][$seller][$day] : null; $day_count['api'][$seller][$day] = !empty($time_array['api'][$seller][$day]) ? $time_array['api'][$seller][$day] : null; } } } // Stats for marketplaces } elseif ($input_role == 'seller' && $selspec == 'mplace') { // Array of marketplaces/days/count foreach ($seller_stats as $seller => $seller_info) { foreach ($seller_info as $seller_day => $seller_count) { $day_index = 0; foreach ($days as $day) { $unixts = strtotime($seller_day); if ($unixts == $day) { $time_array['seller'][$seller][$day] = $seller_count; } $day_index++; // Number of user's tasks for a day $day_count['seller'][$seller][$day] = !empty($time_array['seller'][$seller][$day]) ? $time_array['seller'][$seller][$day] : null; } } } // Stats for seller langs } elseif ($input_role == 'seller' && $selspec == 'lang') { // Array of langs/days/count foreach ($seller_stats as $seller => $seller_info) { foreach ($seller_info as $seller_day => $seller_count) { $day_index = 0; foreach ($days as $day) { $unixts = strtotime($seller_day); if ($unixts == $day) { $time_array['seller'][$seller][$day] = $seller_count; } $day_index++; // Number of user's tasks for a day $day_count['seller'][$seller][$day] = !empty($time_array['seller'][$seller][$day]) ? $time_array['seller'][$seller][$day] : null; } } } } // ------------------------------------------- // Regular stats if ($input_role == null) { $done['photocoder'] = PProductMain::count("hasphoto = 1 AND status >= 3"); $done['copywriter'] = PProdInfo::count("coder_status >= 3 AND lang = 'ru'"); $done['moderatorCopywriting'] = PProdInfo::count("coder_status = 5 AND lang = 'ru'"); $done['translator'] = PProdInfo::count(["coder_status >= 3", 'group' => 'lang', 'order' => 'id']); $done['moderatorTranslating'] = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id']); $todo['photocoder'] = PProductMain::count("hasphoto = 1 AND status < 3 OR status IS NULL AND hold = 0"); $todo['copywriter'] = $done['photocoder'] - $done['copywriter']; $todo['moderatorCopywriting'] = PProdInfo::count("coder_status = 3 AND lang = 'ru'"); $todo['translator'] = $done['translator']; $todo['moderatorTranslating'] = PProdInfo::count(["coder_status = 3", 'group' => 'lang', 'order' => 'id']); $langs = PProdInfo::count(['group' => 'lang', 'order' => 'id']); foreach ($langs as $lang) { $all_langs[] = $lang->lang; } $this->view->total = PProdInfo::count("coder_status = 5 AND lang = 'ru'"); $this->view->done = $done; $this->view->todo = $todo; $this->view->all_langs = $all_langs; } $this->view->day_count = $day_count; $this->view->days = $days; $this->view->user_roles = $user_roles; $this->view->assignee = $assignee; $this->view->month = $months[substr($month_and_year, 0, 2)]; $this->view->month_and_year = $month_and_year; $this->view->year = substr($month_and_year, 3); $this->view->days_ru = $days_ru; $this->view->total_num_of_placements = MPlacement::count(); }