Ejemplo n.º 1
0
 /**
  * init
  */
 public function init()
 {
     $fac = $this->getConfig()->getPluginFactory();
     $this->plugin = $fac->getPlugin($this->getNamespace());
     $arr = $this->plugin->getDataArray()->exportFormArray();
     $backUrl = \Tk\Url::createHomeUrl('/plugin/manager.html');
     $ff = \Form\Factory::getInstance();
     $this->form = $ff->createForm('Config', $arr);
     $this->form->attach(new Save('update'))->setRedirectUrl($backUrl);
     $this->form->attach($ff->createEventLink('cancel'), 'cancel')->setRedirectUrl($backUrl);
     $courseList = \Ext\Db\Course::findAll(\Tk\Db\Tool::create('`name`'));
     $this->form->addField($ff->createFieldDualSelect('coa-course-enable', $courseList))->setLabel('Enable Courses')->setRequired();
     $this->addChild($ff->createFormRenderer($this->form), $this->form->getId());
 }
Ejemplo n.º 2
0
    /**
     * Find filtered records
     *
     * @param array $filter
     * @param \Tk\Db\Tool $tool
     * @return \Tk\Db\ArrayObject
     */
    protected function findCompanies($filter = array(), $tool = null)
    {
        /* @var \Ext\Db\CompanyMap $mapper */
        $mapper = \Ext\Db\Company::getMapper();
        $now = \Tk\Date::create();
        $where = '';
        if (!isset($filter['dateFrom'])) {
            $filter['dateFrom'] = \Tk\Date::create($now->getYear() . '-01-01')->floor();
        }
        if (!isset($filter['dateTo'])) {
            $filter['dateTo'] = \Tk\Date::create($now->getYear() . '-12-31')->ceil();
        }
        $orderBy = $tool->getOrderBy();
        $dateFrom = $mapper->getDb()->quote($filter['dateFrom']->toString());
        $dateTo = $mapper->getDb()->quote($filter['dateTo']->toString());
        if (!empty($filter['courseId'])) {
            $where .= ' AND b.courseId = ' . (int) $filter['courseId'];
        }
        if (!empty($filter['termId'])) {
            $where .= ' AND d.termId = ' . (int) $filter['termId'];
        }
        if (!empty($filter['placementTypeId'])) {
            if (!is_array($filter['placementTypeId'])) {
                $filter['placementTypeId'] = array($filter['placementTypeId']);
            }
            $statusStr = '';
            foreach ($filter['placementTypeId'] as $s) {
                $statusStr .= sprintf('d.`placementTypeId` =  %s OR ', (int) $s);
            }
            if ($statusStr) {
                $where .= ' AND (' . substr($statusStr, 0, -3) . ') ';
            }
        }
        if (!empty($filter['keywords'])) {
            $kw = '%' . $mapper->getDb()->escapeString($filter['keywords']) . '%';
            $w = '';
            $w .= sprintf('a.`name` LIKE %s OR ', $mapper->getDb()->quote($kw));
            if (is_numeric($filter['keywords'])) {
                $id = (int) $filter['keywords'];
                $w .= sprintf('a.`id` = %d OR ', $id);
            }
            if ($w) {
                $where .= ' AND (' . substr($w, 0, -3) . ') ';
            }
        }
        $sql = <<<SQL
SELECT a.id, a.name, a.email, a.country, a.status, a.created
 ,SUM(d.units) as 'totalUnits'
 ,COUNT(d.id) as 'totalPlaces'

FROM company a, company_course b
  LEFT JOIN term c ON (b.courseId = c.courseId )
  LEFT JOIN placement d ON (c.id = d.termId AND d.status = 'completed' AND d.dateTo > {$dateFrom} AND d.dateFrom < {$dateTo})

WHERE a.id = b.companyId
  AND a.status = 'approved'
  AND d.companyId = a.id
  AND d.units > 0
  {$where}

GROUP BY a.id

ORDER BY {$orderBy}
SQL;
        $result = $mapper->getDb()->query($sql);
        $list = $result->fetchAll();
        return $list;
    }