public function fillCategoryData() { foreach ($this->categories as $category) { if (!($data = $this->modx->getObject('mSkladCategoryData', array('category_id' => $category['id'])))) { $data = $this->modx->newObject('mSkladCategoryData', array('category_id' => $category['id'])); $data->set('category_id', $category['id']); $data->save(); } if (!$data->get('uuid_1c')) { $uuid1c = ''; if ($exchange = $this->modx->getObject('mSkladCategoryExchange', array('category_id' => $category['id']))) { $uuid1c = $exchange->get('uuid_1c'); } if (!$uuid1c) { $uuid = new uuid(); $uuid1c = $uuid->get(); } $data->set('uuid_1c', $uuid1c); $data->save(); } if (!$data->get('uuid')) { if ($exchange = $this->modx->getObject('mSkladCategoryExchange', array('category_id' => $category['id']))) { $data->set('uuid', $exchange->get('uuid')); $data->save(); } } $data->set('active', 1); $data->save(); unset($data); } return true; }
public function process() { if (count($this->products) == 0) { return $this->failure($this->modx->lexicon('msklad_product_err_no_product')); } $stop = 0; if ($this->start == 0) { $this->modx->exec("UPDATE {$this->modx->getTableName('mSkladProductData')} SET active = 0"); } foreach ($this->products as $product) { if (!($data = $this->modx->getObject('mSkladProductData', array('product_id' => $product['id'])))) { $data = $this->modx->newObject('mSkladProductData', array('product_id' => $product['id'])); $data->set('product_id', $product['id']); $data->save(); } if (!$data->get('uuid_1c')) { $uuid1c = ''; if ($exchange = $this->modx->getObject('mSkladProductExchange', array('product_id' => $product['id']))) { $uuid1c = $exchange->get('uuid_1c'); } if (!$uuid1c) { $uuid = new uuid(); $uuid1c = $uuid->get(); } $data->set('uuid_1c', $uuid1c); $data->save(); } if (!$data->get('uuid')) { if ($exchange = $this->modx->getObject('mSkladProductExchange', array('product_id' => $product['id']))) { $data->set('uuid', $exchange->get('uuid')); $data->save(); } } if (!$data->get('price_uuid')) { if ($exchange = $this->modx->getObject('mSkladProductExchange', array('product_id' => $product['id']))) { $data->set('price_uuid', $exchange->get('price_uuid')); $data->save(); } } $data->set('active', 1); $data->save(); unset($data); } if ($this->start + 500 > $this->total) { $stop = 1; } return $this->success(array('total' => $this->total, 'stop' => $stop)); }
public function add($name = '', $id, $idName, $functionName, $sqlFile) { $this->loadConfig($name); $name = ($name === '' ? '' : '_') . $name; Logger::Log('starts ' . $functionName, LogLevel::DEBUG); // decode the received attachment data, as an object $insert = Transaction::decodeTransaction($this->_app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } $name = DBJson::mysql_real_escape_string($name); $id = DBJson::mysql_real_escape_string($id); $uuid = new uuid(); // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { $random = str_replace('-', '', $uuid->get()); $in->setTransactionId(null); // generates the insert data for the object $data = $in->getInsertData(); // starts a query, by using a given file $result = DBRequest::getRoutedSqlFile($this->query, $sqlFile, array('object' => $in, 'name' => $name, $idName => $id, 'random' => $random)); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $queryResult = Query::decodeQuery($result['content']); // sets the new auto-increment id $obj = new Transaction(); $course = Course::ExtractCourse($queryResult[count($queryResult) - 1]->getResponse(), true); $obj->setTransactionId($course->getId() . '_' . $queryResult[count($queryResult) - 2]->getInsertId() . '_' . $random); $res[] = $obj; $this->_app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { Logger::Log($functionName . ' failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->_app->response->setBody(Transaction::encodeTransaction($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Transaction::encodeTransaction($res[0])); } else { $this->_app->response->setBody(Transaction::encodeTransaction($res)); } }
public function init() { parent::init(); $uuid = new uuid(); $invite = new Zend_Form_Element_Hidden('invite'); $invite->setValue($uuid->get())->setRequired(true)->addValidator(new TA_Form_Validator_Uuid())->setDecorators(array('Composite')); $userModel = new Core_Model_User(); $roles = new Zend_Form_Element_Select('role_id'); $roles->setAttrib('class', 'small')->setLabel('Role')->setOrder(4)->addFilter('Null')->setMultiOptions($userModel->getRolesForSelect('---'))->setDecorators(array('Composite')); $this->addElements(array($roles, $invite)); }