/** * Save the data of the server group * * @param string $name * @param integer $fill_type * @param boolean $active * @param integer $serverGroupId * * @return number|boolean */ public static function saveAll($name, $fill_type, $active = false, $serverGroupId = null) { if (!empty($serverGroupId) && is_numeric($serverGroupId)) { $servergroup = Doctrine::getTable('ServersGroups')->find($serverGroupId); } else { $servergroup = new ServersGroups(); } $servergroup->name = $name; $servergroup->fill_type = intval($fill_type); $servergroup->active = $active ? 1 : 0; if ($servergroup->trySave()) { return $servergroup->group_id; } return false; }
public function init() { // Set the custom decorator $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $translate = Shineisp_Registry::get('Zend_Translate'); $this->addElement('text', 'name', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Product name'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'nickname', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Product Nickname'), 'description' => $translate->_('This is the short name of the product'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'uri', array('filters' => array('StringTrim'), 'label' => $translate->_('URI'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'sku', array('filters' => array('StringTrim'), 'label' => $translate->_('SKU'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('textarea', 'shortdescription', array('filters' => array('StringTrim'), 'label' => $translate->_('Short Description'), 'id' => 'shortdescription', 'class' => 'col-lg-12 form-control wysiwyg')); $this->addElement('textarea', 'metakeywords', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'label' => $translate->_('Keywords'), 'rows' => 5, 'class' => 'col-lg-12 form-control')); $this->addElement('textarea', 'metadescription', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'label' => $translate->_('Meta Description'), 'rows' => 5, 'class' => 'col-lg-12 form-control')); $this->addElement('textarea', 'description', array('filters' => array('StringTrim'), 'label' => $translate->_('Description'), 'id' => 'description', 'class' => 'col-lg-12 form-control wysiwyg')); $this->addElement('select', 'category_id', array('label' => $translate->_('Category'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('category_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(ProductsCategories::getList()); $this->addElement('select', 'welcome_mail_id', array('label' => $translate->_('Welcome E-Mail'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('welcome_mail_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(EmailsTemplates::getList()); $this->addElement('select', 'server_group_id', array('label' => $translate->_('Server group'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('server_group_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(ServersGroups::getList(true)); $this->addElement('select', 'autosetup', array('label' => $translate->_('Automatic setup'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('autosetup')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(array('0' => 'Do not automatically setup this product', '1' => 'Automatically setup the product as soon as an order is placed', '2' => 'Automatically setup the product as soon as the first payment is received', '3' => 'Automatically setup the product when you manually accept a pending order', '4' => 'Automatically setup the product as soon as the payment is complete')); $this->addElement('multiselect', 'related', array('label' => $translate->_('Related Products'), 'decorators' => array('Bootstrap'), 'size' => '20x', 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->addElement('multiselect', 'upgrade', array('label' => $translate->_('Product Upgrades'), 'decorators' => array('Bootstrap'), 'size' => '20x', 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->getElement('related')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Products::getList()); $this->getElement('upgrade')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Products::getList()); $this->addElement('select', 'tax_id', array('label' => 'Tax', 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('tax_id')->setAllowEmpty(false)->setMultiOptions(Taxes::getList(true)); $this->addElement('text', 'cost', array('filters' => array('StringTrim'), 'label' => $translate->_('Cost'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'price_1', array('filters' => array('StringTrim'), 'label' => $translate->_('Price'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'setupfee', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup Fee'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('textarea', 'setup', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup'), 'decorators' => array('Bootstrap'), 'description' => $translate->_('XML Setup Configuration. See the manual'), 'class' => 'col-lg-12 form-control')); $this->addElement('select', 'enabled', array('label' => $translate->_('Enabled'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'Disabled', '1' => 'Active'))); $this->addElement('select', 'ishighlighted', array('label' => $translate->_('Is Highlighted'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'isrefundable', array('label' => $translate->_('Is Refundable'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'default', array('label' => $translate->_('Default Image'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'iscomparable', array('label' => $translate->_('Is Comparable'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'showonrss', array('label' => $translate->_('Publish on RSS Feed'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'downgradable', array('label' => $translate->_('Allow downgrades'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'type', array('label' => $translate->_('Product Type'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('generic' => $translate->_('Generic'), 'domain' => $translate->_('Domain'), 'hosting' => $translate->_('Hosting')))); // If the browser client is an Apple client hide the file upload html object if (false == Shineisp_Commons_Utilities::isAppleClient()) { $this->addElement('text', 'filedescription', array('filters' => array('StringTrim'), 'label' => $translate->_('Description'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $MBlimit = Settings::findbyParam('adminuploadlimit'); $Byteslimit = Shineisp_Commons_Utilities::MB2Bytes($MBlimit); $filetypes = Settings::findbyParam('adminuploadfiletypes', 'Admin'); $file = $this->createElement('file', 'attachments', array('label' => $translate->_('Attachment'), 'decorators' => array('File', array('ViewScript', array('viewScript' => 'partials/file.phtml', 'placement' => false))), 'description' => $translate->_('Select the document to upload. Files allowed are (%s) - Max %s', $filetypes, Shineisp_Commons_Utilities::formatSizeUnits($Byteslimit)), 'data-classButton' => 'btn btn-primary', 'data-input' => 'false', 'class' => 'filestyle')); $file->addValidator('Extension', false, $filetypes)->addValidator('Size', false, $Byteslimit)->addValidator('Count', false, 1); $this->addElement($file); } $this->addElement('multiselect', 'wikipages', array('label' => $translate->_('Wiki Pages'), 'decorators' => array('Bootstrap'), 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->getElement('wikipages')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Wiki::getList()); $this->addElement('select', 'tranche_billing_cycle_id', array('label' => $translate->_('Billing Cycle'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('tranche_billing_cycle_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(BillingCycle::getList()); $this->addElement('text', 'tranche_qty', array('filters' => array('StringTrim'), 'label' => $translate->_('Quantity'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'tranche_measure', array('filters' => array('StringTrim'), 'label' => $translate->_('Measurement label'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'tranche_setupfee', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup fee'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'tranche_price', array('filters' => array('StringTrim'), 'label' => $translate->_('Unit Price'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('multiselect', 'tranche_includes_domains', array('isArray' => true, 'label' => $translate->_('Domain included'), 'decorators' => array('Bootstrap'), 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->getElement('tranche_includes_domains')->setAllowEmpty(true)->setRegisterInArrayValidator(false)->setMultiOptions(DomainsTlds::getList()); $this->addElement('select', 'group_id', array('decorators' => array('Bootstrap'), 'label' => $translate->_('Attribute Group'), 'required' => true, 'class' => 'form-control')); $this->getElement('group_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(ProductsAttributesGroups::getList()); $this->addElement('text', 'position', array('decorators' => array('Bootstrap'), 'label' => $translate->_('Position'), 'class' => 'form-control')); $this->addElement('textarea', 'blocks', array('filters' => array('StringTrim'), 'label' => $translate->_('Blocks'), 'decorators' => array('Bootstrap'), 'class' => 'col-lg-12 form-control')); $this->addElement('hidden', 'product_id'); }
/** * extractServersFromGroup: * extract servers from group accordingly to server group fill_type * @param INT $group_id: id of the group to extract from * @param INT $server_type: optional server type id to extract. If empty, one server for each type is extracted * @return ARRAY * */ public static function extractServersFromGroup($group_id, $server_type = null) { $arrOutput = array(); $group_id = isset($group_id) ? intval($group_id) : null; $server_type = isset($server_type) ? intval($server_type) : null; if (!$group_id) { return $arrOutput; } // Get the fill_type for requested group $ServersGroups = ServersGroups::find($group_id); if (!$ServersGroups || !isset($ServersGroups->fill_type)) { return $arrOutput; } $fill_type = (int) $ServersGroups->fill_type; /* '1' => 'Create services on the least full server', '2' => 'Fill default server until full then switch to next least used', '3' => 'Fill servers starting from the newest to the older', '4' => 'Fill servers starting from the older to the newest', '5' => 'Fill servers randomly', '6' => 'Fill manually. Only default server will be used.', '7' => 'Fill servers starting from the cheaper to the expensive.', '8' => 'Fill servers starting from the expensive to the cheaper.', */ // Get all servers inside this group $serverIds = ServersGroups::getServers($group_id, 's.*'); // Get servers details $ORM = Doctrine_Query::create()->from('Servers s')->leftJoin('s.Servers_Types st')->leftJoin('s.Statuses stat')->leftJoin('s.Panels panel')->leftJoin('s.Servers_Types')->leftJoin('s.CustomAttributesValues')->whereIn('s.server_id', $serverIds); if ($server_type) { $ORM = $ORM->andWhere('s.type_id = ?', $server_type); } $ORM = $ORM->execute(); // Create an array with type_id as index $arrServers = array(); foreach ($ORM as $y) { $type_id = $y->type_id; $server_id = $y->server_id; $services = isset($y->services) ? intval($y->services) : 0; $max_services = isset($y->max_services) && $y->max_services > 0 ? intval($y->max_services) : 10000; $buy_timestamp = isset($y->buy_date) ? strtotime($y->buy_date) : 0; $is_default = isset($y->is_default) ? intval($y->is_default) : 0; // Skip full servers if ($services >= $max_services) { Shineisp_Commons_Utilities::logs(__METHOD__ . " " . $server_type . " is full!", 'servers.log'); continue; } $usagePercent = round($services * 100 / $max_services); $arrServers[$type_id][$server_id] = $y->toArray(); $arrServers[$type_id][$server_id]['is_default'] = $is_default; $arrServers[$type_id][$server_id]['_usagePercent'] = $usagePercent; $arrServers[$type_id][$server_id]['_buyTimestamp'] = $buy_timestamp; } // Cycle servers by type foreach ($arrServers as $type_id => $serverType) { $tmp = array(); // temporary array // Extract server switch ($fill_type) { case 1: // 'Create services on the least full server' // 'Create services on the least full server' case 2: // 'Fill default server until full then switch to next least used' $method = $fill_type === 1 ? SORT_ASC : SORT_DESC; $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, '_usagePercent', $method); break; case 3: // 'Fill servers starting from the newest to the older' // 'Fill servers starting from the newest to the older' case 4: // 'Fill servers starting from the older to the newest' $method = $fill_type === 3 ? SORT_DESC : SORT_ASC; $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, '_buyTimestamp', $method); break; case 5: // 'Fill servers randomly' $randKey = array_rand($serverType); $tmp = array($randKey => $randKey); break; case 6: // 'Fill manually. Only default server will be used.' $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, 'is_default', SORT_DESC); break; case 7: // 'Fill servers starting from the cheaper to the expensive.' // 'Fill servers starting from the cheaper to the expensive.' case 8: // 'Fill servers starting from the expensive to the cheaper.' $method = $fill_type === 7 ? SORT_ASC : SORT_DESC; $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, 'cost', $method); } reset($tmp); $selectedServer = key($tmp); $arrOutput[$type_id][$selectedServer] = $arrServers[$type_id][$selectedServer]; } if (isset($server_type) && isset($arrOutput[$server_type])) { // return just the server array $key = key($arrOutput[$server_type]); $arrOutput = $arrOutput[$server_type][$key]; } Shineisp_Commons_Utilities::logs(__METHOD__ . '(' . $group_id . ', ' . $server_type . '): ' . serialize($arrOutput), 'servers.log'); // Return return $arrOutput; }
/** * processAction * Update the record previously selected * @return unknown_type */ public function processAction() { $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $form = $this->getForm("/admin/serversgroups/process"); $request = $this->getRequest(); // Create the buttons in the edit form $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/serversgroups/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/serversgroups/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null))); try { // Check if we have a POST request if (!$request->isPost()) { return $this->_helper->redirector('list', 'serversgroups', 'admin'); } if ($form->isValid($request->getPost())) { // Get the values posted $params = $form->getValues(); // Save the data $id = ServersGroups::saveAll($params['name'], $params['fill_type'], $params['active'], $this->getRequest()->getParam('group_id')); // Delete the old group ServersGroupsIndexes::deleteAllServers($id); if (!empty($params['servers'])) { ServersGroupsIndexes::AddServers($id, $params['servers']); } $this->_helper->redirector('edit', 'serversgroups', 'admin', array('id' => $id, 'mex' => $this->translator->translate('The task requested has been executed successfully.'), 'status' => 'success')); } else { $this->view->form = $form; $this->view->title = $this->translator->translate("Servers Groups"); $this->view->description = $this->translator->translate("Here you can edit the group detail"); return $this->render('applicantform'); } } catch (Exception $e) { $this->_helper->redirector('edit', 'serversgroups', 'admin', array('id' => $id, 'mex' => $e->getMessage(), 'status' => 'danger')); } }