/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get video parent $item->get_parent = static::lazy_load(function () use($item) { return Model_Application::find_one_by_id($item->content_id); }, $item->id, 'parent', 'object'); // Get video details $item->get_youtube = static::lazy_load(function () use($item) { $object = new \stdClass(); $youtube = \App\Youtube::forge(); $object->data = $youtube->parse($item->url)->get(); $object->embed = $youtube->embed($item->url); return $object; }, $item->id, 'youtube', 'object'); } } } // return the result return $result; }
/** * Добавление нового платежа по заявке. * * @param float $amount Размер платежа. * @param int $app_id Идентификатор заявки. * @return boolean */ public function add($amount, $app_id) { $sql = ' INSERT INTO ' . $this->_tables['payments'] . ' (app_id, amount, created) VALUES (:app_id, :amount, NOW()) '; $values = array(':app_id' => $app_id, ':amount' => $amount); $stmt = $this->prepare($sql); $exRes = $stmt->execute($values); // типа триггер: проверка на то, что новый платеж сделает дисциплину/программу полностью оплаченной if ($this->isAppPrepaid($app_id)) { $app = Model_Application::create(); $app->setAppStatus(Model_Application::STATUS_PREPAID, $app_id); } return $exRes; }
public static function get_by_slug($slug = false) { if ($seo = \Application\Model_Seo::find_one_by_slug($slug)) { return Model_Application::find_one_by_id($seo->content_id); } return false; }
/** * Delete content image * * @param $content_id = Content ID */ public function action_delete_image($content_id = null) { try { if ($application = Model_Application::find_one_by_id($content_id)) { if (!empty($application->hotspot) && !empty($application->hotspot->images)) { foreach ($application->hotspot->images as $image) { $this->delete_image($image->image); $image->delete(); } } $this->delete_image($application->hotspot_image); $application->hotspot_alt_text = null; $application->hotspot_image = null; if ($application->save()) { \Messages::success('Hotspot image was successfully deleted.'); } else { \Messages::error('There was an error while trying to delete hotspot image.'); } } } catch (\Database_Exception $e) { // show validation errors \Messages::error('There was an error while trying to delete hotspot image.'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } \Response::redirect(\Input::referrer()); }
public function action_sort($type = false) { if (!$type) { return false; } $items = \Input::post('sort'); if (is_array($items)) { foreach ($items as $item) { list($item, $old_item) = explode('_', $item); if (is_numeric($item)) { $sort[] = $item; } if (is_numeric($old_item)) { $old_sort[] = $old_item; } } if (is_array($sort)) { // Get starting point for sort $start = min($old_sort); $start = $start > 0 ? --$start : $start; $model = Model_Application::factory(ucfirst($type)); foreach ($sort as $key => $id) { $item = $model::find_one_by_id($id); $item->set(array('cover' => $key == 0 ? 1 : 0, 'sort' => ++$start)); $item->save(); } \Messages::success('Items successfully reordered.'); echo \Messages::display('left', false); } } }
/** * Отображение доступных учебных материалов. */ public function action_show(array $params = array()) { $a = Model_Test::create(); $a->test(); $links = Resources::getInstance()->links; if (!isset($params['discipline_id']) || is_int($params['discipline_id'])) { $this->flash('Не указан идентификатор дисциплины', $links->get('student.programs')); } $discipline_id = intval($params['discipline_id']); $user = Model_User::create(); $udata = (object) $user->getAuth(); $session = Resources_Abstract::getInstance()->session; // если данных о доступных дисциплинах нет - вычислить if (!isset($session->availDisciplines)) { $student = Model_Education_Students::create(); $avail_programs = $student->getAvailDisciplinesForPrograms($udata->user_id); $avail_disciplines = $student->getAvailDisciplinesSeparate($udata->user_id); } $discipline_open = in_array($discipline_id, $session->availDisciplines); if ($discipline_open) { // дисциплина доступна $disc = Model_Discipline::create(); $discipline_data = $disc->get($discipline_id); $section = Model_Section::create(); $sections = $section->getAllByDiscipline($discipline_id); $modelApps = Model_Application::create(); $statuses = $modelApps->getAppsStatus($discipline_id, $udata->user_id); //== Model_Application::STATUS_FINISHED; $statusFinished = array_key_exists(Model_Application::STATUS_FINISHED, $statuses); $material = Model_Educational_Materials::create(); $materials = $material->getAllByDiscipline($discipline_id, $statusFinished); $control_work = Model_ControlWork::create(); $tests = $control_work->getTestsByDiscipline($discipline_id); $this->set('discipline', $discipline_data); $this->set('sections', $sections); $this->set('materials', $materials); $this->set('tests', $tests); $this->set('user_id', $udata->user_id); //print_r($materials); $this->render(); } else { $this->flash('Данная дисциплина на данный Вам недоступна. Возможно Вы не полностью оплатили заявку по данной дисциплине или программе, содержащей данную дисциплину, либо вообще не подавали заявку на ее изучение.', $links->get('student.programs'), 5); } }
/** * Manage related products * * @param $id = Product ID */ public function action_list($id) { if (!is_numeric($id)) { \Response::redirect('admin/application/list'); } // Get news item to edit if (!($item = Model_Application::find_one_by_id($id))) { \Response::redirect('admin/application/list'); } if (\Input::post()) { $add = \Input::post('products.add', array()); $remove = \Input::post('products.remove', array()); if (\Input::post('add', false)) { foreach ($add as $value) { $related = Model_Application_To_Related::forge(array('related_id' => $value, 'application_id' => $item->id)); $related->save(); } \Messages::success('Related products successfully added.'); } else { if (\Input::post('remove', false)) { foreach ($remove as $value) { $related = Model_Application_To_Related::find_one_by(array(array('related_id', '=', $value), array('application_id', '=', $item->id))); if (!is_null($related)) { $related->delete(); } } \Messages::success('Related products successfully removed.'); } } if (\Input::is_ajax()) { echo \Messages::display('left', false); exit; } else { \Response::redirect(\Input::referrer(\Uri::create('admin/application/list'))); } } \View::set_global('title', 'List Related Products'); $search = $this->get_search_items($item); $pagination = $search['pagination']; $status = $search['status']; $item = $search['item']; \Theme::instance()->set_partial('content', $this->view_dir . 'list')->set('application', $item)->set('pagination', $pagination, false)->set('status', $status); }
/** * Удаление заявки из базы данных. * * @todo Удалять ли платежи из базы при удалении заявки? * Зачем нукжно вообще удалять заявки??? Какому бизнес-процессу это соответствует? */ public function action_delete($params) { $links = Resources::getInstance()->links; //$return_url = $links->get('admin.applications',array ('sort_field' => 'fio', 'sort_direction' => 'asc')); //$return_url = $links->get('admin.applications',array ('sort_field' => $params['sort_field'], 'sort_direction' => $params['sort_direction'])); $return_url = $links->get('admin.applications'); if (empty($params)) { $this->flash('Не указан номер заявки', $return_url); } $app_id = intval(array_shift($params)); $app = Model_Application::create(); if (!$app->delete($app_id)) { $msg = 'Не удалось удалить заявку с номером ' . $app_id; } else { $msg = 'Заявка успешно удалена'; } $this->flash($msg, $return_url); }
/** * Открыта ли дисциплина для студента * * @param int $disciplineId * @param int $studentId * @param array $statuses Статусы заявок студента * @return bool */ public function isDisciplineOpenForStudent($disciplineId, $studentId, $statuses = false) { $result = false; $modelApps = Model_Application::create(); if (!$statuses) { $statuses = $modelApps->getAppsStatus($disciplineId, $studentId); } if (array_key_exists(Model_Application::STATUS_PREPAID, $statuses) || array_key_exists(Model_Application::STATUS_FINISHED, $statuses)) { $result = true; } elseif ($k = array_search(Model_Application::STATUS_SIGNED, $statuses) !== false) { foreach ($statuses[$k] as $appId) { $appInfo = $modelApps->getAppInfo($appId); $modelEducationPrograms = Model_Education_Programs::create(); if ($appInfo['type'] == 'discipline') { $programId = $modelEducationPrograms->getProgramIdByDiscipline($appInfo['object_id']); } elseif ($appInfo['type'] == 'program') { $programId = $appInfo['object_id']; } $programInfo = $modelEducationPrograms->getProgramInfo($programId); if ($programInfo['paid_type'] == Model_Education_Programs::PAID_TYPE_FREE) { $result = true; break; } else { $modelPayment = Model_Payment::create(); $total_payment = $modelPayment->getTotal($appId); $cost_total = $program_data['cost']; $ar = $this->_getAllowed(array($disciplineId), $payment_total, $cost_total); if (!empty($ar)) { $result = true; break; } } } } return $result; }
/** * Получить список доступных отдельных дисциплин для студента * Идентификаторы доступных дисциплин сохраняются в сессии в массив availDisciplines * * @param int $student_id * @return array */ public function getAvailDisciplinesSeparate($student_id) { $result = array(); $disc = Model_Discipline::create(); $session = Resources_Abstract::getInstance()->session; $app = Model_Application::create(); // Получаем список заявок на отдельные дициплины $disc_app = $app->getProcessedAppsForDisciplines($student_id); foreach ($disc_app as $a) { $a['cost'] = null === $a['cost'] ? 0 : $a['cost']; $a['total_sum'] = null === $a['total_sum'] ? 0 : $a['total_sum']; $a['disc_sum'] = $a['cost'] / 100 * $a['coef']; /* Если программа, которой принадлежит дисциплина, платная */ if (Model_Education_Programs::PAID_TYPE_PAID == $a['paid_type']) { /* и статус заявки подобает, */ if (Model_Application::STATUS_SIGNED !== $a['status'] && Model_Application::STATUS_PREPAID !== $a['status'] && Model_Application::STATUS_FINISHED !== $a['status']) { continue; } $active = true; // сохраняем в сессии как доступную $session->availDisciplines[] = $a['object_id']; } elseif (Model_Education_Programs::PAID_TYPE_FREE == $a['paid_type']) { /* и статус заявки подобает, */ if (Model_Application::STATUS_SIGNED !== $a['status'] && Model_Application::STATUS_FINISHED !== $a['status']) { continue; } $active = true; // сохраняем в сессии как доступную $session->availDisciplines[] = $a['object_id']; } /* И заносим её в список доступных */ $disc = array('discipline_id' => $a['object_id'], 'title' => $a['title'], 'app_id' => $a['app_id'], 'disc_sum' => $a['disc_sum'], 'total_sum' => $a['total_sum'], 'active' => $active); $result[] = $disc; } return $result; }